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
=== modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java'
--- src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java 2021-08-27 08:42:36 +0000
+++ src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java 2021-12-23 09:04:13 +0000
@@ -5,7 +5,6 @@
5import dk.aau.cs.gui.undo.Colored.*;5import dk.aau.cs.gui.undo.Colored.*;
6import dk.aau.cs.model.CPN.*;6import dk.aau.cs.model.CPN.*;
7import dk.aau.cs.model.CPN.Expressions.*;7import dk.aau.cs.model.CPN.Expressions.*;
8import org.jetbrains.annotations.NotNull;
9import pipe.gui.MessengerImpl;8import pipe.gui.MessengerImpl;
10import dk.aau.cs.gui.undo.Command;9import dk.aau.cs.gui.undo.Command;
11import dk.aau.cs.model.tapn.event.ConstantChangedEvent;10import dk.aau.cs.model.tapn.event.ConstantChangedEvent;
@@ -195,10 +194,6 @@
195 }194 }
196 }195 }
197196
198 public boolean isConstantNameUsed(String newName) {
199 return constants.containsConstantByName(newName);
200 }
201
202 public void buildConstraints() {197 public void buildConstraints() {
203 constants.buildConstraints(this);198 constants.buildConstraints(this);
204 }199 }
@@ -691,15 +686,15 @@
691 }686 }
692 return null;687 return null;
693 }688 }
689
694 public boolean isNameUsedForColorType(String name) {690 public boolean isNameUsedForColorType(String name) {
695 for (ColorType element : colorTypes) {691 for (ColorType element : colorTypes) {
696 if (element.getName().equals(name)) {692 if (element.getName().equalsIgnoreCase(name)) {
697 return true;693 return true;
698 }694 }
699 }695 }
700 return false;696 return false;
701 }697 }
702
703 public boolean isNameUsedForVariable(String name) {698 public boolean isNameUsedForVariable(String name) {
704 for (Variable element : variables) {699 for (Variable element : variables) {
705 if (element.getName().equalsIgnoreCase(name)) {700 if (element.getName().equalsIgnoreCase(name)) {
@@ -708,10 +703,26 @@
708 }703 }
709 return false;704 return false;
710 }705 }
706 public boolean isNameUsedForColor(String name, ColorType ignored) {
707 for (ColorType e : colorTypes) {
708 if (e != ignored && !e.isIntegerRange() && !e.isProductColorType()){
709 for (Color c : e.getColors()) {
710 if (c.getName().equalsIgnoreCase(name)) {
711 return true;
712 }
713 }
714 }
715 }
716 return false;
717 }
718 public boolean isNameUsedForConstant(String newName) {
719 return constants.containsConstantByName(newName);
720 }
721
711 public Variable getVariableByName(String name){722 public Variable getVariableByName(String name){
712 for (int i = 0; i < variables.size(); i++) {723 for (Variable variable : variables) {
713 if (variables.get(i).getName().equalsIgnoreCase(name)) {724 if (variable.getName().equalsIgnoreCase(name)) {
714 return variables.get(i);725 return variable;
715 }726 }
716 }727 }
717 return null;728 return null;
718729
=== modified file 'src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java'
--- src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java 2021-08-30 07:07:52 +0000
+++ src/pipe/gui/widgets/ColoredWidgets/ColorTypeDialogPanel.java 2021-12-23 09:04:13 +0000
@@ -189,7 +189,7 @@
189 private JPanel createNameAndTypePanel() {189 private JPanel createNameAndTypePanel() {
190 JPanel nameAndTypePanel = new JPanel();190 JPanel nameAndTypePanel = new JPanel();
191 nameAndTypePanel.setLayout(new GridBagLayout());191 nameAndTypePanel.setLayout(new GridBagLayout());
192 nameAndTypePanel.setBorder(BorderFactory.createTitledBorder("Name and Color Type"));192 nameAndTypePanel.setBorder(BorderFactory.createTitledBorder("Name of Color Type"));
193193
194 JLabel nameLabel = new JLabel();194 JLabel nameLabel = new JLabel();
195 nameLabel.setText("Name: ");195 nameLabel.setText("Name: ");
@@ -451,16 +451,20 @@
451 "The color cannot be named \"" + enumerationName + "\", as the name is reserved",451 "The color cannot be named \"" + enumerationName + "\", as the name is reserved",
452 "Error", JOptionPane.ERROR_MESSAGE);452 "Error", JOptionPane.ERROR_MESSAGE);
453 } else {453 } else {
454 boolean inList = false;454 boolean nameIsInUse = network.isNameUsedForVariable(enumerationName) || network.isNameUsedForColor(enumerationName, null) || network.isNameUsedForColorType(enumerationName) || network.isNameUsedForConstant(enumerationName) || nameTextField.getText().equalsIgnoreCase(enumerationName);
455 int i = 0;455 for (int i = 0; i < cyclicModel.getSize(); i++) {
456 while (!inList && i < cyclicModel.getSize() && cyclicModel.getElementAt(i) != null) {456 String n = cyclicModel.getElementAt(i).toString();
457 inList = cyclicModel.getElementAt(i).toString().equals(enumTextField.getText());457
458 i++;458 if (n.equalsIgnoreCase(enumerationName)) {
459 nameIsInUse = true;
460 break;
461 }
459 }462 }
460 if (inList) {463
464 if (nameIsInUse) {
461 JOptionPane.showMessageDialog(465 JOptionPane.showMessageDialog(
462 CreateGui.getApp(),466 CreateGui.getApp(),
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.",
464 "Error", JOptionPane.ERROR_MESSAGE);468 "Error", JOptionPane.ERROR_MESSAGE);
465 } else {469 } else {
466 cyclicModel.addElement(enumTextField.getText());470 cyclicModel.addElement(enumTextField.getText());
@@ -877,6 +881,30 @@
877 "Error", JOptionPane.ERROR_MESSAGE);881 "Error", JOptionPane.ERROR_MESSAGE);
878 return;882 return;
879 }883 }
884 if (network.isNameUsedForVariable(name)) {
885 JOptionPane.showMessageDialog(
886 CreateGui.getApp(),
887 "There is already variable with the same name.\n\n"
888 + "Choose a different name for the color type.",
889 "Error", JOptionPane.ERROR_MESSAGE);
890 return;
891 }
892 if (network.isNameUsedForConstant(name)) {
893 JOptionPane.showMessageDialog(
894 CreateGui.getApp(),
895 "There is already a constant with the same name.\n\n"
896 + "Choose a different name for the color type.",
897 "Error", JOptionPane.ERROR_MESSAGE);
898 return;
899 }
900 if (network.isNameUsedForColor(name, null)) {
901 JOptionPane.showMessageDialog(
902 CreateGui.getApp(),
903 "There is already a color with the same name.\n\n"
904 + "Choose a different name for the color type.",
905 "Error", JOptionPane.ERROR_MESSAGE);
906 return;
907 }
880 if (!oldName.equals("") && !oldName.equalsIgnoreCase(name) && network.isNameUsedForColorType(name)) {908 if (!oldName.equals("") && !oldName.equalsIgnoreCase(name) && network.isNameUsedForColorType(name)) {
881 JOptionPane.showMessageDialog(909 JOptionPane.showMessageDialog(
882 CreateGui.getApp(),910 CreateGui.getApp(),
@@ -953,6 +981,34 @@
953981
954 //If everything is false add the colortype982 //If everything is false add the colortype
955 String selectedColorType = colorTypeComboBox.getSelectedItem().toString();983 String selectedColorType = colorTypeComboBox.getSelectedItem().toString();
984
985 //Enum named are not allow to overlap with variable names
986 switch (selectedColorType) {
987 case finiteEnumeration: //Fall through
988 case cyclicEnumeration:
989
990 ArrayList<String> overlaps = new ArrayList<>();
991 for (int i = 0; i < enumList.getModel().getSize(); i++) {
992 String e = enumList.getModel().getElementAt(i).toString();
993 if (network.isNameUsedForVariable(e) || network.isNameUsedForColor(e, oldColorType) || network.isNameUsedForColorType(e) || network.isNameUsedForConstant(e) || name.equalsIgnoreCase(e)) {
994 overlaps.add(e);
995 }
996 }
997 if (overlaps.size() > 0) {
998 JOptionPane.showMessageDialog(
999 CreateGui.getApp(),
1000 "Color names must not overlap with variable names or other color names: \n" +
1001 "Remove or rename the following: \n" +
1002 String.join(", ", overlaps),
1003 "Error", JOptionPane.ERROR_MESSAGE);
1004 return;
1005 }
1006
1007 //No overlap between
1008
1009 break;
1010 }
1011
956 ColorType newColorType = new ColorType(name);1012 ColorType newColorType = new ColorType(name);
9571013
958 switch (selectedColorType) {1014 switch (selectedColorType) {
9591015
=== modified file 'src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java'
--- src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java 2021-07-02 12:10:22 +0000
+++ src/pipe/gui/widgets/ColoredWidgets/VariablesDialogPanel.java 2021-12-23 09:04:13 +0000
@@ -261,7 +261,7 @@
261 return;261 return;
262 }262 }
263 //If we are editing a variable it is allowed to have the same name263 //If we are editing a variable it is allowed to have the same name
264 if (network.isNameUsedForVariable(newName) && (variable == null || !variable.getName().equals(newName))) {264 if ((variable == null || !variable.getName().equalsIgnoreCase(newName)) && network.isNameUsedForVariable(newName) ) {
265 JOptionPane265 JOptionPane
266 .showMessageDialog(266 .showMessageDialog(
267 CreateGui.getApp(),267 CreateGui.getApp(),
@@ -281,6 +281,38 @@
281 nameTextField.requestFocusInWindow();281 nameTextField.requestFocusInWindow();
282 return;282 return;
283 }283 }
284
285 if (network.isNameUsedForConstant(newName)) {
286 JOptionPane
287 .showMessageDialog(
288 CreateGui.getApp(),
289 "There is already a constant with this name.\n\n"
290 + "Choose a different name for the variable.",
291 "Error", JOptionPane.ERROR_MESSAGE);
292 return;
293 }
294
295 if (network.isNameUsedForColorType(newName)) {
296 JOptionPane
297 .showMessageDialog(
298 CreateGui.getApp(),
299 "There is already a Color Type with this name.\n\n"
300 + "Choose a different name for the variable.",
301 "Error", JOptionPane.ERROR_MESSAGE);
302 return;
303 }
304
305 //Variable name is not allow to overlap with enum names
306 if (network.isNameUsedForColor(newName, null)) {
307 JOptionPane
308 .showMessageDialog(
309 CreateGui.getApp(),
310 "There is already a Color with this name.\n\n"
311 + "Choose a different name for the variable.",
312 "Error", JOptionPane.ERROR_MESSAGE);
313 return;
314 }
315
284 Command cmd;316 Command cmd;
285 if (!oldName.equals("")) {317 if (!oldName.equals("")) {
286 cmd = new UpdateVariableCommand(variable, nameTextField.getText(), colorTypes.get(colorTypeComboBox.getSelectedIndex()), listModel);318 cmd = new UpdateVariableCommand(variable, nameTextField.getText(), colorTypes.get(colorTypeComboBox.getSelectedIndex()), listModel);
287319
=== modified file 'src/pipe/gui/widgets/ConstantsDialogPanel.java'
--- src/pipe/gui/widgets/ConstantsDialogPanel.java 2021-11-04 13:34:08 +0000
+++ src/pipe/gui/widgets/ConstantsDialogPanel.java 2021-12-23 09:04:13 +0000
@@ -11,7 +11,6 @@
11import javax.swing.JLabel;11import javax.swing.JLabel;
12import javax.swing.JOptionPane;12import javax.swing.JOptionPane;
13import javax.swing.JPanel;13import javax.swing.JPanel;
14import javax.swing.JRootPane;
15import javax.swing.JSpinner;14import javax.swing.JSpinner;
16import javax.swing.JTextField;15import javax.swing.JTextField;
1716
@@ -197,6 +196,17 @@
197 return;196 return;
198 }197 }
199198
199 if (model.isNameUsedForColorType(newName) || model.isNameUsedForVariable(newName) || model.isNameUsedForColor(newName, null)) {
200 JOptionPane
201 .showMessageDialog(
202 CreateGui.getApp(),
203 "There is already another Color, Color Type or Variable with the same name.\n\n"
204 + "Choose a different name for the constant.",
205 "Error", JOptionPane.ERROR_MESSAGE);
206 nameTextField.requestFocusInWindow();
207 return;
208 }
209
200 if (newName.trim().isEmpty()) {210 if (newName.trim().isEmpty()) {
201 JOptionPane.showMessageDialog(CreateGui.getApp(),211 JOptionPane.showMessageDialog(CreateGui.getApp(),
202 "You must specify a name.", "Missing name",212 "You must specify a name.", "Missing name",
@@ -207,7 +217,7 @@
207 int val = (Integer) valueSpinner.getValue();217 int val = (Integer) valueSpinner.getValue();
208 if (!oldName.equals("")) {218 if (!oldName.equals("")) {
209 if (!oldName.equalsIgnoreCase(newName)219 if (!oldName.equalsIgnoreCase(newName)
210 && model.isConstantNameUsed(newName)) {220 && model.isNameUsedForConstant(newName)) {
211 JOptionPane221 JOptionPane
212 .showMessageDialog(222 .showMessageDialog(
213 CreateGui.getApp(),223 CreateGui.getApp(),
@@ -217,6 +227,7 @@
217 nameTextField.requestFocusInWindow();227 nameTextField.requestFocusInWindow();
218 return;228 return;
219 }229 }
230
220 //Kyrke - This is messy, but a quck fix for bug #815487 231 //Kyrke - This is messy, but a quck fix for bug #815487
221 //Check that the value is within the allowed bounds232 //Check that the value is within the allowed bounds
222 if (!( lowerBound <= val && val <= upperBound )){233 if (!( lowerBound <= val && val <= upperBound )){

Subscribers

People subscribed via source and target branches