Skip to content

Commit 45d6af7

Browse files
committed
Modify GUI export dialog to support both export modes.
1 parent bad6994 commit 45d6af7

3 files changed

Lines changed: 145 additions & 18 deletions

File tree

src/main/java/nl/rug/jbi/jsm/frontend/GUIFrontend.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import com.google.common.collect.Sets;
88
import nl.rug.jbi.jsm.core.JSMCore;
99
import nl.rug.jbi.jsm.core.calculator.MetricResult;
10-
import nl.rug.jbi.jsm.frontend.ui.ControlsPanel;
11-
import nl.rug.jbi.jsm.frontend.ui.SourceSelection;
12-
import nl.rug.jbi.jsm.frontend.ui.TabbedResultScreen;
13-
import nl.rug.jbi.jsm.frontend.ui.UserConsole;
10+
import nl.rug.jbi.jsm.frontend.ui.*;
1411
import nl.rug.jbi.jsm.util.ClassDiscoverer;
1512
import nl.rug.jbi.jsm.util.ResultsExporter;
1613
import org.apache.logging.log4j.LogManager;
@@ -171,20 +168,14 @@ private void endExecution() {
171168
}
172169

173170
private void exportResults() {
174-
final String exportPath = JOptionPane.showInputDialog(
175-
this,
176-
"Please give a path where to export the data.\nThe path has to contain '%s' which will get " +
177-
"replaced by an identifier for each metric.",
178-
"Export Path",
179-
JOptionPane.PLAIN_MESSAGE
180-
);
171+
final ExportDialog.Result result = ExportDialog.showDialog(this);
181172

182-
if (exportPath == null) return;
173+
if (result == null || result.exportPath == null) return;
183174

184175
ResultsExporter exporter = null;
185176
try {
186-
exporter = new ResultsExporter(exportPath);
187-
this.tabbedResults.exportResults(exporter);
177+
exporter = new ResultsExporter(result.exportPath);
178+
this.tabbedResults.exportResults(exporter, result.groupScopes);
188179
logger.info("Results exported, mapping file located at: '{}'", exporter.getMappingFileName());
189180
} catch (Exception e) {
190181
JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package nl.rug.jbi.jsm.frontend.ui;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
import java.awt.event.ActionEvent;
6+
import java.awt.event.ActionListener;
7+
8+
public class ExportDialog extends JDialog implements ActionListener {
9+
10+
private Result result = null;
11+
private boolean exportByScope = false;
12+
private JTextField exportPath = new JTextField();
13+
14+
private ExportDialog(final Frame frame) {
15+
super(frame, "Export Results", true);
16+
17+
final JPanel centerPane = new JPanel();
18+
centerPane.setLayout(new BoxLayout(centerPane, BoxLayout.Y_AXIS));
19+
20+
final JLabel l1 = new JLabel("Please give a path where to export the data.");
21+
l1.setAlignmentX(0.5f);
22+
centerPane.add(l1);
23+
24+
final JLabel l2 = new JLabel("The path has to contain '%s' which will get replaced by an identifier for each metric.");
25+
l2.setAlignmentX(0.5f);
26+
centerPane.add(l2);
27+
28+
centerPane.add(createExportPathTextField());
29+
centerPane.add(createExportTypeSwitch());
30+
centerPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
31+
32+
final Container contentPane = getContentPane();
33+
contentPane.add(centerPane, BorderLayout.CENTER);
34+
contentPane.add(createButtonPane(), BorderLayout.PAGE_END);
35+
36+
pack();
37+
setLocationRelativeTo(frame);
38+
}
39+
40+
public static Result showDialog(final Component frameComp) {
41+
final Frame frame = JOptionPane.getFrameForComponent(frameComp);
42+
final ExportDialog ed = new ExportDialog(frame);
43+
ed.setVisible(true);
44+
return ed.getResult();
45+
}
46+
47+
private JComponent createButtonPane() {
48+
//Export button
49+
final JButton exportButton = new JButton("Export");
50+
exportButton.setActionCommand("export");
51+
exportButton.addActionListener(this);
52+
//Cancel button
53+
final JButton cancelButton = new JButton("Cancel");
54+
cancelButton.setActionCommand("cancel");
55+
cancelButton.addActionListener(this);
56+
getRootPane().setDefaultButton(cancelButton);
57+
58+
final JPanel buttonPane = new JPanel();
59+
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
60+
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
61+
buttonPane.add(Box.createHorizontalGlue());
62+
buttonPane.add(exportButton);
63+
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
64+
buttonPane.add(cancelButton);
65+
66+
return buttonPane;
67+
}
68+
69+
private JComponent createExportTypeSwitch() {
70+
final JRadioButton metricExport = new JRadioButton("Export by Metric");
71+
metricExport.setActionCommand("metric-export");
72+
metricExport.setSelected(true);
73+
metricExport.setToolTipText("Each metric will be exported into an individual file.");
74+
75+
final JRadioButton scopeExport = new JRadioButton("Export by Scope");
76+
scopeExport.setActionCommand("scope-export");
77+
scopeExport.setToolTipText("Each scope will be exported into a file containing all metrics.");
78+
79+
final ButtonGroup group = new ButtonGroup();
80+
group.add(metricExport);
81+
group.add(scopeExport);
82+
83+
metricExport.addActionListener(this);
84+
scopeExport.addActionListener(this);
85+
86+
final JPanel choicePanel = new JPanel(new FlowLayout());
87+
choicePanel.add(metricExport);
88+
choicePanel.add(scopeExport);
89+
90+
return choicePanel;
91+
}
92+
93+
private JComponent createExportPathTextField() {
94+
final JPanel exportPathPanel = new JPanel();
95+
exportPathPanel.setLayout(new BoxLayout(exportPathPanel, BoxLayout.LINE_AXIS));
96+
97+
exportPathPanel.add(new JLabel("Export Path: "));
98+
exportPathPanel.add(this.exportPath);
99+
100+
return exportPathPanel;
101+
}
102+
103+
private Result getResult() {
104+
return this.result;
105+
}
106+
107+
@Override
108+
public void actionPerformed(ActionEvent e) {
109+
if ("export".equals(e.getActionCommand())) {
110+
this.result = new Result(this.exportPath.getText(), this.exportByScope);
111+
this.setVisible(false);
112+
} else if ("cancel".equals(e.getActionCommand())) {
113+
this.setVisible(false);
114+
} else if ("metric-export".equals(e.getActionCommand())) {
115+
this.exportByScope = false;
116+
} else if ("scope-export".equals(e.getActionCommand())) {
117+
this.exportByScope = true;
118+
}
119+
}
120+
121+
public static class Result {
122+
public final String exportPath;
123+
public final boolean groupScopes;
124+
125+
public Result(final String exportPath, final boolean groupScopes) {
126+
this.exportPath = exportPath;
127+
this.groupScopes = groupScopes;
128+
}
129+
}
130+
}

src/main/java/nl/rug/jbi/jsm/frontend/ui/TabbedResultScreen.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@ public void processResults(final List<MetricResult> results) {
7171
}
7272
}
7373

74-
public void exportResults(final ResultsExporter exporter) throws IOException {
75-
exportResultsForTable(exporter, MetricScope.CLASS, classData.getResultsMap());
76-
exportResultsForTable(exporter, MetricScope.PACKAGE, packageData.getResultsMap());
77-
exportResultsForTable(exporter, MetricScope.COLLECTION, collectionData.getResultsMap());
74+
public void exportResults(final ResultsExporter exporter, final boolean groupScopes) throws IOException {
75+
if (groupScopes) {
76+
exporter.exportDataCollection(MetricScope.CLASS, classData.getResultsMap());
77+
exporter.exportDataCollection(MetricScope.PACKAGE, packageData.getResultsMap());
78+
exporter.exportDataCollection(MetricScope.COLLECTION, collectionData.getResultsMap());
79+
} else {
80+
exportResultsForTable(exporter, MetricScope.CLASS, classData.getResultsMap());
81+
exportResultsForTable(exporter, MetricScope.PACKAGE, packageData.getResultsMap());
82+
exportResultsForTable(exporter, MetricScope.COLLECTION, collectionData.getResultsMap());
83+
}
7884
}
7985

8086
public void clearResults() {

0 commit comments

Comments
 (0)