Added confirmation dialog before deleting a building block

Fix the exception on block delete
This commit is contained in:
Branislav Stojkovic
2019-02-02 21:31:38 +01:00
parent cad26211b3
commit efceedc924
3 changed files with 23 additions and 7 deletions
@@ -96,7 +96,7 @@ public class ComponentTree implements IPlugIn {
public TreePanel getTreePanel() { public TreePanel getTreePanel() {
if (treePanel == null) { if (treePanel == null) {
treePanel = new TreePanel(plugInPort); treePanel = new TreePanel(plugInPort, swingUI);
} }
return treePanel; return treePanel;
} }
@@ -75,9 +75,11 @@ import org.diylc.common.ComponentType;
import org.diylc.common.IBlockProcessor.InvalidBlockException; import org.diylc.common.IBlockProcessor.InvalidBlockException;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.core.Template; import org.diylc.core.Template;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import org.diylc.presenter.ComponentProcessor; import org.diylc.presenter.ComponentProcessor;
import org.diylc.swing.ISwingUI;
import org.diylc.swing.plugins.toolbox.ComponentButtonFactory; import org.diylc.swing.plugins.toolbox.ComponentButtonFactory;
public class TreePanel extends JPanel { public class TreePanel extends JPanel {
@@ -98,11 +100,13 @@ public class TreePanel extends JPanel {
private List<String> blocks; private List<String> blocks;
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private ISwingUI swingUI;
private JPopupMenu popup; private JPopupMenu popup;
public TreePanel(IPlugInPort plugInPort) { public TreePanel(IPlugInPort plugInPort, ISwingUI swingUI) {
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.swingUI = swingUI;
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
@@ -255,6 +259,8 @@ public class TreePanel extends JPanel {
} }
private void refreshBuildingBlocks(List<String> blocks) { private void refreshBuildingBlocks(List<String> blocks) {
this.blocks = blocks;
getBlocksNode().removeAllChildren(); getBlocksNode().removeAllChildren();
for (final String block : blocks) { for (final String block : blocks) {
Payload payload = new Payload(block, new MouseAdapter() { Payload payload = new Payload(block, new MouseAdapter() {
@@ -323,6 +329,9 @@ public class TreePanel extends JPanel {
@Override @Override
public void valueChanged(TreeSelectionEvent e) { public void valueChanged(TreeSelectionEvent e) {
if (!e.isAddedPath())
return;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
if (node != null && node.getUserObject() != null) { if (node != null && node.getUserObject() != null) {
Payload payload = (Payload) node.getUserObject(); Payload payload = (Payload) node.getUserObject();
@@ -464,7 +473,7 @@ public class TreePanel extends JPanel {
} }
} else if (selectedNode.isLeaf()) { } else if (selectedNode.isLeaf()) {
popup.add(shortcutSubmenu); popup.add(shortcutSubmenu);
popup.add(new DeleteBlockAction(plugInPort, payload.toString())); popup.add(new DeleteBlockAction(plugInPort, swingUI, payload.toString()));
} }
} }
@@ -731,11 +740,13 @@ public class TreePanel extends JPanel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private ISwingUI swingUI;
private String blockName; private String blockName;
public DeleteBlockAction(IPlugInPort plugInPort, String blockName) { public DeleteBlockAction(IPlugInPort plugInPort, ISwingUI swingUI, String blockName) {
super(); super();
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.swingUI = swingUI;
this.blockName = blockName; this.blockName = blockName;
putValue(AbstractAction.NAME, "Delete Building Block"); putValue(AbstractAction.NAME, "Delete Building Block");
} }
@@ -743,6 +754,7 @@ public class TreePanel extends JPanel {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
LOG.info(getValue(AbstractAction.NAME) + " triggered"); LOG.info(getValue(AbstractAction.NAME) + " triggered");
if (swingUI.showConfirmDialog("Are you sure you want to delete building block \"" + blockName + "\"?", "Delete Building Block", IView.YES_NO_OPTION, IView.QUESTION_MESSAGE) == IView.YES_OPTION)
plugInPort.deleteBlock(blockName); plugInPort.deleteBlock(blockName);
} }
} }
+4
View File
@@ -2374,6 +2374,10 @@
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Better rendering precision when exporting to PDF and PNG files</description> <description>Better rendering precision when exporting to PDF and PNG files</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Added confirmation dialog before deleting a building block</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType> <changeType>BUG_FIX</changeType>
<description>"PCB Text" components are not included in trace mask exports</description> <description>"PCB Text" components are not included in trace mask exports</description>