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;
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;
/** The “edit node” dialog. */
private EditNodeDialog editNodeDialog;
+ /** The warning label. */
+ private I18nLabel immediatelyEffectiveLabel;
+
/** The node list. */
private JList nodeList;
/**
* Creates a new node manager dialog.
- *
+ *
* @param swingInterface
* The Swing interface
*/
/**
* Expose the edit node dialog for the simple mode.
- *
+ *
* @return The edit node dialog
*/
EditNodeDialog getEditNodeDialog() {
/**
* Returns the list of nodes.
- *
+ *
* @return The list of nodes
*/
public List<Node> getNodeList() {
/**
* Sets the list of nodes.
- *
+ *
* @param nodeList
* The list of nodes
*/
public void setNodeList(List<Node> nodeList) {
- originalNodeList = nodeList;
+ originalNodeList = new ArrayList<Node>(nodeList);
nodeListModel.clear();
for (Node node: nodeList) {
nodeListModel.addNode(node);
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));
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);
+ }
}
}
/**
* 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
*/
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 <bombe@freenetproject.org>
* @version $Id$
*/
/**
* Adds the given node to the list model.
- *
+ *
* @see Collection#add(Object)
* @param node
* The node to add
/**
* Removes the given node from the list model.
- *
+ *
* @see Collection#remove(Object)
* @param node
* The node to remove
/**
* Removes all nodes from the list model.
- *
+ *
* @see Collection#clear()
*/
public void clear() {