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

Proposed by Kenneth Yrke Jørgensen
Status: Superseded
Proposed branch: lp:~tapaal-contributor/tapaal/fix1953355
Merge into: lp:~tapaal-contributor/tapaal/cpn-gui-dev
Diff against target: 181 lines (+112/-4)
4 files modified
src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java (+16/-4)
src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java (+52/-0)
src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java (+32/-0)
src/pipe/gui/widgets/ConstantsDialogPanel.java (+12/-0)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/fix1953355
Reviewer Review Type Date Requested Status
Jiri Srba Needs Fixing
Review via email: mp+413441@code.launchpad.net

This proposal has been superseded by a proposal from 2021-12-21.

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

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 :

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
1488. By Kenneth Yrke Jørgensen

Added extra check to distinct color, colortype,variable and constants

1489. By Kenneth Yrke Jørgensen

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

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

Unmerged revisions

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-21 13:25:09 +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@@ -708,10 +707,23 @@
13 }
14 return false;
15 }
16+ public boolean isNameUsedForColor(String name, ColorType ignored) {
17+ for (ColorType e : colorTypes) {
18+ if (e != ignored && !e.isIntegerRange() && !e.isProductColorType()){
19+ for (Color c : e.getColors()) {
20+ if (c.getName().equals(name)) {
21+ return true;
22+ }
23+ }
24+ }
25+ }
26+ return false;
27+ }
28+
29 public Variable getVariableByName(String name){
30- for (int i = 0; i < variables.size(); i++) {
31- if (variables.get(i).getName().equalsIgnoreCase(name)) {
32- return variables.get(i);
33+ for (Variable variable : variables) {
34+ if (variable.getName().equalsIgnoreCase(name)) {
35+ return variable;
36 }
37 }
38 return null;
39
40=== modified file 'src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java'
41--- src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java 2021-08-30 07:07:52 +0000
42+++ src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java 2021-12-21 13:25:09 +0000
43@@ -877,6 +877,30 @@
44 "Error", JOptionPane.ERROR_MESSAGE);
45 return;
46 }
47+ if (network.isNameUsedForVariable(name)) {
48+ JOptionPane.showMessageDialog(
49+ CreateGui.getApp(),
50+ "There is already variable with the same name.\n\n"
51+ + "Choose a different name for the color type.",
52+ "Error", JOptionPane.ERROR_MESSAGE);
53+ return;
54+ }
55+ if (network.isConstantNameUsed(name)) {
56+ JOptionPane.showMessageDialog(
57+ CreateGui.getApp(),
58+ "There is already a constant with the same name.\n\n"
59+ + "Choose a different name for the color type.",
60+ "Error", JOptionPane.ERROR_MESSAGE);
61+ return;
62+ }
63+ if (network.isNameUsedForColor(name, null)) {
64+ JOptionPane.showMessageDialog(
65+ CreateGui.getApp(),
66+ "There is already a color with the same name.\n\n"
67+ + "Choose a different name for the color type.",
68+ "Error", JOptionPane.ERROR_MESSAGE);
69+ return;
70+ }
71 if (!oldName.equals("") && !oldName.equalsIgnoreCase(name) && network.isNameUsedForColorType(name)) {
72 JOptionPane.showMessageDialog(
73 CreateGui.getApp(),
74@@ -953,6 +977,34 @@
75
76 //If everything is false add the colortype
77 String selectedColorType = colorTypeComboBox.getSelectedItem().toString();
78+
79+ //Enum named are not allow to overlap with variable names
80+ switch (selectedColorType) {
81+ case finiteEnumeration: //Fall through
82+ case cyclicEnumeration:
83+
84+ ArrayList<String> overlaps = new ArrayList<>();
85+ for (int i = 0; i < enumList.getModel().getSize(); i++) {
86+ String e = enumList.getModel().getElementAt(i).toString();
87+ if (network.isNameUsedForVariable(e) || network.isNameUsedForColor(e, oldColorType) || network.isNameUsedForColorType(e) || name.equals(e)) {
88+ overlaps.add(e);
89+ }
90+ }
91+ if (overlaps.size() > 0) {
92+ JOptionPane.showMessageDialog(
93+ CreateGui.getApp(),
94+ "Color names must not overlap with variable names or other color names: \n" +
95+ "Remove or rename the following: \n" +
96+ String.join(", ", overlaps),
97+ "Error", JOptionPane.ERROR_MESSAGE);
98+ return;
99+ }
100+
101+ //No overlap between
102+
103+ break;
104+ }
105+
106 ColorType newColorType = new ColorType(name);
107
108 switch (selectedColorType) {
109
110=== modified file 'src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java'
111--- src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java 2021-07-02 12:10:22 +0000
112+++ src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java 2021-12-21 13:25:09 +0000
113@@ -281,6 +281,38 @@
114 nameTextField.requestFocusInWindow();
115 return;
116 }
117+
118+ if (network.isConstantNameUsed(newName)) {
119+ JOptionPane
120+ .showMessageDialog(
121+ CreateGui.getApp(),
122+ "There is already a constant with this name.\n\n"
123+ + "Choose a different name for the variable.",
124+ "Error", JOptionPane.ERROR_MESSAGE);
125+ return;
126+ }
127+
128+ if (network.isNameUsedForColorType(newName)) {
129+ JOptionPane
130+ .showMessageDialog(
131+ CreateGui.getApp(),
132+ "There is already a Color Type with this name.\n\n"
133+ + "Choose a different name for the variable.",
134+ "Error", JOptionPane.ERROR_MESSAGE);
135+ return;
136+ }
137+
138+ //Variable name is not allow to overlap with enum names
139+ if (network.isNameUsedForColor(newName, null)) {
140+ JOptionPane
141+ .showMessageDialog(
142+ CreateGui.getApp(),
143+ "There is already a Color with this name.\n\n"
144+ + "Choose a different name for the variable.",
145+ "Error", JOptionPane.ERROR_MESSAGE);
146+ return;
147+ }
148+
149 Command cmd;
150 if (!oldName.equals("")) {
151 cmd = new UpdateVariableCommand(variable, nameTextField.getText(), colorTypes.get(colorTypeComboBox.getSelectedIndex()), listModel);
152
153=== modified file 'src/pipe/gui/widgets/ConstantsDialogPanel.java'
154--- src/pipe/gui/widgets/ConstantsDialogPanel.java 2021-11-04 13:34:08 +0000
155+++ src/pipe/gui/widgets/ConstantsDialogPanel.java 2021-12-21 13:25:09 +0000
156@@ -197,6 +197,17 @@
157 return;
158 }
159
160+ if (model.isNameUsedForColorType(newName) || model.isNameUsedForVariable(newName) || model.isNameUsedForColor(newName, null)) {
161+ JOptionPane
162+ .showMessageDialog(
163+ CreateGui.getApp(),
164+ "There is already another Color, Color Type or Variable with the same name.\n\n"
165+ + "Choose a different name for the constant.",
166+ "Error", JOptionPane.ERROR_MESSAGE);
167+ nameTextField.requestFocusInWindow();
168+ return;
169+ }
170+
171 if (newName.trim().isEmpty()) {
172 JOptionPane.showMessageDialog(CreateGui.getApp(),
173 "You must specify a name.", "Missing name",
174@@ -217,6 +228,7 @@
175 nameTextField.requestFocusInWindow();
176 return;
177 }
178+
179 //Kyrke - This is messy, but a quck fix for bug #815487
180 //Check that the value is within the allowed bounds
181 if (!( lowerBound <= val && val <= upperBound )){

Subscribers

People subscribed via source and target branches