Merge lp:~jonathan-r-beaumont/workcraft/trunk-bug-1537854 into lp:workcraft

Proposed by Jonny Beaumont
Status: Merged
Merged at revision: 728
Proposed branch: lp:~jonathan-r-beaumont/workcraft/trunk-bug-1537854
Merge into: lp:workcraft
Diff against target: 355 lines (+119/-59)
6 files modified
CpogsPlugin/src/org/workcraft/plugins/cpog/CustomToolsProvider.java (+1/-1)
CpogsPlugin/src/org/workcraft/plugins/cpog/VisualCPOG.java (+21/-0)
CpogsPlugin/src/org/workcraft/plugins/cpog/tools/CpogParsingTool.java (+2/-1)
CpogsPlugin/src/org/workcraft/plugins/cpog/tools/CpogSelectionTool.java (+53/-13)
CpogsPlugin/src/org/workcraft/plugins/cpog/tools/PGMinerImportTool.java (+25/-26)
CpogsPlugin/src/org/workcraft/plugins/cpog/tools/PGMinerSelectedGraphsExtractionTool.java (+17/-18)
To merge this branch: bzr merge lp:~jonathan-r-beaumont/workcraft/trunk-bug-1537854
Reviewer Review Type Date Requested Status
Danil Sokolov Approve
Review via email: mp+284005@code.launchpad.net

Description of the change

Fixed bug 1537854. This includes a clear message when a user attempts to extract concurrency of a selected graph not grouped as a scenario, and some code refinements for when trimming whitespace from strings.

To post a comment you must log in.
Revision history for this message
Danil Sokolov (danilovesky) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CustomToolsProvider.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/CustomToolsProvider.java 2015-02-05 21:35:30 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/CustomToolsProvider.java 2016-01-26 16:51:52 +0000
@@ -17,7 +17,7 @@
17 {17 {
18 ArrayList<GraphEditorTool> result = new ArrayList<GraphEditorTool>();18 ArrayList<GraphEditorTool> result = new ArrayList<GraphEditorTool>();
1919
20 result.add(new CpogSelectionTool(true));20 result.add(new CpogSelectionTool());
21 result.add(new CommentGeneratorTool());21 result.add(new CommentGeneratorTool());
22 result.add(new ConnectionTool());22 result.add(new ConnectionTool());
23 23
2424
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/VisualCPOG.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/VisualCPOG.java 2015-08-04 18:28:42 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/VisualCPOG.java 2016-01-26 16:51:52 +0000
@@ -31,6 +31,7 @@
31import org.workcraft.dom.Container;31import org.workcraft.dom.Container;
32import org.workcraft.dom.Node;32import org.workcraft.dom.Node;
33import org.workcraft.dom.math.MathConnection;33import org.workcraft.dom.math.MathConnection;
34import org.workcraft.dom.math.PageNode;
34import org.workcraft.dom.visual.AbstractVisualModel;35import org.workcraft.dom.visual.AbstractVisualModel;
35import org.workcraft.dom.visual.SelectionHelper;36import org.workcraft.dom.visual.SelectionHelper;
36import org.workcraft.dom.visual.TransformHelper;37import org.workcraft.dom.visual.TransformHelper;
@@ -289,5 +290,25 @@
289 ((VisualGroup) node.getParent()).removeWithoutNotify(node);290 ((VisualGroup) node.getParent()).removeWithoutNotify(node);
290 }291 }
291 }292 }
293
294 public VisualScenarioPage groupScenarioPageSelection(String graphName) {
295 VisualScenarioPage scenario = null;
296 PageNode pageNode = new PageNode();
297 Collection<Node> nodes = SelectionHelper.getGroupableCurrentLevelSelection(this);
298 if (nodes.size() >= 1) {
299 scenario = new VisualScenarioPage(pageNode);
300 if (graphName != null) {
301 scenario.setLabel(graphName);
302 }
303 getCurrentLevel().add(scenario);
304 getCurrentLevel().reparent(nodes, scenario);
305 Point2D centre = TransformHelper.getSnappedCentre(nodes);
306 VisualModelTransformer.translateNodes(nodes, -centre.getX(), -centre.getY());
307 scenario.setPosition(centre);
308 select(scenario);
309 }
310 return scenario;
311
312 }
292 313
293}314}
294315
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tools/CpogParsingTool.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/tools/CpogParsingTool.java 2015-11-09 11:00:13 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/tools/CpogParsingTool.java 2016-01-26 16:51:52 +0000
@@ -365,7 +365,8 @@
365 }365 }
366 }366 }
367 367
368 368 if (total.endsWith("+")) total = total.substring(0, total.length() - 1);
369 total = total.trim();
369 370
370 371
371 return total;372 return total;
372373
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tools/CpogSelectionTool.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/tools/CpogSelectionTool.java 2016-01-18 13:36:55 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/tools/CpogSelectionTool.java 2016-01-26 16:51:52 +0000
@@ -2,6 +2,7 @@
22
3import java.awt.BorderLayout;3import java.awt.BorderLayout;
4import java.awt.Checkbox;4import java.awt.Checkbox;
5import java.awt.Component;
5import java.awt.Font;6import java.awt.Font;
6import java.awt.Rectangle;7import java.awt.Rectangle;
7import java.awt.event.ActionEvent;8import java.awt.event.ActionEvent;
@@ -78,6 +79,7 @@
78import org.workcraft.plugins.cpog.optimisation.BooleanFormula;79import org.workcraft.plugins.cpog.optimisation.BooleanFormula;
79import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString;80import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString;
80import org.workcraft.plugins.stg.VisualNamedTransition;81import org.workcraft.plugins.stg.VisualNamedTransition;
82import org.workcraft.util.GUI;
81import org.workcraft.workspace.WorkspaceEntry;83import org.workcraft.workspace.WorkspaceEntry;
8284
8385
@@ -106,14 +108,13 @@
106 108
107 private GraphEditor editor;109 private GraphEditor editor;
108 protected boolean cancelInPlaceEdit;110 protected boolean cancelInPlaceEdit;
111
112 int scenarioNo = 0;
109113
110 public CpogSelectionTool() {114 public CpogSelectionTool() {
111 super();115 super(false);
112 }116 }
113117
114 public CpogSelectionTool(boolean enablePages) {
115 super(enablePages);
116 }
117118
118 @Override119 @Override
119 public void createInterfacePanel(final GraphEditor editor) {120 public void createInterfacePanel(final GraphEditor editor) {
@@ -270,8 +271,53 @@
270 interfacePanel.add(expressionScroll, BorderLayout.CENTER);271 interfacePanel.add(expressionScroll, BorderLayout.CENTER);
271 interfacePanel.add(buttonPanel, BorderLayout.SOUTH);272 interfacePanel.add(buttonPanel, BorderLayout.SOUTH);
272 273
274 scenarioPageGroupButton(getGroupPanel());
275
276
273 renderTypeChangeHandler();277 renderTypeChangeHandler();
274 }278 }
279
280 public void scenarioPageGroupButton(JPanel groupPanel) {
281 JButton groupPageButton = GUI.createIconButton(GUI.createIconFromSVG(
282 "images/icons/svg/selection-page.svg"), "Combine selection as a scenario (Alt+G)");
283 groupPageButton.addActionListener(new ActionListener(){
284 @Override
285 public void actionPerformed(ActionEvent e) {
286 VisualCPOG visualCpog = (VisualCPOG)editor.getWorkspaceEntry().getModelEntry().getVisualModel();
287 visualCpog.groupScenarioPageSelection("scenario" + scenarioNo);
288 scenarioNo++;
289 editor.requestFocus();
290 }
291 });
292 groupPanel.add(groupPageButton, 1);
293 }
294
295 public JPanel getGroupPanel() {
296 Component[] comps = interfacePanel.getComponents();
297 JPanel groupPanel = null;
298 for (int i = 0; i < comps.length; i++) {
299 if (comps[i] instanceof JPanel) {
300 JPanel panel = (JPanel) comps[i];
301 Component[] cmp = panel.getComponents();
302 for (int j = 0; j < cmp.length; j++) {
303 if (cmp[j] instanceof JPanel) {
304 JPanel pan = (JPanel) cmp[j];
305 Component[] c = pan.getComponents();
306 for (int k = 0; k < c.length; k++) {
307 if (c[k] instanceof JButton) {
308 JButton b = (JButton) c[k];
309 System.out.println(b.getText());
310 if (b.getToolTipText() != null && b.getToolTipText() == "Group selection (Ctrl+G)") {
311 groupPanel = pan;
312 }
313 }
314 }
315 }
316 }
317 }
318 }
319 return groupPanel;
320 }
275321
276 public HashMap<String, VisualVertex> insertExpression(String text, final VisualCPOG visualCpog,322 public HashMap<String, VisualVertex> insertExpression(String text, final VisualCPOG visualCpog,
277 final boolean createDuplicates, boolean getVertList, boolean zoomFit, boolean blockTransitiveRemoval) {323 final boolean createDuplicates, boolean getVertList, boolean zoomFit, boolean blockTransitiveRemoval) {
@@ -289,9 +335,9 @@
289335
290 if (text.contains("=")) {336 if (text.contains("=")) {
291 name = text.substring(0, text.indexOf("="));337 name = text.substring(0, text.indexOf("="));
292 while (name.endsWith(" ")) name = name.substring(0, name.length() - 1);338 name = name.trim();
293 text = text.substring(text.indexOf("=") + 1);339 text = text.substring(text.indexOf("=") + 1);
294 while (text.startsWith(" ")) text = text.substring(1);340 text = text.trim();
295 }341 }
296 342
297 CpogFormula f = null;343 CpogFormula f = null;
@@ -914,13 +960,7 @@
914960
915 String newExpression = parsingTool.getExpressionFromGraph(visualCpog);961 String newExpression = parsingTool.getExpressionFromGraph(visualCpog);
916 newExpression = newExpression.replace("\n", "");962 newExpression = newExpression.replace("\n", "");
917 while (newExpression.startsWith(" ")) {963 newExpression = newExpression.trim();
918 newExpression = newExpression.substring(1);
919 }
920 while (newExpression.endsWith(" ")) {
921 newExpression = newExpression.substring(0, newExpression.length() - 1);
922 }
923
924 GraphReference g = referenceMap.get(page.getLabel());964 GraphReference g = referenceMap.get(page.getLabel());
925965
926 int eqLocation;966 int eqLocation;
927967
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tools/PGMinerImportTool.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/tools/PGMinerImportTool.java 2015-11-01 11:50:12 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/tools/PGMinerImportTool.java 2016-01-26 16:51:52 +0000
@@ -53,7 +53,6 @@
53 }53 }
54 54
55 try {55 try {
56
57 File inputFile = File.createTempFile("input", ".tr");56 File inputFile = File.createTempFile("input", ".tr");
58 int c = 0;57 int c = 0;
59 File originalFile = new File(dialog.getFilePath());58 File originalFile = new File(dialog.getFilePath());
@@ -73,6 +72,7 @@
73 c++;72 c++;
74 }73 }
75 k.close();74 k.close();
75
76 HashSet<String> visitedEvents;76 HashSet<String> visitedEvents;
77 int i = 0;77 int i = 0;
78 String[] newLines = new String[lines.length];78 String[] newLines = new String[lines.length];
@@ -116,45 +116,44 @@
116 @Override116 @Override
117 public void run(WorkspaceEntry we) {117 public void run(WorkspaceEntry we) {
118 118
119
120 File inputFile;119 File inputFile;
121 inputFile = getInputFile(we);120 inputFile = getInputFile(we);
121
122 final Framework framework = Framework.getInstance();
123 final GraphEditorPanel editor = framework.getMainWindow().getCurrentEditor();
124 final ToolboxPanel toolbox = editor.getToolBox();
125 final CpogSelectionTool tool = toolbox.getToolInstance(CpogSelectionTool.class);
126
127
122 try {128 try {
123 if (inputFile != null) {129 if (inputFile != null) {
124 130
125 if (dialog.getExtractConcurrency()) {131 if (dialog.getExtractConcurrency()) {
126 PGMinerTask task = new PGMinerTask(inputFile, dialog.getSplit());132 PGMinerTask task = new PGMinerTask(inputFile, dialog.getSplit());
127 133
128 final Framework framework = Framework.getInstance();134
129 PGMinerResultHandler result = new PGMinerResultHandler((VisualCPOG) we.getModelEntry().getVisualModel(), we, false);135 PGMinerResultHandler result = new PGMinerResultHandler((VisualCPOG) we.getModelEntry().getVisualModel(), we, false);
130 framework.getTaskManager().queue(task, "PGMiner", result);136 framework.getTaskManager().queue(task, "PGMiner", result);
131 } else {137 } else {
132 138 Scanner k;
133 final Framework framework = Framework.getInstance();139
134 final GraphEditorPanel editor = framework.getMainWindow().getCurrentEditor();140 k = new Scanner(inputFile);
135 final ToolboxPanel toolbox = editor.getToolBox();141 int i = 0;
136 final CpogSelectionTool tool = toolbox.getToolInstance(CpogSelectionTool.class);142 double yPos = tool.getLowestVertex((VisualCPOG) editor.getWorkspaceEntry().getModelEntry().getVisualModel()).getY() + 3;
137 143 editor.getWorkspaceEntry().captureMemento();
138 Scanner k;144 while (k.hasNext()) {
139 145 String line = k.nextLine();
140 k = new Scanner(inputFile);146
141 int i = 0;147 tool.insertEventLog((VisualCPOG) editor.getWorkspaceEntry().getModelEntry().getVisualModel(), i++, line.split(" "), yPos);
142 double yPos = tool.getLowestVertex((VisualCPOG) editor.getWorkspaceEntry().getModelEntry().getVisualModel()).getY() + 3;148
143 editor.getWorkspaceEntry().captureMemento();149 yPos = yPos + 5;
144 while (k.hasNext()) {150 }
145 String line = k.nextLine();151 k.close();
146 152 editor.getWorkspaceEntry().saveMemento();
147 tool.insertEventLog((VisualCPOG) editor.getWorkspaceEntry().getModelEntry().getVisualModel(), i++, line.split(" "), yPos);
148
149 yPos = yPos + 5;
150
151 }
152 k.close();
153 editor.getWorkspaceEntry().saveMemento();
154 }153 }
155 }154 }
156 } catch (Exception e) {155 } catch (Exception e) {
157 156 editor.getWorkspaceEntry().cancelMemento();
158 }157 }
159 } 158 }
160159
161160
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tools/PGMinerSelectedGraphsExtractionTool.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/tools/PGMinerSelectedGraphsExtractionTool.java 2015-11-01 11:50:12 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/tools/PGMinerSelectedGraphsExtractionTool.java 2016-01-26 16:51:52 +0000
@@ -41,53 +41,51 @@
41 String allGraphs = CpogParsingTool.getExpressionFromGraph(visualCpog);41 String allGraphs = CpogParsingTool.getExpressionFromGraph(visualCpog);
42 ArrayList<String> tempGraphs = new ArrayList<>();42 ArrayList<String> tempGraphs = new ArrayList<>();
43 ArrayList<String> graphs = new ArrayList<>();43 ArrayList<String> graphs = new ArrayList<>();
44 String prefix = "input", suffix = ".tr";
45 inputFile = File.createTempFile("input", ".tr");44 inputFile = File.createTempFile("input", ".tr");
46 45
47 PrintStream expressions = new PrintStream(inputFile);46
48 47
49 int i = allGraphs.indexOf(" + ");48 int i = allGraphs.indexOf(" + ");
50 while (i > -1) {49 while (i > -1) {
51 allGraphs = allGraphs.substring(0, i) + "\n" + allGraphs.substring(i + 2);50 allGraphs = allGraphs.substring(0, i) + "\n" + allGraphs.substring(i + 2);
52 i = allGraphs.indexOf(" + ");51 i = allGraphs.indexOf(" + ");
53 }52 }
53 allGraphs = allGraphs + "\n";
54 allGraphs = allGraphs.replaceAll(" -> ", " ");54 allGraphs = allGraphs.replaceAll(" -> ", " ");
55 55
56 while (allGraphs.contains("\n")) {56 String[] graphList = allGraphs.split("\n");
57 int index = allGraphs.indexOf("\n");
58 String graph = (allGraphs.substring(0, index));
59 allGraphs = allGraphs.substring(index + 1);
60 tempGraphs.add(graph);
61 }
62 57
63 //tempGraphs.add(allGraphs);58 for (String g : graphList) tempGraphs.add(g);
64 59
65 for (String graph : tempGraphs) {60 for (String graph : tempGraphs) {
66 int index = graph.indexOf("= ");61 int index = graph.indexOf("= ");
67 if (index >= 0) {62 if (index >= 0) {
68 graph = graph.substring(index + 2);63 graph = graph.substring(index + 2);
69 }64 } else {
70 while (graph.startsWith(" ")) {65 JOptionPane.showMessageDialog(null,
71 graph = graph.substring(1);66 "Error: A graph which is not a scenario has been selected.\n"
72 }67 + "Please remove this from the selection, or group this as a page to continue",
73 while (graph.endsWith(" ")) {68 "Error",
74 graph = graph.substring(0, graph.length() - 1);69 JOptionPane.ERROR_MESSAGE);
75 }70 return null;
71 }
72 graph = graph.trim();
76 graphs.add(graph);73 graphs.add(graph);
77 }74 }
78 75
76 PrintStream expressions = new PrintStream(inputFile);
77
79 for (String graph : graphs) {78 for (String graph : graphs) {
80 expressions.println(graph);79 expressions.println(graph);
81 }80 }
82 81
83 expressions.close();82 expressions.close();
84 83
85
86 } catch (IOException exception) {84 } catch (IOException exception) {
87 exception.printStackTrace();85 exception.printStackTrace();
88 } catch (ArrayIndexOutOfBoundsException e2) {86 } catch (ArrayIndexOutOfBoundsException e2) {
89 JOptionPane.showMessageDialog(null,87 JOptionPane.showMessageDialog(null,
90 "Error: No graphs have been selected",88 "Error: No scenarios have been selected",
91 "Error",89 "Error",
92 JOptionPane.ERROR_MESSAGE);90 JOptionPane.ERROR_MESSAGE);
93 throw e2;91 throw e2;
@@ -102,6 +100,7 @@
102 try {100 try {
103 101
104 File inputFile = getInputFile(we);102 File inputFile = getInputFile(we);
103 if (inputFile == null) return;
105 PGMinerTask task = new PGMinerTask(inputFile, false);104 PGMinerTask task = new PGMinerTask(inputFile, false);
106 105
107 final Framework framework = Framework.getInstance();106 final Framework framework = Framework.getInstance();

Subscribers

People subscribed via source and target branches