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

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

Introduction

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

Prototype

public CustomizableAction addCancelAction() 

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();//from   w  w  w.j av a2  s  .  c  om
    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.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();/*  w ww.j av  a  2s .c om*/
    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  w  w  w.java2  s .c  o  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.machak.idea.plugins.actions.CopyHippoSharedFiles.java

License:Apache License

private void showProjectRootPopup(final String basePath, final File tomcatDirectory) {

    final DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle("Create project file:");
    final JPanel simplePanel = new JPanel();
    simplePanel.add(new JLabel("Following path will be used as project base:\n" + basePath));
    dialogBuilder.setCenterPanel(simplePanel);

    final Action acceptAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/*from   w  w  w  . j  a va  2s. c o  m*/
        public void actionPerformed(final ActionEvent e) {
            // check if file exists and overwrite:
            final String filePath = tomcatDirectory.getAbsolutePath() + File.separator + "bin" + File.separator
                    + PROJECT_FILE;
            createAndWriteFile(filePath, basePath);

            dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
        }
    };
    acceptAction.putValue(Action.NAME, "OK");
    dialogBuilder.addAction(acceptAction);

    dialogBuilder.addCancelAction();
    dialogBuilder.showModal(true);
}

From source file:com.machak.idea.plugins.actions.CopyHippoSharedFiles.java

License:Apache License

private void processJars(final ApplicationComponent component, final String tomcatSharedDirectory,
        final File sharedDirectory, final Map<String, String> depMap) {

    final FilenameFilter fileFilter = createJarsFilter(component, depMap);
    final File[] jars = sharedDirectory.listFiles(fileFilter);
    if (!component.isShowDialog()) {
        for (File jar : jars) {
            deleteFile(jar);// ww  w  . j a v  a 2 s .  c  o m
        }
        copyJars(tomcatSharedDirectory, depMap);
        return;
    }
    final int length = jars.length;
    myFiles = new String[length];
    myCheckedMarks = new boolean[length];
    for (int i = 0; i < length; i++) {
        final File file = jars[i];
        myFiles[i] = file.getAbsolutePath();
        myCheckedMarks[i] = true;
    }

    final TableModel model = new MyTableModel();
    final JBTable myTable = new JBTable();
    myTable.setPreferredSize(new Dimension(700, 400));
    myTable.setModel(model);
    final TableColumnModel columnModel = myTable.getColumnModel();
    columnModel.getColumn(CHECKED_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    columnModel.getColumn(CHECKED_COLUMN).setPreferredWidth(40);
    columnModel.getColumn(FILE_COLUMN).setPreferredWidth(660);

    final DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle("Files to delete");
    dialogBuilder.setCenterPanel(myTable);

    final Action deleteAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(final ActionEvent e) {
            final int length = model.getRowCount();
            for (int i = 0; i < length; i++) {
                final Boolean checked = (Boolean) model.getValueAt(i, CHECKED_COLUMN);
                if (checked) {
                    final File jar = jars[i];
                    deleteFile(jar);
                }
            }
            // do copy:
            copyJars(tomcatSharedDirectory, depMap);
            dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
        }
    };
    deleteAction.putValue(Action.NAME, "OK");
    dialogBuilder.addAction(deleteAction);

    dialogBuilder.addCancelAction();
    dialogBuilder.showModal(true);

}

From source file:com.machak.idea.plugins.tomcat.actions.DeleteTomcatWebapps.java

License:Apache License

private void showDeletePopup(final String webappsDirectory, final File webappDir) {

    final String absolutePath = webappDir.getAbsolutePath();
    final DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle("Create project file:");
    final JPanel simplePanel = new JPanel();
    simplePanel.add(new JLabel("All directories within: " + absolutePath + " will be deleted"));
    dialogBuilder.setCenterPanel(simplePanel);

    final Action acceptAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/*from  www.  j a va 2s  .co  m*/
        public void actionPerformed(final ActionEvent e) {
            deleteFiles(webappsDirectory, webappDir);
            dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);

        }
    };
    acceptAction.putValue(Action.NAME, "OK");
    dialogBuilder.addAction(acceptAction);

    dialogBuilder.addCancelAction();
    dialogBuilder.showModal(true);
}

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();/*from   ww  w . j a  v a  2  s  .  c  o 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// ww w.j a  v a  2  s.  co 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;
}