メインクラスを探す その 4

結局はプログレスモニターが使えればいいんですよね。ということはプログレスモニタが表示できるものを作ってしまえばいいわけです。つまり CrateJarDialog クラスの中で ProgressMonitorDialog クラスを作って、使えばいいのではないかと。

なんでこんなこと気がつかなかったのだろう。結局、[Search...] ボタンを押されたときの処理は次のようになりました。

    protected void handleSearchButtonSelected() {
        IJavaElement[] elements = null;
        if ((project == null) || !project.exists()) {
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IJavaModel model = JavaCore.create(root);
            if (model != null) {
                try {
                    elements = model.getJavaProjects();
                } catch (JavaModelException e) {
                }
            }
        } else {
            elements = new IJavaElement[]{project};
        }       
        if (elements == null) {
            elements = new IJavaElement[]{};
        }
        int constraints = IJavaSearchScope.SOURCES;
        IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints);
        
        MainMethodSearchEngine engine = new MainMethodSearchEngine();
        Shell shell = getShell();
        ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(shell);
        IType[] types = null;
        try {
            types = engine.searchMainMethods(monitorDialog, searchScope, true);
        } catch (InvocationTargetException e) {
            setErrorMessage(e.getMessage());
            return;
        } catch (InterruptedException e) {
            setErrorMessage(e.getMessage());
            return;
        }

        SelectionDialog dialog = new MainTypeSelectionDialog(shell, types); 
        dialog.setTitle(LauncherMessages.JavaMainTab_Choose_Main_Type_11); //$NON-NLS-1$
        dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12); //$NON-NLS-1$
        if (dialog.open() == Window.CANCEL) {
            return;
        }
        
        Object[] results = dialog.getResult();
        if ((results == null) || (results.length < 1)) {
            return;
        }
        
        IType type = (IType)results[0];
        if (type != null) {
            mainClassText.setText(type.getFullyQualifiedName());
        }
    }

実行して、[Search...] ボタンを押してみると、

MainClassSearchDialog

の後に

MainClassSearchDialog

が表示されました。