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

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

Introduction

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

Prototype

public static void showWarningDialog(@NotNull Component component, String message,
            @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Usage

From source file:com.android.tools.idea.avdmanager.AccelerationErrorSolution.java

License:Apache License

private Runnable getAction() {
    switch (myError.getSolution()) {
    case DOWNLOAD_EMULATOR:
    case UPDATE_EMULATOR:
        return new Runnable() {
            @Override//from  w w  w . ja  v a 2s . c  om
            public void run() {
                try {
                    showQuickFix(ImmutableList.of(SdkConstants.FD_TOOLS, SdkConstants.FD_PLATFORM_TOOLS));
                } finally {
                    reportBack();
                }
            }
        };

    case UPDATE_PLATFORM_TOOLS:
        return new Runnable() {
            @Override
            public void run() {
                try {
                    showQuickFix(ImmutableList.of(SdkConstants.FD_PLATFORM_TOOLS));
                } finally {
                    reportBack();
                }
            }
        };

    case UPDATE_SYSTEM_IMAGES:
        return new Runnable() {
            @Override
            public void run() {
                try {
                    AvdManagerConnection avdManager = AvdManagerConnection.getDefaultAvdManagerConnection();
                    showQuickFix(avdManager.getSystemImageUpdates());
                } finally {
                    reportBack();
                }
            }
        };

    case INSTALL_KVM:
        return new Runnable() {
            @Override
            public void run() {
                try {
                    GeneralCommandLine install = createKvmInstallCommand();
                    if (install == null) {
                        BrowserUtil.browse(KVM_INSTRUCTIONS, myProject);
                    } else {
                        String text = String.format(
                                "Linux systems vary a great deal; the installation steps we will attempt may not work in your particular scenario.\n\n"
                                        + "The steps are:\n\n" + "  %1$s\n\n"
                                        + "If you prefer, you can skip this step and perform the KVM installation steps on your own.\n\n"
                                        + "There might be more details at: %2$s\n",
                                install.getCommandLineString(), KVM_INSTRUCTIONS);
                        int response = Messages.showDialog(text, myError.getSolution().getDescription(),
                                new String[] { "Skip", "Proceed" }, 1, Messages.getQuestionIcon());
                        if (response == 1) {
                            try {
                                execute(install);
                                myChangesMade = true;
                            } catch (ExecutionException ex) {
                                LOG.error(ex);
                                BrowserUtil.browse(KVM_INSTRUCTIONS, myProject);
                                Messages.showWarningDialog(myProject, "Please install KVM on your own",
                                        "Installation Failed");
                            }
                        } else {
                            BrowserUtil.browse(KVM_INSTRUCTIONS, myProject);
                        }
                    }
                } finally {
                    reportBack();
                }
            }
        };

    case INSTALL_HAXM:
    case REINSTALL_HAXM:
        return new Runnable() {
            @Override
            public void run() {
                try {
                    HaxmWizard wizard = new HaxmWizard(false);
                    wizard.init();
                    myChangesMade = wizard.showAndGet();
                } finally {
                    reportBack();
                }
            }
        };

    case TURNOFF_HYPER_V:
        return new Runnable() {
            @Override
            public void run() {
                try {
                    GeneralCommandLine turnHyperVOff = new ElevatedCommandLine();
                    turnHyperVOff.setExePath("bcdedit");
                    turnHyperVOff.addParameters("/set", "hypervisorlaunchtype", "off");
                    turnHyperVOff.setWorkDirectory(FileUtilRt.getTempDirectory());
                    try {
                        execute(turnHyperVOff);
                        promptAndReboot(SOLUTION_REBOOT_AFTER_TURNING_HYPER_V_OFF);
                    } catch (ExecutionException ex) {
                        LOG.error(ex);
                        Messages.showWarningDialog(myProject, SOLUTION_TURN_OFF_HYPER_V, "Operation Failed");
                    }
                } finally {
                    reportBack();
                }
            }
        };

    default:
        return new Runnable() {
            @Override
            public void run() {
                try {
                    Messages.showWarningDialog(myProject, myError.getSolutionMessage(),
                            myError.getSolution().getDescription());
                } finally {
                    reportBack();
                }
            }
        };
    }
}

From source file:com.atlassian.theplugin.idea.config.ProjectConfigurationComponent.java

License:Apache License

private void migrateOldPrivateProjectSettings(final JDomProjectConfigurationDao cfgFactory) {
    final SAXBuilder builder = new SAXBuilder(false);
    final File privateCfgFile = getPrivateOldCfgFilePath();
    boolean someMigrationHappened = false;
    if (privateCfgFile != null) {
        try {/*from w  w w  . j av  a 2  s  .c om*/
            final Document privateRoot = builder.build(privateCfgFile);
            final PrivateProjectConfiguration ppc = cfgFactory
                    .loadOldPrivateConfiguration(privateRoot.getRootElement());
            for (PrivateServerCfgInfo privateServerCfgInfo : ppc.getPrivateServerCfgInfos()) {
                try {
                    final PrivateServerCfgInfo newPsci = privateCfgDao.load(privateServerCfgInfo.getServerId());
                    if (newPsci == null) {
                        privateCfgDao.save(privateServerCfgInfo);
                        someMigrationHappened = true;
                    }
                } catch (ServerCfgFactoryException e) {
                    // ignore here - just don't try to overwrite it with data from old XML file
                }
            }
        } catch (Exception e) {
            handleServerCfgFactoryException(project, e);
        }
    }

    if (someMigrationHappened) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            public void run() {
                int value = Messages.showYesNoCancelDialog(project,
                        "Configuration has been succesfully migrated to new location (home directory).\n"
                                + "Would you like to delete the old configuration file?\n\nDelete file: ["
                                + privateCfgFile + "]",
                        PluginUtil.PRODUCT_NAME + " upgrade process", Messages.getQuestionIcon());

                if (value == DialogWrapper.OK_EXIT_CODE) {
                    if (!privateCfgFile.delete()) {
                        Messages.showWarningDialog(project,
                                "Cannot remove file [" + privateCfgFile.getAbsolutePath()
                                        + "].\nTry removing it manually.\n" + PluginUtil.PRODUCT_NAME
                                        + " should still behave correctly.",
                                PluginUtil.PRODUCT_NAME);
                    }

                }
            }
        });
    }
}

From source file:com.atlassian.theplugin.idea.config.ProjectConfigurationComponent.java

License:Apache License

private void writeXmlFile(final Element element, final String filepath) {
    if (filepath == null) {
        return; // handlig for instance default dummy project
    }//www.  j a va 2  s  . co m
    try {
        final FileWriter writer = new FileWriter(filepath);

        final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
        //outputter.setLineSeparator(System.getProperty("line.separator"));
        outputter.output(element, writer);
        writer.close();
    } catch (IOException e) {
        Messages.showWarningDialog(project,
                "Cannot save project configuration settings to [" + filepath + ":\n" + e.getMessage(), "Error");
    }
}

From source file:com.boxysystems.libraryfinder.view.intellij.actions.AddToModuleClasspathAction.java

License:Apache License

private void addLibrary(LibraryTable libraryTable, String libraryPath, String escapedLibraryURL) {
    if (!isLibraryAlreadyInClasspath(libraryTable, escapedLibraryURL)) {
        Library library = libraryTable.createLibrary();
        Library.ModifiableModel modifiableModel = library.getModifiableModel();
        modifiableModel.addRoot(escapedLibraryURL, OrderRootType.CLASSES);
        modifiableModel.commit();// w w w. ja va2  s.  c  o m
    } else {
        Messages.showWarningDialog(project, "Library '" + libraryPath + "' already exists in classpath!",
                "Warning");
    }
}

From source file:com.github.pshirshov.ShowByteCodeAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = e.getProject();
    if (project == null) {
        return;/*from   w ww .  j  a  v  a 2s . c o  m*/
    }
    final Editor editor = e.getData(CommonDataKeys.EDITOR);

    final PsiElement psiElement = PsiUtils.getPsiElement(dataContext, project, editor);
    if (psiElement == null) {
        return;
    }

    final String psiElementTitle = PsiUtils.getTitle(psiElement);

    final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
    if (virtualFile == null) {
        return;
    }

    final SmartPsiElementPointer element = SmartPointerManager.getInstance(project)
            .createSmartPsiElementPointer(psiElement);

    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Looking for bytecode...") {
        private String myByteCode;
        private String myErrorMessage;
        private String myErrorTitle;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile)
                    && isMarkedForCompilation(project, virtualFile)) {
                myErrorMessage = "Unable to show bytecode for '" + psiElementTitle
                        + "'. Class file does not exist or is out-of-date.";
                myErrorTitle = "Class File Out-Of-Date";
            } else {
                myByteCode = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
                    @Override
                    public String compute() {
                        return new BytecodeConverter(disassembleStrategy).getByteCode(psiElement);
                    }
                });
            }
        }

        @Override
        public void onSuccess() {
            if (project.isDisposed()) {
                return;
            }

            if ((myErrorMessage != null) && (myTitle != null)) {
                Messages.showWarningDialog(project, myErrorMessage, myErrorTitle);
                return;
            }
            final PsiElement targetElement = element.getElement();
            if (targetElement == null) {
                return;
            }

            if (myByteCode == null) {
                Messages.showErrorDialog(project, "Unable to parse class file for '" + psiElementTitle + "'.",
                        "Bytecode not Found");
                return;
            }

            PsiClass psiClass = PsiUtils.getContainingClass(psiElement);

            FileEditorManager manager = FileEditorManager.getInstance(project);

            final String filename = '/' + psiClass.getQualifiedName().replace('.', '/') + ".bc";
            BCEVirtualFile BCEVirtualFile = new BCEVirtualFile(filename, JavaClassFileType.INSTANCE,
                    myByteCode.getBytes(), psiElement, disassembleStrategy);

            for (FileEditor fileEditor : FileEditorManager.getInstance(project).getAllEditors()) {
                if (fileEditor instanceof ByteCodeEditor) {
                    final ByteCodeEditor asBce = (ByteCodeEditor) fileEditor;
                    if (asBce.getFile().getPath().equals(BCEVirtualFile.getPath())) {
                        FileEditorManager.getInstance(project).openFile(asBce.getFile(), true, true);
                        asBce.update(BCEVirtualFile);
                        return;
                    }
                }
            }

            manager.openFile(BCEVirtualFile, true, true);

        }
    });
}

From source file:com.google.cloud.tools.intellij.vcs.SetupCloudRepositoryAction.java

License:Apache License

private static boolean isGitSupported(final Project project) {
    final GitVcsApplicationSettings settings = GitVcsApplicationSettings.getInstance();
    final String executable = settings.getPathToGit();
    final GitVersion version;
    try {//from  w w w  .  j  a va  2s . c o  m
        version = GitVersion.identifyVersion(executable);
    } catch (Exception ex) {
        Messages.showErrorDialog(project, GctBundle.message("uploadtogcp.giterror"), ex.getMessage());
        return false;
    }

    if (!version.isSupported()) {
        Messages.showWarningDialog(project,
                GctBundle.message("uploadtogcp.git.unsupported.message", version.toString(), GitVersion.MIN),
                GctBundle.message("uploadtogcp.giterror"));
        return false;
    }
    return true;
}

From source file:com.google.gct.idea.git.UploadSourceAction.java

License:Apache License

private static boolean isGitSupported(final Project project) {
    final GitVcsApplicationSettings settings = GitVcsApplicationSettings.getInstance();
    final String executable = settings.getPathToGit();
    final GitVersion version;
    try {//w ww . j  ava2 s .c  o m
        version = GitVersion.identifyVersion(executable);
    } catch (Exception e) {
        Messages.showErrorDialog(project, GctBundle.message("uploadtogcp.giterror"), e.getMessage());
        return false;
    }

    if (!version.isSupported()) {
        Messages.showWarningDialog(project,
                GctBundle.message("uploadtogcp.git.unsupported.message", version.toString(), GitVersion.MIN),
                GctBundle.message("uploadtogcp.giterror"));
        return false;
    }
    return true;
}

From source file:com.google.gct.intellij.endpoints.action.GenerateClientLibrariesAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    final Module appEngineModule = e.getData(LangDataKeys.MODULE);

    if (project == null || appEngineModule == null) {
        Messages.showErrorDialog(project, "Please select an App Engine module", ERROR_MESSAGE_TITLE);
        return;/*from   www  .  j ava2  s  .c om*/
    }

    AppEngineMavenProject appEngineMavenProject = AppEngineMavenProject.get(appEngineModule);
    if (appEngineMavenProject == null) {
        Messages.showErrorDialog(project, "Please select a valid Maven enabled App Engine project",
                ERROR_MESSAGE_TITLE);
        return;
    }

    Module androidLibModule = ModuleManager.getInstance(project)
            .findModuleByName(project.getName() + GctConstants.ANDROID_GCM_LIB_MODULE_SUFFIX);
    if (androidLibModule == null) {
        Messages.showWarningDialog(project,
                "Could not find associated Android library module (" + project.getName()
                        + GctConstants.ANDROID_GCM_LIB_MODULE_SUFFIX
                        + "), skipping copying of client libraries into Android",
                "Warning");
    }

    doAction(appEngineMavenProject, androidLibModule);
}

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

License:Apache License

@Override
public void msgWarn(final String text) {
    Messages.showWarningDialog(this.project, text, "Warning");
}

From source file:com.intellij.byteCodeViewer.ShowByteCodeAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null)
        return;/*from  w ww.  ja  va2 s . com*/
    final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);

    final PsiElement psiElement = getPsiElement(dataContext, project, editor);
    if (psiElement == null)
        return;

    final String psiElementTitle = ByteCodeViewerManager.getInstance(project).getTitle(psiElement);

    final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
    if (virtualFile == null)
        return;

    final SmartPsiElementPointer element = SmartPointerManager.getInstance(project)
            .createSmartPsiElementPointer(psiElement);
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Searching byte code...") {
        private String myByteCode;
        private String myErrorMessage;
        private String myErrorTitle;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile)
                    && TranslatingCompilerFilesMonitor.getInstance().isMarkedForCompilation(project,
                            virtualFile)) {
                myErrorMessage = "Unable to show byte code for '" + psiElementTitle
                        + "'. Class file does not exist or is out-of-date.";
                myErrorTitle = "Class File Out-Of-Date";
            } else {
                myByteCode = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
                    @Override
                    public String compute() {
                        return ByteCodeViewerManager.getByteCode(psiElement);
                    }
                });
            }
        }

        @Override
        public void onSuccess() {
            if (project.isDisposed())
                return;

            if (myErrorMessage != null && myTitle != null) {
                Messages.showWarningDialog(project, myErrorMessage, myErrorTitle);
                return;
            }
            final PsiElement targetElement = element.getElement();
            if (targetElement == null)
                return;

            final ByteCodeViewerManager codeViewerManager = ByteCodeViewerManager.getInstance(project);
            if (codeViewerManager.hasActiveDockedDocWindow()) {
                codeViewerManager.doUpdateComponent(targetElement, myByteCode);
            } else {
                if (myByteCode == null) {
                    Messages.showErrorDialog(project,
                            "Unable to parse class file for '" + psiElementTitle + "'.", "Byte Code not Found");
                    return;
                }
                final ByteCodeViewerComponent component = new ByteCodeViewerComponent(project, null);
                component.setText(myByteCode, targetElement);
                Processor<JBPopup> pinCallback = new Processor<JBPopup>() {
                    @Override
                    public boolean process(JBPopup popup) {
                        codeViewerManager.recreateToolWindow(targetElement, targetElement);
                        popup.cancel();
                        return false;
                    }
                };

                final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, null)
                        .setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE)
                        .setProject(project)
                        .setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false)
                        .setResizable(true).setMovable(true)
                        .setRequestFocus(LookupManager.getActiveLookup(editor) == null)
                        .setTitle(psiElementTitle + " Bytecode").setCouldPin(pinCallback).createPopup();
                Disposer.register(popup, component);

                PopupPositionManager.positionPopupInBestPosition(popup, editor, dataContext);
            }
        }
    });
}