final DialogBuilder dialogBuilder = new DialogBuilder(project);
dialogBuilder.addOkAction();
dialogBuilder.addCancelAction();
dialogBuilder.setTitle("Import previous saved bug collection xml");
final FindBugsPreferences preferences = getPluginInterface(project).getPreferences();
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 FindBugsPlugin findBugsPlugin = getPluginInterface(project);
final BugCollection bugCollection = findBugsPlugin.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;
}
}
//Create a task to export the bug collection to html
final AtomicReference<Task> importTask = new AtomicReference<Task>(new BackgroundableTask(project, "Importing Findbugs Result", true) {
private ProgressIndicator _indicator;
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"})
@Override
public void run(@NotNull final ProgressIndicator indicator) {
EventManagerImpl.getInstance().fireEvent(new BugReporterEventImpl(Operation.ANALYSIS_STARTED, null, 0, project.getName()));
setProgressIndicator(indicator);
indicator.setFraction(0.0);
indicator.setIndeterminate(false);
indicator.setText(fileToImport);
try {
_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;