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

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

Introduction

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

Prototype

public static void showMessageDialog(String message,
        @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon) 

Source Link

Document

Use this method only if you do not know project or component

Usage

From source file:com.intellij.application.options.SchemesToImportPopup.java

License:Apache License

public void show(Collection<T> schemes) {
    if (schemes.isEmpty()) {
        Messages.showMessageDialog("There are no available schemes to import", "Import",
                Messages.getWarningIcon());
        return;/*from w  ww  .j av  a 2 s  . c o m*/
    }

    final JList list = new JBList(new CollectionListModel<T>(schemes));
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setCellRenderer(new SchemesToImportListCellRenderer());

    Runnable selectAction = new Runnable() {
        @Override
        public void run() {
            onSchemeSelected((T) list.getSelectedValue());
        }
    };

    showList(list, selectAction);
}

From source file:com.intellij.designer.propertyTable.PropertyTable.java

License:Apache License

private static void showInvalidInput(Exception e) {
    Throwable cause = e.getCause();
    String message = cause == null ? e.getMessage() : cause.getMessage();

    if (message == null || message.length() == 0) {
        message = "No message";
    }/*from w w  w  . ja  v a  2  s .  co m*/

    Messages.showMessageDialog(formatErrorGettingValueMesage(message), "Invalid Input",
            Messages.getErrorIcon());
}

From source file:com.intellij.ide.fileTemplates.impl.FTManager.java

License:Apache License

/** Save template to file. If template is new, it is saved to specified directory. Otherwise it is saved to file from which it was read.
 *  If template was not modified, it is not saved.
 *  todo: review saving algorithm/*from ww w .  ja v  a2 s .  c o m*/
 */
private static void saveTemplate(File parentDir, FileTemplateBase template, final String lineSeparator)
        throws IOException {
    final File templateFile = new File(parentDir, template.getName() + "." + template.getExtension());

    FileOutputStream fileOutputStream;
    try {
        fileOutputStream = new FileOutputStream(templateFile);
    } catch (FileNotFoundException e) {
        // try to recover from the situation 'file exists, but is a directory'
        FileUtil.delete(templateFile);
        fileOutputStream = new FileOutputStream(templateFile);
    }
    OutputStreamWriter outputStreamWriter;
    try {
        outputStreamWriter = new OutputStreamWriter(fileOutputStream, CONTENT_ENCODING);
    } catch (UnsupportedEncodingException e) {
        Messages.showMessageDialog(IdeBundle.message("error.unable.to.save.file.template.using.encoding",
                template.getName(), CONTENT_ENCODING), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        outputStreamWriter = new OutputStreamWriter(fileOutputStream);
    }
    String content = template.getText();

    if (!lineSeparator.equals("\n")) {
        content = StringUtil.convertLineSeparators(content, lineSeparator);
    }

    outputStreamWriter.write(content);
    outputStreamWriter.close();
    fileOutputStream.close();
}

From source file:com.intellij.ide.ui.laf.LafManagerImpl.java

License:Apache License

/**
 * Sets current LAF. The method doesn't update component hierarchy.
 */// w w w  . j a  va  2s .  c o  m
@Override
public void setCurrentLookAndFeel(UIManager.LookAndFeelInfo lookAndFeelInfo) {
    if (findLaf(lookAndFeelInfo.getClassName()) == null) {
        LOG.error("unknown LookAndFeel : " + lookAndFeelInfo);
        return;
    }
    try {
        LookAndFeel laf = ((LookAndFeel) Class.forName(lookAndFeelInfo.getClassName()).newInstance());
        if (laf instanceof MetalLookAndFeel) {
            MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
        }

        boolean dark = laf instanceof BuildInLookAndFeel && ((BuildInLookAndFeel) laf).isDark();
        JBColor.setDark(dark);
        IconLoader.setUseDarkIcons(dark);
        fireUpdate();
        UIManager.setLookAndFeel(laf);
    } catch (Exception e) {
        Messages.showMessageDialog(
                IdeBundle.message("error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;
    }
    myCurrentLaf = lookAndFeelInfo;

    checkLookAndFeel(lookAndFeelInfo, false);
}

From source file:com.intellij.ide.util.projectWizard.ExistingModuleLoader.java

License:Apache License

public boolean validate(final Project current, final Project dest) {
    if (getName() == null)
        return false;
    String moduleFilePath = getModuleDirPath();
    if (moduleFilePath == null)
        return false;
    final File file = new File(moduleFilePath);
    if (file.exists()) {
        try {//w  w  w  . j a  v  a 2  s .  co  m
            final ConversionResult result = ConversionService.getInstance().convertModule(dest, file);
            if (result.openingIsCanceled()) {
                return false;
            }
            final Document document = JDOMUtil.loadDocument(file);
            final Element root = document.getRootElement();
            final Set<String> usedMacros = PathMacrosCollector.getMacroNames(root);
            final Set<String> definedMacros = PathMacros.getInstance().getAllMacroNames();
            usedMacros.remove("$" + PathMacrosImpl.MODULE_DIR_MACRO_NAME + "$");
            usedMacros.removeAll(definedMacros);

            if (usedMacros.size() > 0) {
                final boolean ok = ProjectMacrosUtil.showMacrosConfigurationDialog(current, usedMacros);
                if (!ok) {
                    return false;
                }
            }
        } catch (JDOMException e) {
            Messages.showMessageDialog(e.getMessage(), IdeBundle.message("title.error.reading.file"),
                    Messages.getErrorIcon());
            return false;
        } catch (IOException e) {
            Messages.showMessageDialog(e.getMessage(), IdeBundle.message("title.error.reading.file"),
                    Messages.getErrorIcon());
            return false;
        }
    } else {
        Messages.showErrorDialog(current, IdeBundle.message("title.module.file.does.not.exist", moduleFilePath),
                CommonBundle.message("title.error"));
        return false;
    }
    return true;
}

From source file:com.intellij.internal.statistic.tmp.SendStatisticsAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    if (project != null) {
        StatisticsService service = StatisticsUploadAssistant.getStatisticsService();
        StatisticsResult result = service.send();
        Messages.showMessageDialog(result.getDescription(), "Result", AllIcons.FileTypes.Custom);
    }/*w  w  w  . ja v  a  2  s. c  om*/
}

From source file:com.intellij.psi.statistics.impl.StatisticsManagerImpl.java

License:Apache License

private void saveUnit(int unitNumber) {
    if (!createStoreFolder())
        return;/*from ww w .j av  a 2  s  .c o  m*/
    StatisticsUnit unit = getUnit(unitNumber);
    String path = getPathToUnit(unitNumber);
    try {
        OutputStream out = new BufferedOutputStream(new FileOutputStream(path));
        out = new ScrambledOutputStream(out);
        try {
            unit.write(out);
        } finally {
            out.close();
        }
    } catch (IOException e) {
        Messages.showMessageDialog(IdeBundle.message("error.saving.statistics", e.getLocalizedMessage()),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
}

From source file:com.intellij.psi.statistics.impl.StatisticsManagerImpl.java

License:Apache License

private static boolean createStoreFolder() {
    File homeFile = new File(STORE_PATH);
    if (!homeFile.exists()) {
        if (!homeFile.mkdirs()) {
            Messages.showMessageDialog(
                    IdeBundle.message("error.saving.statistic.failed.to.create.folder", STORE_PATH),
                    CommonBundle.getErrorTitle(), Messages.getErrorIcon());
            return false;
        }//  ww w  .  j  a  v a  2 s  .  co m
    }
    return true;
}

From source file:com.intellij.refactoring.rename.RenameProcessor.java

License:Apache License

@Override
public void performRefactoring(UsageInfo[] usages) {
    final int[] choice = myAllRenames.size() > 1 ? new int[] { -1 } : null;
    String message = null;//  ww  w  .  java 2 s .c om
    try {
        for (Iterator<Map.Entry<PsiElement, String>> iterator = myAllRenames.entrySet().iterator(); iterator
                .hasNext();) {
            Map.Entry<PsiElement, String> entry = iterator.next();
            if (entry.getKey() instanceof PsiFile) {
                final PsiFile file = (PsiFile) entry.getKey();
                final PsiDirectory containingDirectory = file.getContainingDirectory();
                if (CopyFilesOrDirectoriesHandler.checkFileExist(containingDirectory, choice, file,
                        entry.getValue(), "Rename")) {
                    iterator.remove();
                    continue;
                }
            }
            RenameUtil.checkRename(entry.getKey(), entry.getValue());
        }
    } catch (IncorrectOperationException e) {
        message = e.getMessage();
    }

    if (message != null) {
        CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("rename.title"), message, getHelpID(),
                myProject);
        return;
    }

    List<Runnable> postRenameCallbacks = new ArrayList<Runnable>();

    final MultiMap<PsiElement, UsageInfo> classified = classifyUsages(myAllRenames.keySet(), usages);
    for (final PsiElement element : myAllRenames.keySet()) {
        String newName = myAllRenames.get(element);

        final RefactoringElementListener elementListener = getTransaction().getElementListener(element);
        final RenamePsiElementProcessor renamePsiElementProcessor = RenamePsiElementProcessor
                .forElement(element);
        Runnable postRenameCallback = renamePsiElementProcessor.getPostRenameCallback(element, newName,
                elementListener);
        final Collection<UsageInfo> infos = classified.get(element);
        try {
            RenameUtil.doRename(element, newName, infos.toArray(new UsageInfo[infos.size()]), myProject,
                    elementListener);
        } catch (final IncorrectOperationException e) {
            RenameUtil.showErrorMessage(e, element, myProject);
            return;
        }
        if (postRenameCallback != null) {
            postRenameCallbacks.add(postRenameCallback);
        }
    }

    for (Runnable runnable : postRenameCallbacks) {
        runnable.run();
    }

    List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<NonCodeUsageInfo>();
    for (UsageInfo usage : usages) {
        if (usage instanceof NonCodeUsageInfo) {
            nonCodeUsages.add((NonCodeUsageInfo) usage);
        }
    }
    myNonCodeUsages = nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
    if (!mySkippedUsages.isEmpty()) {
        if (!ApplicationManager.getApplication().isUnitTestMode()
                && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override
                public void run() {
                    final IdeFrame ideFrame = WindowManager.getInstance().getIdeFrame(myProject);
                    if (ideFrame != null) {

                        StatusBarEx statusBar = (StatusBarEx) ideFrame.getStatusBar();
                        HyperlinkListener listener = new HyperlinkListener() {
                            @Override
                            public void hyperlinkUpdate(HyperlinkEvent e) {
                                if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
                                    return;
                                Messages.showMessageDialog("<html>Following usages were safely skipped:<br>"
                                        + StringUtil.join(mySkippedUsages,
                                                new Function<UnresolvableCollisionUsageInfo, String>() {
                                                    @Override
                                                    public String fun(
                                                            UnresolvableCollisionUsageInfo unresolvableCollisionUsageInfo) {
                                                        return unresolvableCollisionUsageInfo.getDescription();
                                                    }
                                                }, "<br>")
                                        + "</html>", "Not All Usages Were Renamed", null);
                            }
                        };
                        statusBar.notifyProgressByBalloon(MessageType.WARNING,
                                "<html><body>Unable to rename certain usages. <a href=\"\">Browse</a></body></html>",
                                null, listener);
                    }
                }
            }, ModalityState.NON_MODAL);
        }
    }
}

From source file:com.intellij.uiDesigner.palette.Palette.java

License:Apache License

/**
 * Adds specified <code>item</code> to the palette.
 * @param item item to be added//www .j  a v  a  2  s  .c om
 * @exception java.lang.IllegalArgumentException  if an item for the same class
 * is already exists in the palette
 */
public void addItem(@NotNull final GroupItem group, @NotNull final ComponentItem item) {
    // class -> item
    final String componentClassName = item.getClassName();
    if (getItem(componentClassName) != null) {
        Messages.showMessageDialog(UIDesignerBundle.message("error.item.already.added", componentClassName),
                ApplicationNamesInfo.getInstance().getFullProductName(), Messages.getErrorIcon());
        return;
    }
    myClassName2Item.put(componentClassName, item);

    // group -> items
    group.addItem(item);

    // Process special predefined item for JPanel
    if ("javax.swing.JPanel".equals(item.getClassName())) {
        myPanelItem = item;
    }
}