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.sylvanaar.idea.errorreporting.BugzReport.java

License:Apache License

@Override
public SubmittedReportInfo submit(IdeaLoggingEvent[] ideaLoggingEvents, Component component) {
    // show modal error submission dialog
    PluginErrorSubmitDialog dialog = new PluginErrorSubmitDialog(component);
    dialog.prepare();//from  w w  w .  ja  va2  s.  c om
    dialog.show();

    // submit error to server if user pressed SEND
    int code = dialog.getExitCode();
    if (code == DialogWrapper.OK_EXIT_CODE) {
        dialog.persist();
        String description = dialog.getDescription();
        String user = dialog.getUser();
        return submit(ideaLoggingEvents, description, user, component);
    }

    // otherwise do nothing
    return null;
}

From source file:com.theoryinpractice.testng.TestNGFramework.java

License:Apache License

@Override
protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
    PsiMethod method = findSetUpMethod(clazz);
    if (method != null)
        return method;

    final PsiManager manager = clazz.getManager();
    final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
    String setUpName = "setUp";
    PsiMethod patternMethod = createSetUpPatternMethod(factory);
    PsiMethod inClass = clazz.findMethodBySignature(patternMethod, false);
    if (inClass != null) {
        int exit = ApplicationManager.getApplication().isUnitTestMode() ? DialogWrapper.OK_EXIT_CODE
                : Messages.showYesNoDialog(
                        "Method \'" + setUpName + "\' already exist but is not annotated as @BeforeMethod.",
                        CommonBundle.getWarningTitle(), "Annotate", "Create new method",
                        Messages.getWarningIcon());
        if (exit == DialogWrapper.OK_EXIT_CODE) {
            new AddAnnotationFix(BeforeMethod.class.getName(), inClass).invoke(inClass.getProject(), null,
                    inClass.getContainingFile());
            return inClass;
        } else if (exit == DialogWrapper.CANCEL_EXIT_CODE) {
            inClass = null;/* ww  w  . j av  a 2 s .  c  om*/
            int i = 0;
            while (clazz.findMethodBySignature(patternMethod, false) != null) {
                patternMethod.setName(setUpName + (++i));
            }
            setUpName = patternMethod.getName();
        }
    }

    final PsiClass superClass = clazz.getSuperClass();
    if (superClass != null) {
        final PsiMethod[] methods = superClass.findMethodsBySignature(patternMethod, false);
        if (methods.length > 0) {
            final PsiModifierList modifierList = methods[0].getModifierList();
            if (!modifierList.hasModifierProperty(PsiModifier.PRIVATE)) { //do not override private method
                @NonNls
                String pattern = "@" + BeforeMethod.class.getName() + "\n";
                if (modifierList.hasModifierProperty(PsiModifier.PROTECTED)) {
                    pattern += "protected ";
                } else if (modifierList.hasModifierProperty(PsiModifier.PUBLIC)) {
                    pattern += "public ";
                }
                patternMethod = factory.createMethodFromText(
                        pattern + "void " + setUpName + "() throws Exception {\nsuper." + setUpName + "();\n}",
                        null);
            }
        }
    }

    final PsiMethod[] psiMethods = clazz.getMethods();

    PsiMethod testMethod = null;
    for (PsiMethod psiMethod : psiMethods) {
        if (inClass == null && AnnotationUtil.isAnnotated(psiMethod, BeforeMethod.class.getName(), false)) {
            inClass = psiMethod;
        }
        if (testMethod == null && AnnotationUtil.isAnnotated(psiMethod, Test.class.getName(), false)
                && !psiMethod.hasModifierProperty(PsiModifier.PRIVATE)) {
            testMethod = psiMethod;
        }
    }
    if (inClass == null) {
        final PsiMethod psiMethod;
        if (testMethod != null) {
            psiMethod = (PsiMethod) clazz.addBefore(patternMethod, testMethod);
        } else {
            psiMethod = (PsiMethod) clazz.add(patternMethod);
        }
        JavaCodeStyleManager.getInstance(clazz.getProject()).shortenClassReferences(clazz);
        return psiMethod;
    } else if (inClass.getBody() == null) {
        return (PsiMethod) inClass.replace(patternMethod);
    }
    return inClass;
}

From source file:com.weebly.opus1269.smoothscroller.OptionsDialog.java

License:Open Source License

@Override
public void show() {
    mOptionsForm.setFromProps();//from www .  j ava 2s .  com

    super.show();

    if (getExitCode() == DialogWrapper.OK_EXIT_CODE && mOptionsForm.isModified()) {
        mOptionsForm.setToProps();
        Props.storeProperties();
    }
}

From source file:geneon.intellij.plugin.jenkins.ui.AppConfigurable.java

License:Open Source License

private boolean editServer(JenkinsServer server) {
    EditServerDialog dialog = new EditServerDialog(configPanel, server);
    dialog.show();/*w  w w  . j a  v  a 2  s.  com*/
    return dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE;
}

From source file:net.andydvorak.intellij.lessc.ui.configurable.VfsLocationChangeDialog.java

License:Apache License

public synchronized boolean shouldMoveCssFile(final VirtualFileEvent virtualFileEvent) {
    DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
        @Override//from w w  w  .j  a  v a  2 s .c om
        public boolean isToBeShown() {
            return myLessProjectState.isPromptOnMove();
        }

        @Override
        public void setToBeShown(boolean value, int exitCode) {
            myLessProjectState.setPromptOnMove(value);
        }

        @Override
        public boolean canBeHidden() {
            return true;
        }

        @Override
        public boolean shouldSaveOptionsOnCancel() {
            return true;
        }

        @Override
        public String getDoNotShowMessage() {
            return UIBundle.message("do.not.ask.me.again");
        }
    };

    if (option.isToBeShown()) {
        if (System.currentTimeMillis() - lastPrompt > promptIntervalMillis) {
            result = Messages.showYesNoDialog(
                    UIBundle.message("vfs.move.message", virtualFileEvent.getFileName()),
                    UIBundle.message("vfs.move.title"), // Title
                    UIBundle.message("vfs.move.yes"), // "Yes" button text
                    UIBundle.message("vfs.move.no"), // "No" button text
                    Messages.getQuestionIcon(), option);
        }
    } else {
        result = myLessProjectState.isMoveCssFiles() ? DialogWrapper.OK_EXIT_CODE
                : DialogWrapper.CANCEL_EXIT_CODE;
    }

    lastPrompt = System.currentTimeMillis();

    final boolean shouldMove = result == DialogWrapper.OK_EXIT_CODE;

    myLessProjectState.setMoveCssFiles(shouldMove);

    return shouldMove;
}

From source file:net.andydvorak.intellij.lessc.ui.configurable.VfsLocationChangeDialog.java

License:Apache License

public synchronized boolean shouldCopyCssFile(final VirtualFileEvent virtualFileEvent) {
    DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
        @Override/* w  w w . j  a  v  a  2s .c o m*/
        public boolean isToBeShown() {
            return myLessProjectState.isPromptOnCopy();
        }

        @Override
        public void setToBeShown(boolean value, int exitCode) {
            myLessProjectState.setPromptOnCopy(value);
        }

        @Override
        public boolean canBeHidden() {
            return true;
        }

        @Override
        public boolean shouldSaveOptionsOnCancel() {
            return true;
        }

        @Override
        public String getDoNotShowMessage() {
            return UIBundle.message("do.not.ask.me.again");
        }
    };

    if (option.isToBeShown()) {
        if (System.currentTimeMillis() - lastPrompt > promptIntervalMillis) {
            result = Messages.showYesNoDialog(
                    UIBundle.message("vfs.copy.message", virtualFileEvent.getFileName()),
                    UIBundle.message("vfs.copy.title"), // Title
                    UIBundle.message("vfs.copy.yes"), // "Yes" button text
                    UIBundle.message("vfs.copy.no"), // "No" button text
                    Messages.getQuestionIcon(), option);
        }
    } else {
        result = myLessProjectState.isCopyCssFiles() ? DialogWrapper.OK_EXIT_CODE
                : DialogWrapper.CANCEL_EXIT_CODE;
    }

    lastPrompt = System.currentTimeMillis();

    final boolean shouldCopy = result == DialogWrapper.OK_EXIT_CODE;

    myLessProjectState.setCopyCssFiles(shouldCopy);

    return shouldCopy;
}

From source file:net.andydvorak.intellij.lessc.ui.configurable.VfsLocationChangeDialog.java

License:Apache License

public synchronized boolean shouldDeleteCssFile(final VirtualFileEvent virtualFileEvent) {
    DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
        @Override//from w  w  w  .  j  ava  2  s .co m
        public boolean isToBeShown() {
            return myLessProjectState.isPromptOnDelete();
        }

        @Override
        public void setToBeShown(boolean value, int exitCode) {
            myLessProjectState.setPromptOnDelete(value);
        }

        @Override
        public boolean canBeHidden() {
            return true;
        }

        @Override
        public boolean shouldSaveOptionsOnCancel() {
            return true;
        }

        @Override
        public String getDoNotShowMessage() {
            return UIBundle.message("do.not.ask.me.again");
        }
    };

    if (option.isToBeShown()) {
        if (System.currentTimeMillis() - lastPrompt > promptIntervalMillis) {
            result = Messages.showYesNoDialog(
                    UIBundle.message("vfs.delete.message", virtualFileEvent.getFileName()),
                    UIBundle.message("vfs.delete.title"), // Title
                    UIBundle.message("vfs.delete.yes"), // "Yes" button text
                    UIBundle.message("vfs.delete.no"), // "No" button text
                    Messages.getQuestionIcon(), option);
        }
    } else {
        result = myLessProjectState.isDeleteCssFiles() ? DialogWrapper.OK_EXIT_CODE
                : DialogWrapper.CANCEL_EXIT_CODE;
    }

    lastPrompt = System.currentTimeMillis();

    final boolean shouldDelete = result == DialogWrapper.OK_EXIT_CODE;

    myLessProjectState.setDeleteCssFiles(shouldDelete);

    return shouldDelete;
}

From source file:net.stevechaloner.intellijad.environment.EnvironmentValidator.java

License:Apache License

/**
 * Shows the error dialog, allowing the user to cancel the decompilation or open the config.
 *
 * @param config the configuration// www  . j a v  a  2s .c  o  m
 * @param envContext the environment context
 * @param consoleContext the console's logging context
 * @param message the error message
 * @return the result of the dialog-based operation
 */
private static ValidationResult showErrorDialog(@NotNull Config config, @NotNull EnvironmentContext envContext,
        @NotNull ConsoleContext consoleContext, @NotNull String message) {
    DialogBuilder builder = new DialogBuilder(envContext.getProject());
    builder.setTitle(IntelliJadResourceBundle.message("plugin.IntelliJad.name"));
    builder.addOkAction().setText(IntelliJadResourceBundle.message("option.open-config"));
    builder.addCancelAction().setText(IntelliJadResourceBundle.message("option.cancel-decompilation"));
    JLabel label = new JLabel(message);
    label.setUI(new MultiLineLabelUI());
    builder.setCenterPanel(label);
    builder.setOkActionEnabled(true);

    ValidationResult result;
    switch (builder.show()) {
    case DialogWrapper.OK_EXIT_CODE:
        // this will cause recursive correction unless cancel is selected
        Project project = envContext.getProject();
        ConfigAccessor configAccessor = config.isUseProjectSpecificSettings()
                ? new ProjectConfigComponent(project)
                : new ApplicationConfigComponent();
        // design point - if this dialog is cancelled, should we assume the decompilation is cancelled?
        ShowSettingsUtil.getInstance().editConfigurable(project, configAccessor);
        config.copyFrom(configAccessor.getConfig());
        result = validateEnvironment(config, envContext, consoleContext);
        break;
    case DialogWrapper.CANCEL_EXIT_CODE:
    default:
        result = new ValidationResult(false, true);
        break;
    }

    return result;
}

From source file:nu.studer.idea.errorreporting.PluginErrorReportSubmitter.java

License:Apache License

@Override
public SubmittedReportInfo submit(IdeaLoggingEvent[] events, final Component parentComponent) {
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);

    StringBuilder stacktrace = new StringBuilder();
    for (IdeaLoggingEvent event : events) {
        stacktrace.append(event.getMessage()).append("\n");
        stacktrace.append(event.getThrowableText()).append("\n");
    }//from www .  j  a v  a 2 s  .c o m

    Properties properties = new Properties();
    queryPluginDescriptor(getPluginDescriptor(), properties);

    StringBuilder versionId = new StringBuilder();
    versionId.append(properties.getProperty(PLUGIN_ID_PROPERTY_KEY)).append(" ")
            .append(properties.getProperty(PLUGIN_VERSION_PROPERTY_KEY));
    versionId.append(", ").append(ApplicationInfo.getInstance().getBuild().asString());

    // show modal error submission dialog
    PluginErrorSubmitDialog dialog = new PluginErrorSubmitDialog(parentComponent);
    dialog.prepare("", stacktrace.toString(), versionId.toString());
    dialog.show();

    final SubmittedReportInfo[] result = { null };

    // submit error to server if user pressed SEND
    int code = dialog.getExitCode();
    if (code == DialogWrapper.OK_EXIT_CODE) {
        dialog.persist();

        String description = dialog.getDescription();
        String user = dialog.getUser();
        String editedStacktrace = dialog.getStackTrace();

        submitToServer(project, editedStacktrace, description, user, new Consumer<SubmittedReportInfo>() {
            @Override
            public void consume(SubmittedReportInfo submittedReportInfo) {
                result[0] = submittedReportInfo;
                //Messages.showInfoMessage(parentComponent, PluginErrorReportSubmitterBundle.message("successful.dialog.message"), PluginErrorReportSubmitterBundle.message("successful.dialog.title"));
            }
        }, new Consumer<Throwable>() {
            @Override
            public void consume(Throwable throwable) {
                LOGGER.info("Error submission failed", throwable);
                result[0] = new SubmittedReportInfo("http://www.ansorg-it.com/en/products_bashsupport.html",
                        "BashSupport", SubmittedReportInfo.SubmissionStatus.FAILED);
            }
        });
    }

    return result[0];
}

From source file:org.cordovastudio.editors.designer.propertyTable.properties.IdProperty.java

License:Apache License

@Override
public void setValue(@NotNull final RadViewComponent component, final Object value) throws Exception {
    final String newId = value != null ? value.toString() : "";

    IdManager idManager = IdManager.get(component);
    final String oldId = component.getId();

    if (ourRefactoringChoice != REFACTOR_NO && oldId != null && !oldId.isEmpty() && !newId.isEmpty()
            && !oldId.equals(newId) && component.getTag().isValid()) {
        // Offer rename refactoring?
        XmlTag tag = component.getTag();
        XmlAttribute attribute = tag.getAttribute(ATTR_ID, CORDOVASTUDIO_URI);
        if (attribute != null) {
            Module module = RadModelBuilder.getModule(component);
            if (module != null) {
                XmlAttributeValue valueElement = attribute.getValueElement();
                if (valueElement != null && valueElement.isValid()) {
                    final Project project = module.getProject();
                    // Exact replace only, no comment/text occurrence changes since it is non-interactive
                    RenameProcessor processor = new RenameProcessor(project, valueElement, 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 = new DialogBuilder(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(new DialogBuilder.ActionDescriptor() {
                                @Override
                                public Action getAction(final DialogWrapper dialogWrapper) {
                                    return new AbstractAction(Messages.NO_BUTTON) {
                                        @Override
                                        public void actionPerformed(ActionEvent actionEvent) {
                                            dialogWrapper.close(DialogWrapper.NEXT_USER_EXIT_CODE);
                                        }
                                    };/*from w w  w  . j a v  a2s  .c om*/
                                }
                            });
                            builder.addCancelAction();
                            int exitCode = builder.show();

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

                            if (!checkBox.isSelected()) {
                                ourRefactoringChoice = REFACTOR_ASK;
                            } else {
                                ourRefactoringChoice = choice;
                            }

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

                        if (choice == REFACTOR_YES) {
                            processor.run();
                            // Fall through to also set the value in the layout editor property; otherwise we'll be out of sync
                        }
                    }
                }
            }
        }
    }

    if (idManager != null) {
        idManager.removeComponent(component, false);
    }

    //noinspection ConstantConditions
    super.setValue(component, value);

    if (idManager != null) {
        idManager.addComponent(component);
    }
}