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

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

Introduction

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

Prototype

int CANCEL

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

Click Source Link

Usage

From source file:com.android.tools.idea.gradle.project.sync.setup.post.upgrade.ForcedPluginPreviewVersionUpgradeStepIdeaTest.java

License:Apache License

public void testCheckAndPerformUpgradeWhenUserDeclinesUpgrade() {
    GradleVersion latestPluginVersion = GradleVersion.parse("2.0.0");
    when(myPluginGeneration.getLatestKnownVersion()).thenReturn(latestPluginVersion.toString());
    when(myPluginInfo.getPluginVersion()).thenReturn(GradleVersion.parse("2.0.0-alpha9"));

    // Simulate user canceling upgrade.
    myOriginalTestDialog = ForcedPluginPreviewVersionUpgradeDialog
            .setTestDialog(new TestMessagesDialog(Messages.CANCEL));

    boolean upgraded = myVersionUpgrade.checkAndPerformUpgrade(getProject(), myPluginInfo);
    assertTrue(upgraded);//  w ww .j av  a  2s  .co m

    List<SyncMessage> messages = mySyncMessages.getReportedMessages();
    assertThat(messages).hasSize(1);
    String message = messages.get(0).getText()[1];
    assertThat(message).contains("Please update your project to use version 2.0.0.");

    verify(mySyncState).syncEnded();
    verify(myVersionUpdater, never()).updatePluginVersionAndSync(latestPluginVersion,
            GradleVersion.parse(GRADLE_LATEST_VERSION), true);
}

From source file:com.android.tools.idea.rendering.webp.ConvertFromWebpAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();//w  w w  .  j  a  v a  2 s  .c  om
    if (project == null) {
        return;
    }

    int answer = Messages.showYesNoCancelDialog(project, "Delete .webp files after saving as .png?", TITLE,
            null);
    if (answer == Messages.CANCEL) {
        return;
    }
    boolean delete = answer == Messages.YES;
    VirtualFile[] files = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    perform(project, files, delete);
}

From source file:com.headwire.aem.tooling.intellij.action.VerifyConfigurationAction.java

License:Apache License

/**
 * Verity the project setup//ww  w  . ja  v a  2s .c om
 * @param project
 * @param dataContext
 * @param progressHandler Progress Handler
 * @return True if the project was successfully verified
 */
public boolean doVerify(final Project project, final DataContext dataContext,
        final ProgressHandler progressHandler) {
    ProgressHandler progressHandlerSubTask = progressHandler == null ? new EmptyProgresssHandler()
            : progressHandler.startSubTasks(1, "progress.verify.project", project.getName());
    progressHandlerSubTask.next("progress.verify.check.environment");
    MessageManager messageManager = getMessageManager(project);
    boolean ret = true;
    int exitNow = Messages.OK;
    SlingServerTreeSelectionHandler selectionHandler = getSelectionHandler(project);
    ServerConnectionManager serverConnectionManager = ComponentProvider.getComponent(project,
            ServerConnectionManager.class);
    ServerConfigurationManager serverConfigurationManager = getConfigurationManager(project);
    if (selectionHandler != null && serverConnectionManager != null && messageManager != null) {
        ServerConfiguration source = selectionHandler.getCurrentConfiguration();
        if (source != null) {
            try {
                progressHandlerSubTask.next("progress.verify.rebind.module");
                messageManager.sendInfoNotification("server.configuration.start.verification",
                        source.getName());
                // Before we can verify we need to ensure the Configuration is properly bound to Maven
                List<ServerConfiguration.Module> unboundModules = null;
                try {
                    unboundModules = serverConnectionManager.findUnboundModules(source);
                } catch (IllegalArgumentException e) {
                    messageManager.showAlertWithOptions(NotificationType.ERROR,
                            "server.configuration.verification.failed.due.to.bind.exception", source.getName(),
                            e.getMessage());
                    return false;
                } finally {
                    serverConfigurationManager.updateCurrentServerConfiguration();
                }
                if (unboundModules != null && !unboundModules.isEmpty()) {
                    progressHandlerSubTask.next("progress.verify.update.server.configuration");
                    ret = false;
                    ProgressHandler progressHandlerSubTaskLoop = progressHandlerSubTask
                            .startSubTasks(unboundModules.size(), "Check Server Configuration Modules");
                    for (ServerConfiguration.Module module : unboundModules) {
                        progressHandlerSubTaskLoop.next("progress.veriy.update.server.configuration",
                                module.getName());
                        exitNow = messageManager.showAlertWithOptions(NotificationType.WARNING,
                                "server.configuration.unresolved.module", module.getName());
                        if (exitNow == 1) {
                            source.removeModule(module);
                            if (serverConfigurationManager != null) {
                                serverConfigurationManager.updateServerConfiguration(source);
                            }
                        } else if (exitNow == Messages.CANCEL) {
                            return false;
                        }
                    }
                }
                // Verify each Module to see if all prerequisites are met
                Repository repository = ServerConnectionManager.obtainRepository(source, messageManager);
                if (repository != null) {
                    progressHandlerSubTask.next("progress.verify.check.modules");
                    ProgressHandler progressHandlerSubTaskLoop = progressHandlerSubTask
                            .startSubTasks(2 * source.getModuleList().size(), "progress.verify.check.modules");
                    for (ServerConfiguration.Module module : source.getModuleList()) {
                        progressHandlerSubTaskLoop.next("progress.verify.check.module", module.getName());
                        if (module.isSlingPackage()) {
                            // Check if the Filter is available for Content Modules
                            Filter filter = null;
                            try {
                                filter = module.getSlingProject().loadFilter();
                                if (filter == null) {
                                    ret = false;
                                    exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                            "server.configuration.filter.file.not.found", module.getName());
                                    module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                                    if (exitNow == Messages.CANCEL) {
                                        return false;
                                    }
                                }
                            } catch (ConnectorException e) {
                                ret = false;
                                exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                        "server.configuration.filter.file.failure", module.getName(),
                                        e.getMessage());
                                module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                                if (exitNow == Messages.CANCEL) {
                                    return false;
                                }
                            }
                            // Check if the Content Modules have a Content Resource
                            List<String> resourceList = serverConnectionManager.findContentResources(module);
                            if (resourceList.isEmpty()) {
                                ret = false;
                                exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                        "server.configuration.content.folder.not.found", module.getName());
                                module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                                if (exitNow == Messages.CANCEL) {
                                    return false;
                                }
                            }
                            // Check if Content Module Folders all have a .content.xml
                            Object temp = dataContext.getData(VERIFY_CONTENT_WITH_WARNINGS);
                            boolean verifyWithWarnings = !(temp instanceof Boolean) || ((Boolean) temp);
                            if (verifyWithWarnings && filter != null) {
                                progressHandlerSubTaskLoop.next("progress.verify.check.resource.files");
                                ProgressHandler progressHandlerSubTaskLoop2 = progressHandlerSubTaskLoop
                                        .startSubTasks(resourceList.size(), "Check Resources");
                                // Get the Content Root /jcr_root)
                                for (String contentPath : resourceList) {
                                    progressHandlerSubTaskLoop2.next("progress.verify.check.resource.files",
                                            contentPath);
                                    VirtualFile rootFile = project.getProjectFile().getFileSystem()
                                            .findFileByPath(contentPath);
                                    if (rootFile != null) {
                                        // Loop over all folders and check if .content.xml file is there
                                        Result childResult = checkFolderContent(repository, messageManager,
                                                serverConnectionManager, module, null, rootFile, filter);
                                        if (childResult.isCancelled) {
                                            return false;
                                        } else if (!childResult.isOk) {
                                            ret = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    ret = false;
                }
            } catch (RuntimeException e) {
                messageManager.sendUnexpectedException(e);
            } finally {
                messageManager.sendInfoNotification("server.configuration.end.verification", source.getName());
            }
        }
    }
    return ret;
}

From source file:com.headwire.aem.tooling.intellij.action.VerifyConfigurationAction.java

License:Apache License

private Result checkFolderContent(Repository repository, MessageManager messageManager,
        ServerConnectionManager serverConnectionManager, ServerConfiguration.Module module, File rootDirectory,
        VirtualFile parentDirectory, Filter filter) {
    int exitNow = Messages.OK;
    Result ret = new Result();
    // Loop over all files in the given folder
    for (VirtualFile child : parentDirectory.getChildren()) {
        // We only need to check Folders
        if (child.isDirectory()) {
            // If the Root Directory is null then just started -> Create Root Directory File and work on its children
            if (rootDirectory == null) {
                rootDirectory = new File(parentDirectory.getPath());
            } else {
                // Get Relative Paths
                String relativeParentPath = parentDirectory.getPath()
                        .substring(rootDirectory.getPath().length());
                String relativeChildPath = child.getPath().substring(rootDirectory.getPath().length());
                List<ResourceProxy> childNodes = null;
                FilterResult filterResult = null;
                if (filter != null) {
                    // Check if the Resource is part of the Filter
                    filterResult = filter.filter(relativeChildPath);
                }/*from   www.  j a va  2s . c  om*/
                // We don't need to check anything if it is part of one of the filter entries
                if (filterResult != FilterResult.ALLOW) {
                    if (filterResult == FilterResult.DENY) {
                        ret.failed();
                        // File is not part of a filter entry so it will never be deployed
                        exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                "server.configuration.content.folder.filtered.out", relativeChildPath,
                                module.getName());
                        module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                        if (exitNow == Messages.CANCEL) {
                            return ret.doExit();
                        }
                    } else if (child.findChild(Constants.CONTENT_FILE_NAME) == null) {
                        boolean isOk = false;
                        if (repository != null && childNodes == null) {
                            // First check if there are only folders as children and if all of them are inside the filters
                            boolean isGood = true;
                            for (VirtualFile grandChild : child.getChildren()) {
                                filterResult = filter.filter(relativeChildPath + "/" + grandChild.getName());
                                if (filterResult != FilterResult.ALLOW) {
                                    isGood = false;
                                    break;
                                }
                            }
                            if (isGood) {
                                isOk = true;
                            } else {
                                // .content.xml file not found in the filter -> check if that folder exists on the Server
                                childNodes = serverConnectionManager.getChildrenNodes(repository,
                                        relativeParentPath);
                                for (ResourceProxy childNode : childNodes) {
                                    String path = childNode.getPath();
                                    boolean found = path.equals(relativeChildPath);
                                    if (found) {
                                        isOk = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!isOk) {
                            ret.failed();
                            exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                    "server.configuration.content.folder.configuration.not.found",
                                    relativeChildPath, module.getName());
                            module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                            if (exitNow == Messages.CANCEL) {
                                return ret.doExit();
                            }
                        }
                    }
                }
            }
            // Check the children of the current folder
            Result childResult = checkFolderContent(repository, messageManager, serverConnectionManager, module,
                    rootDirectory, child, filter);
            if (childResult.isCancelled) {
                return ret.doExit();
            } else if (!childResult.isOk) {
                ret.failed();
            }
        }
    }
    return ret;
}

From source file:com.hp.alm.ali.idea.entity.EntityEditManager.java

License:Apache License

@Override
public synchronized void contentRemoveQuery(ContentManagerEvent contentManagerEvent) {
    Entity entity = ((HasEntity) contentManagerEvent.getContent().getComponent()).getEntity();
    if (!edited.containsKey(entity)) {
        // not edited
        return;/*  w w w .  j a v  a2  s  .c om*/
    }
    if (!Boolean.TRUE.equals(edited.get(entity))) {
        // not dirty
        return;
    }
    if (closeContentsCanceled) {
        // dirty and canceled
        contentManagerEvent.consume();
        return;
    }
    switch (askUser()) {
    case Messages.YES:
        // approve
        return;

    case Messages.CANCEL:
        closeContentsCanceled = true;
    }
    // dirty and rejected or canceled
    contentManagerEvent.consume();
}

From source file:com.igormaznitsa.ideamindmap.editor.MindMapDialogProvider.java

License:Apache License

@Override
public Boolean msgConfirmYesNoCancel(final String title, final String text) {
    final int result = Messages.showYesNoCancelDialog(this.project, text, title, Messages.getQuestionIcon());
    return result == Messages.CANCEL ? null : result == Messages.YES;
}

From source file:com.intellij.ide.impl.ProjectUtil.java

License:Apache License

/**
 * @return {@link com.intellij.ide.GeneralSettings#OPEN_PROJECT_SAME_WINDOW}
 *         {@link com.intellij.ide.GeneralSettings#OPEN_PROJECT_NEW_WINDOW}
 *         {@link com.intellij.openapi.ui.Messages#CANCEL} - if user canceled the dialog
 * @param isNewProject//from   ww w.  jav  a2  s.c  o m
 */
public static int confirmOpenNewProject(boolean isNewProject) {
    final GeneralSettings settings = GeneralSettings.getInstance();
    int confirmOpenNewProject = settings.getConfirmOpenNewProject();
    if (confirmOpenNewProject == GeneralSettings.OPEN_PROJECT_ASK) {
        if (isNewProject) {
            int exitCode = Messages.showYesNoDialog(IdeBundle.message("prompt.open.project.in.new.frame"),
                    IdeBundle.message("title.new.project"), IdeBundle.message("button.existingframe"),
                    IdeBundle.message("button.newframe"), Messages.getQuestionIcon(),
                    new ProjectNewWindowDoNotAskOption());
            return exitCode == 0 ? GeneralSettings.OPEN_PROJECT_SAME_WINDOW
                    : GeneralSettings.OPEN_PROJECT_NEW_WINDOW;
        } else {
            int exitCode = Messages.showYesNoCancelDialog(IdeBundle.message("prompt.open.project.in.new.frame"),
                    IdeBundle.message("title.open.project"), IdeBundle.message("button.existingframe"),
                    IdeBundle.message("button.newframe"), CommonBundle.getCancelButtonText(),
                    Messages.getQuestionIcon(), new ProjectNewWindowDoNotAskOption());
            return exitCode == 0 ? GeneralSettings.OPEN_PROJECT_SAME_WINDOW
                    : exitCode == 1 ? GeneralSettings.OPEN_PROJECT_NEW_WINDOW : Messages.CANCEL;
        }
    }
    return confirmOpenNewProject;
}

From source file:com.intellij.ide.plugins.ActionInstallPlugin.java

License:Apache License

private static boolean suggestToEnableInstalledPlugins(final InstalledPluginsTableModel pluginsModel,
        final Set<IdeaPluginDescriptor> disabled, final Set<IdeaPluginDescriptor> disabledDependants,
        final ArrayList<PluginNode> list) {
    if (!disabled.isEmpty() || !disabledDependants.isEmpty()) {
        String message = "";
        if (disabled.size() == 1) {
            message += "Updated plugin '" + disabled.iterator().next().getName() + "' is disabled.";
        } else if (!disabled.isEmpty()) {
            message += "Updated plugins "
                    + StringUtil.join(disabled, new Function<IdeaPluginDescriptor, String>() {
                        @Override
                        public String fun(IdeaPluginDescriptor pluginDescriptor) {
                            return pluginDescriptor.getName();
                        }/*from w  ww.j  a  va2s  . com*/
                    }, ", ") + " are disabled.";
        }

        if (!disabledDependants.isEmpty()) {
            message += "<br>";
            message += "Updated plugin" + (list.size() > 1 ? "s depend " : " depends ") + "on disabled";
            if (disabledDependants.size() == 1) {
                message += " plugin '" + disabledDependants.iterator().next().getName() + "'.";
            } else {
                message += " plugins "
                        + StringUtil.join(disabledDependants, new Function<IdeaPluginDescriptor, String>() {
                            @Override
                            public String fun(IdeaPluginDescriptor pluginDescriptor) {
                                return pluginDescriptor.getName();
                            }
                        }, ", ") + ".";
            }
        }
        message += " Disabled plugins and plugins which depends on disabled plugins won't be activated after restart.";

        int result;
        if (!disabled.isEmpty() && !disabledDependants.isEmpty()) {
            result = Messages.showYesNoCancelDialog(XmlStringUtil.wrapInHtml(message),
                    CommonBundle.getWarningTitle(), "Enable all",
                    "Enable updated plugin" + (disabled.size() > 1 ? "s" : ""),
                    CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
            if (result == Messages.CANCEL)
                return false;
        } else {
            message += "<br>Would you like to enable ";
            if (!disabled.isEmpty()) {
                message += "updated plugin" + (disabled.size() > 1 ? "s" : "");
            } else {
                //noinspection SpellCheckingInspection
                message += "plugin dependenc" + (disabledDependants.size() > 1 ? "ies" : "y");
            }
            message += "?</body></html>";
            result = Messages.showYesNoDialog(message, CommonBundle.getWarningTitle(),
                    Messages.getQuestionIcon());
            if (result == Messages.NO)
                return false;
        }

        if (result == Messages.YES) {
            disabled.addAll(disabledDependants);
            pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true);
        } else if (result == Messages.NO && !disabled.isEmpty()) {
            pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true);
        }
        return true;
    }
    return false;
}

From source file:com.intellij.projectImport.ProjectOpenProcessorBase.java

License:Apache License

@Override
@Nullable//  w ww .  ja  v a 2  s.  c o  m
public Project doOpenProject(@NotNull VirtualFile virtualFile, Project projectToClose,
        boolean forceOpenInNewFrame) {
    try {
        getBuilder().setUpdate(false);
        final WizardContext wizardContext = new WizardContext(null);
        if (virtualFile.isDirectory()) {
            final String[] supported = getSupportedExtensions();
            for (VirtualFile file : getFileChildren(virtualFile)) {
                if (canOpenFile(file, supported)) {
                    virtualFile = file;
                    break;
                }
            }
        }

        wizardContext.setProjectFileDirectory(virtualFile.getParent().getPath());

        if (!doQuickImport(virtualFile, wizardContext))
            return null;

        if (wizardContext.getProjectName() == null) {
            wizardContext.setProjectName(IdeBundle.message("project.import.default.name.dotIdea", getName()));
        }

        final String dotIdeaFilePath = wizardContext.getProjectFileDirectory() + File.separator
                + Project.DIRECTORY_STORE_FOLDER;

        File dotIdeaFile = new File(dotIdeaFilePath);

        String pathToOpen = dotIdeaFile.getParent();

        boolean shouldOpenExisting = false;
        if (!ApplicationManager.getApplication().isHeadlessEnvironment() && dotIdeaFile.exists()) {
            String existingName = "an existing project";

            int result = Messages.showYesNoCancelDialog(projectToClose,
                    IdeBundle.message("project.import.open.existing", existingName, pathToOpen,
                            virtualFile.getName()),
                    IdeBundle.message("title.open.project"),
                    IdeBundle.message("project.import.open.existing.openExisting"),
                    IdeBundle.message("project.import.open.existing.reimport"),
                    CommonBundle.message("button.cancel"), Messages.getQuestionIcon());
            if (result == Messages.CANCEL)
                return null;
            shouldOpenExisting = result == Messages.OK;
        }

        final Project projectToOpen;
        if (shouldOpenExisting) {
            try {
                projectToOpen = ProjectManagerEx.getInstanceEx().loadProject(pathToOpen);
            } catch (IOException e) {
                return null;
            } catch (JDOMException e) {
                return null;
            } catch (InvalidDataException e) {
                return null;
            }
        } else {
            projectToOpen = ProjectManagerEx.getInstanceEx().newProject(wizardContext.getProjectName(),
                    pathToOpen, true, false);

            if (projectToOpen == null || !getBuilder().validate(projectToClose, projectToOpen)) {
                return null;
            }

            projectToOpen.save();

            getBuilder().commit(projectToOpen, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
        }

        if (!forceOpenInNewFrame) {
            NewProjectUtilPlatform.closePreviousProject(projectToClose);
        }
        ProjectUtil.updateLastProjectLocation(pathToOpen);
        ProjectManagerEx.getInstanceEx().openProject(projectToOpen);

        return projectToOpen;
    } finally {
        getBuilder().cleanup();
    }
}

From source file:com.intellij.refactoring.rename.inplace.InplaceRefactoring.java

License:Apache License

protected boolean buildTemplateAndStart(final Collection<PsiReference> refs,
        final Collection<Pair<PsiElement, TextRange>> stringUsages, final PsiElement scope,
        final PsiFile containingFile) {
    final PsiElement context = InjectedLanguageManager.getInstance(containingFile.getProject())
            .getInjectionHost(containingFile);
    myScope = context != null ? context.getContainingFile() : scope;
    final TemplateBuilderImpl builder = new TemplateBuilderImpl(myScope);

    PsiElement nameIdentifier = getNameIdentifier();
    int offset = myEditor.getCaretModel().getOffset();
    PsiElement selectedElement = getSelectedInEditorElement(nameIdentifier, refs, stringUsages, offset);

    boolean subrefOnPrimaryElement = false;
    boolean hasReferenceOnNameIdentifier = false;
    for (PsiReference ref : refs) {
        if (isReferenceAtCaret(selectedElement, ref)) {
            builder.replaceElement(ref, PRIMARY_VARIABLE_NAME, createLookupExpression(selectedElement), true);
            subrefOnPrimaryElement = true;
            continue;
        }/*from   w  w w .j  a v a2  s .  co  m*/
        addVariable(ref, selectedElement, builder, offset);
        hasReferenceOnNameIdentifier |= isReferenceAtCaret(nameIdentifier, ref);
    }
    if (nameIdentifier != null) {
        hasReferenceOnNameIdentifier |= selectedElement.getTextRange().contains(nameIdentifier.getTextRange());
        if (!subrefOnPrimaryElement || !hasReferenceOnNameIdentifier) {
            addVariable(nameIdentifier, selectedElement, builder);
        }
    }
    for (Pair<PsiElement, TextRange> usage : stringUsages) {
        addVariable(usage.first, usage.second, selectedElement, builder);
    }
    addAdditionalVariables(builder);
    try {
        myMarkAction = startRename();
    } catch (final StartMarkAction.AlreadyStartedException e) {
        final Document oldDocument = e.getDocument();
        if (oldDocument != myEditor.getDocument()) {
            final int exitCode = Messages.showYesNoCancelDialog(myProject, e.getMessage(), getCommandName(),
                    "Navigate to Started", "Cancel Started", "Cancel", Messages.getErrorIcon());
            if (exitCode == Messages.CANCEL)
                return true;
            navigateToAlreadyStarted(oldDocument, exitCode);
            return true;
        } else {

            if (!ourRenamersStack.isEmpty() && ourRenamersStack.peek() == this) {
                ourRenamersStack.pop();
                if (!ourRenamersStack.empty()) {
                    myOldName = ourRenamersStack.peek().myOldName;
                }
            }

            revertState();
            final TemplateState templateState = TemplateManagerImpl
                    .getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor));
            if (templateState != null) {
                templateState.gotoEnd(true);
            }
        }
        return false;
    }

    beforeTemplateStart();

    new WriteCommandAction(myProject, getCommandName()) {
        @Override
        protected void run(com.intellij.openapi.application.Result result) throws Throwable {
            startTemplate(builder);
        }
    }.execute();

    if (myBalloon == null) {
        showBalloon();
    }
    return true;
}