add virtual entries
[jSite2.git] / src / net / pterodactylus / jsite / gui / ManageNodesDialog.java
index cf32cae..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;
@@ -46,6 +48,7 @@ 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;
 
 /**
@@ -56,6 +59,10 @@ import net.pterodactylus.util.swing.SwingUtils;
  */
 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;
 
@@ -265,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);
+                       }
                }
        }
 
@@ -374,7 +391,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener,
        }
 
        /**
-        * List model for the {@link ManageNodesDialog#nodeList}. TODO
+        * List model for the {@link ManageNodesDialog#nodeList}.
         * 
         * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
         * @version $Id$