ビューがファストビューになってるかどうかの判定
ビュープラグインから自身が可視状態なのか、ファストビューとして最小化されているかを判定したい。
public class MyPlugin extends ViewPart {
…
private boolean isMinimized() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IViewReference[] references = page.getViewReferences();
for (int i = 0; i < references.length; i++) {
IViewPart view = references[i].getView(true);
if (this.equals(view)) {
return references[i].isFastView();
}
}
}
// ビューが見つからなかった
return false;
}
…
}
自身のIViewReferenceを取ってくるのをもっと簡単にできるかもしれない。
Eclipse pluginでエクスポートしたjarファイル内のリソースの取得
プラグインをjarファイルにエクスポートするときに、一緒に突っ込んだイメージファイルなどを、プラグイン起動後に参照したい。
plugin.xmlのBuild画面で
icon/sample.svg
をjarファイルに突っ込んだ場合、下記のように参照できる。
URL url1 = MyPlugin.getDefault().getBundle().getEntry("icon/sample.svg");
URL url2 = FileLocator.toFileURL(url1);結果は、それぞれ下記のようになる。
bundleentry://518/icon/sample.svg
file:/C:/eclipse/workspace/MyPlugin/icon/sample.svg
Eclipse pluginのエクスポートしたjarファイル内のリソースの取得
参考:http://d.hatena.ne.jp/ykhr-kokko/20071127
プラグインをjarファイルにエクスポートするときに、一緒に突っ込んだイメージファイルなどを、プラグイン起動後に参照したい。
plugin.xmlのBuild画面で
icon/sample.svg
をjarファイルに突っ込んだ場合、下記のように参照できる。
URL url1 = MyPlugin.getDefault().getBundle().getEntry("icon/sample.svg");
URL url2 = FileLocator.toFileURL(url1);結果は、
url1:bundleentry://518/icon/sample.svg
url2:file:/C:/eclipse/configuration/org.eclipse.osgi/bundles/375/1/.cp/icon/sample.svg
のようになる。
IJavaElementにおけるプリミティブ型のシグネチャの扱い
IJavaProject project = …;
IType type project.findType("test1.DataField");
String methodName = "setData"
String[] paramNames = {"QData;"};
IMethod m = newType.getMethod(methodName, paramNames);型を取得する場合は,「パッケージ名.クラス名」
メソッドを取得する場合は,「メソッド名(括弧はいらない)」と
パラメータ型名は「Qパラメータ型名;」パッケージ名はいらない(ソースでパッケージ名書いている場合はいるかも?)
プリミティブ型の場合は,以下のとおり
"C" // char
"D" // double
"F" // float
"I" // int
"J" // long
"S" // short
"Z" // boolean
配列は「[型名」となる
voidはnull
別スレッドからSWTのUIの操作を行う
http://cjasmin.fc2web.com/basic/thread.htmlを参考に.
Eclipseプラグイン内のSwingコンポーネントから指定したJavaElementをEclipseのエディタで開く.
final IJavaElement je = …;
if (je != null) {
Display display = ControllerUtil.getDisplay();
if (!display.isDisposed()) {
display.asyncExec(new Runnable() {
public void run() {
try {
JavaUI.openInEditor(je);
} catch (PartInitException e) {
e.printStackTrace();
} catch (JavaModelException e) {
e.printStackTrace();
}
}
});
}
}
サクラエディタで文字数を数える
Sakura Editor BBSからの抜粋ものより
http://www.geocities.jp/maru3128/sakura_bbs.html
適当にjsファイルで保存して、~\AppData\roaming\sakuraフォルダ以下に配置。
マクロに指定して実行できる。