Merge lp:~tapaal-contributor/tapaal/fix1953355 into lp:~tapaal-contributor/tapaal/cpn-gui-dev

Proposed by Kenneth Yrke Jørgensen
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
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.

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote : Posted in a previous version of this proposal

Add also a check against constants please - now I can declare e.g. constant c and also color type c.

review: Needs Fixing
Revision history for this message
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]

review: Needs Fixing
Revision history for this message
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".

review: Needs Fixing
1489. By Kenneth Yrke Jørgensen

Fixed Enum Color not checking variable named and added check when adding enum type

Revision history for this message
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.

review: Needs Fixing
Revision history for this message
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

Revision history for this message
Jiri Srba (srba) wrote :

tested and works perfectly fine

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/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 import dk.aau.cs.gui.undo.Colored.*;
6 import dk.aau.cs.model.CPN.*;
7 import dk.aau.cs.model.CPN.Expressions.*;
8-import org.jetbrains.annotations.NotNull;
9 import pipe.gui.MessengerImpl;
10 import dk.aau.cs.gui.undo.Command;
11 import dk.aau.cs.model.tapn.event.ConstantChangedEvent;
12@@ -195,10 +194,6 @@
13 }
14 }
15
16- public boolean isConstantNameUsed(String newName) {
17- return constants.containsConstantByName(newName);
18- }
19-
20 public void buildConstraints() {
21 constants.buildConstraints(this);
22 }
23@@ -691,15 +686,15 @@
24 }
25 return null;
26 }
27+
28 public boolean isNameUsedForColorType(String name) {
29 for (ColorType element : colorTypes) {
30- if (element.getName().equals(name)) {
31+ if (element.getName().equalsIgnoreCase(name)) {
32 return true;
33 }
34 }
35 return false;
36 }
37-
38 public boolean isNameUsedForVariable(String name) {
39 for (Variable element : variables) {
40 if (element.getName().equalsIgnoreCase(name)) {
41@@ -708,10 +703,26 @@
42 }
43 return false;
44 }
45+ public boolean isNameUsedForColor(String name, ColorType ignored) {
46+ for (ColorType e : colorTypes) {
47+ if (e != ignored && !e.isIntegerRange() && !e.isProductColorType()){
48+ for (Color c : e.getColors()) {
49+ if (c.getName().equalsIgnoreCase(name)) {
50+ return true;
51+ }
52+ }
53+ }
54+ }
55+ return false;
56+ }
57+ public boolean isNameUsedForConstant(String newName) {
58+ return constants.containsConstantByName(newName);
59+ }
60+
61 public Variable getVariableByName(String name){
62- for (int i = 0; i < variables.size(); i++) {
63- if (variables.get(i).getName().equalsIgnoreCase(name)) {
64- return variables.get(i);
65+ for (Variable variable : variables) {
66+ if (variable.getName().equalsIgnoreCase(name)) {
67+ return variable;
68 }
69 }
70 return null;
71
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 private JPanel createNameAndTypePanel() {
77 JPanel nameAndTypePanel = new JPanel();
78 nameAndTypePanel.setLayout(new GridBagLayout());
79- nameAndTypePanel.setBorder(BorderFactory.createTitledBorder("Name and Color Type"));
80+ nameAndTypePanel.setBorder(BorderFactory.createTitledBorder("Name of Color Type"));
81
82 JLabel nameLabel = new JLabel();
83 nameLabel.setText("Name: ");
84@@ -451,16 +451,20 @@
85 "The color cannot be named \"" + enumerationName + "\", as the name is reserved",
86 "Error", JOptionPane.ERROR_MESSAGE);
87 } else {
88- boolean inList = false;
89- int i = 0;
90- while (!inList && i < cyclicModel.getSize() && cyclicModel.getElementAt(i) != null) {
91- inList = cyclicModel.getElementAt(i).toString().equals(enumTextField.getText());
92- i++;
93+ boolean nameIsInUse = network.isNameUsedForVariable(enumerationName) || network.isNameUsedForColor(enumerationName, null) || network.isNameUsedForColorType(enumerationName) || network.isNameUsedForConstant(enumerationName) || nameTextField.getText().equalsIgnoreCase(enumerationName);
94+ for (int i = 0; i < cyclicModel.getSize(); i++) {
95+ String n = cyclicModel.getElementAt(i).toString();
96+
97+ if (n.equalsIgnoreCase(enumerationName)) {
98+ nameIsInUse = true;
99+ break;
100+ }
101 }
102- if (inList) {
103+
104+ if (nameIsInUse) {
105 JOptionPane.showMessageDialog(
106 CreateGui.getApp(),
107- "A color with the name \"" + enumerationName + "\" already exists",
108+ "A color, color type, variable or constant with the name \"" + enumerationName + "\" already exists. Please chose an other name.",
109 "Error", JOptionPane.ERROR_MESSAGE);
110 } else {
111 cyclicModel.addElement(enumTextField.getText());
112@@ -877,6 +881,30 @@
113 "Error", JOptionPane.ERROR_MESSAGE);
114 return;
115 }
116+ if (network.isNameUsedForVariable(name)) {
117+ JOptionPane.showMessageDialog(
118+ CreateGui.getApp(),
119+ "There is already variable with the same name.\n\n"
120+ + "Choose a different name for the color type.",
121+ "Error", JOptionPane.ERROR_MESSAGE);
122+ return;
123+ }
124+ if (network.isNameUsedForConstant(name)) {
125+ JOptionPane.showMessageDialog(
126+ CreateGui.getApp(),
127+ "There is already a constant with the same name.\n\n"
128+ + "Choose a different name for the color type.",
129+ "Error", JOptionPane.ERROR_MESSAGE);
130+ return;
131+ }
132+ if (network.isNameUsedForColor(name, null)) {
133+ JOptionPane.showMessageDialog(
134+ CreateGui.getApp(),
135+ "There is already a color with the same name.\n\n"
136+ + "Choose a different name for the color type.",
137+ "Error", JOptionPane.ERROR_MESSAGE);
138+ return;
139+ }
140 if (!oldName.equals("") && !oldName.equalsIgnoreCase(name) && network.isNameUsedForColorType(name)) {
141 JOptionPane.showMessageDialog(
142 CreateGui.getApp(),
143@@ -953,6 +981,34 @@
144
145 //If everything is false add the colortype
146 String selectedColorType = colorTypeComboBox.getSelectedItem().toString();
147+
148+ //Enum named are not allow to overlap with variable names
149+ switch (selectedColorType) {
150+ case finiteEnumeration: //Fall through
151+ case cyclicEnumeration:
152+
153+ ArrayList<String> overlaps = new ArrayList<>();
154+ for (int i = 0; i < enumList.getModel().getSize(); i++) {
155+ String e = enumList.getModel().getElementAt(i).toString();
156+ if (network.isNameUsedForVariable(e) || network.isNameUsedForColor(e, oldColorType) || network.isNameUsedForColorType(e) || network.isNameUsedForConstant(e) || name.equalsIgnoreCase(e)) {
157+ overlaps.add(e);
158+ }
159+ }
160+ if (overlaps.size() > 0) {
161+ JOptionPane.showMessageDialog(
162+ CreateGui.getApp(),
163+ "Color names must not overlap with variable names or other color names: \n" +
164+ "Remove or rename the following: \n" +
165+ String.join(", ", overlaps),
166+ "Error", JOptionPane.ERROR_MESSAGE);
167+ return;
168+ }
169+
170+ //No overlap between
171+
172+ break;
173+ }
174+
175 ColorType newColorType = new ColorType(name);
176
177 switch (selectedColorType) {
178
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 return;
184 }
185 //If we are editing a variable it is allowed to have the same name
186- if (network.isNameUsedForVariable(newName) && (variable == null || !variable.getName().equals(newName))) {
187+ if ((variable == null || !variable.getName().equalsIgnoreCase(newName)) && network.isNameUsedForVariable(newName) ) {
188 JOptionPane
189 .showMessageDialog(
190 CreateGui.getApp(),
191@@ -281,6 +281,38 @@
192 nameTextField.requestFocusInWindow();
193 return;
194 }
195+
196+ if (network.isNameUsedForConstant(newName)) {
197+ JOptionPane
198+ .showMessageDialog(
199+ CreateGui.getApp(),
200+ "There is already a constant with this name.\n\n"
201+ + "Choose a different name for the variable.",
202+ "Error", JOptionPane.ERROR_MESSAGE);
203+ return;
204+ }
205+
206+ if (network.isNameUsedForColorType(newName)) {
207+ JOptionPane
208+ .showMessageDialog(
209+ CreateGui.getApp(),
210+ "There is already a Color Type with this name.\n\n"
211+ + "Choose a different name for the variable.",
212+ "Error", JOptionPane.ERROR_MESSAGE);
213+ return;
214+ }
215+
216+ //Variable name is not allow to overlap with enum names
217+ if (network.isNameUsedForColor(newName, null)) {
218+ JOptionPane
219+ .showMessageDialog(
220+ CreateGui.getApp(),
221+ "There is already a Color with this name.\n\n"
222+ + "Choose a different name for the variable.",
223+ "Error", JOptionPane.ERROR_MESSAGE);
224+ return;
225+ }
226+
227 Command cmd;
228 if (!oldName.equals("")) {
229 cmd = new UpdateVariableCommand(variable, nameTextField.getText(), colorTypes.get(colorTypeComboBox.getSelectedIndex()), listModel);
230
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 import javax.swing.JLabel;
236 import javax.swing.JOptionPane;
237 import javax.swing.JPanel;
238-import javax.swing.JRootPane;
239 import javax.swing.JSpinner;
240 import javax.swing.JTextField;
241
242@@ -197,6 +196,17 @@
243 return;
244 }
245
246+ if (model.isNameUsedForColorType(newName) || model.isNameUsedForVariable(newName) || model.isNameUsedForColor(newName, null)) {
247+ JOptionPane
248+ .showMessageDialog(
249+ CreateGui.getApp(),
250+ "There is already another Color, Color Type or Variable with the same name.\n\n"
251+ + "Choose a different name for the constant.",
252+ "Error", JOptionPane.ERROR_MESSAGE);
253+ nameTextField.requestFocusInWindow();
254+ return;
255+ }
256+
257 if (newName.trim().isEmpty()) {
258 JOptionPane.showMessageDialog(CreateGui.getApp(),
259 "You must specify a name.", "Missing name",
260@@ -207,7 +217,7 @@
261 int val = (Integer) valueSpinner.getValue();
262 if (!oldName.equals("")) {
263 if (!oldName.equalsIgnoreCase(newName)
264- && model.isConstantNameUsed(newName)) {
265+ && model.isNameUsedForConstant(newName)) {
266 JOptionPane
267 .showMessageDialog(
268 CreateGui.getApp(),
269@@ -217,6 +227,7 @@
270 nameTextField.requestFocusInWindow();
271 return;
272 }
273+
274 //Kyrke - This is messy, but a quck fix for bug #815487
275 //Check that the value is within the allowed bounds
276 if (!( lowerBound <= val && val <= upperBound )){

Subscribers

People subscribed via source and target branches