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
=== modified file 'src/pipe/gui/widgets/ConstantsPane.java'
--- src/pipe/gui/widgets/ConstantsPane.java 2020-08-04 08:53:19 +0000
+++ src/pipe/gui/widgets/ConstantsPane.java 2021-08-30 07:20:37 +0000
@@ -14,7 +14,8 @@
1414
15import java.awt.event.MouseAdapter;15import java.awt.event.MouseAdapter;
16import java.awt.event.MouseEvent;16import java.awt.event.MouseEvent;
17import java.io.IOException;17import java.util.ArrayList;
18import java.util.Arrays;
1819
1920
20import javax.swing.BorderFactory;21import javax.swing.BorderFactory;
@@ -22,7 +23,6 @@
22import javax.swing.JList;23import javax.swing.JList;
23import javax.swing.JOptionPane;24import javax.swing.JOptionPane;
24import javax.swing.JPanel;25import javax.swing.JPanel;
25import javax.swing.JRootPane;
26import javax.swing.JScrollPane;26import javax.swing.JScrollPane;
27import javax.swing.ListModel;27import javax.swing.ListModel;
28import javax.swing.ListSelectionModel;28import javax.swing.ListSelectionModel;
@@ -32,17 +32,15 @@
32import javax.swing.event.ListSelectionEvent;32import javax.swing.event.ListSelectionEvent;
33import javax.swing.event.ListSelectionListener;33import javax.swing.event.ListSelectionListener;
3434
35import dk.aau.cs.gui.undo.MoveElementDownCommand;35import dk.aau.cs.gui.undo.*;
36import dk.aau.cs.gui.undo.MoveElementUpCommand;
37import net.tapaal.resourcemanager.ResourceManager;36import net.tapaal.resourcemanager.ResourceManager;
38import pipe.gui.CreateGui;37import pipe.gui.CreateGui;
39import dk.aau.cs.gui.TabContent;38import dk.aau.cs.gui.TabContent;
40import dk.aau.cs.gui.undo.Command;
41import dk.aau.cs.gui.undo.SortConstantsCommand;
42import dk.aau.cs.model.tapn.Constant;39import dk.aau.cs.model.tapn.Constant;
43import dk.aau.cs.model.tapn.TimedArcPetriNetNetwork;40import dk.aau.cs.model.tapn.TimedArcPetriNetNetwork;
44import dk.aau.cs.gui.components.ConstantsListModel;41import dk.aau.cs.gui.components.ConstantsListModel;
45import dk.aau.cs.gui.components.NonsearchableJList;42import dk.aau.cs.gui.components.NonsearchableJList;
43import pipe.gui.MessengerImpl;
4644
47public class ConstantsPane extends JPanel implements SidePane {45public class ConstantsPane extends JPanel implements SidePane {
4846
@@ -95,10 +93,10 @@
95 });93 });
9694
97 constantsList = new NonsearchableJList<>(listModel);95 constantsList = new NonsearchableJList<>(listModel);
98 constantsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);96 constantsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
99 constantsList.addListSelectionListener(new ListSelectionListener() {97 constantsList.addListSelectionListener(new ListSelectionListener() {
100 public void valueChanged(ListSelectionEvent e) {98 public void valueChanged(ListSelectionEvent e) {
101 if (!(e.getValueIsAdjusting())) {99 if (!e.getValueIsAdjusting()) {
102 if (constantsList.getSelectedIndex() == -1) {100 if (constantsList.getSelectedIndex() == -1) {
103 editBtn.setEnabled(false);101 editBtn.setEnabled(false);
104 removeBtn.setEnabled(false);102 removeBtn.setEnabled(false);
@@ -305,8 +303,7 @@
305 removeBtn.setEnabled(false);303 removeBtn.setEnabled(false);
306 removeBtn.setToolTipText(toolTipRemoveConstant);304 removeBtn.setToolTipText(toolTipRemoveConstant);
307 removeBtn.addActionListener(e -> {305 removeBtn.addActionListener(e -> {
308 String constName = ((Constant) constantsList.getSelectedValue()).name();306 removeConstants();
309 removeConstant(constName);
310 });307 });
311 gbc = new GridBagConstraints();308 gbc = new GridBagConstraints();
312 gbc.gridx = 1;309 gbc.gridx = 1;
@@ -413,19 +410,34 @@
413 showConstants();410 showConstants();
414 }411 }
415412
416 protected void removeConstant(String name) {413 protected void removeConstants() {
417 TimedArcPetriNetNetwork model = parent.network();414 TimedArcPetriNetNetwork model = parent.network();
418 Command edit = model.removeConstant(name);415 java.util.List<String> unremovableConstants = new ArrayList<>();
419 if (edit == null) {416 parent.getUndoManager().newEdit();
420 JOptionPane.showMessageDialog(CreateGui.getApp(),417
421 "You cannot remove a constant that is used in the net.\nRemove all references "418 for (Object o : constantsList.getSelectedValuesList()) {
422 + "to the constant in the net and try again.",419 String name = ((Constant)o).name();
423 "Constant in use", JOptionPane.ERROR_MESSAGE);420 Command command = model.removeConstant(name);
424 } else {421 if (command == null) {
425 parent.getUndoManager().addNewEdit(edit);422 unremovableConstants.add(name);
426 }423 } else {
427424 parent.getUndoManager().addEdit(command);
428 //showConstants();425 }
426 }
427 if (unremovableConstants.size() > 0) {
428 StringBuilder message = new StringBuilder("The following constants could not be removed: \n");
429
430 for (String name : unremovableConstants) {
431 message.append(" - ");
432 message.append(name);
433 message.append("\n");
434 }
435 message.append("\nYou cannot remove a constant that is used in the net.\nRemove all references " +
436 "to the constant(s) in the net and try again.");
437
438 JOptionPane.showMessageDialog(CreateGui.getApp(), message.toString(),
439 "Constant in use", JOptionPane.ERROR_MESSAGE);
440 }
429 }441 }
430442
431 public void setNetwork(TimedArcPetriNetNetwork tapnNetwork) {443 public void setNetwork(TimedArcPetriNetNetwork tapnNetwork) {

Subscribers

People subscribed via source and target branches