Merge lp:~tapaal-contributor/tapaal/unshare-transitions-in-all-components-1820014 into lp:tapaal

Proposed by Peter Haahr Taankvist on 2019-03-14
Status: Merged
Approved by: Jiri Srba on 2019-03-15
Approved revision: 994
Merged at revision: 997
Proposed branch: lp:~tapaal-contributor/tapaal/unshare-transitions-in-all-components-1820014
Merge into: lp:tapaal
Diff against target: 104 lines (+32/-9)
3 files modified
src/dk/aau/cs/gui/DeleteSharedPlaceOrTransition.java (+18/-8)
src/dk/aau/cs/model/tapn/SharedTransition.java (+12/-0)
src/dk/aau/cs/model/tapn/TimedArcPetriNet.java (+2/-1)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/unshare-transitions-in-all-components-1820014
Reviewer Review Type Date Requested Status
Jiri Srba 2019-03-14 Approve on 2019-03-15
Review via email: mp+364458@code.launchpad.net

Commit message

Transitions shared via the error dialog (when every transition with the same name is shared as well) will now correctly be removed when removing them in the sidepanel.

To post a comment you must log in.
Jiri Srba (srba) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dk/aau/cs/gui/DeleteSharedPlaceOrTransition.java'
2--- src/dk/aau/cs/gui/DeleteSharedPlaceOrTransition.java 2019-01-24 14:23:06 +0000
3+++ src/dk/aau/cs/gui/DeleteSharedPlaceOrTransition.java 2019-03-14 19:45:52 +0000
4@@ -91,15 +91,17 @@
5 messageShown = false;
6 if(list.getSelectedValuesList() != null){
7 ArrayList<String> affectedComponents = new ArrayList<String>();
8+ ArrayList<String> affectedComponentsWithDupes = new ArrayList<String>();
9 if(sharedPlacesAndTransitionsPanel.isDisplayingTransitions()){
10 for(Object transition : list.getSelectedValuesList()) {
11- for(TimedTransition t : ((SharedTransition)transition).transitions()){
12- if(!(affectedComponents.contains(t.model().name())))
13- affectedComponents.add(t.model().name());
14+ affectedComponentsWithDupes.addAll(((SharedTransition)transition).getComponentsUsingThisTransition());
15+ }
16+ for(String component : affectedComponentsWithDupes) {
17+ if(!(affectedComponents.contains(component))) {
18+ affectedComponents.add(component);
19 }
20 }
21 } else {
22- ArrayList<String> affectedComponentsWithDupes = new ArrayList<String>();
23 for(Object place : list.getSelectedValuesList()) {
24 affectedComponentsWithDupes.addAll(((SharedPlace)place).getComponentsUsingThisPlace());
25 }
26@@ -296,17 +298,25 @@
27 sharedTransitionsListModel.removeElement(sharedTransition);
28 undoManager.addEdit(new DeleteSharedTransitionCommand(sharedTransition, sharedTransitionsListModel));
29 }else{
30- Collection<TimedTransition> copy = sharedTransition.transitions();
31- for(TimedTransition transition : copy){
32+
33+ ArrayList<TimedTransition> transitions = new ArrayList<TimedTransition> ();
34+ for(Template template : tab.allTemplates()) {
35+ TimedTransition timedTransition = template.model().getTransitionByName(sharedTransition.name());
36+ if(timedTransition != null)
37+ transitions.add(timedTransition);
38+ }
39+ for(TimedTransition transition : transitions){
40 transition.unshare();
41 undoManager.addEdit(new UnshareTransitionCommand(sharedTransition, transition));
42 }
43 sharedTransitionsListModel.removeElement(sharedTransition);
44 undoManager.addEdit(new DeleteSharedTransitionCommand(sharedTransition, sharedTransitionsListModel));
45- for(TimedTransition transition : copy){
46+ for(TimedTransition transition : transitions){
47 String name = nameGenerator.getNewTransitionName(transition.model());
48 // We add this invisible transition renaming to avoid problems with undo
49- undoManager.addEdit(new RenameTimedTransitionCommand(tab, transition, name, transition.name()));
50+ Command renameCommand = new RenameTimedTransitionCommand(tab, transition, name, transition.name());
51+ renameCommand.redo();
52+ undoManager.addEdit(renameCommand);
53 }
54 }
55 }
56
57=== modified file 'src/dk/aau/cs/model/tapn/SharedTransition.java'
58--- src/dk/aau/cs/model/tapn/SharedTransition.java 2016-04-28 13:18:00 +0000
59+++ src/dk/aau/cs/model/tapn/SharedTransition.java 2019-03-14 19:45:52 +0000
60@@ -7,6 +7,8 @@
61
62 import dk.aau.cs.util.IntervalOperations;
63 import dk.aau.cs.util.Require;
64+import pipe.dataLayer.Template;
65+import pipe.gui.CreateGui;
66
67 public class SharedTransition {
68 private static final Pattern namePattern = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$");
69@@ -152,4 +154,14 @@
70 }
71 return true;
72 }
73+ public ArrayList<String> getComponentsUsingThisTransition(){
74+ ArrayList<String> components = new ArrayList<String>();
75+ for(Template t : CreateGui.getCurrentTab().allTemplates()){
76+ TimedTransition tt = t.model().getTransitionByName(this.name);
77+ if(tt != null){
78+ components.add(t.model().name());
79+ }
80+ }
81+ return components;
82+ }
83 }
84
85=== modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNet.java'
86--- src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2019-02-03 11:41:57 +0000
87+++ src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2019-03-14 19:45:52 +0000
88@@ -5,6 +5,8 @@
89 import java.util.Collection;
90 import java.util.List;
91
92+import pipe.gui.CreateGui;
93+import pipe.gui.GuiFrame;
94 import pipe.gui.undo.AddArcPathPointEdit;
95 import pipe.gui.widgets.PlaceEditorPanel;
96 import dk.aau.cs.model.tapn.Bound.InfBound;
97@@ -63,7 +65,6 @@
98 public void add(TimedTransition transition) {
99 Require.that(transition != null, "Argument must be a non-null transition");
100 Require.that(!isNameUsed(transition.name()) || transition.isShared(), "A place or transition with the specified name already exists in the petri net.");
101-
102 transition.setModel(this);
103 transitions.add(transition);
104 }

Subscribers

People subscribed via source and target branches