From d1bf7681d79cf88ee860b6f5fa1732714cbd5055 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 5 Apr 2008 16:29:13 +0000 Subject: [PATCH] export core from swing interface hand in swing interface to child dialogs git-svn-id: http://trooper/svn/projects/jSite/trunk@605 c3eda9e8-030b-0410-8277-bc7414b0a119 --- .../pterodactylus/jsite/gui/ManageNodesDialog.java | 25 ++++++++++++++++----- .../pterodactylus/jsite/gui/SwingInterface.java | 26 ++++++++++++++++++---- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java b/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java index c2d6adf..9d993a0 100644 --- a/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java +++ b/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java @@ -32,7 +32,6 @@ import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -41,6 +40,7 @@ import javax.swing.border.EtchedBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import net.pterodactylus.jsite.core.Core; import net.pterodactylus.jsite.core.Node; import net.pterodactylus.jsite.i18n.I18n; import net.pterodactylus.jsite.main.Version; @@ -54,6 +54,9 @@ import net.pterodactylus.util.swing.SwingUtils; */ public class ManageNodesDialog extends JDialog implements ListSelectionListener { + /** The core. */ + private final Core core; + /** The original list of nodes. */ private List originalNodeList; @@ -84,11 +87,12 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener /** * Creates a new node manager dialog. * - * @param parentFrame - * The parent frame of the dialog + * @param swingInterface + * The Swing interface */ - public ManageNodesDialog(JFrame parentFrame) { - super(parentFrame, I18n.get("manageNodesDialog.title") + " – jSite " + Version.getVersion(), true); + public ManageNodesDialog(SwingInterface swingInterface) { + super(swingInterface.getMainWindow(), I18n.get("manageNodesDialog.title") + " – jSite " + Version.getVersion(), true); + this.core = swingInterface.getCore(); initActions(); initComponents(); initDialogs(); @@ -271,7 +275,16 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener private void deleteNodes() { Object[] selectedNodes = nodeList.getSelectedValues(); for (Object node: selectedNodes) { - nodeListModel.removeNode((Node) node); + Node selectedNode = (Node) node; + if (core.isNodeConnected(selectedNode)) { + int response = JOptionPane.showConfirmDialog(this, I18n.get("manageNodesDialog.error.nodeConnected.message", selectedNode.getName()), I18n.get("manageNodesDialog.error.nodeConnected.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); + if (response == JOptionPane.CANCEL_OPTION) { + break; + } else if (response == JOptionPane.NO_OPTION) { + continue; + } + } + nodeListModel.removeNode(selectedNode); } nodeList.clearSelection(); } diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index cb5d24c..edcc0df 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -74,11 +74,29 @@ public class SwingInterface implements CoreListener { // /** + * Returns the core that is controlled by the Swing interface. + * + * @return The core + */ + Core getCore() { + return core; + } + + /** + * Returns the main window of the Swing interface. + * + * @return The main window + */ + MainWindow getMainWindow() { + return mainWindow; + } + + /** * Returns the “manage nodes” action. * * @return The “manage nodes” action */ - public Action getManageNodesAction() { + Action getManageNodesAction() { return manageNodesAction; } @@ -87,7 +105,7 @@ public class SwingInterface implements CoreListener { * * @return The “connect to node” action */ - public Action getNodeConnectAction() { + Action getNodeConnectAction() { return nodeConnectAction; } @@ -96,7 +114,7 @@ public class SwingInterface implements CoreListener { * * @return The “disconnect from node” action */ - public Action getNodeDisconnectAction() { + Action getNodeDisconnectAction() { return nodeDisconnectAction; } @@ -157,7 +175,7 @@ public class SwingInterface implements CoreListener { * Initializes all child dialogs. */ private void initDialogs() { - manageNodesDialog = new ManageNodesDialog(mainWindow); + manageNodesDialog = new ManageNodesDialog(this); } /** -- 2.7.4