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

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

Introduction

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

Prototype

public int show() 

Source Link

Usage

From source file:com.android.tools.idea.apk.viewer.ApkEditor.java

License:Apache License

@Override
public void selectApkAndCompare() {
    FileChooserDescriptor desc = new FileChooserDescriptor(true, false, false, false, false, false);
    desc.withFileFilter(file -> ApkFileSystem.EXTENSIONS.contains(file.getExtension()));
    VirtualFile file = FileChooser.chooseFile(desc, myProject, null);
    if (file == null) {
        // user canceled
        return;/*from  ww w .ja  v  a  2  s.c  o  m*/
    }
    VirtualFile newApk = ApkFileSystem.getInstance().getRootByLocal(file);
    assert newApk != null;

    DialogBuilder builder = new DialogBuilder(myProject);
    builder.setTitle(myRoot.getName() + " vs " + newApk.getName());
    ApkDiffParser parser = new ApkDiffParser(myRoot, newApk);
    ApkDiffPanel panel = new ApkDiffPanel(parser);
    builder.setCenterPanel(panel.getContainer());
    builder.setPreferredFocusComponent(panel.getPreferredFocusedComponent());
    builder.show();
}

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();// w w  w . ja v  a  2 s. 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.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   w ww. jav  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.history.integration.ui.views.HistoryDialog.java

License:Apache License

private boolean showAsDialog(CreatePatchConfigurationPanel p) {
    final DialogBuilder b = new DialogBuilder(myProject);
    JComponent createPatchPanel = p.getPanel();
    b.setPreferredFocusComponent(IdeFocusTraversalPolicy.getPreferredFocusedComponent(createPatchPanel));
    b.setTitle(message("create.patch.dialog.title"));
    b.setCenterPanel(createPatchPanel);/*from   w w w  . java 2  s.co  m*/
    p.installOkEnabledListener(new Consumer<Boolean>() {
        public void consume(final Boolean aBoolean) {
            b.setOkActionEnabled(aBoolean);
        }
    });
    return b.show() == DialogWrapper.OK_EXIT_CODE;
}

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 www  . j  av a 2 s .  co 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));
    }/*  w ww. java  2  s. com*/
    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 {/*ww w . ja  v  a 2 s. c  o 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:com.intellij.util.xml.ui.TextControl.java

License:Apache License

@Override
protected TextPanel createMainComponent(TextPanel boundedComponent, final Project project) {
    if (boundedComponent == null) {
        boundedComponent = new TextPanel();
    }//from   ww  w .ja v  a  2s.com
    boundedComponent.removeAll();
    final Function<String, Document> factory = new Function<String, Document>() {
        @Override
        public Document fun(final String s) {
            return PsiDocumentManager.getInstance(project).getDocument(PsiFileFactory.getInstance(project)
                    .createFileFromText("a.txt", PlainTextLanguage.INSTANCE, "", true, false));
        }
    };
    final TextPanel boundedComponent1 = boundedComponent;
    final EditorTextField editorTextField = new EditorTextField(factory.fun(""), project,
            PlainTextFileType.INSTANCE) {
        @Override
        protected EditorEx createEditor() {
            final EditorEx editor = super.createEditor();
            return boundedComponent1 instanceof MultiLineTextPanel
                    ? makeBigEditor(editor, ((MultiLineTextPanel) boundedComponent1).getRowCount())
                    : editor;
        }
    };
    editorTextField.setOneLineMode(false);

    if (boundedComponent instanceof BigTextPanel) {
        final ReferenceEditorWithBrowseButton editor = new ReferenceEditorWithBrowseButton(null,
                editorTextField, factory);
        boundedComponent.add(editor);
        editor.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                EditorTextField textArea = new EditorTextField(editorTextField.getDocument(), project,
                        PlainTextFileType.INSTANCE) {
                    @Override
                    protected EditorEx createEditor() {
                        final EditorEx editor = super.createEditor();
                        editor.setEmbeddedIntoDialogWrapper(true);
                        return makeBigEditor(editor, 5);
                    }
                };
                textArea.setOneLineMode(false);

                DialogBuilder builder = new DialogBuilder(project);
                builder.setDimensionServiceKey("TextControl");
                builder.setCenterPanel(textArea);
                builder.setPreferredFocusComponent(textArea);
                builder.setTitle(UIBundle.message("big.text.control.window.title"));
                builder.addCloseButton();
                builder.show();
            }
        });
        return boundedComponent;
    }

    boundedComponent.add(editorTextField);
    return boundedComponent;
}