Example usage for com.intellij.openapi.ui Messages showYesNoDialog

List of usage examples for com.intellij.openapi.ui Messages showYesNoDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showYesNoDialog.

Prototype

@YesNoResult
public static int showYesNoDialog(@NotNull Component parent, String message,
        @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon) 

Source Link

Usage

From source file:com.intellij.refactoring.safeDelete.JavaSafeDeleteProcessor.java

License:Apache License

public Collection<PsiElement> getAdditionalElementsToDelete(final PsiElement element,
        final Collection<PsiElement> allElementsToDelete, final boolean askUser) {
    if (element instanceof PsiField) {
        PsiField field = (PsiField) element;
        final Project project = element.getProject();
        String propertyName = JavaCodeStyleManager.getInstance(project)
                .variableNameToPropertyName(field.getName(), VariableKind.FIELD);

        PsiClass aClass = field.getContainingClass();
        if (aClass != null) {
            boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
            PsiMethod[] getters = GetterSetterPrototypeProvider.findGetters(aClass, propertyName, isStatic);
            if (getters != null) {
                final List<PsiMethod> validGetters = new ArrayList<PsiMethod>(1);
                for (PsiMethod getter : getters) {
                    if (!allElementsToDelete.contains(getter) && (getter != null && getter.isPhysical())) {
                        validGetters.add(getter);
                    }//from   w w  w  .j a v  a2  s.c  o m
                }
                getters = validGetters.isEmpty() ? null
                        : validGetters.toArray(new PsiMethod[validGetters.size()]);
            }

            PsiMethod setter = PropertyUtil.findPropertySetter(aClass, propertyName, isStatic, false);
            if (allElementsToDelete.contains(setter) || setter != null && !setter.isPhysical())
                setter = null;
            if (askUser && (getters != null || setter != null)) {
                final String message = RefactoringMessageUtil.getGetterSetterMessage(field.getName(),
                        RefactoringBundle.message("delete.title"), getters != null ? getters[0] : null, setter);
                if (!ApplicationManager.getApplication().isUnitTestMode() && Messages.showYesNoDialog(project,
                        message, RefactoringBundle.message("safe.delete.title"),
                        Messages.getQuestionIcon()) != 0) {
                    getters = null;
                    setter = null;
                }
            }
            List<PsiElement> elements = new ArrayList<PsiElement>();
            if (setter != null)
                elements.add(setter);
            if (getters != null)
                Collections.addAll(elements, getters);
            return elements;
        }
    }
    return null;
}

From source file:com.intellij.refactoring.util.duplicates.DuplicatesImpl.java

License:Apache License

public static void processDuplicates(@NotNull MatchProvider provider, @NotNull Project project,
        @NotNull Editor editor) {/*from   w w w . j a  v a 2  s  . co m*/
    boolean hasDuplicates = provider.hasDuplicates();
    if (hasDuplicates) {
        List<Match> duplicates = provider.getDuplicates();
        if (duplicates.size() == 1) {
            previewMatch(project, duplicates.get(0), editor);
        }
        final int answer = ApplicationManager.getApplication().isUnitTestMode() ? 0
                : Messages.showYesNoDialog(project, RefactoringBundle.message(
                        "0.has.detected.1.code.fragments.in.this.file.that.can.be.replaced.with.a.call.to.extracted.method",
                        ApplicationNamesInfo.getInstance().getProductName(), duplicates.size()),
                        "Process Duplicates", Messages.getQuestionIcon());
        if (answer == 0) {
            invoke(project, editor, provider);
        }
    }
}

From source file:com.intellij.struts2.facet.ui.FileSetConfigurationTab.java

License:Apache License

private void remove() {
    final SimpleNode[] nodes = myTree.getSelectedNodesIfUniform();
    for (final SimpleNode node : nodes) {

        if (node instanceof FileSetNode) {
            final StrutsFileSet fileSet = ((FileSetNode) node).mySet;
            if (fileSet.getFiles().isEmpty()) {
                myBuffer.remove(fileSet);
                return;
            }/*from  w  ww  .j a v a 2s .c  o m*/

            final int result = Messages.showYesNoDialog(myPanel,
                    StrutsBundle.message("facet.fileset.remove.fileset.question", fileSet.getName()),
                    StrutsBundle.message("facet.fileset.remove.fileset.title"), Messages.getQuestionIcon());
            if (result == Messages.YES) {
                if (fileSet.isAutodetected()) {
                    fileSet.setRemoved(true);
                    myBuffer.add(fileSet);
                } else {
                    myBuffer.remove(fileSet);
                }
            }
        } else if (node instanceof ConfigFileNode) {
            final VirtualFilePointer filePointer = ((ConfigFileNode) node).myFilePointer;
            final StrutsFileSet fileSet = ((FileSetNode) node.getParent()).mySet;
            fileSet.removeFile(filePointer);
        }
    }
}

From source file:com.intellij.tools.BaseToolsPanel.java

License:Apache License

private void removeSelected() {
    CheckedTreeNode node = getSelectedToolNode();
    if (node != null) {
        int result = Messages.showYesNoDialog(this, ToolsBundle.message("tools.delete.confirmation"),
                CommonBundle.getWarningTitle(), Messages.getWarningIcon());
        if (result != 0) {
            return;
        }//  w  w w  . j  av a2s. c  om
        myIsModified = true;
        if (node.getUserObject() instanceof Tool) {
            Tool tool = (Tool) node.getUserObject();
            CheckedTreeNode parentNode = (CheckedTreeNode) node.getParent();
            ((ToolsGroup) parentNode.getUserObject()).removeElement(tool);
            removeNodeFromParent(node);
            if (parentNode.getChildCount() == 0) {
                removeNodeFromParent(parentNode);
            }
        } else if (node.getUserObject() instanceof ToolsGroup) {
            removeNodeFromParent(node);
        }
        update();
        myTree.requestFocus();
    }
}

From source file:com.intellij.uiDesigner.FormEditingUtil.java

License:Apache License

public static void deleteRowOrColumn(final GuiEditor editor, final RadContainer container,
        final int[] cellsToDelete, final boolean isRow) {
    Arrays.sort(cellsToDelete);//w w  w .j  a v  a2s  .  c o m
    final int[] cells = ArrayUtil.reverseArray(cellsToDelete);
    if (!editor.ensureEditable()) {
        return;
    }

    Runnable runnable = new Runnable() {
        public void run() {
            if (!GridChangeUtil.canDeleteCells(container, cells, isRow)) {
                Set<RadComponent> componentsInColumn = new HashSet<RadComponent>();
                for (RadComponent component : container.getComponents()) {
                    GridConstraints c = component.getConstraints();
                    for (int cell : cells) {
                        if (c.contains(isRow, cell)) {
                            componentsInColumn.add(component);
                            break;
                        }
                    }
                }

                if (componentsInColumn.size() > 0) {
                    String message = isRow
                            ? UIDesignerBundle.message("delete.row.nonempty", componentsInColumn.size(),
                                    cells.length)
                            : UIDesignerBundle.message("delete.column.nonempty", componentsInColumn.size(),
                                    cells.length);

                    final int rc = Messages.showYesNoDialog(editor, message,
                            isRow ? UIDesignerBundle.message("delete.row.title")
                                    : UIDesignerBundle.message("delete.column.title"),
                            Messages.getQuestionIcon());
                    if (rc != Messages.YES) {
                        return;
                    }

                    deleteComponents(componentsInColumn, false);
                }
            }

            for (int cell : cells) {
                container.getGridLayoutManager().deleteGridCells(container, cell, isRow);
            }
            editor.refreshAndSave(true);
        }
    };
    CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable,
            isRow ? UIDesignerBundle.message("command.delete.row")
                    : UIDesignerBundle.message("command.delete.column"),
            null);
}

From source file:com.intellij.uiDesigner.palette.DeleteComponentAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    ComponentItem selectedItem = e.getData(ComponentItem.DATA_KEY);
    GroupItem groupItem = e.getData(GroupItem.DATA_KEY);
    if (project == null || selectedItem == null || groupItem == null)
        return;/*from w  ww  . j av a2  s  .  com*/

    if (!selectedItem.isRemovable()) {
        Messages.showInfoMessage(project, UIDesignerBundle.message("error.cannot.remove.default.palette"),
                CommonBundle.getErrorTitle());
        return;
    }

    int rc = Messages.showYesNoDialog(project,
            UIDesignerBundle.message("delete.component.prompt", selectedItem.getClassShortName()),
            UIDesignerBundle.message("delete.component.title"), Messages.getQuestionIcon());
    if (rc != 0)
        return;

    final Palette palette = Palette.getInstance(project);
    palette.removeItem(groupItem, selectedItem);
    palette.fireGroupsChanged();
}

From source file:com.intellij.uiDesigner.propertyInspector.properties.BindingProperty.java

License:Apache License

public static void updateBoundFieldName(final RadRootContainer root, final String oldName, final String newName,
        final String fieldClassName) {
    final String classToBind = root.getClassToBind();
    if (classToBind == null)
        return;/*from   www  . j  a  va 2s .c  o m*/

    final Project project = root.getProject();
    if (newName.length() == 0) {
        checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project));
        return;
    }

    final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(classToBind,
            GlobalSearchScope.allScope(project));
    if (aClass == null) {
        return;
    }

    if (oldName == null) {
        if (aClass.findFieldByName(newName, true) == null) {
            CreateFieldFix.runImpl(project, root, aClass, fieldClassName, newName, false,
                    FormEditingUtil.getNextSaveUndoGroupId(project));
        }
        return;
    }

    final PsiField oldField = aClass.findFieldByName(oldName, true);
    if (oldField == null) {
        return;
    }

    if (aClass.findFieldByName(newName, true) != null) {
        checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project));
        return;
    }

    // Show question to the user

    if (!isFieldUnreferenced(oldField)) {
        final int option = Messages.showYesNoDialog(project,
                MessageFormat.format(UIDesignerBundle.message("message.rename.field"), oldName, newName),
                UIDesignerBundle.message("title.rename"), Messages.getQuestionIcon());

        if (option != 0/*Yes*/) {
            return;
        }
    }

    // Commit document before refactoring starts
    GuiEditor editor = DesignerToolWindowManager.getInstance(project).getActiveFormEditor();
    if (editor != null) {
        editor.refreshAndSave(false);
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();

    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass)) {
        return;
    }

    final RenameProcessor processor = new RenameProcessor(project, oldField, newName, true, true);
    processor.run();
}

From source file:com.intellij.uiDesigner.snapShooter.CreateSnapShotAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    if (project == null || view == null) {
        return;/*from   www  .  java 2 s. com*/
    }

    final PsiDirectory dir = view.getOrChooseDirectory();
    if (dir == null)
        return;

    final SnapShotClient client = new SnapShotClient();
    List<RunnerAndConfigurationSettings> appConfigurations = new ArrayList<RunnerAndConfigurationSettings>();
    RunnerAndConfigurationSettings snapshotConfiguration = null;
    boolean connected = false;

    ApplicationConfigurationType cfgType = ApplicationConfigurationType.getInstance();
    List<RunnerAndConfigurationSettings> racsi = RunManager.getInstance(project)
            .getConfigurationSettingsList(cfgType);

    for (RunnerAndConfigurationSettings config : racsi) {
        if (config.getConfiguration() instanceof ApplicationConfiguration) {
            ApplicationConfiguration appConfig = (ApplicationConfiguration) config.getConfiguration();
            appConfigurations.add(config);
            if (appConfig.ENABLE_SWING_INSPECTOR) {
                SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
                snapshotConfiguration = config;
                if (settings.getLastPort() > 0) {
                    try {
                        client.connect(settings.getLastPort());
                        connected = true;
                    } catch (IOException ex) {
                        connected = false;
                    }
                }
            }
            if (connected)
                break;
        }
    }

    if (snapshotConfiguration == null) {
        snapshotConfiguration = promptForSnapshotConfiguration(project, appConfigurations);
        if (snapshotConfiguration == null)
            return;
    }

    if (!connected) {
        int rc = Messages.showYesNoDialog(project, UIDesignerBundle.message("snapshot.run.prompt"),
                UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon());
        if (rc == 1)
            return;
        final ApplicationConfiguration appConfig = (ApplicationConfiguration) snapshotConfiguration
                .getConfiguration();
        final SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
        settings.setNotifyRunnable(new Runnable() {
            public void run() {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.prepare.notice"),
                                UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
                        try {
                            client.connect(settings.getLastPort());
                        } catch (IOException ex) {
                            Messages.showMessageDialog(project,
                                    UIDesignerBundle.message("snapshot.connection.error"),
                                    UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
                            return;
                        }
                        runSnapShooterSession(client, project, dir, view);
                    }
                });
            }
        });

        try {
            final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(DefaultRunExecutor.EXECUTOR_ID,
                    appConfig);
            LOG.assertTrue(runner != null, "Runner MUST not be null!");
            Executor executor = DefaultRunExecutor.getRunExecutorInstance();
            runner.execute(new ExecutionEnvironment(executor, runner, snapshotConfiguration, project));
        } catch (ExecutionException ex) {
            Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.run.error", ex.getMessage()),
                    UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
        }
    } else {
        runSnapShooterSession(client, project, dir, view);
    }
}

From source file:com.intellij.uiDesigner.snapShooter.CreateSnapShotAction.java

License:Apache License

@Nullable
private static RunnerAndConfigurationSettings promptForSnapshotConfiguration(final Project project,
        final List<RunnerAndConfigurationSettings> configurations) {
    if (configurations.isEmpty()) {
        Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.no.configuration.error"),
                UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
        return null;
    }//from   ww w .j  av  a 2s .c om

    for (int i = configurations.size() - 1; i >= 0; i--) {
        final JreVersionDetector detector = new JreVersionDetector();
        final ApplicationConfiguration configuration = (ApplicationConfiguration) configurations.get(i)
                .getConfiguration();
        if (!detector.isJre50Configured(configuration) && !detector.isModuleJre50Configured(configuration)) {
            configurations.remove(i);
        }
    }

    if (configurations.isEmpty()) {
        Messages.showMessageDialog(project,
                UIDesignerBundle.message("snapshot.no.compatible.configuration.error"),
                UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
        return null;
    }

    final RunnerAndConfigurationSettings snapshotConfiguration;
    if (configurations.size() == 1) {
        final int rc = Messages.showYesNoDialog(project,
                UIDesignerBundle.message("snapshot.confirm.configuration.prompt",
                        configurations.get(0).getConfiguration().getName()),
                UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon());
        if (rc == 1) {
            return null;
        }
        snapshotConfiguration = configurations.get(0);
    } else {
        String[] names = new String[configurations.size()];
        for (int i = 0; i < configurations.size(); i++) {
            names[i] = configurations.get(i).getConfiguration().getName();
        }
        int rc = Messages.showChooseDialog(project,
                UIDesignerBundle.message("snapshot.choose.configuration.prompt"),
                UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon(), names, names[0]);
        if (rc < 0)
            return null;
        snapshotConfiguration = configurations.get(rc);
    }
    ((ApplicationConfiguration) snapshotConfiguration.getConfiguration()).ENABLE_SWING_INSPECTOR = true;
    return snapshotConfiguration;
}

From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.InstallPluginAction.java

License:Apache License

private boolean userConfirm(IdeaPluginDescriptor[] selection) {
    String message;// www.  ja  v  a  2  s . c  o  m
    if (selection.length == 1) {
        if (selection[0] instanceof IdeaPluginDescriptorImpl) {
            message = IdeBundle.message("prompt.update.plugin", selection[0].getName());
        } else {
            message = IdeBundle.message("prompt.download.and.install.plugin", selection[0].getName());
        }
    } else {
        message = IdeBundle.message("prompt.install.several.plugins", selection.length);
    }

    return Messages.showYesNoDialog(myHost.getMainPanel(), message,
            IdeBundle.message("action.download.and.install.plugin"),
            Messages.getQuestionIcon()) == Messages.YES;
}