Example usage for com.intellij.openapi.ui DialogBuilder addOkAction

List of usage examples for com.intellij.openapi.ui DialogBuilder addOkAction

Introduction

In this page you can find the example usage for com.intellij.openapi.ui DialogBuilder addOkAction.

Prototype

public CustomizableAction addOkAction() 

Source Link

Usage

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();//  ww w .j  a  va  2s.com
    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.github.intelliguard.ui.FormDialogWrapper.java

License:Apache License

@Nullable
public static JarOptionsForm showJarOptionsForm(@NotNull GuardFacet guardFacet) {
    DialogBuilder builder = new DialogBuilder(guardFacet.getModule().getProject());
    JarOptionsForm jarOptionsForm = new JarOptionsForm(guardFacet);
    builder.setCenterPanel(jarOptionsForm.getContentPane());
    builder.setTitle("Obfuscate Jar");
    builder.addOkAction().setText("Build");
    builder.addCancelAction().setText("Cancel");

    int res = builder.show();

    return res == 0 ? jarOptionsForm : null;
}

From source file:com.github.intelliguard.ui.FormDialogWrapper.java

License:Apache License

@Nullable
public static ExportOptionsForm showExportOptionsForm(@NotNull GuardFacet guardFacet) {
    DialogBuilder builder = new DialogBuilder(guardFacet.getModule().getProject());
    ExportOptionsForm exportOptionsForm = new ExportOptionsForm(guardFacet);
    builder.setCenterPanel(exportOptionsForm.getContentPane());
    builder.setTitle("Export Configuration");
    builder.addOkAction().setText("Export");
    builder.addCancelAction().setText("Cancel");

    int res = builder.show();

    return res == 0 ? exportOptionsForm : null;
}

From source file:com.intellij.execution.util.ExecutionErrorDialog.java

License:Apache License

public static void show(final ExecutionException e, final String title, final Project project) {
    if (e instanceof RunCanceledByUserException) {
        return;/*from ww w.  j a v a  2s .c  o  m*/
    }

    if (ApplicationManager.getApplication().isUnitTestMode()) {
        throw new RuntimeException(e.getLocalizedMessage());
    }
    final String message = e.getMessage();
    if (message == null || message.length() < 100) {
        Messages.showErrorDialog(project, message == null ? "exception was thrown" : message, title);
        return;
    }
    final DialogBuilder builder = new DialogBuilder(project);
    builder.setTitle(title);
    final JTextArea textArea = new JTextArea();
    textArea.setEditable(false);
    textArea.setForeground(UIUtil.getLabelForeground());
    textArea.setBackground(UIUtil.getLabelBackground());
    textArea.setFont(UIUtil.getLabelFont());
    textArea.setText(message);
    textArea.setWrapStyleWord(false);
    textArea.setLineWrap(true);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(textArea);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    final JPanel panel = new JPanel(new BorderLayout(10, 0));
    panel.setPreferredSize(new Dimension(500, 200));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.add(new JLabel(Messages.getErrorIcon()), BorderLayout.WEST);
    builder.setCenterPanel(panel);
    builder.setButtonsAlignment(SwingConstants.CENTER);
    builder.addOkAction();
    builder.show();
}

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   w w w  . j  a  va  2 s  . c  o m*/
    builder.addOkAction();
    builder.addCancelAction();
    builder.setHelpId("reference.dialogs.buildfileproperties");

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

From source file:com.intellij.packaging.impl.run.AbstractArtifactsBeforeRunTaskProvider.java

License:Apache License

@Override
public boolean configureTask(RunConfiguration runConfiguration, T task) {
    final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getArtifacts();
    Set<ArtifactPointer> pointers = new THashSet<ArtifactPointer>();
    for (Artifact artifact : artifacts) {
        pointers.add(ArtifactPointerUtil.getPointerManager(myProject).create(artifact));
    }/*from   ww w.  jav a2s . co m*/
    pointers.addAll(task.getArtifactPointers());
    ArtifactChooser chooser = new ArtifactChooser(new ArrayList<ArtifactPointer>(pointers));
    chooser.markElements(task.getArtifactPointers());
    chooser.setPreferredSize(new Dimension(400, 300));

    DialogBuilder builder = new DialogBuilder(myProject);
    builder.setTitle(CompilerBundle.message("build.artifacts.before.run.selector.title"));
    builder.setDimensionServiceKey("#BuildArtifactsBeforeRunChooser");
    builder.addOkAction();
    builder.addCancelAction();
    builder.setCenterPanel(chooser);
    builder.setPreferredFocusComponent(chooser);
    if (builder.show() == DialogWrapper.OK_EXIT_CODE) {
        task.setArtifactPointers(chooser.getMarkedElements());
        return true;
    }
    return false;
}

From source file:com.intellij.uiDesigner.designSurface.GuiEditor.java

License:Apache License

public void showFormSource() {
    EditorFactory editorFactory = EditorFactory.getInstance();

    Editor editor = editorFactory.createViewer(myDocument, myProject);

    try {//from  w  w  w.jav  a  2  s  .  co  m
        ((EditorEx) editor).setHighlighter(new LexerEditorHighlighter(new XmlFileHighlighter(),
                EditorColorsManager.getInstance().getGlobalScheme()));

        JComponent component = editor.getComponent();
        component.setPreferredSize(new Dimension(640, 480));

        DialogBuilder dialog = new DialogBuilder(myProject);

        dialog.title("Form - " + myFile.getPresentableName()).dimensionKey("GuiDesigner.FormSource.Dialog");
        dialog.centerPanel(component).setPreferredFocusComponent(editor.getContentComponent());
        dialog.addOkAction();

        dialog.show();
    } finally {
        editorFactory.releaseEditor(editor);
    }
}

From source file:io.github.holgerbrandl.send2terminal.connectors.AppleScriptConnector.java

License:BSD License

private static void submitCodeInternal(String codeSelection, boolean switchFocusToTerminal,
        @Nullable FileType fileType) {//from   ww w  . j  ava 2s .  c o m
    try {

        if (Utils.isMacOSX()) {
            Runtime runtime = Runtime.getRuntime();

            boolean isKotlin = fileType != null && fileType.getName().toLowerCase().equals("kotlin");

            boolean pasteModeRequired = isKotlin
                    && Arrays.stream(codeSelection.split("\\r?\\n")).map(String::trim).anyMatch(s ->
                    //is chained call or javadoc
                    s.startsWith(".") || s.startsWith("*"));

            if (pasteModeRequired && !S2TSettings.getInstance().usePasteMode) {
                DialogBuilder builder = new DialogBuilder();
                JLabel jLabel = new JLabel(
                        "<html>Can not send multi-line expression to terminal. <br>Please vote for <a href='https://youtrack.jetbrains.net/issue/KT-13319'>KT-13319</a> to push for a REPL paste-mode.<br>Alternatively you could use kshell from <a href='https://github.com/khud/sparklin'>https://github.com/khud/sparklin</a> and enable the paste mode support in the preferences of this plugin</html>");
                builder.centerPanel(jLabel);
                //                    builder.setDimensionServiceKey("GrepConsoleSound");
                builder.setTitle("Multi-line Expression Error");
                builder.removeAllActions();

                builder.addOkAction();

                //                    builder.addCancelAction();

                builder.show();

                return;
            }

            boolean usePasteMode = S2TSettings.getInstance().usePasteMode && isKotlin;

            // just use paste mode if any line starts with a dot
            usePasteMode = usePasteMode && pasteModeRequired;

            if (usePasteMode) {
                codeSelection = ":paste\n" + codeSelection;
            }

            String dquotesExpandedText = codeSelection.replace("\\", "\\\\");
            dquotesExpandedText = dquotesExpandedText.replace("\"", "\\\"");

            // trim to remove tailing newline for blocks and especially line evaluation
            dquotesExpandedText = dquotesExpandedText.trim();

            String evalTarget = S2TSettings.getInstance().codeSnippetEvalTarget;
            //                String evalTarget = "R64";

            //                http://stackoverflow.com/questions/1870270/sending-commands-and-strings-to-terminal-app-with-applescript

            String evalSelection;
            if (evalTarget.equals("Terminal")) {
                //                    if (codeSelection.length() > 1000) {
                //                        DialogBuilder db = new DialogBuilder();
                //                        db.setTitle("Operation canceled: ");
                //                        db.setCenterPanel(new JLabel("Can't paste more that 1024 characters to MacOS terminal."));
                //                        db.addOkAction();
                //                        db.show();
                //
                //                        return;
                //                    }

                evalSelection = "tell application \"" + "Terminal" + "\" to do script \"" + dquotesExpandedText
                        + "\" in window 0";

                if (switchFocusToTerminal) {
                    evalSelection = "tell application \"Terminal\" to activate\n" + evalSelection;
                }

                if (usePasteMode) {
                    // https://stackoverflow.com/questions/3690167/how-can-one-invoke-a-keyboard-shortcut-from-within-an-applescript

                    evalSelection = evalSelection + "\n" + "tell application \"System Events\"\n" +
                    //                                "    set currentApplication to name of 1st process whose frontmost is true\n" +
                    //                                "    set currentApplication to process appName\n" +
                            "    set currentApplication to path to frontmost application as text\n" + "end tell"
                            + "\n" +
                            //                                "delay 1\n" +
                            "activate application \"Terminal\"\n" + "tell application  \"System Events\"\n"
                            + "    keystroke \"d\" using {control down}\n" + "end tell\n" + "\n"
                            + "activate application currentApplication\n";
                    //                                "activate \"Intellij IDEA\"";
                }

            } else if (evalTarget.equals("iTerm")) {
                evalSelection = "tell application \"iTerm\" to tell current session of current terminal  to write text  \""
                        + dquotesExpandedText + "\"";
                if (switchFocusToTerminal) {
                    evalSelection = "tell application \"iTerm\" to activate\n" + evalSelection;
                }

            } else {
                if (switchFocusToTerminal) {
                    evalSelection = "tell application \"" + evalTarget + "\" to activate\n"
                            + "tell application \"" + evalTarget + "\" to cmd \"" + dquotesExpandedText + "\"";
                } else {
                    evalSelection = "tell application \"" + evalTarget + "\" to cmd \"" + dquotesExpandedText
                            + "\"";
                }
            }

            String[] args = { "osascript", "-e", evalSelection };

            runtime.exec(args);
        }
    } catch (IOException e1) {
        ConnectorUtils.log.error(e1);
    }
}

From source file:manuylov.maxim.ocaml.toolWindow.OCamlToolWindowSettingsAction.java

License:Open Source License

public void showSettingsDialog() {
    final OCamlSettings settings = OCamlSettings.getInstance(myProject);
    final OCamlToolWindowSettingsForm settingsForm = new OCamlToolWindowSettingsForm(myProject);
    settingsForm.setSelectedSdk(settings.getTopLevelSdk());
    settingsForm.setCmdParams(settings.getTopLevelCmdOptions());
    settingsForm.setWorkingDirectory(settings.getTopLevelCmdWorkingDir());

    final DialogBuilder dialogBuilder = new DialogBuilder(myProject);
    dialogBuilder.setCenterPanel(settingsForm.getRootPanel());
    dialogBuilder.addOkAction().setText("Ok");
    dialogBuilder.addCancelAction().setText("Cancel");
    dialogBuilder.setPreferredFocusComponent(settingsForm.getSdkComboBox());
    dialogBuilder.setTitle("OCaml Top Level Console Settings");
    dialogBuilder.setOkOperation(new Runnable() {
        public void run() {
            settings.setTopLevelSdk(settingsForm.getSelectedSdk());
            settings.setTopLevelCmdOptions(settingsForm.getCmdParams());
            settings.setTopLevelCmdWorkingDir(settingsForm.getWorkingDirectory());
            dialogBuilder.getWindow().setVisible(false);
            if (myAction != null) {
                myAction.run();//  w  ww  . j  ava  2  s  .co m
            }
        }
    });
    dialogBuilder.show();
}

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//from   w w  w.  j  a va 2  s .  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;
}