From 2fd72a007b33241a5dfac13d2d6c18a6ab044022 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 4 Apr 2008 22:04:59 +0000 Subject: [PATCH] store original node list and only change it when the okay button is clicked git-svn-id: http://trooper/svn/projects/jSite/trunk@590 c3eda9e8-030b-0410-8277-bc7414b0a119 --- .../pterodactylus/jsite/gui/ManageNodesDialog.java | 50 +++++++++++++--------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java b/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java index ceb9904..d4c8397 100644 --- a/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java +++ b/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java @@ -53,8 +53,11 @@ import net.pterodactylus.util.swing.SwingUtils; */ public class ManageNodesDialog extends JDialog implements ListSelectionListener { - /** The current list of nodes. */ - private List nodes = new ArrayList(); + /** The original list of nodes. */ + private List originalNodeList; + + /** The current list of wrapped nodes. */ + private List wrappedNodeList = new ArrayList(); /** The current default node. */ private Node defaultNode; @@ -132,25 +135,22 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener * @return The list of nodes */ public List getNodeList() { - List nodes = new ArrayList(); - for (NodeWrapper nodeWrapper: this.nodes) { - nodes.add(nodeWrapper.getWrappedNode()); - } - return nodes; + return originalNodeList; } /** * Sets the list of nodes. * - * @param nodes + * @param nodeList * The list of nodes */ - public void setNodeList(List nodes) { - this.nodes.clear(); - for (Node node: nodes) { - this.nodes.add(new NodeWrapper(node)); + public void setNodeList(List nodeList) { + originalNodeList = nodeList; + wrappedNodeList.clear(); + for (Node node: nodeList) { + wrappedNodeList.add(new NodeWrapper(node)); } - nodeListModel.setNodeList(this.nodes); + nodeListModel.setNodeList(wrappedNodeList); } // @@ -284,12 +284,12 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener newNode.setHostname(editNodeDialog.getNodeHostname()); newNode.setPort(editNodeDialog.getNodePort()); NodeWrapper newNodeWrapper = new NodeWrapper(newNode); - if (nodes.isEmpty()) { + if (wrappedNodeList.isEmpty()) { defaultNode = newNode; newNodeWrapper.setDefaultNode(true); } - nodes.add(new NodeWrapper(newNode)); - nodeListModel.setNodeList(nodes); + wrappedNodeList.add(new NodeWrapper(newNode)); + nodeListModel.setNodeList(wrappedNodeList); } } @@ -318,7 +318,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener */ private void deleteNode() { NodeWrapper selectedNode = (NodeWrapper) nodeList.getSelectedValue(); - nodes.remove(selectedNode); + wrappedNodeList.remove(selectedNode); nodeList.clearSelection(); nodeList.repaint(); } @@ -328,7 +328,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener */ private void setDefaultNode() { NodeWrapper selectedNode = (NodeWrapper) nodeList.getSelectedValue(); - for (NodeWrapper nodeWrapper: nodes) { + for (NodeWrapper nodeWrapper: wrappedNodeList) { nodeWrapper.setDefaultNode(nodeWrapper == selectedNode); } nodeList.repaint(); @@ -336,11 +336,19 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener /** * This method is called when the “okay” button is pressed. The nodes from - * the list are read and the {@link #nodes} and {@link #defaultNode} members - * are set so that the calling code can use {@link #getNodeList()} and - * {@link #getDefaultNode()} to get the changed values. + * the list are read and the {@link #wrappedNodeList} and + * {@link #defaultNode} members are set so that the calling code can use + * {@link #getNodeList()} and {@link #getDefaultNode()} to get the changed + * values. */ private void confirm() { + originalNodeList.clear(); + for (NodeWrapper nodeWrapper: wrappedNodeList) { + originalNodeList.add(nodeWrapper.getWrappedNode()); + if (nodeWrapper.isDefaultNode()) { + defaultNode = nodeWrapper.getWrappedNode(); + } + } setVisible(false); } -- 2.7.4