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

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

Introduction

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

Prototype

@NotNull
    public static Icon getWarningIcon() 

Source Link

Usage

From source file:com.intellij.execution.junit.JUnit4Framework.java

License:Apache License

@Override
@Nullable//w  w w . j a v a2 s  .c o  m
protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
    PsiMethod method = findSetUpMethod(clazz);
    if (method != null)
        return method;

    PsiManager manager = clazz.getManager();
    PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();

    method = createSetUpPatternMethod(factory);
    PsiMethod existingMethod = clazz.findMethodBySignature(method, false);
    if (existingMethod != null) {
        int exit = ApplicationManager.getApplication().isUnitTestMode() ? DialogWrapper.OK_EXIT_CODE
                : Messages.showOkCancelDialog(
                        "Method setUp already exist but is not annotated as @Before. Annotate?",
                        CommonBundle.getWarningTitle(), Messages.getWarningIcon());
        if (exit == DialogWrapper.OK_EXIT_CODE) {
            new AddAnnotationFix(JUnitUtil.BEFORE_ANNOTATION_NAME, existingMethod)
                    .invoke(existingMethod.getProject(), null, existingMethod.getContainingFile());
            return existingMethod;
        }
    }
    final PsiMethod testMethod = JUnitUtil.findFirstTestMethod(clazz);
    if (testMethod != null) {
        method = (PsiMethod) clazz.addBefore(method, testMethod);
    } else {
        method = (PsiMethod) clazz.add(method);
    }
    JavaCodeStyleManager.getInstance(manager.getProject()).shortenClassReferences(method);

    return method;
}

From source file:com.intellij.execution.TerminateRemoteProcessDialog.java

License:Apache License

public static int show(final Project project, final String sessionName, final TerminateOption option) {
    final String message = option.myAlwaysUseDefault && !option.myDetach
            ? ExecutionBundle.message("terminate.process.confirmation.text", sessionName)
            : ExecutionBundle.message("disconnect.process.confirmation.text", sessionName);
    final String okButtonText = option.myAlwaysUseDefault && !option.myDetach
            ? ExecutionBundle.message("button.terminate")
            : ExecutionBundle.message("button.disconnect");
    final String[] options = new String[] { okButtonText, CommonBundle.getCancelButtonText() };
    return Messages.showDialog(project, message,
            ExecutionBundle.message("process.is.running.dialog.title", sessionName), options, 0,
            Messages.getWarningIcon(), option);
}

From source file:com.intellij.find.replaceInProject.ReplaceInProjectManager.java

License:Apache License

private boolean ensureUsagesWritable(ReplaceContext replaceContext, Collection<Usage> selectedUsages) {
    Set<VirtualFile> readOnlyFiles = null;
    for (final Usage usage : selectedUsages) {
        final VirtualFile file = ((UsageInFile) usage).getFile();

        if (file != null && !file.isWritable()) {
            if (readOnlyFiles == null)
                readOnlyFiles = new HashSet<VirtualFile>();
            readOnlyFiles.add(file);// w w w  .  j av a2 s  . c o m
        }
    }

    if (readOnlyFiles != null) {
        ReadonlyStatusHandler.getInstance(myProject)
                .ensureFilesWritable(VfsUtilCore.toVirtualFileArray(readOnlyFiles));
    }

    if (hasReadOnlyUsages(selectedUsages)) {
        int result = Messages.showOkCancelDialog(replaceContext.getUsageView().getComponent(),
                FindBundle.message("find.replace.occurrences.in.read.only.files.prompt"),
                FindBundle.message("find.replace.occurrences.in.read.only.files.title"),
                Messages.getWarningIcon());
        if (result != Messages.OK) {
            return false;
        }
    }
    return true;
}

From source file:com.intellij.history.integration.ui.views.HistoryDialog.java

License:Apache License

private boolean askForProceeding(Reverter r) throws IOException {
    List<String> questions = r.askUserForProceeding();
    if (questions.isEmpty())
        return true;

    return Messages.showYesNoDialog(myProject,
            message("message.do.you.want.to.proceed", formatQuestions(questions)),
            CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == Messages.YES;
}

From source file:com.intellij.ide.actionMacro.ActionMacroConfigurationPanel.java

License:Apache License

public JPanel getPanel() {
    if (mySplitter == null) {
        mySplitter = new Splitter(false, 0.5f);
        final String value = PropertiesComponent.getInstance().getValue(SPLITTER_PROPORTION);
        if (value != null) {
            mySplitter.setProportion(Float.parseFloat(value));
        }/* w ww.j  a v a 2 s.  c om*/

        mySplitter.setFirstComponent(
                ToolbarDecorator.createDecorator(myMacrosList).setEditAction(new AnActionButtonRunnable() {
                    @Override
                    public void run(AnActionButton button) {
                        final int selIndex = myMacrosList.getSelectedIndex();
                        if (selIndex == -1)
                            return;
                        final ActionMacro macro = (ActionMacro) myMacrosModel.getElementAt(selIndex);
                        String newName;
                        do {
                            newName = Messages.showInputDialog(mySplitter,
                                    IdeBundle.message("prompt.enter.new.name"),
                                    IdeBundle.message("title.rename.macro"), Messages.getQuestionIcon(),
                                    macro.getName(), null);
                            if (newName == null || macro.getName().equals(newName))
                                return;
                        } while (!canRenameMacro(newName));

                        if (myRenamingList == null)
                            myRenamingList = new ArrayList<Pair<String, String>>();
                        myRenamingList.add(new Pair<String, String>(macro.getName(), newName));
                        macro.setName(newName);
                        myMacrosList.repaint();
                    }

                    private boolean canRenameMacro(final String name) {
                        final Enumeration elements = myMacrosModel.elements();
                        while (elements.hasMoreElements()) {
                            final ActionMacro macro = (ActionMacro) elements.nextElement();
                            if (macro.getName().equals(name)) {
                                if (Messages.showYesNoDialog(IdeBundle.message("message.macro.exists", name),
                                        IdeBundle.message("title.macro.name.already.used"),
                                        Messages.getWarningIcon()) != 0) {
                                    return false;
                                }
                                myMacrosModel.removeElement(macro);
                                break;
                            }
                        }
                        return true;
                    }
                }).disableAddAction().disableUpDownActions().createPanel());

        mySplitter.setSecondComponent(ToolbarDecorator.createDecorator(myMacroActionsList)
                .setRemoveAction(new AnActionButtonRunnable() {
                    @Override
                    public void run(AnActionButton button) {
                        final int macrosSelectedIndex = myMacrosList.getSelectedIndex();
                        if (macrosSelectedIndex != -1) {
                            final ActionMacro macro = (ActionMacro) myMacrosModel
                                    .getElementAt(macrosSelectedIndex);
                            macro.deleteAction(myMacroActionsList.getSelectedIndex());
                        }
                        ListUtil.removeSelectedItems(myMacroActionsList);
                    }
                }).disableAddAction().disableUpDownActions().createPanel());
    }
    return mySplitter;
}

From source file:com.intellij.ide.actionMacro.ActionMacroManager.java

License:Apache License

public boolean checkCanCreateMacro(String name) {
    final ActionManagerEx actionManager = (ActionManagerEx) ActionManager.getInstance();
    final String actionId = ActionMacro.MACRO_ACTION_PREFIX + name;
    if (actionManager.getAction(actionId) != null) {
        if (Messages.showYesNoDialog(IdeBundle.message("message.macro.exists", name),
                IdeBundle.message("title.macro.name.already.used"), Messages.getWarningIcon()) != 0) {
            return false;
        }// w ww . j ava  2  s .c  om
        actionManager.unregisterAction(actionId);
        removeMacro(name);
    }

    return true;
}

From source file:com.intellij.ide.actions.ExportSettingsAction.java

License:Apache License

@Override
public void actionPerformed(@Nullable AnActionEvent e) {
    ApplicationManager.getApplication().saveSettings();

    ChooseComponentsToExportDialog dialog = new ChooseComponentsToExportDialog(
            getExportableComponentsMap(true, true), true,
            IdeBundle.message("title.select.components.to.export"),
            IdeBundle.message("prompt.please.check.all.components.to.export"));
    if (!dialog.showAndGet()) {
        return;/*from  ww w. j  av  a  2  s  .c  o  m*/
    }

    Set<ExportableComponent> markedComponents = dialog.getExportableComponents();
    if (markedComponents.isEmpty()) {
        return;
    }

    Set<File> exportFiles = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY);
    for (ExportableComponent markedComponent : markedComponents) {
        ContainerUtil.addAll(exportFiles, markedComponent.getExportFiles());
    }

    final File saveFile = dialog.getExportFile();
    try {
        if (saveFile.exists()) {
            final int ret = Messages.showOkCancelDialog(
                    IdeBundle.message("prompt.overwrite.settings.file",
                            FileUtil.toSystemDependentName(saveFile.getPath())),
                    IdeBundle.message("title.file.already.exists"), Messages.getWarningIcon());
            if (ret != Messages.OK)
                return;
        }
        final JarOutputStream output = new JarOutputStream(
                new BufferedOutputStream(new FileOutputStream(saveFile)));
        try {
            final File configPath = new File(PathManager.getConfigPath());
            final HashSet<String> writtenItemRelativePaths = new HashSet<String>();
            for (File file : exportFiles) {
                final String rPath = FileUtil.getRelativePath(configPath, file);
                assert rPath != null;
                final String relativePath = FileUtil.toSystemIndependentName(rPath);
                if (file.exists()) {
                    ZipUtil.addFileOrDirRecursively(output, saveFile, file, relativePath, null,
                            writtenItemRelativePaths);
                }
            }

            exportInstalledPlugins(saveFile, output, writtenItemRelativePaths);

            final File magicFile = new File(FileUtil.getTempDirectory(),
                    ImportSettingsFilenameFilter.SETTINGS_JAR_MARKER);
            FileUtil.createIfDoesntExist(magicFile);
            magicFile.deleteOnExit();
            ZipUtil.addFileToZip(output, magicFile, ImportSettingsFilenameFilter.SETTINGS_JAR_MARKER,
                    writtenItemRelativePaths, null);
        } finally {
            output.close();
        }
        ShowFilePathAction.showDialog(getEventProject(e),
                IdeBundle.message("message.settings.exported.successfully"),
                IdeBundle.message("title.export.successful"), saveFile, null);
    } catch (IOException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.writing.settings", e1.toString()),
                IdeBundle.message("title.error.writing.file"));
    }
}

From source file:com.intellij.ide.actions.InvalidateCachesAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final Application app = ApplicationManager.getApplication();
    final boolean mac = Messages.canShowMacSheetPanel();
    String[] options = new String[3];
    options[0] = app.isRestartCapable() ? "Invalidate and Restart" : "Invalidate and Exit";
    options[1] = mac ? "Cancel" : "Invalidate";
    options[2] = mac ? "Invalidate" : "Cancel";

    int result = Messages.showYesNoCancelDialog(e.getData(CommonDataKeys.PROJECT),
            "The caches will be invalidated and rebuilt on the next startup.\n"
                    + "WARNING: Local History will be also cleared.\n\n" + "Would you like to continue?\n\n",
            "Invalidate Caches", options[0], options[1], options[2], Messages.getWarningIcon());

    if (result == -1 || result == (mac ? 1 : 2)) {
        return;/*  w  w w .  ja  v a 2 s. co m*/
    }
    FSRecords.invalidateCaches();
    if (result == 0)
        app.restart();
}

From source file:com.intellij.ide.actions.ReloadFromDiskAction.java

License:Apache License

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

    int res = Messages.showOkCancelDialog(project,
            IdeBundle.message("prompt.reload.file.from.disk", psiFile.getVirtualFile().getPresentableUrl()),
            IdeBundle.message("title.reload.file"), Messages.getWarningIcon());
    if (res != 0)
        return;

    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                @Override
                public void run() {
                    PsiManager.getInstance(project).reloadFromDisk(psiFile);
                }
            });
        }
    }, IdeBundle.message("command.reload.from.disk"), null);
}

From source file:com.intellij.ide.actions.SaveAsDirectoryBasedFormatAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    if (project instanceof ProjectEx) {
        final IProjectStore projectStore = ((ProjectEx) project).getStateStore();
        if (StorageScheme.DIRECTORY_BASED != projectStore.getStorageScheme()) {
            final int result = Messages.showOkCancelDialog(project,
                    "Project will be saved and reopened in new Directory-Based format.\nAre you sure you want to continue?",
                    "Save project to Directory-Based format", Messages.getWarningIcon());
            if (result == 0) {
                final VirtualFile baseDir = project.getBaseDir();
                assert baseDir != null;

                File ideaDir = new File(baseDir.getPath(),
                        ProjectEx.DIRECTORY_STORE_FOLDER + File.separatorChar);
                final boolean ok = (ideaDir.exists() && ideaDir.isDirectory()) || createDir(ideaDir);
                if (ok) {
                    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ideaDir);

                    final StateStorageManager storageManager = projectStore.getStateStorageManager();
                    final Collection<String> storageFileNames = new ArrayList<String>(
                            storageManager.getStorageFileNames());
                    for (String file : storageFileNames) {
                        storageManager.clearStateStorage(file);
                    }//from w  ww. j  a  va  2 s  . c  om

                    projectStore.setProjectFilePath(baseDir.getPath());
                    project.save();
                    ProjectUtil.closeAndDispose(project);
                    ProjectUtil.openOrImport(baseDir.getPath(), null, false);
                } else {
                    Messages.showErrorDialog(project,
                            String.format("Unable to create '.idea' directory (%s)", ideaDir),
                            "Error saving project!");
                }
            }
        }
    }
}