Merge lp:~tapaal-contributor/tapaal/remove-entire-selection-1940416 into lp:tapaal

Proposed by Lena Ernstsen
Status: Merged
Approved by: Jiri Srba
Approved revision: 1139
Merged at revision: 1139
Proposed branch: lp:~tapaal-contributor/tapaal/remove-entire-selection-1940416
Merge into: lp:tapaal
Diff against target: 112 lines (+35/-23)
1 file modified
src/pipe/gui/widgets/ConstantsPane.java (+35/-23)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/remove-entire-selection-1940416
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Review via email: mp+407812@code.launchpad.net

Commit message

Can select multiple constants and delete them at once

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

Tested and works fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/pipe/gui/widgets/ConstantsPane.java'
2--- src/pipe/gui/widgets/ConstantsPane.java 2020-08-04 08:53:19 +0000
3+++ src/pipe/gui/widgets/ConstantsPane.java 2021-08-30 07:20:37 +0000
4@@ -14,7 +14,8 @@
5
6 import java.awt.event.MouseAdapter;
7 import java.awt.event.MouseEvent;
8-import java.io.IOException;
9+import java.util.ArrayList;
10+import java.util.Arrays;
11
12
13 import javax.swing.BorderFactory;
14@@ -22,7 +23,6 @@
15 import javax.swing.JList;
16 import javax.swing.JOptionPane;
17 import javax.swing.JPanel;
18-import javax.swing.JRootPane;
19 import javax.swing.JScrollPane;
20 import javax.swing.ListModel;
21 import javax.swing.ListSelectionModel;
22@@ -32,17 +32,15 @@
23 import javax.swing.event.ListSelectionEvent;
24 import javax.swing.event.ListSelectionListener;
25
26-import dk.aau.cs.gui.undo.MoveElementDownCommand;
27-import dk.aau.cs.gui.undo.MoveElementUpCommand;
28+import dk.aau.cs.gui.undo.*;
29 import net.tapaal.resourcemanager.ResourceManager;
30 import pipe.gui.CreateGui;
31 import dk.aau.cs.gui.TabContent;
32-import dk.aau.cs.gui.undo.Command;
33-import dk.aau.cs.gui.undo.SortConstantsCommand;
34 import dk.aau.cs.model.tapn.Constant;
35 import dk.aau.cs.model.tapn.TimedArcPetriNetNetwork;
36 import dk.aau.cs.gui.components.ConstantsListModel;
37 import dk.aau.cs.gui.components.NonsearchableJList;
38+import pipe.gui.MessengerImpl;
39
40 public class ConstantsPane extends JPanel implements SidePane {
41
42@@ -95,10 +93,10 @@
43 });
44
45 constantsList = new NonsearchableJList<>(listModel);
46- constantsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
47+ constantsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
48 constantsList.addListSelectionListener(new ListSelectionListener() {
49 public void valueChanged(ListSelectionEvent e) {
50- if (!(e.getValueIsAdjusting())) {
51+ if (!e.getValueIsAdjusting()) {
52 if (constantsList.getSelectedIndex() == -1) {
53 editBtn.setEnabled(false);
54 removeBtn.setEnabled(false);
55@@ -305,8 +303,7 @@
56 removeBtn.setEnabled(false);
57 removeBtn.setToolTipText(toolTipRemoveConstant);
58 removeBtn.addActionListener(e -> {
59- String constName = ((Constant) constantsList.getSelectedValue()).name();
60- removeConstant(constName);
61+ removeConstants();
62 });
63 gbc = new GridBagConstraints();
64 gbc.gridx = 1;
65@@ -413,19 +410,34 @@
66 showConstants();
67 }
68
69- protected void removeConstant(String name) {
70- TimedArcPetriNetNetwork model = parent.network();
71- Command edit = model.removeConstant(name);
72- if (edit == null) {
73- JOptionPane.showMessageDialog(CreateGui.getApp(),
74- "You cannot remove a constant that is used in the net.\nRemove all references "
75- + "to the constant in the net and try again.",
76- "Constant in use", JOptionPane.ERROR_MESSAGE);
77- } else {
78- parent.getUndoManager().addNewEdit(edit);
79- }
80-
81- //showConstants();
82+ protected void removeConstants() {
83+ TimedArcPetriNetNetwork model = parent.network();
84+ java.util.List<String> unremovableConstants = new ArrayList<>();
85+ parent.getUndoManager().newEdit();
86+
87+ for (Object o : constantsList.getSelectedValuesList()) {
88+ String name = ((Constant)o).name();
89+ Command command = model.removeConstant(name);
90+ if (command == null) {
91+ unremovableConstants.add(name);
92+ } else {
93+ parent.getUndoManager().addEdit(command);
94+ }
95+ }
96+ if (unremovableConstants.size() > 0) {
97+ StringBuilder message = new StringBuilder("The following constants could not be removed: \n");
98+
99+ for (String name : unremovableConstants) {
100+ message.append(" - ");
101+ message.append(name);
102+ message.append("\n");
103+ }
104+ message.append("\nYou cannot remove a constant that is used in the net.\nRemove all references " +
105+ "to the constant(s) in the net and try again.");
106+
107+ JOptionPane.showMessageDialog(CreateGui.getApp(), message.toString(),
108+ "Constant in use", JOptionPane.ERROR_MESSAGE);
109+ }
110 }
111
112 public void setNetwork(TimedArcPetriNetNetwork tapnNetwork) {

Subscribers

People subscribed via source and target branches