Example usage for com.intellij.openapi.ui Messages OK

List of usage examples for com.intellij.openapi.ui Messages OK

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages OK.

Prototype

int OK

To view the source code for com.intellij.openapi.ui Messages OK.

Click Source Link

Usage

From source file:liveplugin.IDEUtil.java

License:Apache License

public static void askIsUserWantsToRestartIde(String message) {
    int answer = showOkCancelDialog(message, "Restart Is Required", "Restart", "Postpone",
            Messages.getQuestionIcon());
    if (answer == Messages.OK) {
        ApplicationManagerEx.getApplicationEx().restart(true);
    }//from w ww. j  a  va 2 s  .  co m
}

From source file:nieldw.plugins.idea.ImportSettings.java

License:Apache License

public static void doImport(String path) {
    File saveFile = new File(path);
    try {//from w  ww .j av  a2 s .c o m
        if (!saveFile.exists()) {
            Messages.showErrorDialog(IdeBundle.message("error.cannot.find.file", presentableFileName(saveFile)),
                    IdeBundle.message("title.file.not.found"));
            return;
        }

        ZipEntry magicEntry = new ZipFile(saveFile).getEntry("IntelliJ IDEA Global Settings");
        if (magicEntry == null) {
            Messages.showErrorDialog(
                    IdeBundle.message("error.file.contains.no.settings.to.import",
                            presentableFileName(saveFile), promptLocationMessage()),
                    IdeBundle.message("title.invalid.file"));
            return;
        }

        ArrayList<ExportableComponent> registeredComponents = new ArrayList<ExportableComponent>();
        Map<File, Set<ExportableComponent>> filesToComponents = ExportSettingsAction
                .getRegisteredComponentsAndFiles(registeredComponents);
        List<ExportableComponent> components = getComponentsStored(saveFile, registeredComponents);
        ChooseComponentsToImportDialog dialog = new ChooseComponentsToImportDialog(components,
                filesToComponents, IdeBundle.message("title.select.components.to.import"),
                IdeBundle.message("prompt.check.components.to.import"));
        dialog.show();
        if (!dialog.isOK())
            return;
        Set<ExportableComponent> chosenComponents = dialog.getExportableComponents();
        Set<String> relativeNamesToExtract = new HashSet<String>();
        for (ExportableComponent chosenComponent : chosenComponents) {
            File[] exportFiles = chosenComponent.getExportFiles();
            for (File exportFile : exportFiles) {
                File configPath = new File(PathManager.getConfigPath());
                String rPath = FileUtil.getRelativePath(configPath, exportFile);
                assert rPath != null;
                String relativePath = FileUtil.toSystemIndependentName(rPath);
                relativeNamesToExtract.add(relativePath);
            }
        }

        relativeNamesToExtract.add(PluginManager.INSTALLED_TXT);

        File tempFile = new File(PathManager.getPluginTempPath() + "/" + saveFile.getName());
        FileUtil.copy(saveFile, tempFile);
        File outDir = new File(PathManager.getConfigPath());
        ImportSettingsFilenameFilter filenameFilter = new ImportSettingsFilenameFilter(relativeNamesToExtract);
        StartupActionScriptManager.ActionCommand unzip = new StartupActionScriptManager.UnzipCommand(tempFile,
                outDir, filenameFilter);
        StartupActionScriptManager.addActionCommand(unzip);
        // remove temp file
        StartupActionScriptManager.ActionCommand deleteTemp = new StartupActionScriptManager.DeleteCommand(
                tempFile);
        StartupActionScriptManager.addActionCommand(deleteTemp);

        UpdateSettings.getInstance().forceCheckForUpdateAfterRestart();

        String key = ApplicationManager.getApplication().isRestartCapable()
                ? "message.settings.imported.successfully.restart"
                : "message.settings.imported.successfully";
        int ret = Messages.showOkCancelDialog(
                IdeBundle.message(key, ApplicationNamesInfo.getInstance().getProductName(),
                        ApplicationNamesInfo.getInstance().getFullProductName()),
                IdeBundle.message("title.restart.needed"), Messages.getQuestionIcon());
        if (ret == Messages.OK) {
            ((ApplicationEx) ApplicationManager.getApplication()).restart(true);
        }
    } catch (ZipException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.reading.settings.file", presentableFileName(saveFile),
                e1.getMessage(), promptLocationMessage()), IdeBundle.message("title.invalid.file"));
    } catch (IOException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.reading.settings.file.2",
                presentableFileName(saveFile), e1.getMessage()), IdeBundle.message("title.error.reading.file"));
    }
}

From source file:org.jetbrains.android.exportSignedPackage.ExportSignedPackageWizard.java

License:Apache License

private void createAndAlignApk(final String apkPath) {
    AndroidPlatform platform = getFacet().getConfiguration().getAndroidPlatform();
    assert platform != null;
    String sdkPath = platform.getSdkData().getLocation();
    String zipAlignPath = sdkPath + File.separatorChar + AndroidCommonUtils.toolPath(SdkConstants.FN_ZIPALIGN);
    File zipalign = new File(zipAlignPath);
    final boolean runZipAlign = zipalign.isFile();
    File destFile = null;/*from   w  w w.j  av  a  2 s. c  o  m*/
    try {
        destFile = runZipAlign ? FileUtil.createTempFile("android", ".apk") : new File(apkPath);
        createApk(destFile);
    } catch (Exception e) {
        showErrorInDispatchThread(e.getMessage());
    }
    if (destFile == null)
        return;

    if (runZipAlign) {
        File realDestFile = new File(apkPath);
        final String message = AndroidCommonUtils.executeZipAlign(zipAlignPath, destFile, realDestFile);
        if (message != null) {
            showErrorInDispatchThread(message);
            return;
        }
    }
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            String title = AndroidBundle.message("android.export.package.wizard.title");
            final Project project = getProject();
            final File apkFile = new File(apkPath);

            final VirtualFile vApkFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(apkFile);
            if (vApkFile != null) {
                vApkFile.refresh(true, false);
            }

            if (!runZipAlign) {
                Messages.showWarningDialog(project,
                        AndroidCommonBundle.message("android.artifact.building.cannot.find.zip.align.error"),
                        title);
            }

            if (ShowFilePathAction.isSupported()) {
                if (Messages.showOkCancelDialog(project,
                        AndroidBundle.message("android.export.package.success.message", apkFile.getName()),
                        title, RevealFileAction.getActionName(), IdeBundle.message("action.close"),
                        Messages.getInformationIcon()) == Messages.OK) {
                    ShowFilePathAction.openFile(apkFile);
                }
            } else {
                Messages.showInfoMessage(project,
                        AndroidBundle.message("android.export.package.success.message", apkFile), title);
            }
        }
    }, ModalityState.NON_MODAL);
}

From source file:org.jetbrains.android.inspections.MoveFileQuickFix.java

License:Apache License

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final XmlFile xmlFile = myFile.getElement();
    if (xmlFile == null) {
        return;/* www  .ja  v  a 2  s  .c om*/
    }

    // Following assertions should be satisfied by xmlFile being passed to the constructor
    final PsiDirectory directory = xmlFile.getContainingDirectory();
    assert directory != null;

    final PsiDirectory parent = directory.getParent();
    assert parent != null;

    PsiDirectory existingDirectory = parent.findSubdirectory(myFolderName);
    final PsiDirectory resultDirectory = existingDirectory == null ? parent.createSubdirectory(myFolderName)
            : existingDirectory;

    final boolean removeFirst;
    if (resultDirectory.findFile(xmlFile.getName()) != null) {
        final String message = String.format("File %s already exists in directory %s. Overwrite it?",
                xmlFile.getName(), resultDirectory.getName());
        removeFirst = Messages.showOkCancelDialog(project, message, "Move Resource File",
                Messages.getWarningIcon()) == Messages.OK;

        if (!removeFirst) {
            // User pressed "Cancel", do nothing
            return;
        }
    } else {
        removeFirst = false;
    }

    new WriteCommandAction.Simple(project, xmlFile) {
        @Override
        protected void run() throws Throwable {
            if (removeFirst) {
                final PsiFile file = resultDirectory.findFile(xmlFile.getName());
                if (file != null) {
                    file.delete();
                }
            }
            MoveFilesOrDirectoriesUtil.doMoveFile(xmlFile, resultDirectory);
        }
    }.execute();
}

From source file:org.jetbrains.idea.svn.checkin.SvnCheckinHandlerFactory.java

License:Apache License

@NotNull
@Override/*from   ww w .  j  a v  a 2 s. c  om*/
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
    final Project project = panel.getProject();
    final Collection<VirtualFile> commitRoots = panel.getRoots();
    return new CheckinHandler() {
        private Collection<Change> myChanges = panel.getSelectedChanges();

        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            return null;
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor,
                PairConsumer<Object, Object> additionalDataConsumer) {
            if (executor instanceof LocalCommitExecutor)
                return ReturnResult.COMMIT;
            final SvnVcs vcs = SvnVcs.getInstance(project);
            final Map<String, Integer> copiesInfo = splitIntoCopies(vcs, myChanges);
            final List<String> repoUrls = new ArrayList<String>();
            for (Map.Entry<String, Integer> entry : copiesInfo.entrySet()) {
                if (entry.getValue() == 3) {
                    repoUrls.add(entry.getKey());
                }
            }
            if (!repoUrls.isEmpty()) {
                final String join = StringUtil.join(repoUrls.toArray(new String[repoUrls.size()]), ",\n");
                final int isOk = Messages.showOkCancelDialog(
                        project, SvnBundle.message("checkin.different.formats.involved",
                                repoUrls.size() > 1 ? 1 : 0, join),
                        "Subversion: Commit Will Split", Messages.getWarningIcon());
                if (Messages.OK == isOk) {
                    return ReturnResult.COMMIT;
                }
                return ReturnResult.CANCEL;
            }
            return ReturnResult.COMMIT;
        }

        @Override
        public void includedChangesChanged() {
            myChanges = panel.getSelectedChanges();
        }

        @Override
        public void checkinSuccessful() {
            if (SvnConfiguration.getInstance(project).isAutoUpdateAfterCommit()) {
                final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project)
                        .getRootsUnderVcs(SvnVcs.getInstance(project));
                final List<FilePath> paths = new ArrayList<FilePath>();
                for (int i = 0; i < roots.length; i++) {
                    VirtualFile root = roots[i];
                    boolean take = false;
                    for (VirtualFile commitRoot : commitRoots) {
                        if (VfsUtil.isAncestor(root, commitRoot, false)) {
                            take = true;
                            break;
                        }
                    }
                    if (!take)
                        continue;
                    paths.add(new FilePathImpl(root));
                }
                if (paths.isEmpty())
                    return;
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        AutoSvnUpdater.run(
                                new AutoSvnUpdater(project, paths.toArray(new FilePath[paths.size()])),
                                ActionInfo.UPDATE.getActionName());
                    }
                }, ModalityState.NON_MODAL);
            }
        }
    };
}

From source file:org.jetbrains.idea.svn.dialogs.CopiesPanel.java

License:Apache License

private void updateList(@NotNull final List<WCInfo> infoList,
        @NotNull final List<WorkingCopyFormat> supportedFormats) {
    myPanel.removeAll();/*from w  ww  . j av  a2  s .c om*/
    final Insets nullIndent = new Insets(1, 3, 1, 0);
    final GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(2, 2, 0, 0), 0, 0);
    gb.insets.left = 4;
    myPanel.add(myRefreshLabel, gb);
    gb.insets.left = 1;

    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    final Insets topIndent = new Insets(10, 3, 0, 0);
    for (final WCInfo wcInfo : infoList) {
        final Collection<WorkingCopyFormat> upgradeFormats = getUpgradeFormats(wcInfo, supportedFormats);

        final VirtualFile vf = lfs.refreshAndFindFileByIoFile(new File(wcInfo.getPath()));
        final VirtualFile root = (vf == null) ? wcInfo.getVcsRoot() : vf;

        final JEditorPane editorPane = new JEditorPane(UIUtil.HTML_MIME, "");
        editorPane.setEditable(false);
        editorPane.setFocusable(true);
        editorPane.setBackground(UIUtil.getPanelBackground());
        editorPane.setOpaque(false);
        editorPane.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    if (CONFIGURE_BRANCHES.equals(e.getDescription())) {
                        if (!checkRoot(root, wcInfo.getPath(), " invoke Configure Branches"))
                            return;
                        BranchConfigurationDialog.configureBranches(myProject, root, true);
                    } else if (FIX_DEPTH.equals(e.getDescription())) {
                        final int result = Messages.showOkCancelDialog(myVcs.getProject(),
                                "You are going to checkout into '" + wcInfo.getPath()
                                        + "' with 'infinity' depth.\n"
                                        + "This will update your working copy to HEAD revision as well.",
                                "Set Working Copy Infinity Depth", Messages.getWarningIcon());
                        if (result == Messages.OK) {
                            // update of view will be triggered by roots changed event
                            SvnCheckoutProvider.checkout(myVcs.getProject(), new File(wcInfo.getPath()),
                                    wcInfo.getRootUrl(), SVNRevision.HEAD, SVNDepth.INFINITY, false, null,
                                    wcInfo.getFormat());
                        }
                    } else if (CHANGE_FORMAT.equals(e.getDescription())) {
                        changeFormat(wcInfo, upgradeFormats);
                    } else if (MERGE_FROM.equals(e.getDescription())) {
                        if (!checkRoot(root, wcInfo.getPath(), " invoke Merge From"))
                            return;
                        mergeFrom(wcInfo, root, editorPane);
                    } else if (CLEANUP.equals(e.getDescription())) {
                        if (!checkRoot(root, wcInfo.getPath(), " invoke Cleanup"))
                            return;
                        new CleanupWorker(new VirtualFile[] { root }, myVcs.getProject(),
                                "action.Subversion.cleanup.progress.title").execute();
                    }
                }
            }

            private boolean checkRoot(VirtualFile root, final String path, final String actionName) {
                if (root == null) {
                    Messages.showWarningDialog(myProject, "Invalid working copy root: " + path,
                            "Can not " + actionName);
                    return false;
                }
                return true;
            }
        });
        editorPane.setBorder(null);
        editorPane.setText(formatWc(wcInfo, upgradeFormats));

        final JPanel copyPanel = new JPanel(new GridBagLayout());

        final GridBagConstraints gb1 = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
                GridBagConstraints.NONE, nullIndent, 0, 0);
        gb1.insets.top = 1;
        gb1.gridwidth = 3;

        gb.insets = topIndent;
        gb.fill = GridBagConstraints.HORIZONTAL;
        ++gb.gridy;

        final JPanel contForCopy = new JPanel(new BorderLayout());
        contForCopy.add(copyPanel, BorderLayout.WEST);
        myPanel.add(contForCopy, gb);

        copyPanel.add(editorPane, gb1);
        gb1.insets = nullIndent;
    }

    myPanel.revalidate();
    myPanel.repaint();
}

From source file:org.jetbrains.idea.svn.integrate.IntegratedSelectedOptionsDialog.java

License:Apache License

public IntegratedSelectedOptionsDialog(final Project project, final SVNURL currentBranch,
        final String selectedBranchUrl) {
    super(project, true);
    myMustSelectBeforeOk = true;/*from  w ww . j  a v a 2  s. c om*/
    myProject = project;
    mySelectedBranchUrl = selectedBranchUrl;
    myVcs = SvnVcs.getInstance(myProject);

    mySelectedRepositoryUUID = SvnUtil.getRepositoryUUID(myVcs, currentBranch);

    setTitle(SvnBundle.message("action.Subversion.integrate.changes.dialog.title"));
    init();

    myWorkingCopiesList.setModel(new DefaultListModel());
    myWorkingCopiesList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent e) {
            setOKActionEnabled((!myMustSelectBeforeOk) || (myWorkingCopiesList.getSelectedIndex() != -1));
        }
    });
    setOKActionEnabled((!myMustSelectBeforeOk) || (myWorkingCopiesList.getSelectedIndex() != -1));

    final List<WorkingCopyInfo> workingCopyInfoList = new ArrayList<WorkingCopyInfo>();
    final Set<String> workingCopies = SvnBranchMapperManager.getInstance().get(mySelectedBranchUrl);
    if (workingCopies != null) {
        for (String workingCopy : workingCopies) {
            workingCopyInfoList.add(new WorkingCopyInfo(workingCopy, underProject(new File(workingCopy))));
        }
    }
    Collections.sort(workingCopyInfoList, WorkingCopyInfoComparator.getInstance());

    for (WorkingCopyInfo info : workingCopyInfoList) {
        ((DefaultListModel) myWorkingCopiesList.getModel()).addElement(info);
    }
    if (!workingCopyInfoList.isEmpty()) {
        myWorkingCopiesList.setSelectedIndex(0);
    }

    SvnConfiguration svnConfig = SvnConfiguration.getInstance(myVcs.getProject());
    myDryRunCheckbox.setSelected(svnConfig.isMergeDryRun());
    myIgnoreWhitespacesCheckBox.setSelected(svnConfig.isIgnoreSpacesInMerge());

    mySourceInfoLabel.setText(SvnBundle
            .message("action.Subversion.integrate.changes.branch.info.source.label.text", currentBranch));
    myTargetInfoLabel.setText(SvnBundle
            .message("action.Subversion.integrate.changes.branch.info.target.label.text", selectedBranchUrl));

    final String addText = SvnBundle.message("action.Subversion.integrate.changes.dialog.add.wc.text");
    final AnAction addAction = new AnAction(addText, addText, IconUtil.getAddIcon()) {
        {
            registerCustomShortcutSet(CommonShortcuts.INSERT, myWorkingCopiesList);
        }

        public void actionPerformed(final AnActionEvent e) {
            final VirtualFile vFile = FileChooser
                    .chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), myProject, null);
            if (vFile != null) {
                final File file = new File(vFile.getPath());
                if (hasDuplicate(file)) {
                    return; // silently do not add duplicate
                }

                final String repositoryUUID = SvnUtil.getRepositoryUUID(myVcs, file);

                // local not consistent copy can not prevent us from integration: only remote local copy is really involved
                if ((mySelectedRepositoryUUID != null) && (!mySelectedRepositoryUUID.equals(repositoryUUID))) {
                    if (Messages.OK == Messages.showOkCancelDialog((repositoryUUID == null)
                            ? SvnBundle.message(
                                    "action.Subversion.integrate.changes.message.not.under.control.text")
                            : SvnBundle.message("action.Subversion.integrate.changes.message.another.wc.text"),
                            getTitle(), UIUtil.getWarningIcon())) {
                        onOkToAdd(file);
                    }
                } else {
                    onOkToAdd(file);
                }
            }
        }
    };

    myGroup.add(addAction);

    final String removeText = SvnBundle.message("action.Subversion.integrate.changes.dialog.remove.wc.text");
    myGroup.add(new AnAction(removeText, removeText, PlatformIcons.DELETE_ICON) {
        {
            registerCustomShortcutSet(CommonShortcuts.getDelete(), myWorkingCopiesList);
        }

        public void update(final AnActionEvent e) {
            final Presentation presentation = e.getPresentation();
            final int idx = (myWorkingCopiesList == null) ? -1 : myWorkingCopiesList.getSelectedIndex();
            presentation.setEnabled(idx != -1);
        }

        public void actionPerformed(final AnActionEvent e) {
            final int idx = myWorkingCopiesList.getSelectedIndex();
            if (idx != -1) {
                final DefaultListModel model = (DefaultListModel) myWorkingCopiesList.getModel();
                final WorkingCopyInfo info = (WorkingCopyInfo) model.get(idx);
                model.removeElementAt(idx);
                SvnBranchMapperManager.getInstance().remove(mySelectedBranchUrl, new File(info.getLocalPath()));
            }
        }
    });
}

From source file:org.jetbrains.idea.svn.integrate.QuickMergeInteractionImpl.java

License:Apache License

private boolean prompt(final String question) {
    return Messages.showOkCancelDialog(myProject, question, myTitle, Messages.getQuestionIcon()) == Messages.OK;
}

From source file:org.jetbrains.idea.svn.treeConflict.MergeFromTheirsResolver.java

License:Apache License

public void execute() {
    int ok = Messages.showOkCancelDialog(myVcs.getProject(),
            (myChange.isMoved()/*ww  w .  j  a v a 2  s . c  o m*/
                    ? SvnBundle.message("confirmation.resolve.tree.conflict.merge.moved", myOldPresentation,
                            myNewPresentation)
                    : SvnBundle.message("confirmation.resolve.tree.conflict.merge.renamed", myOldPresentation,
                            myNewPresentation)),
            TreeConflictRefreshablePanel.TITLE, Messages.getQuestionIcon());
    if (Messages.OK != ok)
        return;

    FileDocumentManager.getInstance().saveAllDocuments();
    //final String name = "Merge changes from theirs for: " + myOldPresentation;

    final Continuation fragmented = Continuation.createFragmented(myVcs.getProject(), false);
    fragmented.addExceptionHandler(VcsException.class, new Consumer<VcsException>() {
        @Override
        public void consume(VcsException e) {
            myWarnings.add(e);
            if (e.isWarning()) {
                return;
            }
            AbstractVcsHelper.getInstance(myVcs.getProject()).showErrors(myWarnings,
                    TreeConflictRefreshablePanel.TITLE);
        }
    });

    final List<TaskDescriptor> tasks = new SmartList<TaskDescriptor>();
    if (SVNNodeKind.DIR.equals(myDescription.getNodeKind())) {
        tasks.add(new PreloadChangesContentsForDir());
    } else {
        tasks.add(new PreloadChangesContentsForFile());
    }
    tasks.add(new ConvertTextPaths());
    tasks.add(new PatchCreator());
    tasks.add(new SelectPatchesInApplyPatchDialog());
    tasks.add(new SelectBinaryFiles());

    fragmented.run(tasks);
}

From source file:org.jetbrains.idea.svn.treeConflict.TreeConflictRefreshablePanel.java

License:Apache License

private ActionListener createRight(final SVNTreeConflictDescription description) {
    return new ActionListener() {
        @Override/*  w w  w  .j a  v  a  2s.  c  o m*/
        public void actionPerformed(ActionEvent e) {
            int ok = Messages.showOkCancelDialog(myVcs.getProject(),
                    "Accept theirs for " + filePath(myPath) + "?", TITLE, Messages.getQuestionIcon());
            if (Messages.OK != ok)
                return;
            FileDocumentManager.getInstance().saveAllDocuments();
            final Paths paths = getPaths(description);
            ProgressManager.getInstance().run(new VcsBackgroundTask<SVNTreeConflictDescription>(
                    myVcs.getProject(), "Accepting theirs for: " + filePath(paths.myMainPath),
                    BackgroundFromStartOption.getInstance(), Collections.singletonList(description), true) {
                @Override
                protected void process(SVNTreeConflictDescription d) throws VcsException {
                    new SvnTreeConflictResolver(myVcs, paths.myMainPath, myCommittedRevision,
                            paths.myAdditionalPath).resolveSelectTheirsFull(d);
                }

                @Override
                public void onSuccess() {
                    super.onSuccess();
                    if (executedOk()) {
                        VcsBalloonProblemNotifier.showOverChangesView(myProject,
                                "Theirs accepted for " + filePath(paths.myMainPath), MessageType.INFO);
                    }
                }
            });
        }
    };
}