List of usage examples for com.intellij.openapi.ui DialogWrapper CANCEL_EXIT_CODE
int CANCEL_EXIT_CODE
To view the source code for com.intellij.openapi.ui DialogWrapper CANCEL_EXIT_CODE.
Click Source Link
From source file:org.twodividedbyzero.idea.findbugs.actions.ImportBugCollection.java
License:Open Source License
@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") @Override/*from ww w .ja va 2 s. c om*/ void actionPerformedImpl(@NotNull final AnActionEvent e, @NotNull final Project project, @Nullable final Module module, @NotNull final FindBugsPlugin plugin, @NotNull final ToolWindow toolWindow, @NotNull final FindBugsState state, @NotNull final FindBugsPreferences preferences) { final DialogBuilder dialogBuilder = new DialogBuilder(project); dialogBuilder.addOkAction(); dialogBuilder.addCancelAction(); dialogBuilder.setTitle("Import previous saved bug collection xml"); final String exportDir = preferences.getProperty(FindBugsPreferences.EXPORT_BASE_DIR, FindBugsPluginConstants.DEFAULT_EXPORT_DIR) + File.separatorChar + project.getName(); final ImportFileDialog importFileDialog = new ImportFileDialog(exportDir, dialogBuilder); dialogBuilder.showModal(true); if (dialogBuilder.getDialogWrapper().getExitCode() == DialogWrapper.CANCEL_EXIT_CODE) { return; } final String fileToImport = importFileDialog.getText(); if (fileToImport == null || fileToImport.trim().isEmpty()) { return; } final BugCollection bugCollection = plugin.getToolWindowPanel().getBugCollection(); if (bugCollection != null && !bugCollection.getCollection().isEmpty()) { //noinspection DialogTitleCapitalization final int result = Messages.showYesNoDialog(project, "Current result in the 'Found bugs view' will be deleted. Continue ?", "Delete found bugs?", Messages.getQuestionIcon()); if (result == 1) { return; } } final AtomicBoolean taskCanceled = new AtomicBoolean(); final TransferToEDTQueue<Runnable> transferToEDTQueue = new TransferToEDTQueue<Runnable>( "Add New Bug Instance", new Processor<Runnable>() { @Override public boolean process(Runnable runnable) { runnable.run(); return true; } }, new Condition<Object>() { @Override public boolean value(Object o) { return project.isDisposed() || taskCanceled.get(); } }, 500); //Create a task to import the bug collection from XML final BackgroundableTask task = new BackgroundableTask(project, "Importing Findbugs Result", true) { private ProgressIndicator _indicator; @SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" }) @Override public void run(@NotNull final ProgressIndicator indicator) { MessageBusManager.publishAnalysisStartedToEDT(project); setProgressIndicator(indicator); indicator.setFraction(0.0); indicator.setIndeterminate(false); indicator.setText(fileToImport); SortedBugCollection importBugCollection = null; try { final SortedBugCollection bugCollection = new SortedBugCollection(); final FindBugsPlugin pluginComponent = IdeaUtilImpl.getPluginComponent(project); importBugCollection = bugCollection.createEmptyCollectionWithMetadata(); final edu.umd.cs.findbugs.Project importProject = importBugCollection.getProject(); importProject.setGuiCallback(new PluginGuiCallback(pluginComponent)); importBugCollection.setDoNotUseCloud(true); for (final Plugin plugin : Plugin.getAllPlugins()) { importProject.setPluginStatusTrinary(plugin.getPluginId(), !preferences.isPluginDisabled(plugin.getPluginId())); } importBugCollection.readXML(fileToImport); final ProjectStats projectStats = importBugCollection.getProjectStats(); int bugCount = 0; for (final BugInstance bugInstance : importBugCollection) { if (indicator.isCanceled()) { taskCanceled.set(true); MessageBusManager.publishAnalysisAbortedToEDT(project); Thread.currentThread().interrupt(); return; } final Integer bugCounter = bugCount++; final double fraction = bugCounter.doubleValue() / projectStats.getTotalBugs(); indicator.setFraction(fraction); indicator.setText2("Importing bug '" + bugCount + "' of '" + projectStats.getTotalBugs() + "' - " + bugInstance.getMessageWithoutPrefix()); /** * Guarantee thread visibility *one* time. */ final AtomicReference<BugInstance> bugInstanceRef = New.atomicRef(bugInstance); final AtomicReference<ProjectStats> projectStatsRef = New.atomicRef(projectStats); transferToEDTQueue.offer(new Runnable() { /** * Invoked by EDT. */ @Override public void run() { MessageBusManager.publishNewBugInstance(project, bugInstanceRef.get(), projectStatsRef.get()); } }); } EventDispatchThreadHelper.invokeLater(new Runnable() { public void run() { transferToEDTQueue.drain(); FindBugsPluginImpl.showToolWindowNotifier(project, "Imported bug collection from '" + fileToImport + "'.", MessageType.INFO); } }); importBugCollection.setDoNotUseCloud(false); importBugCollection.setTimestamp(System.currentTimeMillis()); importBugCollection.reinitializeCloud(); } catch (final IOException e1) { MessageBusManager.publishAnalysisAbortedToEDT(project); final String message = "Import failed"; showToolWindowNotifier(project, message, MessageType.ERROR); LOGGER.error(message, e1); } catch (final DocumentException e1) { MessageBusManager.publishAnalysisAbortedToEDT(project); final String message = "Import failed"; showToolWindowNotifier(project, message, MessageType.ERROR); LOGGER.error(message, e1); } finally { MessageBusManager.publishAnalysisFinishedToEDT(project, importBugCollection, null, null); Thread.currentThread().interrupt(); } } @Override public void setProgressIndicator(@NotNull final ProgressIndicator indicator) { _indicator = indicator; } @Override public ProgressIndicator getProgressIndicator() { return _indicator; } }; task.setCancelText("Cancel"); task.asBackgroundable(); task.queue(); }