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:org.jetbrains.plugins.ruby.ruby.module.wizard.ui.RubySdkSelectStep.java

License:Apache License

@Override
public boolean validate() {
    Sdk jdk = myPanel.getChosenJdk();//from   w  w w.  jav  a2  s .c  o  m
    if (jdk == null) {
        int result = Messages.showYesNoDialog(
                RBundle.message("sdk.error.no.sdk.prompt.messge.confirm.without.sdk"),
                RBundle.message("sdk.select.prompt.title"), Messages.getWarningIcon());
        return result == DialogWrapper.OK_EXIT_CODE;
    }
    if (!RubySdkUtil.isKindOfRubySDK(jdk)) {
        Messages.showErrorDialog(RBundle.message("sdk.error.prompt.message.sdk.not.valid"),
                RBundle.message("sdk.select.prompt.title"));
        return false;
    }
    /* try to set selected SDK as Project default SDK
          final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
            if (!jdk.equals(projectRootManager.getSdk())) {
    int result = Messages.showYesNoDialog(
            RBundle.message("prompt.confirm.default.sdk.change"),
            RBundle.message("title.default.sdk.change"),
            Messages.getQuestionIcon()
    );
    if (result == 1) {
        projectRootManager.setSdk(jdk);
    }
            }*/
    return true;
}

From source file:org.jetbrains.plugins.ruby.ruby.run.confuguration.tests.ui.RMethodList.java

License:Apache License

public static RVirtualMethod showDialog(final RVirtualClass rClass, final Condition<RVirtualMethod> filter,
        @NotNull final RMethodProvider methodProvider, final JComponent parent) {
    final RMethodList RMethodList = new RMethodList(rClass, filter, methodProvider);
    final DialogBuilder builder = new DialogBuilder(parent);
    builder.setCenterPanel(RMethodList);
    builder.setPreferredFocusComponent(RMethodList.myList);
    builder.setTitle(RBundle.message("choose.test.method.dialog.title"));
    return builder.show() == DialogWrapper.OK_EXIT_CODE ? RMethodList.getSelected() : null;
}

From source file:org.jetbrains.plugins.ruby.settings.GeneralSettingsTab.java

License:Apache License

@Override
public void apply() throws ConfigurationException {
    final RApplicationSettings settings = RApplicationSettings.getInstance();
    settings.useConsoleOutputOtherFilters = otherFiltersCheckBox.isSelected();
    settings.useConsoleOutputRubyStacktraceFilter = rubyStacktraceFilterCheckBox.isSelected();
    settings.useConsoleColorMode = colorModeCheckBox.isSelected();
    settings.additionalEnvPATH = myTFAdditioanlPath.getText().trim();

    final boolean isProjectViewStyleChanged = isProjectViewStyleChanged();
    settings.useRubySpecificProjectView = useRubyProjectViewBox.isSelected();
    if (isProjectViewStyleChanged) {
        final int result = Messages.showYesNoDialog(myContentPane.getParent(),
                RBundle.message("settings.plugin.general.tab.use.ruby.project.view.changed.message"),
                RBundle.message("settings.plugin.general.tab.use.ruby.project.view.changed.title"),
                Messages.getQuestionIcon());
        if (result == DialogWrapper.OK_EXIT_CODE) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override/*  w  w  w.j  a v a  2  s .  c o  m*/
                public void run() {
                    // reload all projects
                    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
                        ProjectManager.getInstance().reloadProject(project);
                    }
                }
            }, ModalityState.NON_MODAL);
        }
    }
}

From source file:org.jetbrains.tfsIntegration.core.tfs.conflicts.DialogContentMerger.java

License:Apache License

public boolean mergeContent(Conflict conflict, ContentTriplet contentTriplet, Project project,
        final VirtualFile localFile, String localPath, VcsRevisionNumber serverVersion) {
    TFSVcs.assertTrue(localFile.isWritable(), localFile.getPresentableUrl() + " must be writable");

    MergeDialogCustomizer c = new MergeDialogCustomizer();
    MergeRequest request = DiffRequestFactory.getInstance().createMergeRequest(
            StreamUtil.convertSeparators(contentTriplet.localContent),
            StreamUtil.convertSeparators(contentTriplet.serverContent),
            StreamUtil.convertSeparators(contentTriplet.baseContent), localFile, project,
            ActionButtonPresentation.APPLY, ActionButtonPresentation.CANCEL_WITH_PROMPT);

    request.setWindowTitle(c.getMergeWindowTitle(localFile));
    request.setVersionTitles(new String[] { c.getLeftPanelTitle(localFile), c.getCenterPanelTitle(localFile),
            c.getRightPanelTitle(localFile, serverVersion) });

    // TODO call canShow() first
    DiffManager.getInstance().getDiffTool().show(request);
    if (request.getResult() == DialogWrapper.OK_EXIT_CODE) {
        return true;
    } else {/*from  w w  w  . j a  v  a2  s .  com*/
        request.restoreOriginalContent();
        // TODO maybe MergeVersion.MergeDocumentVersion.restoreOriginalContent() should save document itself?
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
            public void run() {
                final Document document = FileDocumentManager.getInstance().getDocument(localFile);
                if (document != null) {
                    FileDocumentManager.getInstance().saveDocument(document);
                }
            }
        });
        return false;
    }
}

From source file:org.jetbrains.tfsIntegration.ui.SelectLabelForm.java

License:Apache License

public SelectLabelForm(final SelectLabelDialog dialog, final WorkspaceInfo workspace) {
    myLabelsTableModel = new LabelsTableModel();
    myLabelsTable.setModel(myLabelsTableModel);
    myLabelsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    myLabelsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent e) {
            myEventDispatcher.getMulticaster().selectionChanged();
        }/*from  www.ja v  a 2s.c o  m*/
    });

    new DoubleClickListener() {
        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (isLabelSelected()) {
                dialog.close(DialogWrapper.OK_EXIT_CODE);
                return true;
            }
            return false;
        }
    }.installOn(myLabelsTable);

    myFindButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                String owner = myOwnerField.getText().trim();
                if ("".equals(owner)) {
                    owner = null;
                }
                String name = myNameField.getText().trim();
                if ("".equals(name)) {
                    name = null;
                }

                List<VersionControlLabel> labels = workspace.getServer().getVCS().queryLabels(name,
                        VersionControlPath.ROOT_FOLDER, owner, false, null, null, false, getContentPane(),
                        TFSBundle.message("searching.for.label"));
                myLabelsTableModel.setLabels(labels);
            } catch (TfsException ex) {
                myLabelsTableModel.setLabels(Collections.<VersionControlLabel>emptyList());
                Messages.showErrorDialog(myContentPane, ex.getMessage(), "Find Label");
            } finally {
                myEventDispatcher.getMulticaster().selectionChanged();
            }
        }
    });
}

From source file:org.moe.designer.propertyTable.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() : "";

    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(SdkConstants.ATTR_ID, SdkConstants.ANDROID_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  ww w.j  a  v a 2 s  .  c o  m
                                }
                            });
                            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
                        }
                    }
                }
            }
        }
    }

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

From source file:org.moe.designer.rendering.HtmlLinkManager.java

License:Apache License

private static void handleNewClassUrl(@NotNull String url, @NotNull Module module) {
    assert url.startsWith(URL_CREATE_CLASS) : url;
    String s = url.substring(URL_CREATE_CLASS.length());

    final Project project = module.getProject();
    String title = "Create Custom View";

    final String className;
    final String packageName;
    int index = s.lastIndexOf('.');
    //    if (index == -1) {
    //      className = s;
    //      packageName = ManifestInfo.get(module, false).getPackage();
    //      if (packageName == null) {
    //        return;
    //      }/*from   w w w. jav a 2  s  . co  m*/
    //    } else {
    packageName = s.substring(0, index);
    className = s.substring(index + 1);
    //    }
    CreateClassDialog dialog = new CreateClassDialog(project, title, className, packageName,
            CreateClassKind.CLASS, true, module) {
        @Override
        protected boolean reportBaseInSourceSelectionInTest() {
            return true;
        }
    };
    dialog.show();
    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        final PsiDirectory targetDirectory = dialog.getTargetDirectory();
        if (targetDirectory != null) {
            PsiClass newClass = new WriteCommandAction<PsiClass>(project, "Create Class") {
                @Override
                protected void run(@NotNull Result<PsiClass> result) throws Throwable {
                    PsiClass targetClass = JavaDirectoryService.getInstance().createClass(targetDirectory,
                            className);
                    PsiManager manager = PsiManager.getInstance(project);
                    final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
                    final PsiElementFactory factory = facade.getElementFactory();

                    // Extend android.view.View
                    PsiJavaCodeReferenceElement superclassReference = factory
                            .createReferenceElementByFQClassName(CLASS_VIEW, targetClass.getResolveScope());
                    PsiReferenceList extendsList = targetClass.getExtendsList();
                    if (extendsList != null) {
                        extendsList.add(superclassReference);
                    }

                    // Add constructor
                    GlobalSearchScope scope = GlobalSearchScope.allScope(project);
                    PsiJavaFile javaFile = (PsiJavaFile) targetClass.getContainingFile();
                    PsiImportList importList = javaFile.getImportList();
                    if (importList != null) {
                        PsiClass contextClass = JavaPsiFacade.getInstance(project).findClass(CLASS_CONTEXT,
                                scope);
                        if (contextClass != null) {
                            importList.add(factory.createImportStatement(contextClass));
                        }
                        PsiClass attributeSetClass = JavaPsiFacade.getInstance(project)
                                .findClass(CLASS_ATTRIBUTE_SET, scope);
                        if (attributeSetClass != null) {
                            importList.add(factory.createImportStatement(attributeSetClass));
                        }
                    }
                    PsiMethod constructor = factory.createMethodFromText(
                            "public " + className + "(Context context, AttributeSet attrs, int defStyle) {\n"
                                    + "  super(context, attrs, defStyle);\n" + "}\n",
                            targetClass);
                    targetClass.add(constructor);

                    // Format class
                    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject());
                    PsiFile containingFile = targetClass.getContainingFile();
                    if (containingFile != null) {
                        codeStyleManager.reformat(javaFile);
                    }

                    result.setResult(targetClass);
                }
            }.execute().getResultObject();

            if (newClass != null) {
                PsiFile file = newClass.getContainingFile();
                if (file != null) {
                    openEditor(project, file, newClass.getTextOffset());
                }
            }
        }
    }
}

From source file:org.moe.idea.actions.MOENewBindingAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    if (module != null) {
        NewBindingDialog dialog = new NewBindingDialog(module.getProject());
        dialog.show();//from  w w  w .  j a  v a  2 s . c o m
        if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
            VirtualFile file = null;

            String name = dialog.getName();
            String path = ModuleUtils.getModulePath(module);
            if (name != null && !name.isEmpty() && path != null && !path.isEmpty()) {
                File newConfFile = new File(path, name + ".nbc");

                if (!newConfFile.exists()) {
                    try {
                        newConfFile.createNewFile();
                    } catch (IOException e) {
                        LOG.info("Unable create file" + e.getMessage());
                    }

                    file = module.getModuleFile().getParent().getFileSystem()
                            .refreshAndFindFileByPath(newConfFile.getPath());
                    if (file != null && file.exists()) {
                        FileEditorManager.getInstance(module.getProject()).openFile(file, true);
                    }
                }
            }
        }
    }
}

From source file:org.moe.idea.actions.MOENewClassAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    MOECreateClassTemplateDialog dialog = new MOECreateClassTemplateDialog(anActionEvent.getProject(),
            anActionEvent.getDataContext());

    dialog.show();//  ww  w .ja  v  a  2s.  c  o  m

    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return;
    }

    Project project = anActionEvent.getProject();
    if (project == null) {
        return;
    }

    MOEClassTemplate classTemplate = dialog.getClassTemplate();
    if (classTemplate == null) {
        return;
    }

    DataContext dataContext = anActionEvent.getDataContext();

    MOEClassTemplateGenerator generator = new MOEClassTemplateGenerator();
    generator.generate(classTemplate, dataContext);
}

From source file:org.moe.idea.compiler.MOECompileTask.java

License:Apache License

@Override
public boolean execute(CompileContext context) {
    RunConfiguration c = context.getCompileScope().getUserData(CompileStepBeforeRun.RUN_CONFIGURATION);

    if (!(c instanceof MOERunConfiguration)) {
        return true;
    }/*from w  w w.  j ava2 s  . c o  m*/

    final MOERunConfiguration runConfig = (MOERunConfiguration) c;
    isOpenDialog = runConfig.getOpenDeploymentTargetDialog();
    canceled = false;
    runConfig.setCanceled(canceled);

    final MOEToolWindow toolWindow = MOEToolWindow.getInstance(runConfig.getProject());
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        @Override
        public void run() {
            toolWindow.clear();
            if (isOpenDialog) {
                DeviceChooserDialog dialog = new DeviceChooserDialog(runConfig.module(), runConfig);
                dialog.show();
                if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
                    canceled = true;
                    runConfig.setCanceled(canceled);
                }
                isOpenDialog = false;
            }
        }
    });
    try {

        while (isOpenDialog) {
            Thread.sleep(100);
        }

        boolean isMaven = ModuleUtils.isMOEMavenModule(runConfig.module());

        // Start progress
        ProgressIndicator progress = context.getProgressIndicator();
        context.getProgressIndicator().pushState();
        progress.setText("Building MOE application");

        if (canceled) {
            toolWindow.balloon(MessageType.INFO, "BUILD CANCELED");
            return true;
        }

        if (!isMaven) {

            final CompileThread compileThread = new CompileThread(runConfig, context);
            compileThread.start();

            context.addMessage(CompilerMessageCategory.INFORMATION, "Building " + runConfig.moduleName(), null,
                    -1, -1);

            // Wait for completion
            while (compileThread.isAlive() && !progress.isCanceled()) {
                compileThread.join(1000);
            }
            if (compileThread.isAlive() && progress.isCanceled()) {
                compileThread.interrupt();
                compileThread.join(1000);
            }

            // Re-throw error
            if (compileThread.throwable != null) {
                throw compileThread.throwable;
            }

            // Show on failure
            if (compileThread.returnCode != 0) {
                if (!compileThread.canceled) {
                    toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
                    context.addMessage(CompilerMessageCategory.ERROR, "Multi-OS Engine module build failed",
                            null, -1, -1, toolWindow.getNavigatable());
                } else {
                    toolWindow.balloon(MessageType.INFO, "BUILD CANCELED");
                }
                return false;
            }
        } else {
            MOEMavenBuildTask mavenTask = new MOEMavenBuildTask(runConfig, "Building " + runConfig.moduleName(),
                    true);
            boolean result = mavenTask.runTask();
            if (!result) {
                toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
                context.addMessage(CompilerMessageCategory.ERROR, "Multi-OS Engine module build failed", null,
                        -1, -1, toolWindow.getNavigatable());
                return false;
            }
        }

    } catch (Throwable t) {
        toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
        LOG.error("Failed to compile module", t);
        context.addMessage(CompilerMessageCategory.ERROR,
                "Multi-OS Engine module build failed, an internal error occurred", null, -1, -1);
        return false;
    } finally {
        context.getProgressIndicator().popState();
    }
    return true;
}