Example usage for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE

List of usage examples for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE

Introduction

In this page you can find the example usage for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE.

Prototype

int OK_EXIT_CODE

To view the source code for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE.

Click Source Link

Document

The default exit code for "OK" action.

Usage

From source file:com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog.java

License:Apache License

public PsiElement create() {
    if (myAttrPanel != null) {
        if (myAttrPanel.hasSomethingToAsk()) {
            show();/*from   w  ww.ja va 2  s. co  m*/
            return myCreatedElement;
        }
        doCreate(null);
    }
    close(DialogWrapper.OK_EXIT_CODE);
    return myCreatedElement;
}

From source file:com.intellij.ide.startupWizard.StartupWizardAction.java

License:Apache License

public void actionPerformed(final AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    final StartupWizard startupWizard = new StartupWizard(project,
            ApplicationInfoImpl.getShadowInstance().getPluginChooserPages());
    final String title = ApplicationNamesInfo.getInstance().getFullProductName()
            + " Plugin Configuration Wizard";
    startupWizard.setTitle(title);// w  w  w  . j av a 2s . com
    startupWizard.show();
    if (startupWizard.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        Messages.showInfoMessage(project, "To apply the changes, please restart "
                + ApplicationNamesInfo.getInstance().getFullProductName(), title);
    }
}

From source file:com.intellij.ide.todo.configurable.TodoConfigurable.java

License:Apache License

@Override
public JComponent createComponent() {
    // Panel with patterns
    PanelWithButtons patternsPanel = new PanelWithButtons() {
        {//from   w  ww  .  j a  v  a 2s.co m
            initPanel();
        }

        @Override
        protected String getLabelText() {
            return IdeBundle.message("label.todo.patterns");
        }

        @Override
        protected JComponent createMainComponent() {
            // JTable with TodoPaterns
            myPatternsTable = new Table(myPatternsModel);
            myPatternsTable.getEmptyText().setText(IdeBundle.message("text.todo.no.patterns"));
            myPatternsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

            // Column "Icon"
            JComboBox todoTypeCombo = new JComboBox(new Icon[] { AllIcons.General.TodoDefault,
                    AllIcons.General.TodoQuestion, AllIcons.General.TodoImportant });
            todoTypeCombo.setRenderer(new TodoTypeListCellRenderer());
            TableColumn typeColumn = myPatternsTable.getColumnModel().getColumn(0);
            DefaultCellEditor todoTypeEditor = new DefaultCellEditor(todoTypeCombo);
            todoTypeEditor.setClickCountToStart(1);
            typeColumn.setCellEditor(todoTypeEditor);
            TodoTypeTableCellRenderer todoTypeRenderer = new TodoTypeTableCellRenderer();
            typeColumn.setCellRenderer(todoTypeRenderer);

            int width = myPatternsTable.getFontMetrics(myPatternsTable.getFont())
                    .stringWidth(myPatternsTable.getColumnName(0)) + 10;
            typeColumn.setPreferredWidth(width);
            typeColumn.setMaxWidth(width);
            typeColumn.setMinWidth(width);

            // Column "Case Sensitive"
            TableColumn todoCaseSensitiveColumn = myPatternsTable.getColumnModel().getColumn(1);
            width = myPatternsTable.getFontMetrics(myPatternsTable.getFont())
                    .stringWidth(myPatternsTable.getColumnName(1)) + 10;
            todoCaseSensitiveColumn.setPreferredWidth(width);
            todoCaseSensitiveColumn.setMaxWidth(width);
            todoCaseSensitiveColumn.setMinWidth(width);

            // Column "Pattern"
            TodoPatternTableCellRenderer todoPatternRenderer = new TodoPatternTableCellRenderer(myPatterns);
            TableColumn patternColumn = myPatternsTable.getColumnModel().getColumn(2);
            patternColumn.setCellRenderer(todoPatternRenderer);

            ((DefaultCellEditor) myPatternsTable.getDefaultEditor(String.class)).setClickCountToStart(2);

            JPanel panel = ToolbarDecorator.createDecorator(myPatternsTable)
                    .setAddAction(new AnActionButtonRunnable() {
                        @Override
                        public void run(AnActionButton button) {
                            stopEditing();
                            TodoPattern pattern = new TodoPattern(TodoAttributesUtil.createDefault());
                            PatternDialog dialog = new PatternDialog(myPanel, pattern);
                            dialog.setTitle(IdeBundle.message("title.add.todo.pattern"));
                            dialog.show();
                            if (!dialog.isOK()) {
                                return;
                            }
                            myPatterns.add(pattern);
                            int index = myPatterns.size() - 1;
                            myPatternsModel.fireTableRowsInserted(index, index);
                            myPatternsTable.getSelectionModel().setSelectionInterval(index, index);
                            myPatternsTable.scrollRectToVisible(myPatternsTable.getCellRect(index, 0, true));
                        }
                    }).setEditAction(new AnActionButtonRunnable() {
                        @Override
                        public void run(AnActionButton button) {
                            editSelectedPattern();
                        }
                    }).setRemoveAction(new AnActionButtonRunnable() {
                        @Override
                        public void run(AnActionButton button) {
                            stopEditing();
                            int selectedIndex = myPatternsTable.getSelectedRow();
                            if (selectedIndex < 0 || selectedIndex >= myPatternsModel.getRowCount()) {
                                return;
                            }
                            TodoPattern patternToBeRemoved = myPatterns.get(selectedIndex);
                            TableUtil.removeSelectedItems(myPatternsTable);
                            for (int i = 0; i < myFilters.size(); i++) {
                                TodoFilter filter = myFilters.get(i);
                                if (filter.contains(patternToBeRemoved)) {
                                    filter.removeTodoPattern(patternToBeRemoved);
                                    myFiltersModel.fireTableRowsUpdated(i, i);
                                }
                            }
                        }
                    }).disableUpDownActions().createPanel();

            return panel;
        }

        @Override
        protected JButton[] createButtons() {
            return new JButton[] {};
        }
    };

    // double click in "Patterns" table should also start editing of selected pattern
    new DoubleClickListener() {
        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            editSelectedPattern();
            return true;
        }
    }.installOn(myPatternsTable);

    // Panel with filters
    PanelWithButtons filtersPanel = new PanelWithButtons() {
        {
            initPanel();
        }

        @Override
        protected String getLabelText() {
            return IdeBundle.message("label.todo.filters");
        }

        @Override
        protected JComponent createMainComponent() {
            myFiltersTable = new Table(myFiltersModel);
            myFiltersTable.getEmptyText().setText(IdeBundle.message("text.todo.no.filters"));
            myFiltersTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

            // Column "Name"

            TableColumn nameColumn = myFiltersTable.getColumnModel().getColumn(0);
            int width = myPatternsTable.getColumnModel().getColumn(0).getPreferredWidth()
                    /*typeColumn*/ + myPatternsTable.getColumnModel().getColumn(1)
                            .getPreferredWidth()/*todoCaseSensitiveColumn*/;
            nameColumn.setPreferredWidth(width);
            nameColumn.setMaxWidth(width);
            nameColumn.setMinWidth(width);
            nameColumn.setCellRenderer(new MyFilterNameTableCellRenderer());

            JPanel panel = ToolbarDecorator.createDecorator(myFiltersTable)
                    .setAddAction(new AnActionButtonRunnable() {
                        @Override
                        public void run(AnActionButton button) {
                            stopEditing();
                            TodoFilter filter = new TodoFilter();
                            FilterDialog dialog = new FilterDialog(myPanel, filter, -1, myFilters, myPatterns);
                            dialog.setTitle(IdeBundle.message("title.add.todo.filter"));
                            dialog.show();
                            int exitCode = dialog.getExitCode();
                            if (DialogWrapper.OK_EXIT_CODE == exitCode) {
                                myFilters.add(filter);
                                int index = myFilters.size() - 1;
                                myFiltersModel.fireTableRowsInserted(index, index);
                                myFiltersTable.getSelectionModel().setSelectionInterval(index, index);
                                myFiltersTable.scrollRectToVisible(myFiltersTable.getCellRect(index, 0, true));
                            }
                        }
                    }).setEditAction(new AnActionButtonRunnable() {
                        @Override
                        public void run(AnActionButton button) {
                            editSelectedFilter();
                        }
                    }).setRemoveAction(new AnActionButtonRunnable() {
                        @Override
                        public void run(AnActionButton button) {
                            stopEditing();
                            TableUtil.removeSelectedItems(myFiltersTable);
                        }
                    }).disableUpDownActions().createPanel();

            return panel;
        }

        @Override
        protected JButton[] createButtons() {
            return new JButton[] {};
        }
    };
    // double click in "Filters" table should also start editing of selected filter
    new DoubleClickListener() {
        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            editSelectedFilter();
            return true;
        }
    }.installOn(myFiltersTable);

    myPanel = new JPanel(new GridBagLayout());
    myPanel.add(patternsPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.NORTH,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    myPanel.add(filtersPanel, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.NORTH,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    return myPanel;
}

From source file:com.intellij.ide.todo.configurable.TodoConfigurable.java

License:Apache License

private void editSelectedFilter() {
    stopEditing();//from www  .ja  v  a  2  s .c om
    int selectedIndex = myFiltersTable.getSelectedRow();
    if (selectedIndex < 0 || selectedIndex >= myFiltersModel.getRowCount()) {
        return;
    }
    TodoFilter sourceFilter = myFilters.get(selectedIndex);
    TodoFilter filter = sourceFilter.clone();
    FilterDialog dialog = new FilterDialog(myPanel, filter, selectedIndex, myFilters, myPatterns);
    dialog.setTitle(IdeBundle.message("title.edit.todo.filter"));
    dialog.show();
    int exitCode = dialog.getExitCode();
    if (DialogWrapper.OK_EXIT_CODE == exitCode) {
        myFilters.set(selectedIndex, filter);
        myFiltersModel.fireTableRowsUpdated(selectedIndex, selectedIndex);
        myFiltersTable.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
    }
}

From source file:com.intellij.ide.util.DeleteHandler.java

License:Apache License

public static void deletePsiElement(final PsiElement[] elementsToDelete, final Project project,
        boolean needConfirmation) {
    if (elementsToDelete == null || elementsToDelete.length == 0)
        return;//  www  .ja  v  a  2  s  . c om

    final PsiElement[] elements = PsiTreeUtil.filterAncestors(elementsToDelete);

    boolean safeDeleteApplicable = true;
    for (int i = 0; i < elements.length && safeDeleteApplicable; i++) {
        PsiElement element = elements[i];
        safeDeleteApplicable = SafeDeleteProcessor.validElement(element);
    }

    final boolean dumb = DumbService.getInstance(project).isDumb();
    if (safeDeleteApplicable && !dumb) {
        final Ref<Boolean> exit = Ref.create(false);
        final SafeDeleteDialog dialog = new SafeDeleteDialog(project, elements,
                new SafeDeleteDialog.Callback() {
                    @Override
                    public void run(final SafeDeleteDialog dialog) {
                        if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project,
                                Arrays.asList(elements), true))
                            return;
                        SafeDeleteProcessor.createInstance(project, new Runnable() {
                            @Override
                            public void run() {
                                exit.set(true);
                                dialog.close(DialogWrapper.OK_EXIT_CODE);
                            }
                        }, elements, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true)
                                .run();
                    }
                }) {
            @Override
            protected boolean isDelete() {
                return true;
            }
        };
        if (needConfirmation) {
            dialog.show();
            if (!dialog.isOK() || exit.get())
                return;
        }
    } else {
        @SuppressWarnings({ "UnresolvedPropertyKey" })
        String warningMessage = DeleteUtil.generateWarningMessage(IdeBundle.message("prompt.delete.elements"),
                elements);

        boolean anyDirectories = false;
        String directoryName = null;
        for (PsiElement psiElement : elementsToDelete) {
            if (psiElement instanceof PsiDirectory && !PsiUtilBase.isSymLink((PsiDirectory) psiElement)) {
                anyDirectories = true;
                directoryName = ((PsiDirectory) psiElement).getName();
                break;
            }
        }
        if (anyDirectories) {
            if (elements.length == 1) {
                warningMessage += IdeBundle.message("warning.delete.all.files.and.subdirectories",
                        directoryName);
            } else {
                warningMessage += IdeBundle
                        .message("warning.delete.all.files.and.subdirectories.in.the.selected.directory");
            }
        }

        if (safeDeleteApplicable && dumb) {
            warningMessage += "\n\nWarning:\n  Safe delete is not available while "
                    + ApplicationNamesInfo.getInstance().getFullProductName()
                    + " updates indices,\n  no usages will be checked.";
        }

        if (needConfirmation) {
            int result = Messages.showOkCancelDialog(project, warningMessage, IdeBundle.message("title.delete"),
                    ApplicationBundle.message("button.delete"), CommonBundle.getCancelButtonText(),
                    Messages.getQuestionIcon());
            if (result != Messages.OK)
                return;
        }
    }

    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        @Override
        public void run() {
            if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(elements),
                    false)) {
                return;
            }

            // deleted from project view or something like that.
            if (CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext()) == null) {
                CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
            }

            for (final PsiElement elementToDelete : elements) {
                if (!elementToDelete.isValid())
                    continue; //was already deleted
                if (elementToDelete instanceof PsiDirectory) {
                    VirtualFile virtualFile = ((PsiDirectory) elementToDelete).getVirtualFile();
                    if (virtualFile.isInLocalFileSystem() && !virtualFile.is(VFileProperty.SYMLINK)) {
                        ArrayList<VirtualFile> readOnlyFiles = new ArrayList<VirtualFile>();
                        CommonRefactoringUtil.collectReadOnlyFiles(virtualFile, readOnlyFiles);

                        if (!readOnlyFiles.isEmpty()) {
                            String message = IdeBundle.message("prompt.directory.contains.read.only.files",
                                    virtualFile.getPresentableUrl());
                            int _result = Messages.showYesNoDialog(project, message,
                                    IdeBundle.message("title.delete"), Messages.getQuestionIcon());
                            if (_result != Messages.YES)
                                continue;

                            boolean success = true;
                            for (VirtualFile file : readOnlyFiles) {
                                success = clearReadOnlyFlag(file, project);
                                if (!success)
                                    break;
                            }
                            if (!success)
                                continue;
                        }
                    }
                } else if (!elementToDelete.isWritable() && !(elementToDelete instanceof PsiFileSystemItem
                        && PsiUtilBase.isSymLink((PsiFileSystemItem) elementToDelete))) {
                    final PsiFile file = elementToDelete.getContainingFile();
                    if (file != null) {
                        final VirtualFile virtualFile = file.getVirtualFile();
                        if (virtualFile.isInLocalFileSystem()) {
                            int _result = MessagesEx.fileIsReadOnly(project, virtualFile)
                                    .setTitle(IdeBundle.message("title.delete"))
                                    .appendMessage(IdeBundle.message("prompt.delete.it.anyway")).askYesNo();
                            if (_result != Messages.YES)
                                continue;

                            boolean success = clearReadOnlyFlag(virtualFile, project);
                            if (!success)
                                continue;
                        }
                    }
                }

                try {
                    elementToDelete.checkDelete();
                } catch (IncorrectOperationException ex) {
                    Messages.showMessageDialog(project, ex.getMessage(), CommonBundle.getErrorTitle(),
                            Messages.getErrorIcon());
                    continue;
                }

                ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            elementToDelete.delete();
                        } catch (final IncorrectOperationException ex) {
                            ApplicationManager.getApplication().invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    Messages.showMessageDialog(project, ex.getMessage(),
                                            CommonBundle.getErrorTitle(), Messages.getErrorIcon());
                                }
                            });
                        }
                    }
                });
            }
        }
    }, RefactoringBundle.message("safe.delete.command",
            RefactoringUIUtil.calculatePsiElementDescriptionList(elements)), null);
}

From source file:com.intellij.ide.util.scopeChooser.EditScopesDialog.java

License:Apache License

@Override
protected void doOKAction() {
    final Object selectedObject = ((ScopeChooserConfigurable) getConfigurable()).getSelectedObject();
    if (selectedObject instanceof NamedScope) {
        mySelectedScope = (NamedScope) selectedObject;
    }/*w w w  .ja  va2 s  . c  o m*/
    super.doOKAction();
    if (myCheckShared && mySelectedScope != null) {
        final Project project = getProject();
        final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
        NamedScope scope = manager.getScope(mySelectedScope.getName());
        if (scope == null) {
            if (Messages.showYesNoDialog(IdeBundle.message("scope.unable.to.save.scope.message"),
                    IdeBundle.message("scope.unable.to.save.scope.title"),
                    Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) {
                final String newName = Messages.showInputDialog(project,
                        IdeBundle.message("add.scope.name.label"),
                        IdeBundle.message("scopes.save.dialog.title.shared"), Messages.getQuestionIcon(),
                        mySelectedScope.getName(), new InputValidator() {
                            @Override
                            public boolean checkInput(String inputString) {
                                return inputString != null && inputString.length() > 0
                                        && manager.getScope(inputString) == null;
                            }

                            @Override
                            public boolean canClose(String inputString) {
                                return checkInput(inputString);
                            }
                        });
                if (newName != null) {
                    final PackageSet packageSet = mySelectedScope.getValue();
                    scope = new NamedScope(newName, packageSet != null ? packageSet.createCopy() : null);
                    mySelectedScope = scope;
                    manager.addScope(mySelectedScope);
                }
            }
        }
    }
}

From source file:com.intellij.ide.util.SuperMethodWarningUtil.java

License:Apache License

@NotNull
public static PsiMethod[] checkSuperMethods(final PsiMethod method, String actionString,
        Collection<PsiElement> ignore) {
    PsiClass aClass = method.getContainingClass();
    if (aClass == null)
        return new PsiMethod[] { method };

    final Collection<PsiMethod> superMethods = DeepestSuperMethodsSearch.search(method).findAll();
    if (ignore != null) {
        superMethods.removeAll(ignore);//from   w w w  .j a v a 2s . co m
    }

    if (superMethods.isEmpty())
        return new PsiMethod[] { method };

    Set<String> superClasses = new HashSet<String>();
    boolean superAbstract = false;
    boolean parentInterface = false;
    for (final PsiMethod superMethod : superMethods) {
        final PsiClass containingClass = superMethod.getContainingClass();
        superClasses.add(containingClass.getQualifiedName());
        final boolean isInterface = containingClass.isInterface();
        superAbstract |= isInterface || superMethod.hasModifierProperty(PsiModifier.ABSTRACT);
        parentInterface |= isInterface;
    }

    SuperMethodWarningDialog dialog = new SuperMethodWarningDialog(method.getProject(),
            DescriptiveNameUtil.getDescriptiveName(method), actionString, superAbstract, parentInterface,
            aClass.isInterface(), ArrayUtil.toStringArray(superClasses));
    dialog.show();

    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        return superMethods.toArray(new PsiMethod[superMethods.size()]);
    }
    if (dialog.getExitCode() == SuperMethodWarningDialog.NO_EXIT_CODE) {
        return new PsiMethod[] { method };
    }

    return PsiMethod.EMPTY_ARRAY;
}

From source file:com.intellij.ide.util.SuperMethodWarningUtil.java

License:Apache License

public static PsiMethod checkSuperMethod(final PsiMethod method, String actionString) {
    PsiClass aClass = method.getContainingClass();
    if (aClass == null)
        return method;

    PsiMethod superMethod = method.findDeepestSuperMethod();
    if (superMethod == null)
        return method;

    if (ApplicationManager.getApplication().isUnitTestMode())
        return superMethod;

    PsiClass containingClass = superMethod.getContainingClass();

    SuperMethodWarningDialog dialog = new SuperMethodWarningDialog(method.getProject(),
            DescriptiveNameUtil.getDescriptiveName(method), actionString,
            containingClass.isInterface() || superMethod.hasModifierProperty(PsiModifier.ABSTRACT),
            containingClass.isInterface(), aClass.isInterface(), containingClass.getQualifiedName());
    dialog.show();//from w w  w.ja v  a  2s  . co m

    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE)
        return superMethod;
    if (dialog.getExitCode() == SuperMethodWarningDialog.NO_EXIT_CODE)
        return method;

    return null;
}

From source file:com.intellij.internal.GenerateVisitorByHierarchyAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final Ref<String> visitorNameRef = Ref.create("MyVisitor");
    final Ref<PsiClass> parentClassRef = Ref.create(null);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    assert project != null;
    final PsiNameHelper helper = PsiNameHelper.getInstance(project);
    final PackageChooserDialog dialog = new PackageChooserDialog(
            "Choose Target Package and Hierarchy Root Class", project) {

        @Override//  w w w.j  av  a 2 s  . c  o m
        protected ValidationInfo doValidate() {
            PsiDocumentManager.getInstance(project).commitAllDocuments();
            if (!helper.isQualifiedName(visitorNameRef.get())) {
                return new ValidationInfo("Visitor class name is not valid");
            } else if (parentClassRef.isNull()) {
                return new ValidationInfo("Hierarchy root class should be specified");
            } else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) {
                return new ValidationInfo("Hierarchy root class should be an interface or a class");
            }
            return super.doValidate();
        }

        protected JComponent createCenterPanel() {
            final JPanel panel = new JPanel(new BorderLayout());
            panel.add(super.createCenterPanel(), BorderLayout.CENTER);
            panel.add(createNamePanel(), BorderLayout.NORTH);
            panel.add(createBaseClassPanel(), BorderLayout.SOUTH);
            return panel;
        }

        private JComponent createNamePanel() {
            LabeledComponent<JTextField> labeledComponent = new LabeledComponent<JTextField>();
            labeledComponent.setText("Visitor class");
            final JTextField nameField = new JTextField(visitorNameRef.get());
            labeledComponent.setComponent(nameField);
            nameField.getDocument().addDocumentListener(new DocumentAdapter() {
                protected void textChanged(final DocumentEvent e) {
                    visitorNameRef.set(nameField.getText());
                }
            });
            return labeledComponent;
        }

        private JComponent createBaseClassPanel() {
            LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<EditorTextField>();
            labeledComponent.setText("Hierarchy root class");
            final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
            final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true,
                    JavaCodeFragmentFactory.ALLOW_VOID);
            final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
            final EditorTextField editorTextField = new EditorTextField(document, project,
                    JavaFileType.INSTANCE);
            labeledComponent.setComponent(editorTextField);
            editorTextField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
                public void documentChanged(final com.intellij.openapi.editor.event.DocumentEvent e) {
                    parentClassRef.set(null);
                    try {
                        final PsiType psiType = codeFragment.getType();
                        final PsiClass psiClass = psiType instanceof PsiClassType
                                ? ((PsiClassType) psiType).resolve()
                                : null;
                        parentClassRef.set(psiClass);
                    } catch (PsiTypeCodeFragment.IncorrectTypeException e1) {
                        // ok
                    }
                }
            });
            return labeledComponent;
        }
    };
    final PsiElement element = LangDataKeys.PSI_ELEMENT.getData(e.getDataContext());
    if (element instanceof PsiJavaPackage) {
        dialog.selectPackage(((PsiJavaPackage) element).getQualifiedName());
    } else if (element instanceof PsiDirectory) {
        final PsiJavaPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
        if (aPackage != null) {
            dialog.selectPackage(aPackage.getQualifiedName());
        }
    }
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null
            || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) {
        return;
    }
    final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(),
            visitorNameRef.get());
    final IdeView ideView = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
    final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName,
            GlobalSearchScope.projectScope(project));
    if (ideView != null && visitorClass != null) {
        ideView.selectElement(visitorClass);
    }
}

From source file:com.intellij.lang.ant.config.impl.configuration.BuildFilePropertiesPanel.java

License:Apache License

private boolean showDialog() {
    DialogBuilder builder = new DialogBuilder(myBuildFile.getProject());
    builder.setCenterPanel(myForm.myWholePanel);
    builder.setDimensionServiceKey(DIMENSION_SERVICE_KEY);
    builder.setPreferredFocusComponent(myForm.getPreferedFocusComponent());
    builder.setTitle(AntBundle.message("build.file.properties.dialog.title"));
    builder.removeAllActions();//from   www  . jav a2s .com
    builder.addOkAction();
    builder.addCancelAction();
    builder.setHelpId("reference.dialogs.buildfileproperties");

    boolean isOk = builder.show() == DialogWrapper.OK_EXIT_CODE;
    if (isOk) {
        apply();
    }
    beforeClose();
    return isOk;
}