Merge lp:~tapaal-contributor/tapaal/places-with-same-name-shared-1801728 into lp:tapaal
- places-with-same-name-shared-1801728
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jiri Srba | ||||
Approved revision: | 990 | ||||
Merged at revision: | 983 | ||||
Proposed branch: | lp:~tapaal-contributor/tapaal/places-with-same-name-shared-1801728 | ||||
Merge into: | lp:tapaal | ||||
Diff against target: |
569 lines (+297/-29) 9 files modified
src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java (+17/-6) src/dk/aau/cs/gui/undo/MakePlaceNewSharedCommand.java (+6/-4) src/dk/aau/cs/gui/undo/MakePlaceNewSharedMultiCommand.java (+93/-0) src/dk/aau/cs/gui/undo/MakeTransitionNewSharedCommand.java (+4/-2) src/dk/aau/cs/gui/undo/MakeTransitionNewSharedMultiCommand.java (+90/-0) src/dk/aau/cs/model/tapn/TimedArcPetriNet.java (+6/-3) src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java (+39/-6) src/pipe/gui/widgets/PlaceEditorPanel.java (+21/-3) src/pipe/gui/widgets/TAPNTransitionEditor.java (+21/-5) |
||||
To merge this branch: | bzr merge lp:~tapaal-contributor/tapaal/places-with-same-name-shared-1801728 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Approve | ||
Peter Haahr Taankvist (community) | Needs Resubmitting | ||
Review via email: mp+362645@code.launchpad.net |
Commit message
Description of the change
The GUI will now ask if the user wants to make all places of the same name shared, if the user tries to share a place which name is used by other places in different components.
This also applies for transitions.
- 985. By Peter Taankvist <email address hidden>
-
Remove unused code and debug lines
- 986. By Peter Taankvist <email address hidden>
-
Change error message for places and transitions
- 987. By Peter Taankvist <email address hidden>
-
Merge with trunk
- 988. By Peter Taankvist <email address hidden>
-
Add missing brackets, so it false is returned properly
- 989. By Peter Taankvist <email address hidden>
-
return false on no option, so nothing is done
Peter Haahr Taankvist (ptaank) wrote : | # |
Changed the message.
Added brackets around a return statement so it does not return false in either case.
Returns false when the no option is chosen, so that changes that are made when a place is shared, are not made.
Jiri Srba (srba) wrote : | # |
Before the message:
Do you want to share this place/transition name also in all other components?
is an extra empty space that should be removed.
Also, do you want to share this transition/place in the other components offers
yes/no dialog. Answering "no" is not logical, as it (as far as I can tell) does nothing.
The dialog should be rather ask:
"This place/transition name will be changed into shared one also in all other components."
and offer Cancel/OK dialog.
- 990. By Peter Taankvist <email address hidden>
-
Changed error message and made ok/cancel option instead
Peter Haahr Taankvist (ptaank) wrote : | # |
Changed the dialog to ok/cancel and changed the message
Jiri Srba (srba) wrote : | # |
Works as expected now. Will merge to trunk.
Preview Diff
1 | === modified file 'src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java' |
2 | --- src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java 2019-02-12 13:09:06 +0000 |
3 | +++ src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java 2019-03-04 13:28:08 +0000 |
4 | @@ -444,7 +444,10 @@ |
5 | } |
6 | |
7 | public void addSharedPlace(SharedPlace place){ |
8 | - sharedPlacesListModel.addElement(place); |
9 | + addSharedPlace(place, false); |
10 | + } |
11 | + public void addSharedPlace(SharedPlace place, boolean multiAdd){ |
12 | + sharedPlacesListModel.addElement(place, multiAdd); |
13 | } |
14 | |
15 | public void removeSharedTransition(SharedTransition transition){ |
16 | @@ -452,9 +455,11 @@ |
17 | sharedTransitionsListModel.removeElement(transition); |
18 | } |
19 | } |
20 | - |
21 | public void addSharedTransition(SharedTransition transition){ |
22 | - sharedTransitionsListModel.addElement(transition); |
23 | + addSharedTransition(transition, false); |
24 | + } |
25 | + public void addSharedTransition(SharedTransition transition, boolean multiAdd){ |
26 | + sharedTransitionsListModel.addElement(transition, multiAdd); |
27 | } |
28 | |
29 | public class SharedPlacesListModel extends AbstractListModel { |
30 | @@ -506,7 +511,10 @@ |
31 | } |
32 | |
33 | public void addElement(SharedPlace place){ |
34 | - network.add(place); |
35 | + addElement(place, false); |
36 | + } |
37 | + public void addElement(SharedPlace place, boolean multiAdd){ |
38 | + network.add(place, multiAdd); |
39 | fireIntervalAdded(this, network.numberOfSharedPlaces()-1, network.numberOfSharedPlaces()); |
40 | } |
41 | |
42 | @@ -584,9 +592,12 @@ |
43 | public int getSize() { |
44 | return network.numberOfSharedTransitions(); |
45 | } |
46 | - |
47 | public void addElement(SharedTransition transition){ |
48 | - network.add(transition); |
49 | + addElement(transition, false); |
50 | + } |
51 | + |
52 | + public void addElement(SharedTransition transition, boolean multiAdd){ |
53 | + network.add(transition, multiAdd); |
54 | fireIntervalAdded(this, network.numberOfSharedTransitions()-1, network.numberOfSharedTransitions()); |
55 | } |
56 | |
57 | |
58 | === modified file 'src/dk/aau/cs/gui/undo/MakePlaceNewSharedCommand.java' |
59 | --- src/dk/aau/cs/gui/undo/MakePlaceNewSharedCommand.java 2015-11-04 12:51:55 +0000 |
60 | +++ src/dk/aau/cs/gui/undo/MakePlaceNewSharedCommand.java 2019-03-04 13:28:08 +0000 |
61 | @@ -30,8 +30,9 @@ |
62 | private final TabContent currentTab; |
63 | private SharedPlacesAndTransitionsPanel sharedPanel; |
64 | private SharedPlace sharedPlace; |
65 | + private boolean multiShare; |
66 | |
67 | - public MakePlaceNewSharedCommand(TimedArcPetriNet tapn, String newSharedName, TimedPlace place, TimedPlaceComponent placeComponent, TabContent currentTab){ |
68 | + public MakePlaceNewSharedCommand(TimedArcPetriNet tapn, String newSharedName, TimedPlace place, TimedPlaceComponent placeComponent, TabContent currentTab, boolean multiShare){ |
69 | Require.that(tapn != null, "tapn cannot be null"); |
70 | Require.that(newSharedName != null, "newSharedName cannot be null"); |
71 | Require.that(place != null, "timedPlace cannot be null"); |
72 | @@ -45,6 +46,7 @@ |
73 | this.sharedPlace = null; |
74 | this.currentTab = currentTab; |
75 | this.sharedPanel = currentTab.getSharedPlacesAndTransitionsPanel(); |
76 | + this.multiShare = multiShare; |
77 | oldTokens = place.tokens(); |
78 | newQueryToOldQueryMapping = new Hashtable<TAPNQuery, TAPNQuery>(); |
79 | } |
80 | @@ -57,9 +59,9 @@ |
81 | sharedPlace = new SharedPlace(newSharedName); |
82 | } |
83 | |
84 | - sharedPanel.addSharedPlace(sharedPlace); |
85 | + sharedPanel.addSharedPlace(sharedPlace, multiShare); |
86 | updateArcs(place, sharedPlace); |
87 | - tapn.add(sharedPlace); |
88 | + tapn.add(sharedPlace, multiShare); |
89 | placeComponent.setUnderlyingPlace(sharedPlace); |
90 | |
91 | updateQueries(place, sharedPlace); |
92 | @@ -72,7 +74,7 @@ |
93 | } |
94 | updateArcs(sharedPlace, place); |
95 | tapn.remove(sharedPlace); |
96 | - tapn.add(place); |
97 | + tapn.add(place, multiShare); |
98 | place.addTokens(oldTokens); |
99 | placeComponent.setUnderlyingPlace(place); |
100 | |
101 | |
102 | === added file 'src/dk/aau/cs/gui/undo/MakePlaceNewSharedMultiCommand.java' |
103 | --- src/dk/aau/cs/gui/undo/MakePlaceNewSharedMultiCommand.java 1970-01-01 00:00:00 +0000 |
104 | +++ src/dk/aau/cs/gui/undo/MakePlaceNewSharedMultiCommand.java 2019-03-04 13:28:08 +0000 |
105 | @@ -0,0 +1,93 @@ |
106 | +package dk.aau.cs.gui.undo; |
107 | + |
108 | +import java.util.ArrayList; |
109 | +import java.util.HashMap; |
110 | +import java.util.Hashtable; |
111 | +import java.util.List; |
112 | +import java.util.Map.Entry; |
113 | + |
114 | +import javax.swing.undo.UndoManager; |
115 | + |
116 | +import pipe.dataLayer.DataLayer; |
117 | +import pipe.dataLayer.TAPNQuery; |
118 | +import pipe.dataLayer.Template; |
119 | +import pipe.gui.CreateGui; |
120 | +import pipe.gui.GuiFrame; |
121 | +import pipe.gui.graphicElements.Place; |
122 | +import pipe.gui.graphicElements.tapn.TimedPlaceComponent; |
123 | +import dk.aau.cs.TCTL.visitors.BooleanResult; |
124 | +import dk.aau.cs.TCTL.visitors.MakePlaceSharedVisitor; |
125 | +import dk.aau.cs.gui.Context; |
126 | +import dk.aau.cs.gui.NameGenerator; |
127 | +import dk.aau.cs.gui.SharedPlacesAndTransitionsPanel; |
128 | +import dk.aau.cs.gui.TabContent; |
129 | +import dk.aau.cs.model.tapn.LocalTimedPlace; |
130 | +import dk.aau.cs.model.tapn.SharedPlace; |
131 | +import dk.aau.cs.model.tapn.TimedArcPetriNet; |
132 | +import dk.aau.cs.model.tapn.TimedInhibitorArc; |
133 | +import dk.aau.cs.model.tapn.TimedInputArc; |
134 | +import dk.aau.cs.model.tapn.TimedOutputArc; |
135 | +import dk.aau.cs.model.tapn.TimedPlace; |
136 | +import dk.aau.cs.model.tapn.TimedToken; |
137 | +import dk.aau.cs.model.tapn.TransportArc; |
138 | +import dk.aau.cs.util.Require; |
139 | + |
140 | +public class MakePlaceNewSharedMultiCommand extends Command { |
141 | + |
142 | + private final String newSharedName; |
143 | + private final List<TimedArcPetriNet> tapns; |
144 | + private Hashtable<TAPNQuery, TAPNQuery> newQueryToOldQueryMapping; |
145 | + //private final List<TimedToken> oldTokens; |
146 | + private final TabContent currentTab; |
147 | + private SharedPlacesAndTransitionsPanel sharedPanel; |
148 | + private ArrayList<SharedPlace> sharedPlaces; |
149 | + private HashMap<TimedArcPetriNet, DataLayer> guiModels; |
150 | + private String originalName; |
151 | + private ArrayList<TimedPlace> timedPlaces = new ArrayList<TimedPlace>(); |
152 | + private NameGenerator nameGenerator; |
153 | + private pipe.gui.undo.UndoManager undoManager; |
154 | + private Context context; |
155 | + private Place place; |
156 | + private Command command; |
157 | + private List<Command> commands = new ArrayList<Command>(); |
158 | + |
159 | + |
160 | + |
161 | + public MakePlaceNewSharedMultiCommand(dk.aau.cs.gui.Context context, String newSharedName, TimedPlaceComponent place){ |
162 | + Require.that(context.network().allTemplates() != null, "tapns cannot be null"); |
163 | + Require.that(newSharedName != null, "newSharedName cannot be null"); |
164 | + Require.that(context.tabContent() != null, "currentTab cannot be null"); |
165 | + |
166 | + this.place = place; |
167 | + this.context = context; |
168 | + this.tapns = context.network().allTemplates(); |
169 | + this.newSharedName = newSharedName; |
170 | + this.sharedPlaces = new ArrayList<SharedPlace>(); |
171 | + this.currentTab = context.tabContent(); |
172 | + this.sharedPanel = currentTab.getSharedPlacesAndTransitionsPanel(); |
173 | + guiModels = context.tabContent().getGuiModels(); |
174 | + this.originalName = originalName; |
175 | + undoManager = currentTab.drawingSurface().getUndoManager(); |
176 | + //oldTokens = place.tokens(); |
177 | + newQueryToOldQueryMapping = new Hashtable<TAPNQuery, TAPNQuery>(); |
178 | + } |
179 | + |
180 | + @Override |
181 | + public void redo() { |
182 | + for(Template template : context.tabContent().allTemplates()) { |
183 | + TimedPlaceComponent component = (TimedPlaceComponent)template.guiModel().getPlaceByName(place.getName()); |
184 | + if(component != null) { |
185 | + command = new MakePlaceNewSharedCommand(template.model(), newSharedName, component.underlyingPlace(), component, context.tabContent(), true); |
186 | + command.redo(); |
187 | + commands.add(command); |
188 | + } |
189 | + } |
190 | + } |
191 | + |
192 | + @Override |
193 | + public void undo() { |
194 | + for(Command command : commands) |
195 | + command.undo(); |
196 | + } |
197 | + } |
198 | + |
199 | |
200 | === modified file 'src/dk/aau/cs/gui/undo/MakeTransitionNewSharedCommand.java' |
201 | --- src/dk/aau/cs/gui/undo/MakeTransitionNewSharedCommand.java 2015-11-04 20:11:26 +0000 |
202 | +++ src/dk/aau/cs/gui/undo/MakeTransitionNewSharedCommand.java 2019-03-04 13:28:08 +0000 |
203 | @@ -17,14 +17,16 @@ |
204 | private final String oldName; |
205 | private final TimedArcPetriNet tapn; |
206 | private SharedPlacesAndTransitionsPanel sharedPanel; |
207 | + private boolean multiShare; |
208 | |
209 | - public MakeTransitionNewSharedCommand(TimedArcPetriNet tapn, String newName, TimedTransition timedTransition, TabContent tabContent){ |
210 | + public MakeTransitionNewSharedCommand(TimedArcPetriNet tapn, String newName, TimedTransition timedTransition, TabContent tabContent, boolean multiShare){ |
211 | this.sharedTransition = null; |
212 | this.tapn = tapn; |
213 | this.timedTransition = timedTransition; |
214 | this.newName = newName; |
215 | this.oldName = timedTransition.name(); |
216 | this.sharedPanel = tabContent.getSharedPlacesAndTransitionsPanel(); |
217 | + this.multiShare = multiShare; |
218 | } |
219 | |
220 | @Override |
221 | @@ -33,7 +35,7 @@ |
222 | if(sharedTransition == null){ |
223 | sharedTransition = new SharedTransition(newName); |
224 | } |
225 | - sharedPanel.addSharedTransition(sharedTransition); |
226 | + sharedPanel.addSharedTransition(sharedTransition, multiShare); |
227 | sharedTransition.makeShared(timedTransition); |
228 | |
229 | tapn.add(timedTransition); |
230 | |
231 | === added file 'src/dk/aau/cs/gui/undo/MakeTransitionNewSharedMultiCommand.java' |
232 | --- src/dk/aau/cs/gui/undo/MakeTransitionNewSharedMultiCommand.java 1970-01-01 00:00:00 +0000 |
233 | +++ src/dk/aau/cs/gui/undo/MakeTransitionNewSharedMultiCommand.java 2019-03-04 13:28:08 +0000 |
234 | @@ -0,0 +1,90 @@ |
235 | +package dk.aau.cs.gui.undo; |
236 | + |
237 | +import java.util.ArrayList; |
238 | +import java.util.HashMap; |
239 | +import java.util.Hashtable; |
240 | +import java.util.List; |
241 | +import java.util.Map.Entry; |
242 | +import javax.swing.undo.UndoManager; |
243 | +import pipe.dataLayer.DataLayer; |
244 | +import pipe.dataLayer.TAPNQuery; |
245 | +import pipe.dataLayer.Template; |
246 | +import pipe.gui.CreateGui; |
247 | +import pipe.gui.GuiFrame; |
248 | +import pipe.gui.graphicElements.Place; |
249 | +import pipe.gui.graphicElements.Transition; |
250 | +import pipe.gui.graphicElements.tapn.TimedPlaceComponent; |
251 | +import pipe.gui.graphicElements.tapn.TimedTransitionComponent; |
252 | +import dk.aau.cs.TCTL.visitors.BooleanResult; |
253 | +import dk.aau.cs.TCTL.visitors.MakePlaceSharedVisitor; |
254 | +import dk.aau.cs.gui.Context; |
255 | +import dk.aau.cs.gui.NameGenerator; |
256 | +import dk.aau.cs.gui.SharedPlacesAndTransitionsPanel; |
257 | +import dk.aau.cs.gui.TabContent; |
258 | +import dk.aau.cs.model.tapn.LocalTimedPlace; |
259 | +import dk.aau.cs.model.tapn.SharedPlace; |
260 | +import dk.aau.cs.model.tapn.SharedTransition; |
261 | +import dk.aau.cs.model.tapn.TimedArcPetriNet; |
262 | +import dk.aau.cs.model.tapn.TimedInhibitorArc; |
263 | +import dk.aau.cs.model.tapn.TimedInputArc; |
264 | +import dk.aau.cs.model.tapn.TimedOutputArc; |
265 | +import dk.aau.cs.model.tapn.TimedPlace; |
266 | +import dk.aau.cs.model.tapn.TimedToken; |
267 | +import dk.aau.cs.model.tapn.TransportArc; |
268 | +import dk.aau.cs.util.Require; |
269 | + |
270 | +public class MakeTransitionNewSharedMultiCommand extends Command { |
271 | + private final String newSharedName; |
272 | + private final List<TimedArcPetriNet> tapns; |
273 | + private Hashtable<TAPNQuery, TAPNQuery> newQueryToOldQueryMapping; |
274 | + //private final List<TimedToken> oldTokens; |
275 | + private final TabContent currentTab; |
276 | + private SharedPlacesAndTransitionsPanel sharedPanel; |
277 | + private ArrayList<SharedPlace> sharedPlaces; |
278 | + private HashMap<TimedArcPetriNet, DataLayer> guiModels; |
279 | + private String originalName; |
280 | + private ArrayList<TimedPlace> timedPlaces = new ArrayList<TimedPlace>(); |
281 | + private NameGenerator nameGenerator; |
282 | + private pipe.gui.undo.UndoManager undoManager; |
283 | + private Context context; |
284 | + private Transition transition; |
285 | + private Command command; |
286 | + private List<Command> commands = new ArrayList<Command>(); |
287 | + |
288 | + |
289 | + |
290 | + public MakeTransitionNewSharedMultiCommand(dk.aau.cs.gui.Context context, String newSharedName, TimedTransitionComponent transition){ |
291 | + Require.that(context.network().allTemplates() != null, "tapns cannot be null"); |
292 | + Require.that(newSharedName != null, "newSharedName cannot be null"); |
293 | + Require.that(context.tabContent() != null, "currentTab cannot be null"); |
294 | + |
295 | + this.transition = transition; |
296 | + this.context = context; |
297 | + this.tapns = context.network().allTemplates(); |
298 | + this.newSharedName = newSharedName; |
299 | + this.currentTab = context.tabContent(); |
300 | + this.sharedPanel = currentTab.getSharedPlacesAndTransitionsPanel(); |
301 | + guiModels = context.tabContent().getGuiModels(); |
302 | + undoManager = currentTab.drawingSurface().getUndoManager(); |
303 | + //oldTokens = place.tokens(); |
304 | + newQueryToOldQueryMapping = new Hashtable<TAPNQuery, TAPNQuery>(); |
305 | + } |
306 | + |
307 | + @Override |
308 | + public void redo() { |
309 | + for(Template template : context.tabContent().allTemplates()) { |
310 | + TimedTransitionComponent component = (TimedTransitionComponent)template.guiModel().getTransitionByName(transition.getName()); |
311 | + if(component != null) { |
312 | + command = new MakeTransitionNewSharedCommand(template.model(), newSharedName, component.underlyingTransition(), context.tabContent(), true); |
313 | + command.redo(); |
314 | + commands.add(command); |
315 | + } |
316 | + } |
317 | + } |
318 | + |
319 | + @Override |
320 | + public void undo() { |
321 | + for(Command command : commands) |
322 | + command.undo(); |
323 | + } |
324 | +} |
325 | |
326 | === modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNet.java' |
327 | --- src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2016-04-21 19:11:59 +0000 |
328 | +++ src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2019-03-04 13:28:08 +0000 |
329 | @@ -6,7 +6,7 @@ |
330 | import java.util.List; |
331 | |
332 | import pipe.gui.undo.AddArcPathPointEdit; |
333 | - |
334 | +import pipe.gui.widgets.PlaceEditorPanel; |
335 | import dk.aau.cs.model.tapn.Bound.InfBound; |
336 | import dk.aau.cs.util.IntervalOperations; |
337 | import dk.aau.cs.util.Require; |
338 | @@ -49,9 +49,12 @@ |
339 | } |
340 | |
341 | public void add(TimedPlace place) { |
342 | + add(place, false); |
343 | + } |
344 | + public void add(TimedPlace place, boolean multiRemove) { |
345 | Require.that(place != null, "Argument must be a non-null place"); |
346 | - Require.that(!isNameUsed(place.name()) || (place.isShared() && !places.contains(place)), "A place or transition with the specified name already exists in the petri net."); |
347 | - |
348 | + if(!multiRemove) |
349 | + Require.that(!isNameUsed(place.name()) || (place.isShared() && !places.contains(place)), "A place or transition with the specified name already exists in the petri net."); |
350 | if(!place.isShared()) ((LocalTimedPlace)place).setModel(this); |
351 | places.add(place); |
352 | place.setCurrentMarking(currentMarking); |
353 | |
354 | === modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java' |
355 | --- src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java 2015-09-29 09:26:14 +0000 |
356 | +++ src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java 2019-03-04 13:28:08 +0000 |
357 | @@ -8,6 +8,7 @@ |
358 | import java.util.Set; |
359 | |
360 | import pipe.gui.MessengerImpl; |
361 | +import pipe.gui.widgets.PlaceEditorPanel; |
362 | import dk.aau.cs.gui.undo.Command; |
363 | import dk.aau.cs.model.tapn.event.ConstantChangedEvent; |
364 | import dk.aau.cs.model.tapn.event.ConstantEvent; |
365 | @@ -60,22 +61,35 @@ |
366 | currentMarking.addMarking(tapn, marking); |
367 | tapn.setMarking(currentMarking); |
368 | } |
369 | - |
370 | public void add(SharedTransition sharedTransition){ |
371 | + add(sharedTransition, false); |
372 | + } |
373 | + |
374 | + |
375 | + public void add(SharedTransition sharedTransition, boolean multiAdd){ |
376 | Require.that(sharedTransition != null, "sharedTransition must not be null"); |
377 | - Require.that(!isNameUsed(sharedTransition.name()), "There is already a transition or place with that name"); |
378 | + if(!multiAdd) { |
379 | + Require.that(!isNameUsed(sharedTransition.name()), "There is already a transition or place with that name"); |
380 | + } |
381 | |
382 | sharedTransition.setNetwork(this); |
383 | - sharedTransitions.add(sharedTransition); |
384 | + if(!(sharedTransitions.contains(sharedTransition))) |
385 | + sharedTransitions.add(sharedTransition); |
386 | } |
387 | |
388 | public void add(SharedPlace sharedPlace) { |
389 | + add(sharedPlace, false); |
390 | + } |
391 | + |
392 | + public void add(SharedPlace sharedPlace, boolean multiremove) { |
393 | Require.that(sharedPlace != null, "sharedPlace must not be null"); |
394 | - Require.that(!isNameUsed(sharedPlace.name()), "There is already a transition or place with that name"); |
395 | - |
396 | + if(multiremove == false) { |
397 | + Require.that(!isNameUsed(sharedPlace.name()), "There is already a transition or place with that name"); |
398 | + } |
399 | sharedPlace.setNetwork(this); |
400 | sharedPlace.setCurrentMarking(currentMarking); |
401 | - sharedPlaces.add(sharedPlace); |
402 | + if(!(sharedPlaces.contains(sharedPlace))) |
403 | + sharedPlaces.add(sharedPlace); |
404 | } |
405 | |
406 | public boolean isNameUsedForShared(String name){ |
407 | @@ -100,6 +114,25 @@ |
408 | } |
409 | return false; |
410 | } |
411 | + |
412 | + public boolean isNameUsedForPlacesOnly(String name) { |
413 | + for(TimedArcPetriNet net : tapns){ |
414 | + for(TimedTransition transition : net.transitions()) { |
415 | + if(name.equalsIgnoreCase(transition.name())) |
416 | + return false; |
417 | + } |
418 | + } |
419 | + return true; |
420 | + } |
421 | + public boolean isNameUsedForTransitionsOnly(String name) { |
422 | + for(TimedArcPetriNet net : tapns){ |
423 | + for(TimedPlace place : net.places()) { |
424 | + if(name.equalsIgnoreCase(place.name())) |
425 | + return false; |
426 | + } |
427 | + } |
428 | + return true; |
429 | + } |
430 | |
431 | public boolean isNameUsed(String name) { |
432 | return isNameUsedForShared(name) || isNameUsedInTemplates(name); |
433 | |
434 | === modified file 'src/pipe/gui/widgets/PlaceEditorPanel.java' |
435 | --- src/pipe/gui/widgets/PlaceEditorPanel.java 2018-11-05 14:29:27 +0000 |
436 | +++ src/pipe/gui/widgets/PlaceEditorPanel.java 2019-03-04 13:28:08 +0000 |
437 | @@ -13,6 +13,7 @@ |
438 | import java.util.Collection; |
439 | import java.util.Collections; |
440 | import java.util.Comparator; |
441 | +import java.util.HashMap; |
442 | import java.util.Set; |
443 | import java.util.Vector; |
444 | |
445 | @@ -28,15 +29,19 @@ |
446 | import javax.swing.event.ChangeEvent; |
447 | import javax.swing.event.ChangeListener; |
448 | |
449 | +import pipe.dataLayer.DataLayer; |
450 | import pipe.dataLayer.Template; |
451 | import pipe.gui.CreateGui; |
452 | import pipe.gui.Pipe; |
453 | +import pipe.gui.graphicElements.PetriNetObject; |
454 | +import pipe.gui.graphicElements.Place; |
455 | import pipe.gui.graphicElements.tapn.TimedPlaceComponent; |
456 | import dk.aau.cs.gui.Context; |
457 | import dk.aau.cs.gui.undo.ChangedInvariantCommand; |
458 | import dk.aau.cs.gui.undo.Command; |
459 | import dk.aau.cs.gui.undo.MakePlaceSharedCommand; |
460 | import dk.aau.cs.gui.undo.MakePlaceNewSharedCommand; |
461 | +import dk.aau.cs.gui.undo.MakePlaceNewSharedMultiCommand; |
462 | import dk.aau.cs.gui.undo.RenameTimedPlaceCommand; |
463 | import dk.aau.cs.gui.undo.TimedPlaceMarkingEdit; |
464 | import dk.aau.cs.gui.undo.UnsharePlaceCommand; |
465 | @@ -47,6 +52,7 @@ |
466 | import dk.aau.cs.model.tapn.LocalTimedPlace; |
467 | import dk.aau.cs.model.tapn.SharedPlace; |
468 | import dk.aau.cs.model.tapn.TimeInvariant; |
469 | +import dk.aau.cs.model.tapn.TimedArcPetriNet; |
470 | import dk.aau.cs.model.tapn.TimedInhibitorArc; |
471 | import dk.aau.cs.model.tapn.TimedInputArc; |
472 | import dk.aau.cs.model.tapn.TimedOutputArc; |
473 | @@ -701,14 +707,26 @@ |
474 | context.nameGenerator().updateIndices(context.activeModel(), newName); |
475 | |
476 | if(makeNewShared){ |
477 | - Command command = new MakePlaceNewSharedCommand(context.activeModel(), newName, place.underlyingPlace(), place, context.tabContent()); |
478 | + Command command = new MakePlaceNewSharedCommand(context.activeModel(), newName, place.underlyingPlace(), place, context.tabContent(), false); |
479 | context.undoManager().addEdit(command); |
480 | try{ |
481 | command.redo(); |
482 | }catch(RequireException e){ |
483 | context.undoManager().undo(); |
484 | - JOptionPane.showMessageDialog(this, "A transition or place with the specified name already exists in this or another component, or the specified name is invalid.\n\nAcceptable names for transitions are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nNote that \"true\" and \"false\" are reserved keywords.", "Error", JOptionPane.ERROR_MESSAGE); |
485 | - return false; |
486 | + //This is checked as a place cannot be shared if there exists a transition with the same name |
487 | + if(context.activeModel().parentNetwork().isNameUsedForPlacesOnly(newName)) { |
488 | + int dialogResult = JOptionPane.showConfirmDialog(this, "A place with the specified name already exists in one or more components, or the specified name is invalid.\n\nAcceptable names for places are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nNote that \"true\" and \"false\" are reserved keywords. \n\nThis place name will be changed into shared one also in all other components.", "Error", JOptionPane.OK_CANCEL_OPTION); |
489 | + if(dialogResult == JOptionPane.OK_OPTION) { |
490 | + Command cmd = new MakePlaceNewSharedMultiCommand(context, newName, place); |
491 | + cmd.redo(); |
492 | + context.undoManager().addNewEdit(cmd); |
493 | + } else { |
494 | + return false; |
495 | + } |
496 | + } else { |
497 | + JOptionPane.showMessageDialog(this, "A transition with the specified name already exists in one or more components, or the specified name is invalid.\n\nAcceptable names for places are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nNote that \"true\" and \"false\" are reserved keywords.", "Error", JOptionPane.OK_OPTION); |
498 | + return false; |
499 | + } |
500 | } |
501 | } |
502 | } |
503 | |
504 | === modified file 'src/pipe/gui/widgets/TAPNTransitionEditor.java' |
505 | --- src/pipe/gui/widgets/TAPNTransitionEditor.java 2018-05-18 17:51:11 +0000 |
506 | +++ src/pipe/gui/widgets/TAPNTransitionEditor.java 2019-03-04 13:28:08 +0000 |
507 | @@ -21,7 +21,9 @@ |
508 | import pipe.gui.graphicElements.tapn.TimedTransitionComponent; |
509 | import dk.aau.cs.gui.Context; |
510 | import dk.aau.cs.gui.undo.Command; |
511 | +import dk.aau.cs.gui.undo.MakePlaceNewSharedMultiCommand; |
512 | import dk.aau.cs.gui.undo.MakeTransitionNewSharedCommand; |
513 | +import dk.aau.cs.gui.undo.MakeTransitionNewSharedMultiCommand; |
514 | import dk.aau.cs.gui.undo.MakeTransitionSharedCommand; |
515 | import dk.aau.cs.gui.undo.RenameTimedTransitionCommand; |
516 | import dk.aau.cs.gui.undo.ToggleTransitionUrgent; |
517 | @@ -73,6 +75,7 @@ |
518 | |
519 | |
520 | |
521 | + |
522 | sharedTransitionsComboBox = new WidthAdjustingComboBox(maxNumberOfTransitionsToShowAtOnce); |
523 | sharedTransitionsComboBox.setPreferredSize(new Dimension(290,27)); |
524 | sharedTransitionsComboBox.addActionListener(new ActionListener() { |
525 | @@ -402,9 +405,9 @@ |
526 | transition.underlyingTransition().unshare(); |
527 | } |
528 | |
529 | - if(sharedCheckBox.isSelected()){ |
530 | + if(sharedCheckBox.isSelected()){ |
531 | SharedTransition selectedTransition = (SharedTransition)sharedTransitionsComboBox.getSelectedItem(); |
532 | - Command command = new MakeTransitionSharedCommand(context.activeModel(), selectedTransition, transition.underlyingTransition(), context.tabContent()); |
533 | + Command command = new MakeTransitionSharedCommand(context.activeModel(), selectedTransition, transition.underlyingTransition(), context.tabContent()); |
534 | context.undoManager().addEdit(command); |
535 | try{ |
536 | command.redo(); |
537 | @@ -436,16 +439,29 @@ |
538 | return false; |
539 | } |
540 | context.nameGenerator().updateIndices(transition.underlyingTransition().model(), newName); |
541 | + |
542 | |
543 | if(makeNewShared){ |
544 | - Command command = new MakeTransitionNewSharedCommand(context.activeModel(), newName, transition.underlyingTransition(), context.tabContent()); |
545 | + Command command = new MakeTransitionNewSharedCommand(context.activeModel(), newName, transition.underlyingTransition(), context.tabContent(), false); |
546 | context.undoManager().addEdit(command); |
547 | try{ |
548 | command.redo(); |
549 | }catch(RequireException e){ |
550 | context.undoManager().undo(); |
551 | - JOptionPane.showMessageDialog(this,"A transition or place with the specified name already exists, or the specified name is invalid.\n\nAcceptable names are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*", "Error", JOptionPane.ERROR_MESSAGE); |
552 | - return false; |
553 | + //This is checked as a transition cannot be shared if there exists a place with the same name |
554 | + if(transition.underlyingTransition().model().parentNetwork().isNameUsedForTransitionsOnly(newName)) { |
555 | + int dialogResult = JOptionPane.showConfirmDialog(this, "A transition with the specified name already exists in one or more components, or the specified name is invalid.\n\nAcceptable names for transitions are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nNote that \"true\" and \"false\" are reserved keywords. \n\nThis transition name will be changed into shared one also in all other components.", "Error", JOptionPane.OK_CANCEL_OPTION); |
556 | + if(dialogResult == JOptionPane.OK_OPTION) { |
557 | + Command cmd = new MakeTransitionNewSharedMultiCommand(context, newName, transition); |
558 | + cmd.redo(); |
559 | + context.undoManager().addEdit(cmd); |
560 | + } else { |
561 | + return false; |
562 | + } |
563 | + } else { |
564 | + JOptionPane.showMessageDialog(this, "A place with the specified name already exists in one or more components, or the specified name is invalid.\n\nAcceptable names for transitions are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nNote that \"true\" and \"false\" are reserved keywords.", "Error", JOptionPane.OK_OPTION); |
565 | + return false; |
566 | + } |
567 | } |
568 | transition.setUrgent(urgentCheckBox.isSelected()); |
569 | } |
A. Change the message:
Would you like to make the other places of the same name shared too?
into
Do you want to share this place name also in all other components?
The same for transitions.
B. For transitions this does not work. Open workflow- advanced. tapn example net,
remove the A0 shared transition, then double click on the transition and make it shared
and answer "YES". All seems fine but when you click ok, you get the error message:
"The specified name is already used by another place or transition."
C. Another bug is when you open alternating bit protocol with components, unshared the place Medium_A, then double click is and select "Make shared" and then answer "NO". You get NullPointerExce ption widgets. PlaceEditorPane l.switchToNameD ropDown( PlaceEditorPane l.java: 609) widgets. PlaceEditorPane l.access$ 200(PlaceEditor Panel.java: 63) widgets. PlaceEditorPane l$5.actionPerfo rmed(PlaceEdito rPanel. java:268) AbstractButton. fireActionPerfo rmed(AbstractBu tton.java: 2018) AbstractButton$ Handler. actionPerformed (AbstractButton .java:2341) DefaultButtonMo del.fireActionP erformed( DefaultButtonMo del.java: 402) DefaultButtonMo del.setPressed( DefaultButtonMo del.java: 259) plaf.basic. BasicButtonList ener.mouseRelea sed(BasicButton Listener. java:252) Component. processMouseEve nt(Component. java:6505) JComponent. processMouseEve nt(JComponent. java:3321)
NPE:
Exception in thread "AWT-EventQueue-0" java.lang.
at pipe.gui.
at pipe.gui.
at pipe.gui.
at javax.swing.
at javax.swing.
at javax.swing.
at javax.swing.
at javax.swing.
at java.awt.
at javax.swing.