}
public void actionPerformed(ActionEvent evt) {
String btnName = ((JButton) evt.getSource()).getName();
String textAddition = "";
IMetricsConfiguration metricsConfig = ConfigurationManager
.getMetricsConfiguration();
if (btnName != null) {
if (btnName.equals(MetricsBuilderPanel.NEW_BTN)) {
String newMetricID = (String) JOptionPane.showInputDialog(null,
Messages.getString("Metrics.Builder.New.EnterNewID"),
Messages.getString("Metrics.Builder.New.EnterNewID"),
JOptionPane.PLAIN_MESSAGE);
// User canceled
if(newMetricID == null)
return;
else {
clearFields();
currentMetricID = "";
}
if (metricsConfig.isMetricIDInUse(newMetricID))
JOptionPane
.showMessageDialog(
null,
Messages.getString("Metrics.Builder.New.IDAlreadyInUse")
+ "!",
Messages.getString("Metrics.Builder.New.IDAlreadyInUse"),
JOptionPane.ERROR_MESSAGE);
else {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileFilter filter = new LabeledFileFilter() {
public boolean accept(File file) {
if (file.getAbsolutePath().endsWith(".xml"))
return true;
return false;
}
public String getDescription() {
return "Metrics XML file (*.xml)";
}
public String getExtension() {
return ".xml";
}
};
fileChooser.addChoosableFileFilter(filter);
fileChooser.setCurrentDirectory(new File(metricsConfig
.getCustomMetricsDir() + File.separatorChar));
File file = null;
int returnVal = fileChooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String path = fileChooser.getSelectedFile()
.getAbsolutePath();
if (!path.substring(path.length() - 4, path.length())
.equals(".xml"))
path += ".xml";
file = new File(path);
// User selected a new file for the new algorithm, so
// add it
if (metricsConfig.findFileIDToFileName(file
.getAbsolutePath()) == -1)
metricsConfig.addNewMetricFile(file
.getAbsolutePath());
metricsConfig.addNewAlgorithm(newMetricID,
metricsConfig.findFileIDToFileName(file
.getAbsolutePath()));
update();
currentMetricID = newMetricID;
MetricsBuilderPanel.displayMetric(newMetricID);
}
updateMetricWithGUIData();
}
} else if (btnName.equals(MetricsBuilderPanel.SAVE_BTN)) {
updateMetricWithGUIData();
metricsConfig.endEditSession(true);
dirty = false;
metricsConfig.startEditSession();
} else if (btnName.equals(MetricsBuilderPanel.IMPORT_BTN))
importMetricsFile();
else if (btnName.equals(MetricsBuilderPanel.EXPORT_BTN))
exportMetricsFile();
else if (btnName.equals(MetricsBuilderPanel.EXIT_BTN)) {
if (dirty) {
int option = JOptionPane
.showConfirmDialog(
null,
Messages.getString("Metrics.Builder.Exit.SaveChanges"),
Messages.getString("Metrics.Builder.Exit.SaveChanges.Title"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (option == JOptionPane.YES_OPTION) {
metricsConfig.endEditSession(true);
dirty = false;
currentMetricID = "";
closeFrame();
} else if (option == JOptionPane.NO_OPTION) {
metricsConfig.endEditSession(false);
dirty = false;
currentMetricID = "";
closeFrame();
} else
return;
} else {
currentMetricID = "";
closeFrame();
}
} else if (btnName.equals(MetricsBuilderPanel.CHECK_BTN)) {
try {
MetricsCalculator
.checkFormula(MetricsBuilderPanel.jMetricsFormulaTextField
.getText());
JOptionPane
.showMessageDialog(
null,
Messages.getString("Metrics.Builder.ConsistencyCheck.NoIssuesFound"), //$NON-NLS-1$
Messages.getString("Metrics.Builder.ConsistencyCheck.ConsistencyChecker"), //$NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
} catch (CalculateFormulaException cfe) {
boolean showErrorFrame = true;
// This logic should check if there is an enhancement
// available
if (cfe instanceof NestedCalculateFormulaException) {
NestedCalculateFormulaException ncfe = (NestedCalculateFormulaException) cfe;
if (ncfe.hasEnhancementExceptions()) {
String newLine = System
.getProperty("line.separator"); //$NON-NLS-1$
int answer = JOptionPane
.showConfirmDialog(
null,
Messages.getString("Metrics.Builder.ConsistencyCheck.ErrorsCanBeReducedByUsingTheFormula") + newLine + //$NON-NLS-1$
"\""
+ ncfe.getEnhancementExceptions()
.get(0)
.getEnhancedFormula()
+ "\""
+ newLine
+ Messages
.getString("Metrics.Builder.ConsistencyCheck.DoYouWantToUseThisFormula"), //$NON-NLS-1$
Messages.getString("Metrics.Builder.ConsistencyCheck.EnhancementAvailable"), //$NON-NLS-1$
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
// Check if Yes is clicked
if (answer == JOptionPane.YES_OPTION) {
// Writing the new Formula into the Text-Field
MetricsBuilderPanel.jMetricsFormulaTextField
.setText(ncfe
.getEnhancementExceptions()
.get(0).getEnhancedFormula());
// Disable that the original error-screen
showErrorFrame = false;
// Run the check process a second time for
// getting the errors for the new formula
try {
// Run the checker
MetricsCalculator.checkFormula(ncfe
.getEnhancementExceptions().get(0)
.getEnhancedFormula());
// Show the successful Dialog if no errors
// appear
JOptionPane
.showMessageDialog(
null,
Messages.getString("Metrics.Builder.ConsistencyCheck.NoIssuesFound"), //$NON-NLS-1$
Messages.getString("Metrics.Builder.ConsistencyCheck.ConsistencyChecker"), //$NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
} catch (CalculateFormulaException e) {
// Show the Error-Frame
new MetricsBuilderErrorFrame(e);
}
}
}
}
// If had not been any enhancement available or the
// enhancements had not been accepted
// --> the formula has not been changed
if (showErrorFrame) {
new MetricsBuilderErrorFrame(cfe);
}
}
} else if (btnName.equals(MetricsBuilderPanel.DELETE_TAB2_BTN)) {
int row = MetricsBuilderPanel.jTableValues.getSelectedRow();
MetricsBuilderPanel.jTableValues.editingCanceled(new ChangeEvent(MetricsBuilderPanel.jTableValues));
MetricsBuilderPanel.model.removeRow(row);
MetricsBuilderPanel.model.fireTableDataChanged();
} else if (btnName.equals(MetricsBuilderPanel.ADD_TAB2_BTN)) {
MetricsBuilderPanel.model.addRow(MetricsBuilderPanel.DEFAULT_CELL_VALUES);
MetricsBuilderPanel.model.fireTableDataChanged();
} else if (btnName.equals(MetricsBuilderPanel.CLEAR_GROUP_BTN)) {
} else if (btnName.equals(MetricsBuilderPanel.EXIT_GROUP_BTN)) {
closeFrame();
} else if (btnName.equals(MetricsBuilderPanel.SAVE_TAB2_BTN)) {
updateMetricWithGUIData();
metricsConfig.endEditSession(true);
dirty = false;
metricsConfig.startEditSession();
} else if (btnName.equals(MetricsBuilderPanel.EXIT_TAB2_BTN)) {
closeFrame();
} else if (btnName.equals(MetricsBuilderPanel.FUNC_BTN))
textAddition = ((JButton) evt.getSource()).getText()
.toLowerCase() + "(";