現在選択されているプロジェクトのパスを取得しようとしています。以下のコードを使用しています。
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench == null ? null : workbench.getActiveWorkbenchWindow();
IWorkbenchPage activePage = window == null ? null : window.getActivePage();
ISelection selection = activePage.getSelection();
if (selection instanceof TreeSelection) {
List list = ((TreeSelection) selection).toList();
for (Object selectedObject : list) {
String path = ((Project) selectedObject).getFullPath().makeAbsolute().toString();
System.out.println(path);
}
}
ただし、そのようなものを実行すると、次の例外が発生します。
java.lang.ClassCastException: org.eclipse.core.internal.resources.Project cannot be cast to org.eclipse.core.internal.resources.Project
at junitcategories.handlers.SampleHandler.execute(SampleHandler.java:48)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
これはクラスローディングの問題ですか?どうすれば解決できますか? --申し訳ありませんが、プラグイン開発は初めてです。
ありがとう、タマス