add virtual entries
[jSite2.git] / src / net / pterodactylus / jsite / gui / ManageNodesDialog.java
index ea2b6c5..0598144 100644 (file)
@@ -22,10 +22,12 @@ package net.pterodactylus.jsite.gui;
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.logging.Logger;
 
 import javax.swing.AbstractListModel;
 import javax.swing.BorderFactory;
@@ -44,17 +46,23 @@ import net.pterodactylus.jsite.core.Node;
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.I18nable;
 import net.pterodactylus.jsite.i18n.gui.I18nAction;
+import net.pterodactylus.jsite.i18n.gui.I18nLabel;
 import net.pterodactylus.jsite.main.Version;
+import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.util.swing.SwingUtils;
 
 /**
  * Dialog that lets the user manage her nodes.
- *
+ * 
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  * @version $Id$
  */
 public class ManageNodesDialog extends JDialog implements ListSelectionListener, I18nable {
 
+       /** The logger.  */
+       @SuppressWarnings("unused")
+       private static final Logger logger = Logging.getLogger(ManageNodesDialog.class.getName());
+
        /** The core. */
        private final Core core;
 
@@ -79,6 +87,9 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
        /** The “edit node” dialog. */
        private EditNodeDialog editNodeDialog;
 
+       /** The warning label. */
+       private I18nLabel immediatelyEffectiveLabel;
+
        /** The node list. */
        private JList nodeList;
 
@@ -87,7 +98,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
 
        /**
         * Creates a new node manager dialog.
-        *
+        * 
         * @param swingInterface
         *            The Swing interface
         */
@@ -108,7 +119,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
 
        /**
         * Expose the edit node dialog for the simple mode.
-        *
+        * 
         * @return The edit node dialog
         */
        EditNodeDialog getEditNodeDialog() {
@@ -117,7 +128,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
 
        /**
         * Returns the list of nodes.
-        *
+        * 
         * @return The list of nodes
         */
        public List<Node> getNodeList() {
@@ -126,7 +137,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
 
        /**
         * Sets the list of nodes.
-        *
+        * 
         * @param nodeList
         *            The list of nodes
         */
@@ -218,6 +229,11 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
                rootPanel.add(contentPanel, BorderLayout.CENTER);
                contentPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(12, 12, 12, 12)));
 
+               JPanel warningPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 12, 12));
+               warningPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
+               warningPanel.add(immediatelyEffectiveLabel = new I18nLabel("manageNodesDialog.label.immediatelyEffective"));
+               contentPanel.add(warningPanel, BorderLayout.PAGE_START);
+
                JPanel listButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 12, 12));
                contentPanel.add(listButtonPanel, BorderLayout.PAGE_END);
                listButtonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
@@ -256,7 +272,17 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
                        newNode.setName(editNodeDialog.getNodeName());
                        newNode.setHostname(editNodeDialog.getNodeHostname());
                        newNode.setPort(editNodeDialog.getNodePort());
-                       nodeListModel.addNode(newNode);
+                       try {
+                               if (!core.addNode(newNode)) {
+                                       JOptionPane.showMessageDialog(this, I18n.get("manageNodesDialog.error.nodeAlreadyKnown.message", newNode.getHostname(), newNode.getPort()), I18n.get("manageNodesDialog.error.nodeAlreadyKnown.title"), JOptionPane.ERROR_MESSAGE);
+                               }
+                       } catch (UnknownHostException e) {
+                               /*
+                                * normally this shouldn't throw because the node editor catches
+                                * it.
+                                */
+                               JOptionPane.showMessageDialog(this, I18n.get("manageNodesDialog.error.nodeUnresolvable.message", newNode.getHostname()), I18n.get("manageNodesDialog.error.nodeUnresolvable.title"), JOptionPane.ERROR_MESSAGE);
+                       }
                }
        }
 
@@ -299,7 +325,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
 
        /**
         * Checks whether the list of nodes is not empty.
-        *
+        * 
         * @return <code>true</code> if there is at least one node defined,
         *         <code>false</code> otherwise
         */
@@ -359,13 +385,14 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
                addNodeAction.updateI18n();
                editNodeAction.updateI18n();
                deleteNodeAction.updateI18n();
+               immediatelyEffectiveLabel.updateI18n();
                setTitle(I18n.get("manageNodesDialog.title") + " – jSite " + Version.getVersion());
                SwingUtils.repackCentered(this);
        }
 
        /**
-        * List model for the {@link ManageNodesDialog#nodeList}. TODO
-        *
+        * List model for the {@link ManageNodesDialog#nodeList}.
+        * 
         * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
         * @version $Id$
         */
@@ -384,7 +411,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
 
                /**
                 * Adds the given node to the list model.
-                *
+                * 
                 * @see Collection#add(Object)
                 * @param node
                 *            The node to add
@@ -396,7 +423,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
 
                /**
                 * Removes the given node from the list model.
-                *
+                * 
                 * @see Collection#remove(Object)
                 * @param node
                 *            The node to remove
@@ -409,7 +436,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
 
                /**
                 * Removes all nodes from the list model.
-                *
+                * 
                 * @see Collection#clear()
                 */
                public void clear() {