Merge lp:~tapaal-contributor/tapaal/fix1953355 into lp:~tapaal-contributor/tapaal/cpn-gui-dev
- fix1953355
- Merge into cpn-gui-dev
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jiri Srba | ||||
Approved revision: | 1490 | ||||
Merged at revision: | 1497 | ||||
Proposed branch: | lp:~tapaal-contributor/tapaal/fix1953355 | ||||
Merge into: | lp:~tapaal-contributor/tapaal/cpn-gui-dev | ||||
Diff against target: |
276 lines (+131/-21) 4 files modified
src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java (+21/-10) src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java (+64/-8) src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java (+33/-1) src/pipe/gui/widgets/ConstantsDialogPanel.java (+13/-2) |
||||
To merge this branch: | bzr merge lp:~tapaal-contributor/tapaal/fix1953355 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Approve | ||
Review via email: mp+413443@code.launchpad.net |
This proposal supersedes a proposal from 2021-12-21.
Commit message
Description of the change
Jiri Srba (srba) wrote : Posted in a previous version of this proposal | # |
Jiri Srba (srba) wrote : Posted in a previous version of this proposal | # |
It is possible to make an enumeartion color type with element a1 and then created a colortype called a1 - this should be forbidden.
Example what should not be allowed:
c is [a1,a2,a3]
a1 is [2,3]
Jiri Srba (srba) wrote : | # |
There is still one problem, declare a constant called c and the create an enumeration color type and now the element called c can be added there. This should be disabled too.
Finally, it would be nice if the check for enumeration is done at the moment you click "add" the element name and not at the very end once you click "ok".
- 1489. By Kenneth Yrke Jørgensen
-
Fixed Enum Color not checking variable named and added check when adding enum type
Jiri Srba (srba) wrote : | # |
I just realised that the names are case sensitive,
so if I have color type
Votes is [1,2,3]
I can still create a constant
voters
but if I name it as Voters that I get the warning.
Jiri Srba (srba) wrote : | # |
But sometimes it is not case sensitive, if I make a constant c
and try to add it as element to enumearation, I get the warning
both if I try with c and C.
- 1490. By Kenneth Yrke Jørgensen
-
ColorTypes, Colors, Variables and Constant named must be unique ignored case
Also fixes and bug where you could add several Colors of the same name to an color type
Jiri Srba (srba) wrote : | # |
tested and works perfectly fine
Preview Diff
1 | === modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java' | |||
2 | --- src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java 2021-08-27 08:42:36 +0000 | |||
3 | +++ src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java 2021-12-23 09:04:13 +0000 | |||
4 | @@ -5,7 +5,6 @@ | |||
5 | 5 | import dk.aau.cs.gui.undo.Colored.*; | 5 | import dk.aau.cs.gui.undo.Colored.*; |
6 | 6 | import dk.aau.cs.model.CPN.*; | 6 | import dk.aau.cs.model.CPN.*; |
7 | 7 | import dk.aau.cs.model.CPN.Expressions.*; | 7 | import dk.aau.cs.model.CPN.Expressions.*; |
8 | 8 | import org.jetbrains.annotations.NotNull; | ||
9 | 9 | import pipe.gui.MessengerImpl; | 8 | import pipe.gui.MessengerImpl; |
10 | 10 | import dk.aau.cs.gui.undo.Command; | 9 | import dk.aau.cs.gui.undo.Command; |
11 | 11 | import dk.aau.cs.model.tapn.event.ConstantChangedEvent; | 10 | import dk.aau.cs.model.tapn.event.ConstantChangedEvent; |
12 | @@ -195,10 +194,6 @@ | |||
13 | 195 | } | 194 | } |
14 | 196 | } | 195 | } |
15 | 197 | 196 | ||
16 | 198 | public boolean isConstantNameUsed(String newName) { | ||
17 | 199 | return constants.containsConstantByName(newName); | ||
18 | 200 | } | ||
19 | 201 | |||
20 | 202 | public void buildConstraints() { | 197 | public void buildConstraints() { |
21 | 203 | constants.buildConstraints(this); | 198 | constants.buildConstraints(this); |
22 | 204 | } | 199 | } |
23 | @@ -691,15 +686,15 @@ | |||
24 | 691 | } | 686 | } |
25 | 692 | return null; | 687 | return null; |
26 | 693 | } | 688 | } |
27 | 689 | |||
28 | 694 | public boolean isNameUsedForColorType(String name) { | 690 | public boolean isNameUsedForColorType(String name) { |
29 | 695 | for (ColorType element : colorTypes) { | 691 | for (ColorType element : colorTypes) { |
31 | 696 | if (element.getName().equals(name)) { | 692 | if (element.getName().equalsIgnoreCase(name)) { |
32 | 697 | return true; | 693 | return true; |
33 | 698 | } | 694 | } |
34 | 699 | } | 695 | } |
35 | 700 | return false; | 696 | return false; |
36 | 701 | } | 697 | } |
37 | 702 | |||
38 | 703 | public boolean isNameUsedForVariable(String name) { | 698 | public boolean isNameUsedForVariable(String name) { |
39 | 704 | for (Variable element : variables) { | 699 | for (Variable element : variables) { |
40 | 705 | if (element.getName().equalsIgnoreCase(name)) { | 700 | if (element.getName().equalsIgnoreCase(name)) { |
41 | @@ -708,10 +703,26 @@ | |||
42 | 708 | } | 703 | } |
43 | 709 | return false; | 704 | return false; |
44 | 710 | } | 705 | } |
45 | 706 | public boolean isNameUsedForColor(String name, ColorType ignored) { | ||
46 | 707 | for (ColorType e : colorTypes) { | ||
47 | 708 | if (e != ignored && !e.isIntegerRange() && !e.isProductColorType()){ | ||
48 | 709 | for (Color c : e.getColors()) { | ||
49 | 710 | if (c.getName().equalsIgnoreCase(name)) { | ||
50 | 711 | return true; | ||
51 | 712 | } | ||
52 | 713 | } | ||
53 | 714 | } | ||
54 | 715 | } | ||
55 | 716 | return false; | ||
56 | 717 | } | ||
57 | 718 | public boolean isNameUsedForConstant(String newName) { | ||
58 | 719 | return constants.containsConstantByName(newName); | ||
59 | 720 | } | ||
60 | 721 | |||
61 | 711 | public Variable getVariableByName(String name){ | 722 | public Variable getVariableByName(String name){ |
65 | 712 | for (int i = 0; i < variables.size(); i++) { | 723 | for (Variable variable : variables) { |
66 | 713 | if (variables.get(i).getName().equalsIgnoreCase(name)) { | 724 | if (variable.getName().equalsIgnoreCase(name)) { |
67 | 714 | return variables.get(i); | 725 | return variable; |
68 | 715 | } | 726 | } |
69 | 716 | } | 727 | } |
70 | 717 | return null; | 728 | return null; |
71 | 718 | 729 | ||
72 | === modified file 'src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java' | |||
73 | --- src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java 2021-08-30 07:07:52 +0000 | |||
74 | +++ src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java 2021-12-23 09:04:13 +0000 | |||
75 | @@ -189,7 +189,7 @@ | |||
76 | 189 | private JPanel createNameAndTypePanel() { | 189 | private JPanel createNameAndTypePanel() { |
77 | 190 | JPanel nameAndTypePanel = new JPanel(); | 190 | JPanel nameAndTypePanel = new JPanel(); |
78 | 191 | nameAndTypePanel.setLayout(new GridBagLayout()); | 191 | nameAndTypePanel.setLayout(new GridBagLayout()); |
80 | 192 | nameAndTypePanel.setBorder(BorderFactory.createTitledBorder("Name and Color Type")); | 192 | nameAndTypePanel.setBorder(BorderFactory.createTitledBorder("Name of Color Type")); |
81 | 193 | 193 | ||
82 | 194 | JLabel nameLabel = new JLabel(); | 194 | JLabel nameLabel = new JLabel(); |
83 | 195 | nameLabel.setText("Name: "); | 195 | nameLabel.setText("Name: "); |
84 | @@ -451,16 +451,20 @@ | |||
85 | 451 | "The color cannot be named \"" + enumerationName + "\", as the name is reserved", | 451 | "The color cannot be named \"" + enumerationName + "\", as the name is reserved", |
86 | 452 | "Error", JOptionPane.ERROR_MESSAGE); | 452 | "Error", JOptionPane.ERROR_MESSAGE); |
87 | 453 | } else { | 453 | } else { |
93 | 454 | boolean inList = false; | 454 | boolean nameIsInUse = network.isNameUsedForVariable(enumerationName) || network.isNameUsedForColor(enumerationName, null) || network.isNameUsedForColorType(enumerationName) || network.isNameUsedForConstant(enumerationName) || nameTextField.getText().equalsIgnoreCase(enumerationName); |
94 | 455 | int i = 0; | 455 | for (int i = 0; i < cyclicModel.getSize(); i++) { |
95 | 456 | while (!inList && i < cyclicModel.getSize() && cyclicModel.getElementAt(i) != null) { | 456 | String n = cyclicModel.getElementAt(i).toString(); |
96 | 457 | inList = cyclicModel.getElementAt(i).toString().equals(enumTextField.getText()); | 457 | |
97 | 458 | i++; | 458 | if (n.equalsIgnoreCase(enumerationName)) { |
98 | 459 | nameIsInUse = true; | ||
99 | 460 | break; | ||
100 | 461 | } | ||
101 | 459 | } | 462 | } |
103 | 460 | if (inList) { | 463 | |
104 | 464 | if (nameIsInUse) { | ||
105 | 461 | JOptionPane.showMessageDialog( | 465 | JOptionPane.showMessageDialog( |
106 | 462 | CreateGui.getApp(), | 466 | CreateGui.getApp(), |
108 | 463 | "A color with the name \"" + enumerationName + "\" already exists", | 467 | "A color, color type, variable or constant with the name \"" + enumerationName + "\" already exists. Please chose an other name.", |
109 | 464 | "Error", JOptionPane.ERROR_MESSAGE); | 468 | "Error", JOptionPane.ERROR_MESSAGE); |
110 | 465 | } else { | 469 | } else { |
111 | 466 | cyclicModel.addElement(enumTextField.getText()); | 470 | cyclicModel.addElement(enumTextField.getText()); |
112 | @@ -877,6 +881,30 @@ | |||
113 | 877 | "Error", JOptionPane.ERROR_MESSAGE); | 881 | "Error", JOptionPane.ERROR_MESSAGE); |
114 | 878 | return; | 882 | return; |
115 | 879 | } | 883 | } |
116 | 884 | if (network.isNameUsedForVariable(name)) { | ||
117 | 885 | JOptionPane.showMessageDialog( | ||
118 | 886 | CreateGui.getApp(), | ||
119 | 887 | "There is already variable with the same name.\n\n" | ||
120 | 888 | + "Choose a different name for the color type.", | ||
121 | 889 | "Error", JOptionPane.ERROR_MESSAGE); | ||
122 | 890 | return; | ||
123 | 891 | } | ||
124 | 892 | if (network.isNameUsedForConstant(name)) { | ||
125 | 893 | JOptionPane.showMessageDialog( | ||
126 | 894 | CreateGui.getApp(), | ||
127 | 895 | "There is already a constant with the same name.\n\n" | ||
128 | 896 | + "Choose a different name for the color type.", | ||
129 | 897 | "Error", JOptionPane.ERROR_MESSAGE); | ||
130 | 898 | return; | ||
131 | 899 | } | ||
132 | 900 | if (network.isNameUsedForColor(name, null)) { | ||
133 | 901 | JOptionPane.showMessageDialog( | ||
134 | 902 | CreateGui.getApp(), | ||
135 | 903 | "There is already a color with the same name.\n\n" | ||
136 | 904 | + "Choose a different name for the color type.", | ||
137 | 905 | "Error", JOptionPane.ERROR_MESSAGE); | ||
138 | 906 | return; | ||
139 | 907 | } | ||
140 | 880 | if (!oldName.equals("") && !oldName.equalsIgnoreCase(name) && network.isNameUsedForColorType(name)) { | 908 | if (!oldName.equals("") && !oldName.equalsIgnoreCase(name) && network.isNameUsedForColorType(name)) { |
141 | 881 | JOptionPane.showMessageDialog( | 909 | JOptionPane.showMessageDialog( |
142 | 882 | CreateGui.getApp(), | 910 | CreateGui.getApp(), |
143 | @@ -953,6 +981,34 @@ | |||
144 | 953 | 981 | ||
145 | 954 | //If everything is false add the colortype | 982 | //If everything is false add the colortype |
146 | 955 | String selectedColorType = colorTypeComboBox.getSelectedItem().toString(); | 983 | String selectedColorType = colorTypeComboBox.getSelectedItem().toString(); |
147 | 984 | |||
148 | 985 | //Enum named are not allow to overlap with variable names | ||
149 | 986 | switch (selectedColorType) { | ||
150 | 987 | case finiteEnumeration: //Fall through | ||
151 | 988 | case cyclicEnumeration: | ||
152 | 989 | |||
153 | 990 | ArrayList<String> overlaps = new ArrayList<>(); | ||
154 | 991 | for (int i = 0; i < enumList.getModel().getSize(); i++) { | ||
155 | 992 | String e = enumList.getModel().getElementAt(i).toString(); | ||
156 | 993 | if (network.isNameUsedForVariable(e) || network.isNameUsedForColor(e, oldColorType) || network.isNameUsedForColorType(e) || network.isNameUsedForConstant(e) || name.equalsIgnoreCase(e)) { | ||
157 | 994 | overlaps.add(e); | ||
158 | 995 | } | ||
159 | 996 | } | ||
160 | 997 | if (overlaps.size() > 0) { | ||
161 | 998 | JOptionPane.showMessageDialog( | ||
162 | 999 | CreateGui.getApp(), | ||
163 | 1000 | "Color names must not overlap with variable names or other color names: \n" + | ||
164 | 1001 | "Remove or rename the following: \n" + | ||
165 | 1002 | String.join(", ", overlaps), | ||
166 | 1003 | "Error", JOptionPane.ERROR_MESSAGE); | ||
167 | 1004 | return; | ||
168 | 1005 | } | ||
169 | 1006 | |||
170 | 1007 | //No overlap between | ||
171 | 1008 | |||
172 | 1009 | break; | ||
173 | 1010 | } | ||
174 | 1011 | |||
175 | 956 | ColorType newColorType = new ColorType(name); | 1012 | ColorType newColorType = new ColorType(name); |
176 | 957 | 1013 | ||
177 | 958 | switch (selectedColorType) { | 1014 | switch (selectedColorType) { |
178 | 959 | 1015 | ||
179 | === modified file 'src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java' | |||
180 | --- src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java 2021-07-02 12:10:22 +0000 | |||
181 | +++ src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java 2021-12-23 09:04:13 +0000 | |||
182 | @@ -261,7 +261,7 @@ | |||
183 | 261 | return; | 261 | return; |
184 | 262 | } | 262 | } |
185 | 263 | //If we are editing a variable it is allowed to have the same name | 263 | //If we are editing a variable it is allowed to have the same name |
187 | 264 | if (network.isNameUsedForVariable(newName) && (variable == null || !variable.getName().equals(newName))) { | 264 | if ((variable == null || !variable.getName().equalsIgnoreCase(newName)) && network.isNameUsedForVariable(newName) ) { |
188 | 265 | JOptionPane | 265 | JOptionPane |
189 | 266 | .showMessageDialog( | 266 | .showMessageDialog( |
190 | 267 | CreateGui.getApp(), | 267 | CreateGui.getApp(), |
191 | @@ -281,6 +281,38 @@ | |||
192 | 281 | nameTextField.requestFocusInWindow(); | 281 | nameTextField.requestFocusInWindow(); |
193 | 282 | return; | 282 | return; |
194 | 283 | } | 283 | } |
195 | 284 | |||
196 | 285 | if (network.isNameUsedForConstant(newName)) { | ||
197 | 286 | JOptionPane | ||
198 | 287 | .showMessageDialog( | ||
199 | 288 | CreateGui.getApp(), | ||
200 | 289 | "There is already a constant with this name.\n\n" | ||
201 | 290 | + "Choose a different name for the variable.", | ||
202 | 291 | "Error", JOptionPane.ERROR_MESSAGE); | ||
203 | 292 | return; | ||
204 | 293 | } | ||
205 | 294 | |||
206 | 295 | if (network.isNameUsedForColorType(newName)) { | ||
207 | 296 | JOptionPane | ||
208 | 297 | .showMessageDialog( | ||
209 | 298 | CreateGui.getApp(), | ||
210 | 299 | "There is already a Color Type with this name.\n\n" | ||
211 | 300 | + "Choose a different name for the variable.", | ||
212 | 301 | "Error", JOptionPane.ERROR_MESSAGE); | ||
213 | 302 | return; | ||
214 | 303 | } | ||
215 | 304 | |||
216 | 305 | //Variable name is not allow to overlap with enum names | ||
217 | 306 | if (network.isNameUsedForColor(newName, null)) { | ||
218 | 307 | JOptionPane | ||
219 | 308 | .showMessageDialog( | ||
220 | 309 | CreateGui.getApp(), | ||
221 | 310 | "There is already a Color with this name.\n\n" | ||
222 | 311 | + "Choose a different name for the variable.", | ||
223 | 312 | "Error", JOptionPane.ERROR_MESSAGE); | ||
224 | 313 | return; | ||
225 | 314 | } | ||
226 | 315 | |||
227 | 284 | Command cmd; | 316 | Command cmd; |
228 | 285 | if (!oldName.equals("")) { | 317 | if (!oldName.equals("")) { |
229 | 286 | cmd = new UpdateVariableCommand(variable, nameTextField.getText(), colorTypes.get(colorTypeComboBox.getSelectedIndex()), listModel); | 318 | cmd = new UpdateVariableCommand(variable, nameTextField.getText(), colorTypes.get(colorTypeComboBox.getSelectedIndex()), listModel); |
230 | 287 | 319 | ||
231 | === modified file 'src/pipe/gui/widgets/ConstantsDialogPanel.java' | |||
232 | --- src/pipe/gui/widgets/ConstantsDialogPanel.java 2021-11-04 13:34:08 +0000 | |||
233 | +++ src/pipe/gui/widgets/ConstantsDialogPanel.java 2021-12-23 09:04:13 +0000 | |||
234 | @@ -11,7 +11,6 @@ | |||
235 | 11 | import javax.swing.JLabel; | 11 | import javax.swing.JLabel; |
236 | 12 | import javax.swing.JOptionPane; | 12 | import javax.swing.JOptionPane; |
237 | 13 | import javax.swing.JPanel; | 13 | import javax.swing.JPanel; |
238 | 14 | import javax.swing.JRootPane; | ||
239 | 15 | import javax.swing.JSpinner; | 14 | import javax.swing.JSpinner; |
240 | 16 | import javax.swing.JTextField; | 15 | import javax.swing.JTextField; |
241 | 17 | 16 | ||
242 | @@ -197,6 +196,17 @@ | |||
243 | 197 | return; | 196 | return; |
244 | 198 | } | 197 | } |
245 | 199 | 198 | ||
246 | 199 | if (model.isNameUsedForColorType(newName) || model.isNameUsedForVariable(newName) || model.isNameUsedForColor(newName, null)) { | ||
247 | 200 | JOptionPane | ||
248 | 201 | .showMessageDialog( | ||
249 | 202 | CreateGui.getApp(), | ||
250 | 203 | "There is already another Color, Color Type or Variable with the same name.\n\n" | ||
251 | 204 | + "Choose a different name for the constant.", | ||
252 | 205 | "Error", JOptionPane.ERROR_MESSAGE); | ||
253 | 206 | nameTextField.requestFocusInWindow(); | ||
254 | 207 | return; | ||
255 | 208 | } | ||
256 | 209 | |||
257 | 200 | if (newName.trim().isEmpty()) { | 210 | if (newName.trim().isEmpty()) { |
258 | 201 | JOptionPane.showMessageDialog(CreateGui.getApp(), | 211 | JOptionPane.showMessageDialog(CreateGui.getApp(), |
259 | 202 | "You must specify a name.", "Missing name", | 212 | "You must specify a name.", "Missing name", |
260 | @@ -207,7 +217,7 @@ | |||
261 | 207 | int val = (Integer) valueSpinner.getValue(); | 217 | int val = (Integer) valueSpinner.getValue(); |
262 | 208 | if (!oldName.equals("")) { | 218 | if (!oldName.equals("")) { |
263 | 209 | if (!oldName.equalsIgnoreCase(newName) | 219 | if (!oldName.equalsIgnoreCase(newName) |
265 | 210 | && model.isConstantNameUsed(newName)) { | 220 | && model.isNameUsedForConstant(newName)) { |
266 | 211 | JOptionPane | 221 | JOptionPane |
267 | 212 | .showMessageDialog( | 222 | .showMessageDialog( |
268 | 213 | CreateGui.getApp(), | 223 | CreateGui.getApp(), |
269 | @@ -217,6 +227,7 @@ | |||
270 | 217 | nameTextField.requestFocusInWindow(); | 227 | nameTextField.requestFocusInWindow(); |
271 | 218 | return; | 228 | return; |
272 | 219 | } | 229 | } |
273 | 230 | |||
274 | 220 | //Kyrke - This is messy, but a quck fix for bug #815487 | 231 | //Kyrke - This is messy, but a quck fix for bug #815487 |
275 | 221 | //Check that the value is within the allowed bounds | 232 | //Check that the value is within the allowed bounds |
276 | 222 | if (!( lowerBound <= val && val <= upperBound )){ | 233 | if (!( lowerBound <= val && val <= upperBound )){ |
Add also a check against constants please - now I can declare e.g. constant c and also color type c.