store original node list and only change it when the okay button is clicked
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 4 Apr 2008 22:04:59 +0000 (22:04 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 4 Apr 2008 22:04:59 +0000 (22:04 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@590 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/gui/ManageNodesDialog.java

index ceb9904..d4c8397 100644 (file)
@@ -53,8 +53,11 @@ import net.pterodactylus.util.swing.SwingUtils;
  */
 public class ManageNodesDialog extends JDialog implements ListSelectionListener {
 
-       /** The current list of nodes. */
-       private List<NodeWrapper> nodes = new ArrayList<NodeWrapper>();
+       /** The original list of nodes. */
+       private List<Node> originalNodeList;
+
+       /** The current list of wrapped nodes. */
+       private List<NodeWrapper> wrappedNodeList = new ArrayList<NodeWrapper>();
 
        /** 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<Node> getNodeList() {
-               List<Node> nodes = new ArrayList<Node>();
-               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<Node> nodes) {
-               this.nodes.clear();
-               for (Node node: nodes) {
-                       this.nodes.add(new NodeWrapper(node));
+       public void setNodeList(List<Node> 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);
        }