Eclipse プラグイン (Indigo で開発) にハンドラーがあり、テキスト エディターで Java ファイルが保存される (または、理想的には開かれる) たびに実行したいと考えています。私が収集できる限り、これを達成するには2つの方法があります。
CommandService
APIを介してプログラムで。- での構成の使用
plugin.xml
私はこれらの両方を試しました。このような方法1:
public class Activator extends AbstractUIPlugin {
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
ICommandService commandService = (ICommandService) PlatformUI
.getWorkbench().getService(ICommandService.class);
commandService.addExecutionListener(new MyListener());
plugin = this;
}
...
}
public class MyListener implements IExecutionListener {
@Override
public void postExecuteSuccess(final String commandId, final Object returnValue) {
System.out.println("PostEventSuccess:" + commandId);
}
@Override
public void preExecute(final String commandId, final ExecutionEvent event) {}
@Override
public void notHandled(String commandId, NotHandledException exception) {}
@Override
public void postExecuteFailure(String commandId, ExecutionException exception) {}
}
および方法2.次のように:
<extension point="org.eclipse.ui.handlers">
<handler
commandId="org.eclipse.ui.file.save"
class="mypackage.MyHandler">
<activeWhen>
<with variable="activeWorkbenchWindow">
<instanceof value="org.eclipse.ui.IWorkbenchWindow"/>
</with>
</activeWhen>
</handler>
</extension>
方法 1. はリスナーをまったく実行しません。方法 2. は、ハンドラーが実行されるという点で機能しますが、私のハンドラーはデフォルトのハンドラーを置き換えているようです。ユーザーがファイルを保存しようとすると、ハンドラーが実行されますが、ファイルは保存されません。ハンドラー自体は問題ないようです (それを実行するメニュー項目を作成してテストしました)。
方法 1. は現在廃止されていますか、それともサービスを正しく実装していませんか? 方法 2. でファイルを保存するにはどうすればよいですか? 私のハンドラーからデフォルトのハンドラーを実行できますか?