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

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

Introduction

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

Prototype

int CANCEL_EXIT_CODE

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

Click Source Link

Document

The default exit code for "Cancel" action.

Usage

From source file:com.android.tools.idea.ui.resourcechooser.ResourceTablePanel.java

License:Apache License

@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
    //myDialog.doCancelAction();
    myDialog.close(DialogWrapper.CANCEL_EXIT_CODE);
    StringResourceEditorProvider.openEditor(myDialog.getModule());
}

From source file:com.android.tools.idea.uibuilder.property.NlIdPropertyItem.java

License:Apache License

@Override
public void setValue(Object value) {
    String newId = value != null ? stripIdPrefix(value.toString()) : "";
    String oldId = getValue();// www. j a va  2s .c  o  m
    XmlTag tag = getTag();

    if (ourRefactoringChoice != REFACTOR_NO && oldId != null && !oldId.isEmpty() && !newId.isEmpty()
            && !oldId.equals(newId) && tag != null && tag.isValid()) {
        // Offer rename refactoring?
        XmlAttribute attribute = tag.getAttribute(SdkConstants.ATTR_ID, SdkConstants.ANDROID_URI);
        if (attribute != null) {
            Module module = getModel().getModule();
            Project project = module.getProject();
            XmlAttributeValue valueElement = attribute.getValueElement();
            if (valueElement != null && valueElement.isValid()) {
                // Exact replace only, no comment/text occurrence changes since it is non-interactive
                ValueResourceElementWrapper wrapper = new ValueResourceElementWrapper(valueElement);
                RenameProcessor processor = new RenameProcessor(project, wrapper, NEW_ID_PREFIX + newId,
                        false /*comments*/, false /*text*/);
                processor.setPreviewUsages(false);
                // Do a quick usage search to see if we need to ask about renaming
                UsageInfo[] usages = processor.findUsages();
                if (usages.length > 0) {
                    int choice = ourRefactoringChoice;
                    if (choice == REFACTOR_ASK) {
                        DialogBuilder builder = createDialogBuilder(project);
                        builder.setTitle("Update Usages?");
                        JPanel panel = new JPanel(new BorderLayout()); // UGH!
                        JLabel label = new JLabel("<html>" + "Update usages as well?<br>"
                                + "This will update all XML references and Java R field references.<br>"
                                + "<br>" + "</html>");
                        panel.add(label, BorderLayout.CENTER);
                        JBCheckBox checkBox = new JBCheckBox("Don't ask again during this session");
                        panel.add(checkBox, BorderLayout.SOUTH);
                        builder.setCenterPanel(panel);
                        builder.setDimensionServiceKey("idPropertyDimension");
                        builder.removeAllActions();

                        DialogBuilder.CustomizableAction yesAction = builder.addOkAction();
                        yesAction.setText(Messages.YES_BUTTON);

                        builder.addActionDescriptor(dialogWrapper -> new AbstractAction(Messages.NO_BUTTON) {
                            @Override
                            public void actionPerformed(ActionEvent actionEvent) {
                                dialogWrapper.close(DialogWrapper.NEXT_USER_EXIT_CODE);
                            }
                        });
                        builder.addCancelAction();
                        int exitCode = builder.show();

                        choice = exitCode == DialogWrapper.OK_EXIT_CODE ? REFACTOR_YES
                                : exitCode == DialogWrapper.NEXT_USER_EXIT_CODE ? REFACTOR_NO
                                        : ourRefactoringChoice;

                        //noinspection AssignmentToStaticFieldFromInstanceMethod
                        ourRefactoringChoice = checkBox.isSelected() ? choice : REFACTOR_ASK;

                        if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) {
                            return;
                        }
                    }

                    if (choice == REFACTOR_YES) {
                        processor.run();
                        return;
                    }
                }
            }
        }
    }

    super.setValue(!StringUtil.isEmpty(newId) ? NEW_ID_PREFIX + newId : null);
}

From source file:com.intellij.codeInsight.generation.OverrideImplementUtil.java

License:Apache License

private static void registerHandlerForComplementaryAction(final Project project, final Editor editor,
        final PsiElement aClass, final boolean toImplement, final MemberChooser<PsiMethodMember> chooser) {
    final JComponent preferredFocusedComponent = chooser.getPreferredFocusedComponent();
    final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();

    @NonNls//from w w  w  .j a va2s.c  o  m
    final String s = toImplement ? "OverrideMethods" : "ImplementMethods";
    final Shortcut[] shortcuts = keymap.getShortcuts(s);

    if (shortcuts.length > 0 && shortcuts[0] instanceof KeyboardShortcut) {
        preferredFocusedComponent.getInputMap().put(((KeyboardShortcut) shortcuts[0]).getFirstKeyStroke(), s);

        preferredFocusedComponent.getActionMap().put(s, new AbstractAction() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                chooser.close(DialogWrapper.CANCEL_EXIT_CODE);

                // invoke later in order to close previous modal dialog
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        final CodeInsightActionHandler handler = toImplement ? new OverrideMethodsHandler()
                                : new ImplementMethodsHandler();
                        handler.invoke(project, editor, aClass.getContainingFile());
                    }
                });
            }
        });
    }
}

From source file:com.intellij.debugger.ui.HotSwapUIImpl.java

License:Apache License

private void hotSwapSessions(final List<DebuggerSession> sessions,
        @Nullable final Map<String, List<String>> generatedPaths) {
    final boolean shouldAskBeforeHotswap = myAskBeforeHotswap;
    myAskBeforeHotswap = true;/*  ww w  . j a va2  s  .co m*/

    // need this because search with PSI is perormed during hotswap
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    final DebuggerSettings settings = DebuggerSettings.getInstance();
    final String runHotswap = settings.RUN_HOTSWAP_AFTER_COMPILE;
    final boolean shouldDisplayHangWarning = shouldDisplayHangWarning(settings, sessions);

    if (shouldAskBeforeHotswap && DebuggerSettings.RUN_HOTSWAP_NEVER.equals(runHotswap)) {
        return;
    }

    final boolean shouldPerformScan = true;

    final HotSwapProgressImpl findClassesProgress;
    if (shouldPerformScan) {
        findClassesProgress = new HotSwapProgressImpl(myProject);
    } else {
        boolean createProgress = false;
        for (DebuggerSession session : sessions) {
            if (session.isModifiedClassesScanRequired()) {
                createProgress = true;
                break;
            }
        }
        findClassesProgress = createProgress ? new HotSwapProgressImpl(myProject) : null;
    }

    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        public void run() {
            final Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses;
            if (shouldPerformScan) {
                modifiedClasses = scanForModifiedClassesWithProgress(sessions, findClassesProgress, true);
            } else {
                final List<DebuggerSession> toScan = new ArrayList<DebuggerSession>();
                final List<DebuggerSession> toUseGenerated = new ArrayList<DebuggerSession>();
                for (DebuggerSession session : sessions) {
                    (session.isModifiedClassesScanRequired() ? toScan : toUseGenerated).add(session);
                    session.setModifiedClassesScanRequired(false);
                }
                modifiedClasses = new HashMap<DebuggerSession, Map<String, HotSwapFile>>();
                if (!toUseGenerated.isEmpty()) {
                    modifiedClasses.putAll(HotSwapManager.findModifiedClasses(toUseGenerated, generatedPaths));
                }
                if (!toScan.isEmpty()) {
                    modifiedClasses
                            .putAll(scanForModifiedClassesWithProgress(toScan, findClassesProgress, true));
                }
            }

            final Application application = ApplicationManager.getApplication();
            if (modifiedClasses.isEmpty()) {
                final String message = DebuggerBundle.message("status.hotswap.uptodate");
                HotSwapProgressImpl.NOTIFICATION_GROUP.createNotification(message, NotificationType.INFORMATION)
                        .notify(myProject);
                return;
            }

            application.invokeLater(new Runnable() {
                public void run() {
                    if (shouldAskBeforeHotswap && !DebuggerSettings.RUN_HOTSWAP_ALWAYS.equals(runHotswap)) {
                        final RunHotswapDialog dialog = new RunHotswapDialog(myProject, sessions,
                                shouldDisplayHangWarning);
                        dialog.show();
                        if (!dialog.isOK()) {
                            for (DebuggerSession session : modifiedClasses.keySet()) {
                                session.setModifiedClassesScanRequired(true);
                            }
                            return;
                        }
                        final Set<DebuggerSession> toReload = new HashSet<DebuggerSession>(
                                dialog.getSessionsToReload());
                        for (DebuggerSession session : modifiedClasses.keySet()) {
                            if (!toReload.contains(session)) {
                                session.setModifiedClassesScanRequired(true);
                            }
                        }
                        modifiedClasses.keySet().retainAll(toReload);
                    } else {
                        if (shouldDisplayHangWarning) {
                            final int answer = Messages.showCheckboxMessageDialog(
                                    DebuggerBundle.message("hotswap.dialog.hang.warning"),
                                    DebuggerBundle.message("hotswap.dialog.title"),
                                    new String[] { "Perform &Reload Classes", "&Skip Reload Classes" },
                                    CommonBundle.message("dialog.options.do.not.show"), false, 1, 1,
                                    Messages.getWarningIcon(), new PairFunction<Integer, JCheckBox, Integer>() {
                                        @Override
                                        public Integer fun(Integer exitCode, JCheckBox cb) {
                                            settings.HOTSWAP_HANG_WARNING_ENABLED = !cb.isSelected();
                                            return exitCode == DialogWrapper.OK_EXIT_CODE ? exitCode
                                                    : DialogWrapper.CANCEL_EXIT_CODE;
                                        }
                                    });
                            if (answer == DialogWrapper.CANCEL_EXIT_CODE) {
                                for (DebuggerSession session : modifiedClasses.keySet()) {
                                    session.setModifiedClassesScanRequired(true);
                                }
                                return;
                            }
                        }
                    }

                    if (!modifiedClasses.isEmpty()) {
                        final HotSwapProgressImpl progress = new HotSwapProgressImpl(myProject);
                        application.executeOnPooledThread(new Runnable() {
                            public void run() {
                                reloadModifiedClasses(modifiedClasses, progress);
                            }
                        });
                    }
                }
            }, ModalityState.NON_MODAL);
        }
    });
}

From source file:com.intellij.ide.navigationToolbar.NavBarListener.java

License:Apache License

@Override
public void focusLost(final FocusEvent e) {
    if (myPanel.getProject().isDisposed()) {
        myPanel.setContextComponent(null);
        myPanel.hideHint();// www  .  j  av  a 2s .  c o  m
        return;
    }
    final DialogWrapper dialog = DialogWrapper.findInstance(e.getOppositeComponent());
    shouldFocusEditor = dialog != null;
    if (dialog != null) {
        Disposer.register(dialog.getDisposable(), new Disposable() {
            @Override
            public void dispose() {
                if (dialog.getExitCode() == DialogWrapper.CANCEL_EXIT_CODE) {
                    shouldFocusEditor = false;
                }
            }
        });
    }

    // required invokeLater since in current call sequence KeyboardFocusManager is not initialized yet
    // but future focused component
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            processFocusLost(e);
        }
    });
}

From source file:com.intellij.plugins.haxe.ide.refactoring.extractSuperclass.ExtractSuperClassUtil.java

License:Apache License

public static boolean showConflicts(DialogWrapper dialog, MultiMap<PsiElement, String> conflicts,
        final Project project) {
    if (!conflicts.isEmpty()) {
        fireConflictsEvent(conflicts, project);
        ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
        conflictsDialog.show();//from w  w  w.  j ava 2s  .c  o m
        final boolean ok = conflictsDialog.isOK();
        if (!ok && conflictsDialog.isShowConflicts())
            dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
        return ok;
    }
    return true;
}

From source file:com.intellij.plugins.haxe.ide.refactoring.memberPullUp.HaxePullUpHandler.java

License:Apache License

@Override
public boolean checkConflicts(final HaxePullUpDialog dialog) {
    final List<MemberInfo> infos = dialog.getSelectedMemberInfos();
    final MemberInfo[] memberInfos = infos.toArray(new MemberInfo[infos.size()]);
    final PsiClass superClass = dialog.getSuperClass();
    if (!checkWritable(superClass, memberInfos))
        return false;
    final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        @Override//from ww w .j  a  va 2  s. com
        public void run() {
            ApplicationManager.getApplication().runReadAction(new Runnable() {
                @Override
                public void run() {
                    //final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
                    //final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
                    //conflicts
                    //  .putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory,
                    //                                                   dialog.getContainmentVerifier()));
                }
            });
        }
    }, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject))
        return false;
    if (!conflicts.isEmpty()) {
        ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
        conflictsDialog.show();
        final boolean ok = conflictsDialog.isOK();
        if (!ok && conflictsDialog.isShowConflicts())
            dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
        return ok;
    }
    return true;
}

From source file:com.intellij.refactoring.extractSuperclass.ExtractSuperClassMultiUtil.java

License:Apache License

public static boolean showConflicts(DialogWrapper dialog, MultiMap<PsiElement, String> conflicts,
        final Project project) {
    if (!conflicts.isEmpty()) {
        ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
        conflictsDialog.show();/*from   w  ww.j av a 2 s  .c o  m*/
        final boolean ok = conflictsDialog.isOK();
        if (!ok && conflictsDialog.isShowConflicts())
            dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
        return ok;
    }
    return true;
}

From source file:com.intellij.refactoring.introduceVariable.IntroduceVariableHandler.java

License:Apache License

protected boolean reportConflicts(final MultiMap<PsiElement, String> conflicts, final Project project,
        IntroduceVariableSettings dialog) {
    ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
    conflictsDialog.show();//from w  ww  . j  av  a2s.  c o m
    final boolean ok = conflictsDialog.isOK();
    if (!ok && conflictsDialog.isShowConflicts()) {
        if (dialog instanceof DialogWrapper)
            ((DialogWrapper) dialog).close(DialogWrapper.CANCEL_EXIT_CODE);
    }
    return ok;
}

From source file:com.intellij.refactoring.memberPullUp.JavaPullUpGenHandler.java

License:Apache License

public boolean checkConflicts(final PullUpGenDialog dialog) {
    final List<MemberInfo> infos = dialog.getSelectedMemberInfos();
    final MemberInfo[] memberInfos = infos.toArray(new MemberInfo[infos.size()]);
    final PsiClass superClass = dialog.getSuperClass();
    if (!checkWritable(superClass, memberInfos))
        return false;
    final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        public void run() {
            final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
            final PsiPackage targetPackage = targetDirectory != null
                    ? JavaDirectoryService.getInstance().getPackage(targetDirectory)
                    : null;/*from  ww w . j a va 2 s . c o  m*/
            conflicts.putAllValues(PullUpGenConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass,
                    targetPackage, targetDirectory, dialog.getContainmentVerifier()));
        }
    }, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject))
        return false;
    if (!conflicts.isEmpty()) {
        ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
        conflictsDialog.show();
        final boolean ok = conflictsDialog.isOK();
        if (!ok && conflictsDialog.isShowConflicts())
            dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
        return ok;
    }
    return true;
}