List of usage examples for com.intellij.openapi.ui Messages getWarningIcon
@NotNull public static Icon getWarningIcon()
From source file:org.cordovastudio.editors.designer.designSurface.CordovaDesignerEditorPanel.java
License:Apache License
protected void showErrorPage(final ErrorInfo info) { storeState();// w w w . j a v a2 s . c o m hideProgress(); myRootComponent = null; myErrorMessages.removeAll(); if (info.myShowStack) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); info.myThrowable.printStackTrace(new PrintStream(stream)); myErrorStack.setText(stream.toString()); myErrorStackLayout.show(myErrorStackPanel, ERROR_STACK_CARD); } else { myErrorStack.setText(null); myErrorStackLayout.show(myErrorStackPanel, ERROR_NO_STACK_CARD); } addErrorMessage(new FixableMessageInfo(true, info.myDisplayMessage, "", "", null, null), Messages.getErrorIcon()); for (FixableMessageInfo message : info.myMessages) { addErrorMessage(message, message.myErrorIcon ? Messages.getErrorIcon() : Messages.getWarningIcon()); } myErrorPanel.revalidate(); myLayout.show(myPanel, ERROR_CARD); getDesignerToolWindow().refresh(true); repaint(); }
From source file:org.evosuite.intellij.IntelliJNotifier.java
License:Open Source License
@Override public void failed(final String message) { SwingUtilities.invokeLater(new Runnable() { @Override/*from w ww . j a v a2 s . c o m*/ public void run() { Messages.showMessageDialog(project, message, title, Messages.getWarningIcon()); } }); }
From source file:org.intellij.lang.xpath.xslt.refactoring.VariableInlineHandler.java
License:Apache License
public static void invoke(@NotNull final XPathVariable variable, Editor editor) { final String type = LanguageFindUsages.INSTANCE.forLanguage(variable.getLanguage()).getType(variable); final Project project = variable.getProject(); final XmlTag tag = ((XsltElement) variable).getTag(); final String expression = tag.getAttributeValue("select"); if (expression == null) { CommonRefactoringUtil.showErrorHint(project, editor, MessageFormat.format("{0} ''{1}'' has no value.", StringUtil.capitalize(type), variable.getName()), TITLE, null); return;//w ww .ja va 2 s . c o m } final Collection<PsiReference> references = ReferencesSearch .search(variable, new LocalSearchScope(tag.getParentTag()), false).findAll(); if (references.size() == 0) { CommonRefactoringUtil.showErrorHint(project, editor, MessageFormat.format("{0} ''{1}'' is never used.", variable.getName()), TITLE, null); return; } boolean hasExternalRefs = false; if (XsltSupport.isTopLevelElement(tag)) { final Query<PsiReference> query = ReferencesSearch.search(variable, GlobalSearchScope.allScope(project), false); hasExternalRefs = !query.forEach(new Processor<PsiReference>() { int allRefs = 0; public boolean process(PsiReference psiReference) { if (++allRefs > references.size()) { return false; } else if (!references.contains(psiReference)) { return false; } return true; } }); } final HighlightManager highlighter = HighlightManager.getInstance(project); final ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); final PsiReference[] psiReferences = references.toArray(new PsiReference[references.size()]); TextRange[] ranges = ContainerUtil.map2Array(psiReferences, TextRange.class, new Function<PsiReference, TextRange>() { public TextRange fun(PsiReference s) { final PsiElement psiElement = s.getElement(); final XmlAttributeValue context = PsiTreeUtil.getContextOfType(psiElement, XmlAttributeValue.class, true); if (psiElement instanceof XPathElement && context != null) { return XsltCodeInsightUtil.getRangeInsideHostingFile((XPathElement) psiElement) .cutOut(s.getRangeInElement()); } return psiElement.getTextRange().cutOut(s.getRangeInElement()); } }); final Editor e = editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor; for (TextRange range : ranges) { final TextAttributes textAttributes = EditorColors.SEARCH_RESULT_ATTRIBUTES.getDefaultAttributes(); final Color color = getScrollmarkColor(textAttributes); highlighter.addOccurrenceHighlight(e, range.getStartOffset(), range.getEndOffset(), textAttributes, HighlightManagerImpl.HIDE_BY_ESCAPE, highlighters, color); } highlighter.addOccurrenceHighlights(e, new PsiElement[] { ((XsltVariable) variable).getNameIdentifier() }, EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES.getDefaultAttributes(), false, highlighters); if (!hasExternalRefs) { if (!ApplicationManager.getApplication().isUnitTestMode() && Messages.showYesNoDialog( MessageFormat.format("Inline {0} ''{1}''? ({2} occurrence{3})", type, variable.getName(), String.valueOf(references.size()), references.size() > 1 ? "s" : ""), TITLE, Messages.getQuestionIcon()) != 0) { return; } } else { if (!ApplicationManager.getApplication().isUnitTestMode() && Messages .showYesNoDialog(MessageFormat.format("Inline {0} ''{1}''? ({2} local occurrence{3})\n" + "\nWarning: It is being used in external files. Its declaration will not be removed.", type, variable.getName(), String.valueOf(references.size()), references.size() > 1 ? "s" : ""), TITLE, Messages.getWarningIcon()) != 0) { return; } } final boolean hasRefs = hasExternalRefs; new WriteCommandAction.Simple(project, "XSLT.Inline", tag.getContainingFile()) { @Override protected void run() throws Throwable { try { for (PsiReference psiReference : references) { final PsiElement element = psiReference.getElement(); if (element instanceof XPathElement) { final XPathElement newExpr = XPathChangeUtil.createExpression(element, expression); element.replace(newExpr); } else { assert false; } } if (!hasRefs) { tag.delete(); } } catch (IncorrectOperationException e) { Logger.getInstance(VariableInlineHandler.class.getName()).error(e); } } }.execute(); }
From source file:org.intellij.plugins.relaxNG.convert.IdeaDriver.java
License:Apache License
@SuppressWarnings({ "ThrowableInstanceNeverThrown" }) public void convert(SchemaType inputType, IdeaErrorHandler errorHandler, VirtualFile... inputFiles) { if (inputFiles.length == 0) { throw new IllegalArgumentException(); }/* w w w . j a va 2 s . c o m*/ try { final InputFormat inFormat = getInputFormat(inputType); if (inputFiles.length > 1) { if (!(inFormat instanceof MultiInputFormat)) { throw new IllegalArgumentException(); } } final VirtualFile inputFile = inputFiles[0]; final SchemaType type = settings.getOutputType(); final String outputType = type.toString().toLowerCase(); final ArrayList<String> inputParams = new ArrayList<>(); if (inputType != SchemaType.DTD) { final Charset charset = inputFile.getCharset(); inputParams.add("encoding=" + charset.name()); } final ArrayList<String> outputParams = new ArrayList<>(); settings.addAdvancedSettings(inputParams, outputParams); // System.out.println("INPUT: " + inputParams); // System.out.println("OUTPUT: " + outputParams); Resolver catalogResolver = BasicResolver.getInstance(); final SchemaCollection sc; final String input = inputFile.getPath(); final String uri = UriOrFile.toUri(input); try { if (inFormat instanceof MultiInputFormat) { final MultiInputFormat format = (MultiInputFormat) inFormat; final String[] uris = new String[inputFiles.length]; for (int i = 0; i < inputFiles.length; i++) { uris[i] = UriOrFile.toUri(inputFiles[i].getPath()); } sc = format.load(uris, ArrayUtil.toStringArray(inputParams), outputType, errorHandler, catalogResolver); } else { sc = inFormat.load(uri, ArrayUtil.toStringArray(inputParams), outputType, errorHandler, catalogResolver); } } catch (IOException e) { errorHandler.fatalError(new SAXParseException(e.getMessage(), null, uri, -1, -1, e)); return; } final File destination = new File(settings.getOutputDestination()); final File outputFile; if (destination.isDirectory()) { final String name = new File(input).getName(); final int ext = name.lastIndexOf('.'); outputFile = new File(destination, (ext > 0 ? name.substring(0, ext) : name) + "." + outputType); } else { outputFile = destination; } try { final int indent = settings.getIndent(); final int length = settings.getLineLength(); final OutputDirectory od = new LocalOutputDirectory(sc.getMainUri(), outputFile, "." + outputType, settings.getOutputEncoding(), length > 0 ? length : DEFAULT_LINE_LENGTH, indent > 0 ? indent : DEFAULT_INDENT) { @Override public Stream open(String sourceUri, String encoding) throws IOException { final String s = reference(null, sourceUri); final File file = new File(outputFile.getParentFile(), s); if (file.exists()) { final String msg = "The file '" + file.getAbsolutePath() + "' already exists. Overwrite it?"; final int choice = Messages.showYesNoDialog(myProject, msg, "Output File Exists", Messages.getWarningIcon()); if (choice == Messages.YES) { return super.open(sourceUri, encoding); } else if (choice == 1) { throw new CanceledException(); } } return super.open(sourceUri, encoding); } }; final OutputFormat of = getOutputFormat(settings.getOutputType()); of.output(sc, od, ArrayUtil.toStringArray(outputParams), inputType.toString().toLowerCase(), errorHandler); } catch (IOException e) { errorHandler.fatalError( new SAXParseException(e.getMessage(), null, UriOrFile.fileToUri(outputFile), -1, -1, e)); } } catch (CanceledException | InvalidParamsException | InputFailedException e) { // user abort } catch (SAXParseException e) { errorHandler.error(e); } catch (OutputFailedException e) { // handled by ErrorHandler } catch (SAXException e) { // cannot happen or is already handled } }
From source file:org.jetbrains.android.exportSignedPackage.CheckModulePanel.java
License:Apache License
public void addWarning(String message) { JLabel label = new JLabel(); label.setIcon(Messages.getWarningIcon()); label.setText("<html><body><b>Warning: " + message + "</b></body></html>"); add(label);// w w w . j a v a 2 s .co m myHasWarnings = true; }
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;//from ww w . ja v a 2 s . c o m } // 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.generate.tostring.GenerateToStringUtils.java
License:Apache License
/** * Handles any exception during the executing on this plugin. * * @param project PSI project//from w w w. jav a 2 s. c o m * @param e the caused exception. * @throws RuntimeException is thrown for severe exceptions */ public static void handleException(Project project, Exception e) throws RuntimeException { log.info(e); if (e instanceof GenerateCodeException) { // code generation error - display velocity error in error dialog so user can identify problem quicker Messages.showMessageDialog(project, "Velocity error generating code - see IDEA log for more details (stacktrace should be in idea.log):\n" + e.getMessage(), "Warning", Messages.getWarningIcon()); } else if (e instanceof PluginException) { // plugin related error - could be recoverable. Messages.showMessageDialog(project, "A PluginException was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Warning", Messages.getWarningIcon()); } else if (e instanceof RuntimeException) { // unknown error (such as NPE) - not recoverable Messages.showMessageDialog(project, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Error", Messages.getErrorIcon()); throw (RuntimeException) e; // throw to make IDEA alert user } else { // unknown error (such as NPE) - not recoverable Messages.showMessageDialog(project, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Error", Messages.getErrorIcon()); throw new RuntimeException(e); // rethrow as runtime to make IDEA alert user } }
From source file:org.jetbrains.idea.maven.indices.MavenRepositoriesConfigurable.java
License:Apache License
private void testServiceConnection(String url) { myTestButton.setEnabled(false);/*from w ww. jav a 2s . c om*/ RepositoryAttachHandler.searchRepositories(myProject, Collections.singletonList(url), new Processor<Collection<MavenRepositoryInfo>>() { @Override public boolean process(Collection<MavenRepositoryInfo> infos) { myTestButton.setEnabled(true); if (infos.isEmpty()) { Messages.showMessageDialog("No repositories found", "Service Connection Failed", Messages.getWarningIcon()); } else { final StringBuilder sb = new StringBuilder(); sb.append(infos.size()).append(infos.size() == 1 ? "repository" : " repositories") .append(" found"); //for (MavenRepositoryInfo info : infos) { // sb.append("\n "); // sb.append(info.getId()).append(" (").append(info.getName()).append(")").append(": ").append(info.getUrl()); //} Messages.showMessageDialog(sb.toString(), "Service Connection Successful", Messages.getInformationIcon()); } return true; } }); }
From source file:org.jetbrains.idea.svn.actions.ShareProjectAction.java
License:Apache License
private static boolean performImpl(final Project project, final SvnVcs activeVcs, final VirtualFile file) throws VcsException { final ShareDialog shareDialog = new ShareDialog(project, file.getName()); shareDialog.show();/*w w w . j a v a 2 s . c o m*/ final String parent = shareDialog.getSelectedURL(); if (shareDialog.isOK() && parent != null) { final Ref<Boolean> actionStarted = new Ref<Boolean>(Boolean.TRUE); final Exception[] error = new Exception[1]; final ShareDialog.ShareTarget shareTarget = shareDialog.getShareTarget(); final ProgressManager progressManager = ProgressManager.getInstance(); if (ShareDialog.ShareTarget.useSelected.equals(shareTarget)) { final boolean folderEmpty = checkRemoteFolder(project, activeVcs, parent, progressManager); if (!folderEmpty) { final int promptAnswer = Messages.showYesNoDialog(project, "Remote folder \"" + parent + "\" is not empty.\nDo you want to continue sharing?", "Share directory", Messages.getWarningIcon()); if (Messages.YES != promptAnswer) return false; } } final WorkingCopyFormat format = SvnCheckoutProvider .promptForWCopyFormat(VfsUtilCore.virtualToIoFile(file), project); actionStarted.set(format != WorkingCopyFormat.UNKNOWN); // means operation cancelled if (format == WorkingCopyFormat.UNKNOWN) { return true; } ExclusiveBackgroundVcsAction.run(project, new Runnable() { public void run() { progressManager.runProcessWithProgressSynchronously(new Runnable() { public void run() { try { final ProgressIndicator indicator = ProgressManager.getInstance() .getProgressIndicator(); final File path = new File(file.getPath()); SvnWorkingCopyFormatHolder.setPresetFormat(format); final SVNURL parenUrl = SVNURL.parseURIEncoded(parent); final SVNURL checkoutUrl; final SVNRevision revision; final String commitText = shareDialog.getCommitText(); if (ShareDialog.ShareTarget.useSelected.equals(shareTarget)) { checkoutUrl = parenUrl; revision = SVNRevision.HEAD; } else if (ShareDialog.ShareTarget.useProjectName.equals(shareTarget)) { final Pair<SVNRevision, SVNURL> pair = createRemoteFolder(activeVcs, parenUrl, file.getName(), commitText); revision = pair.getFirst(); checkoutUrl = pair.getSecond(); } else { final Pair<SVNRevision, SVNURL> pair = createRemoteFolder(activeVcs, parenUrl, file.getName(), commitText); final Pair<SVNRevision, SVNURL> trunkPair = createRemoteFolder(activeVcs, pair.getSecond(), "trunk", commitText); checkoutUrl = trunkPair.getSecond(); revision = trunkPair.getFirst(); if (shareDialog.createStandardStructure()) { createRemoteFolder(activeVcs, pair.getSecond(), "branches", commitText); createRemoteFolder(activeVcs, pair.getSecond(), "tags", commitText); } } if (indicator != null) { indicator.checkCanceled(); indicator.setText(SvnBundle.message( "share.directory.checkout.back.progress.text", checkoutUrl.toString())); } final ClientFactory factory = SvnCheckoutProvider.getFactory(activeVcs, format); factory.createCheckoutClient().checkout(SvnTarget.fromURL(checkoutUrl), path, revision, SVNDepth.INFINITY, false, false, format, null); addRecursively(activeVcs, factory, file); } catch (SVNException e) { error[0] = e; } catch (VcsException e) { error[0] = e; } finally { activeVcs.invokeRefreshSvnRoots(); SvnWorkingCopyFormatHolder.setPresetFormat(null); } } }, SvnBundle.message("share.directory.title"), true, project); } }); if (Boolean.TRUE.equals(actionStarted.get())) { if (error[0] != null) { throw new VcsException(error[0].getMessage()); } Messages.showInfoMessage(project, SvnBundle.message("share.directory.info.message", file.getName()), SvnBundle.message("share.directory.title")); } return true; } return false; }
From source file:org.jetbrains.idea.svn.checkin.SvnCheckinHandlerFactory.java
License:Apache License
@NotNull @Override//w ww . j av 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); } } }; }