原创

Eclipse検索機能の実装

温馨提示:
本文最后更新于 2024年04月12日,已超过 37 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

.bps ファイルがある Eclipse rcp ベースのアプリケーションがあります。ユーザーが .bps プロジェクトを右クリックすると、ドロップダウン メニューが開きます。このドロップダウン メニューには、Eclipse の Java ファイルがあるように「参照」オプションを追加しました

ユーザーが「参照」オプションをクリックしたときに呼び出されるハンドラーを実装したいと考えています。 たとえば、選択したファイル名が MyBps.bps の場合、他の通常のテキストと同様に MyBps というテキストを検索し、検索列に表示する必要があります。

このハンドラーの実装を考えてください。

私が実装しようとしたのは

public class ReferencesSearchHandler extends AbstractHandler {
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        if (window != null) {
            ICommandService commandService = window.getService(ICommandService.class);
            if (commandService != null) {
                Command command = commandService.getCommand("org.eclipse.search.ui.openSearchDialog");
                if (command != null) {
                    // Check if the command exists and can be executed before executing
                    if (command.isDefined() && command.isEnabled()) {
                        try {
                            command.executeWithChecks(new ExecutionEvent());
                        } catch (ExecutionException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (NotDefinedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (NotEnabledException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (NotHandledException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
        return null;
    }
}

しかし、検索ダイアログが開き、ユーザーは検索するためにテキストをもう一度入力する必要がありますが、選択したファイルの名前を自動的に検索したいと考えています。

正文到此结束
热门推荐
本文目录