*/
public NewProjectWizard(Project curProject) {
project = curProject;
if (project == null) {
ProjectSettings.newInstance();
project = new Project();
isNewProject = true;
}
boolean temp = false;
if (curProject == null) {
setTitle(edu.umd.cs.findbugs.L10N.getLocalString("dlg.new_item", "New Project"));
} else {
setTitle(edu.umd.cs.findbugs.L10N.getLocalString("dlg.reconfig", "Reconfigure"));
temp = true;
}
final boolean reconfig = temp;
JPanel mainPanel = new JPanel();
mainPanel.setBorder(new EmptyBorder(5,5,5,5));
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
wizardComponents[0] = createFilePanel(
edu.umd.cs.findbugs.L10N.getLocalString("dlg.class_jars_dirs_lbl", "Class archives and directories to analyze:"),
analyzeList, analyzeModel, JFileChooser.FILES_AND_DIRECTORIES, directoryOrArchive,
"Choose Class Archives and Directories to Analyze", false,
"http://findbugs.sourceforge.net/manual/gui.html#d0e1087");
wizardComponents[1] = createFilePanel(
edu.umd.cs.findbugs.L10N.getLocalString("dlg.aux_class_lbl", "Auxiliary class locations:"), auxList, auxModel,
JFileChooser.FILES_AND_DIRECTORIES, directoryOrArchive, "Choose Auxilliary Class Archives and Directories", false,
"http://findbugs.sourceforge.net/FAQ.html#q4");
wizardComponents[2] = createFilePanel(
edu.umd.cs.findbugs.L10N.getLocalString("dlg.source_dirs_lbl", "Source directories:"), sourceList, sourceModel,
JFileChooser.FILES_AND_DIRECTORIES, null, "Choose Source Directories", true,
"http://findbugs.sourceforge.net/manual/gui.html#d0e1087");
JPanel cloudPanel = new JPanel(new BorderLayout());
cloudPanel.add(new JLabel("Store bug reviews in:"), BorderLayout.NORTH);
cloudPanel.add(cloudSelector, BorderLayout.CENTER);
wizardComponents[3] = cloudPanel;
@SuppressWarnings("unchecked")
ListCellRenderer<CloudPlugin> aRenderer = new CloudComboBoxRenderer();
cloudSelector.setRenderer(aRenderer);
cloudSelector.addItem(null);
String cloudId = project.getCloudId();
for (CloudPlugin c : DetectorFactoryCollection.instance().getRegisteredClouds().values()) {
String fbid = c.getFindbugsPluginId();
Plugin plugin = Plugin.getByPluginId(fbid);
if (plugin == null) {
continue;
}
Boolean fbPluginStatus = project.getPluginStatus(plugin);
if ((!c.isHidden() || c.getId().equals(cloudId)) && !Boolean.FALSE.equals(fbPluginStatus)) {
cloudSelector.addItem(c);
}
}
if (cloudId != null) {
CloudPlugin c = DetectorFactoryCollection.instance().getRegisteredClouds().get(project.getCloudId());
cloudSelector.setSelectedItem(c);
}
JPanel buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
if (MainFrameHelper.isMacLookAndFeel()) {
buttons.add(Box.createHorizontalStrut(5));
buttons.add(cancelButton);
buttons.add(Box.createHorizontalStrut(5));
buttons.add(finishButton);
} else {
buttons.add(Box.createHorizontalStrut(5));
buttons.add(finishButton);
buttons.add(Box.createHorizontalStrut(5));
buttons.add(cancelButton);
}
finishButton.addActionListener(new ActionListener() {
boolean keepGoing = false;
private boolean displayWarningAndAskIfWeShouldContinue(String msg, String title) {
if (keepGoing) {
return true;
}
boolean result = JOptionPane.showConfirmDialog(NewProjectWizard.this, msg, title, JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION;
if (result) {
keepGoing = true;
}
return result;
}
@Override
public void actionPerformed(ActionEvent evt) {
if (displayWarnings()) {
return;
}
Project p;
String oldCloudId = null;
p = project;
oldCloudId = project.getCloudId();
p.setGuiCallback(MainFrame.getInstance().getGuiCallback());
clearProjectSettings(p);
// Now that p is cleared, we can add in all the correct files.
for (int i = 0; i < analyzeModel.getSize(); i++) {
p.addFile(analyzeModel.get(i));
}
for (int i = 0; i < auxModel.getSize(); i++) {
p.addAuxClasspathEntry(auxModel.get(i));
}
for (int i = 0; i < sourceModel.getSize(); i++) {
p.addSourceDir(sourceModel.get(i));
}
p.setProjectName(projectName.getText());
CloudPlugin cloudPlugin = (CloudPlugin) cloudSelector.getSelectedItem();
String newCloudId;
if (cloudPlugin == null || cloudSelector.getSelectedIndex() == 0) {
newCloudId = null;
} else {
newCloudId = cloudPlugin.getId();
}
p.setCloudId(newCloudId);
MainFrame mainFrame = MainFrame.getInstance();
if (keepGoing) {
mainFrame.setProject(p);
}
if (projectChanged && (isNewProject
|| JOptionPane.showConfirmDialog(NewProjectWizard.this, edu.umd.cs.findbugs.L10N
.getLocalString("dlg.project_settings_changed_lbl",
"Project settings have been changed. Perform a new analysis with the changed files?"),
edu.umd.cs.findbugs.L10N.getLocalString("dlg.redo_analysis_question_lbl", "Redo analysis?"),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)) {
AnalyzingDialog.show(p);
} else if (!Util.nullSafeEquals(newCloudId, oldCloudId)) {
BugCollection bugs = mainFrame.getBugCollection();
try {
bugs.reinitializeCloud();
mainFrame.getComments().updateCloud();
} catch (Exception e) {
JOptionPane.showMessageDialog(NewProjectWizard.this, "Error loading " + newCloudId + "\n\n"
+ e.getClass().getSimpleName() + ": " + e.getMessage(),
"FindBugs Cloud Error", JOptionPane.ERROR_MESSAGE);
return;
}
mainFrame.getComments().updateCommentsFromLeafInformation(mainFrame.getCurrentSelectedBugLeaf());
}
if (reconfig) {
mainFrame.setProjectChanged(true);
}
String name = p.getProjectName();
if (name == null) {
name = Project.UNNAMED_PROJECT;
Debug.println("PROJECT NAME IS NULL!!");
}
if (projectNameChanged) {