List of usage examples for com.intellij.openapi.ui Messages showErrorDialog
public static void showErrorDialog(@Nullable Component component, String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title)
From source file:com.google.idea.blaze.java.libraries.ExcludeLibraryAction.java
License:Open Source License
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject();//from ww w. j a va 2 s . co m assert project != null; BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData(); if (blazeProjectData == null) { return; } Library library = LibraryActionHelper.findLibraryForAction(e); if (library == null) { return; } BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library); if (blazeLibrary == null) { Messages.showErrorDialog(project, "Could not find this library in the project.", CommonBundle.getErrorTitle()); return; } final LibraryArtifact libraryArtifact = blazeLibrary.libraryArtifact; final String path = libraryArtifact.jarForIntellijLibrary().getRelativePath(); ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> { ListSection<Glob> existingSection = builder.getLast(ExcludeLibrarySection.KEY); builder.replace(existingSection, ListSection.update(ExcludeLibrarySection.KEY, existingSection).add(new Glob(path))); return true; }); if (edit == null) { Messages.showErrorDialog( "Could not modify project view. Check for errors in your project view and try again", "Error"); return; } edit.apply(); BlazeSyncManager.getInstance(project) .requestProjectSync(new BlazeSyncParams.Builder("Sync", BlazeSyncParams.SyncMode.INCREMENTAL) .addProjectViewTargets(true) .addWorkingSet(BlazeUserSettings.getInstance().getExpandSyncToWorkingSet()).build()); }
From source file:com.google.idea.blaze.java.libraries.LibraryActionHelper.java
License:Open Source License
static BlazeJarLibrary findLibraryFromIntellijLibrary(Project project, BlazeProjectData blazeProjectData, Library library) {/* w ww .j a va 2 s. c o m*/ LibraryKey libraryKey = LibraryKey.fromIntelliJLibrary(library); BlazeJavaSyncData syncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class); if (syncData == null) { Messages.showErrorDialog(project, "Project isn't synced. Please resync project.", "Error"); return null; } BlazeLibrary blazeLibrary = syncData.importResult.libraries.get(libraryKey); if (!(blazeLibrary instanceof BlazeJarLibrary)) { return null; } return (BlazeJarLibrary) blazeLibrary; }
From source file:com.google.idea.blaze.java.wizard.BlazeImportNewJavaProjectAction.java
License:Open Source License
private static void handleImportException(@Nullable Project project, Exception e) { String message = String.format("Project import failed: %s", e.getMessage()); Messages.showErrorDialog(project, message, "Import Project"); LOG.error(e);//w ww .j a va2 s .c om }
From source file:com.igormaznitsa.ideamindmap.editor.MindMapDialogProvider.java
License:Apache License
@Override public void msgError(final String text) { Messages.showErrorDialog(this.project, text, "Error"); }
From source file:com.igormaznitsa.ideamindmap.utils.IdeaUtils.java
License:Apache License
public static FileEditPanel.DataContainer editFilePath(final MindMapDocumentEditor editor, final String title, final File projectFolder, final FileEditPanel.DataContainer data) { final FileEditPanel filePathEditor = new FileEditPanel(editor.getDialogProvider(), projectFolder, data); filePathEditor.doLayout();//w ww . java 2 s .c o m filePathEditor.setPreferredSize(new Dimension(450, filePathEditor.getPreferredSize().height)); if (plainMessageOkCancel(editor.getProject(), title, filePathEditor)) { final FileEditPanel.DataContainer result = filePathEditor.getData(); if (result.isValid()) { return result; } else { Messages.showErrorDialog(editor.getMindMapPanel(), String.format(BUNDLE.getString("MMDGraphEditor.editFileLinkForTopic.errorCantFindFile"), result.getPath()), "Error"); return null; } } else { return null; } }
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;// ww w. j av a 2 s .c o m 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); } } }); }
From source file:com.intellij.codeEditor.printing.ExportToHTMLManager.java
License:Apache License
/** * Should be invoked in event dispatch thread *//*w w w. jav a 2s. c o m*/ public static void executeExport(final DataContext dataContext) throws FileNotFoundException { PsiDirectory psiDirectory = null; PsiElement psiElement = LangDataKeys.PSI_ELEMENT.getData(dataContext); if (psiElement instanceof PsiDirectory) { psiDirectory = (PsiDirectory) psiElement; } final PsiFile psiFile = LangDataKeys.PSI_FILE.getData(dataContext); Project project = CommonDataKeys.PROJECT.getData(dataContext); String shortFileName = null; String directoryName = null; if (psiFile != null || psiDirectory != null) { if (psiFile != null) { shortFileName = psiFile.getVirtualFile().getName(); if (psiDirectory == null) { psiDirectory = psiFile.getContainingDirectory(); } } if (psiDirectory != null) { directoryName = psiDirectory.getVirtualFile().getPresentableUrl(); } } Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); boolean isSelectedTextEnabled = false; if (editor != null && editor.getSelectionModel().hasSelection()) { isSelectedTextEnabled = true; } ExportToHTMLDialog exportToHTMLDialog = new ExportToHTMLDialog(shortFileName, directoryName, isSelectedTextEnabled, project); ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(project); if (exportToHTMLSettings.OUTPUT_DIRECTORY == null) { final VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) { exportToHTMLSettings.OUTPUT_DIRECTORY = baseDir.getPresentableUrl() + File.separator + "exportToHTML"; } else { exportToHTMLSettings.OUTPUT_DIRECTORY = ""; } } exportToHTMLDialog.reset(); exportToHTMLDialog.show(); if (!exportToHTMLDialog.isOK()) { return; } try { exportToHTMLDialog.apply(); } catch (ConfigurationException e) { Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle()); } PsiDocumentManager.getInstance(project).commitAllDocuments(); final String outputDirectoryName = exportToHTMLSettings.OUTPUT_DIRECTORY; if (exportToHTMLSettings.getPrintScope() != PrintSettings.PRINT_DIRECTORY) { if (psiFile == null || psiFile.getText() == null) { return; } final String dirName = constructOutputDirectory(psiFile, outputDirectoryName); HTMLTextPainter textPainter = new HTMLTextPainter(psiFile, project, dirName, exportToHTMLSettings.PRINT_LINE_NUMBERS); if (exportToHTMLSettings.getPrintScope() == PrintSettings.PRINT_SELECTED_TEXT && editor != null && editor.getSelectionModel().hasSelection()) { int firstLine = editor.getDocument().getLineNumber(editor.getSelectionModel().getSelectionStart()); textPainter.setSegment(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd(), firstLine); } textPainter.paint(null, psiFile.getFileType()); if (exportToHTMLSettings.OPEN_IN_BROWSER) { BrowserUtil.launchBrowser(textPainter.getHTMLFileName()); } } else { myLastException = null; ExportRunnable exportRunnable = new ExportRunnable(exportToHTMLSettings, psiDirectory, outputDirectoryName, project); ProgressManager.getInstance().runProcessWithProgressSynchronously(exportRunnable, CodeEditorBundle.message("export.to.html.title"), true, project); if (myLastException != null) { throw myLastException; } } }
From source file:com.intellij.codeEditor.printing.PrintManager.java
License:Apache License
public static void executePrint(DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); final PrinterJob printerJob = PrinterJob.getPrinterJob(); final PsiDirectory[] psiDirectory = new PsiDirectory[1]; PsiElement psiElement = LangDataKeys.PSI_ELEMENT.getData(dataContext); if (psiElement instanceof PsiDirectory) { psiDirectory[0] = (PsiDirectory) psiElement; }/*from w w w. j a va 2 s.c o m*/ final PsiFile psiFile = LangDataKeys.PSI_FILE.getData(dataContext); final String[] shortFileName = new String[1]; final String[] directoryName = new String[1]; if (psiFile != null || psiDirectory[0] != null) { if (psiFile != null) { shortFileName[0] = psiFile.getVirtualFile().getName(); if (psiDirectory[0] == null) { psiDirectory[0] = psiFile.getContainingDirectory(); } } if (psiDirectory[0] != null) { directoryName[0] = psiDirectory[0].getVirtualFile().getPresentableUrl(); } } Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); String text = null; if (editor != null) { if (editor.getSelectionModel().hasSelection()) { text = CodeEditorBundle.message("print.selected.text.radio"); } else { text = psiFile == null ? "Console text" : null; } } PrintDialog printDialog = new PrintDialog(shortFileName[0], directoryName[0], text, project); printDialog.reset(); printDialog.show(); if (!printDialog.isOK()) { return; } printDialog.apply(); final PageFormat pageFormat = createPageFormat(); PrintSettings printSettings = PrintSettings.getInstance(); Printable painter; if (printSettings.getPrintScope() != PrintSettings.PRINT_DIRECTORY) { if (psiFile == null && editor == null) return; TextPainter textPainter = psiFile != null ? initTextPainter(psiFile, editor) : initTextPainter((DocumentEx) editor.getDocument(), project); if (textPainter == null) return; if (printSettings.getPrintScope() == PrintSettings.PRINT_SELECTED_TEXT && editor != null && editor.getSelectionModel().hasSelection()) { int firstLine = editor.getDocument().getLineNumber(editor.getSelectionModel().getSelectionStart()); textPainter.setSegment(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd(), firstLine + 1); } painter = textPainter; } else { List<Pair<PsiFile, Editor>> filesList = ContainerUtil.newArrayList(); boolean isRecursive = printSettings.isIncludeSubdirectories(); addToPsiFileList(psiDirectory[0], filesList, isRecursive); painter = new MultiFilePainter(filesList); } final Printable painter0 = painter; Pageable document = new Pageable() { @Override public int getNumberOfPages() { return Pageable.UNKNOWN_NUMBER_OF_PAGES; } @Override public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException { return pageFormat; } @Override public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException { return painter0; } }; try { printerJob.setPageable(document); printerJob.setPrintable(painter, pageFormat); if (!printerJob.printDialog()) { return; } } catch (Exception e) { // In case print dialog is not supported on some platform. Strange thing but there was a checking // for Windows only... } PsiDocumentManager.getInstance(project).commitAllDocuments(); ProgressManager.getInstance().run(new Task.Backgroundable(project, CodeEditorBundle.message("print.progress"), true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { @Override public void run(@NotNull ProgressIndicator indicator) { try { ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); if (painter0 instanceof MultiFilePainter) { ((MultiFilePainter) painter0).setProgress(progress); } else { ((TextPainter) painter0).setProgress(progress); } printerJob.print(); } catch (final PrinterException e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle()); } }); LOG.info(e); } catch (ProcessCanceledException e) { printerJob.cancel(); } } }); }
From source file:com.intellij.codeInsight.daemon.impl.AttachSourcesNotificationProvider.java
License:Apache License
public EditorNotificationPanel createNotificationPanel(final VirtualFile file, FileEditor fileEditor) { if (file.getFileType() != JavaClassFileType.INSTANCE) return null; final List<LibraryOrderEntry> libraries = findOrderEntriesContainingFile(file); if (libraries == null) return null; PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); final String fqn = JavaEditorFileSwapper.getFQN(psiFile); if (fqn == null) return null; if (JavaEditorFileSwapper.findSourceFile(myProject, file) != null) return null; final EditorNotificationPanel panel = new EditorNotificationPanel(); final VirtualFile sourceFile = findSourceFile(file); final AttachSourcesProvider.AttachSourcesAction defaultAction; if (sourceFile != null) { panel.setText(ProjectBundle.message("library.sources.not.attached")); defaultAction = new AttachJarAsSourcesAction(file); } else {//from ww w. j a v a 2 s . c om panel.setText(ProjectBundle.message("library.sources.not.found")); defaultAction = new ChooseAndAttachSourcesAction(myProject, panel); } List<AttachSourcesProvider.AttachSourcesAction> actions = new ArrayList<AttachSourcesProvider.AttachSourcesAction>(); boolean hasNonLightAction = false; for (AttachSourcesProvider each : AttachSourcesProvider.EP_NAME.getExtensions()) { for (AttachSourcesProvider.AttachSourcesAction action : each.getActions(libraries, psiFile)) { if (hasNonLightAction) { if (action instanceof AttachSourcesProvider.LightAttachSourcesAction) { continue; // Don't add LightAttachSourcesAction if non light action exists. } } else { if (!(action instanceof AttachSourcesProvider.LightAttachSourcesAction)) { actions.clear(); // All previous actions is LightAttachSourcesAction and should be removed. hasNonLightAction = true; } } actions.add(action); } } Collections.sort(actions, new Comparator<AttachSourcesProvider.AttachSourcesAction>() { public int compare(AttachSourcesProvider.AttachSourcesAction o1, AttachSourcesProvider.AttachSourcesAction o2) { return o1.getName().compareToIgnoreCase(o2.getName()); } }); actions.add(defaultAction); for (final AttachSourcesProvider.AttachSourcesAction each : actions) { panel.createActionLabel(GuiUtils.getTextWithoutMnemonicEscaping(each.getName()), new Runnable() { public void run() { if (!Comparing.equal(libraries, findOrderEntriesContainingFile(file))) { Messages.showErrorDialog(myProject, "Cannot find library for " + StringUtil.getShortName(fqn), "Error"); return; } panel.setText(each.getBusyText()); Runnable onFinish = new Runnable() { public void run() { SwingUtilities.invokeLater(new Runnable() { public void run() { panel.setText(ProjectBundle.message("library.sources.not.found")); } }); } }; ActionCallback callback = each.perform(findOrderEntriesContainingFile(file)); callback.doWhenRejected(onFinish); callback.doWhenDone(onFinish); } }); } return panel; }
From source file:com.intellij.codeInsight.daemon.impl.quickfix.LocateLibraryDialog.java
License:Apache License
@Nullable private String getResultingPath() { final File srcFile = new File(myLibraryFile.getText()); if (!srcFile.exists()) { Messages.showErrorDialog(myProject, QuickFixBundle.message("add.library.error.not.found", srcFile.getPath()), QuickFixBundle.message("add.library.title.error")); return null; }/*from ww w . j a va2 s.c o m*/ if (!myCopyToRadioButton.isSelected()) { return srcFile.getPath(); } final String dstDir = myCopyToDir.getText(); if (dstDir.length() == 0) { return null; } File dstFile = new File(dstDir, srcFile.getName()); try { FileUtil.copy(srcFile, dstFile); return dstFile.getPath(); } catch (IOException e) { Messages.showErrorDialog(myProject, QuickFixBundle.message("add.library.error.cannot.copy", srcFile.getPath(), dstFile.getPath(), e.getMessage()), QuickFixBundle.message("add.library.title.error")); return null; } }