zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mic...@apache.org
Subject svn commit: r1584500 [6/9] - in /zookeeper/branches/branch-3.4: bin/ src/c/ src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/ src/contrib/zooinspector/ src/contrib/zooinspector/lib/ src/contrib/zooinspector/src/java/org/apache/zookeeper/in...
Date Fri, 04 Apr 2014 01:30:25 GMT
Modified: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java (original)
+++ zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java Fri Apr  4 01:30:24 2014
@@ -1,361 +1,361 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.zookeeper.inspector.gui;
-
-import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.ExecutionException;
-
-import javax.swing.JButton;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSplitPane;
-import javax.swing.JToolBar;
-import javax.swing.SwingWorker;
-
-import org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer;
-import org.apache.zookeeper.inspector.logger.LoggerFactory;
-import org.apache.zookeeper.inspector.manager.ZooInspectorManager;
-
-/**
- * The parent {@link JPanel} for the whole application
- */
-public class ZooInspectorPanel extends JPanel implements
-        NodeViewersChangeListener {
-    private final JButton refreshButton;
-    private final JButton disconnectButton;
-    private final JButton connectButton;
-    private final ZooInspectorNodeViewersPanel nodeViewersPanel;
-    private final ZooInspectorTreeViewer treeViewer;
-    private final ZooInspectorManager zooInspectorManager;
-    private final JButton addNodeButton;
-    private final JButton deleteNodeButton;
-    private final JButton nodeViewersButton;
-    private final JButton aboutButton;
-    private final List<NodeViewersChangeListener> listeners = new ArrayList<NodeViewersChangeListener>();
-    {
-        listeners.add(this);
-    }
-
-    /**
-     * @param zooInspectorManager
-     *            - the {@link ZooInspectorManager} for the application
-     */
-    public ZooInspectorPanel(final ZooInspectorManager zooInspectorManager) {
-        this.zooInspectorManager = zooInspectorManager;
-        final ArrayList<ZooInspectorNodeViewer> nodeViewers = new ArrayList<ZooInspectorNodeViewer>();
-        try {
-            List<String> defaultNodeViewersClassNames = this.zooInspectorManager
-                    .getDefaultNodeViewerConfiguration();
-            for (String className : defaultNodeViewersClassNames) {
-                nodeViewers.add((ZooInspectorNodeViewer) Class.forName(
-                        className).newInstance());
-            }
-        } catch (Exception ex) {
-            LoggerFactory.getLogger().error(
-                    "Error loading default node viewers.", ex);
-            JOptionPane.showMessageDialog(ZooInspectorPanel.this,
-                    "Error loading default node viewers: " + ex.getMessage(),
-                    "Error", JOptionPane.ERROR_MESSAGE);
-        }
-        nodeViewersPanel = new ZooInspectorNodeViewersPanel(
-                zooInspectorManager, nodeViewers);
-        treeViewer = new ZooInspectorTreeViewer(zooInspectorManager,
-                nodeViewersPanel);
-        this.setLayout(new BorderLayout());
-        JToolBar toolbar = new JToolBar();
-        toolbar.setFloatable(false);
-        connectButton = new JButton(ZooInspectorIconResources.getConnectIcon());
-        disconnectButton = new JButton(ZooInspectorIconResources
-                .getDisconnectIcon());
-        refreshButton = new JButton(ZooInspectorIconResources.getRefreshIcon());
-        addNodeButton = new JButton(ZooInspectorIconResources.getAddNodeIcon());
-        deleteNodeButton = new JButton(ZooInspectorIconResources
-                .getDeleteNodeIcon());
-        nodeViewersButton = new JButton(ZooInspectorIconResources
-                .getChangeNodeViewersIcon());
-        aboutButton = new JButton(ZooInspectorIconResources
-                .getInformationIcon());
-        toolbar.add(connectButton);
-        toolbar.add(disconnectButton);
-        toolbar.add(refreshButton);
-        toolbar.add(addNodeButton);
-        toolbar.add(deleteNodeButton);
-        toolbar.add(nodeViewersButton);
-        toolbar.add(aboutButton);
-        aboutButton.setEnabled(true);
-        connectButton.setEnabled(true);
-        disconnectButton.setEnabled(false);
-        refreshButton.setEnabled(false);
-        addNodeButton.setEnabled(false);
-        deleteNodeButton.setEnabled(false);
-        nodeViewersButton.setEnabled(true);
-        nodeViewersButton.setToolTipText("Change Node Viewers");
-        aboutButton.setToolTipText("About ZooInspector");
-        connectButton.setToolTipText("Connect");
-        disconnectButton.setToolTipText("Disconnect");
-        refreshButton.setToolTipText("Refresh");
-        addNodeButton.setToolTipText("Add Node");
-        deleteNodeButton.setToolTipText("Delete Node");
-        connectButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                ZooInspectorConnectionPropertiesDialog zicpd = new ZooInspectorConnectionPropertiesDialog(
-                        zooInspectorManager.getLastConnectionProps(),
-                        zooInspectorManager.getConnectionPropertiesTemplate(),
-                        ZooInspectorPanel.this);
-                zicpd.setVisible(true);
-            }
-        });
-        disconnectButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                disconnect();
-            }
-        });
-        refreshButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                treeViewer.refreshView();
-            }
-        });
-        addNodeButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                final List<String> selectedNodes = treeViewer
-                        .getSelectedNodes();
-                if (selectedNodes.size() == 1) {
-                    final String nodeName = JOptionPane.showInputDialog(
-                            ZooInspectorPanel.this,
-                            "Please Enter a name for the new node",
-                            "Create Node", JOptionPane.INFORMATION_MESSAGE);
-                    if (nodeName != null && nodeName.length() > 0) {
-                        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
-
-                            @Override
-                            protected Boolean doInBackground() throws Exception {
-                                return ZooInspectorPanel.this.zooInspectorManager
-                                        .createNode(selectedNodes.get(0),
-                                                nodeName);
-                            }
-
-                            @Override
-                            protected void done() {
-                                treeViewer.refreshView();
-                            }
-                        };
-                        worker.execute();
-                    }
-                } else {
-                    JOptionPane.showMessageDialog(ZooInspectorPanel.this,
-                            "Please select 1 parent node for the new node.");
-                }
-            }
-        });
-        deleteNodeButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                final List<String> selectedNodes = treeViewer
-                        .getSelectedNodes();
-                if (selectedNodes.size() == 0) {
-                    JOptionPane.showMessageDialog(ZooInspectorPanel.this,
-                            "Please select at least 1 node to be deleted");
-                } else {
-                    int answer = JOptionPane.showConfirmDialog(
-                            ZooInspectorPanel.this,
-                            "Are you sure you want to delete the selected nodes?"
-                                    + "(This action cannot be reverted)",
-                            "Confirm Delete", JOptionPane.YES_NO_OPTION,
-                            JOptionPane.WARNING_MESSAGE);
-                    if (answer == JOptionPane.YES_OPTION) {
-                        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
-
-                            @Override
-                            protected Boolean doInBackground() throws Exception {
-                                for (String nodePath : selectedNodes) {
-                                    ZooInspectorPanel.this.zooInspectorManager
-                                            .deleteNode(nodePath);
-                                }
-                                return true;
-                            }
-
-                            @Override
-                            protected void done() {
-                                treeViewer.refreshView();
-                            }
-                        };
-                        worker.execute();
-                    }
-                }
-            }
-        });
-        nodeViewersButton.addActionListener(new ActionListener() {
-
-            public void actionPerformed(ActionEvent e) {
-                ZooInspectorNodeViewersDialog nvd = new ZooInspectorNodeViewersDialog(
-                        JOptionPane.getRootFrame(), nodeViewers, listeners,
-                        zooInspectorManager);
-                nvd.setVisible(true);
-            }
-        });
-        aboutButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                ZooInspectorAboutDialog zicpd = new ZooInspectorAboutDialog(
-                        JOptionPane.getRootFrame());
-                zicpd.setVisible(true);
-            }
-        });
-        JScrollPane treeScroller = new JScrollPane(treeViewer);
-        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
-                treeScroller, nodeViewersPanel);
-        splitPane.setResizeWeight(0.25);
-        this.add(splitPane, BorderLayout.CENTER);
-        this.add(toolbar, BorderLayout.NORTH);
-    }
-
-    /**
-     * @param connectionProps
-     *            the {@link Properties} for connecting to the zookeeper
-     *            instance
-     */
-    public void connect(final Properties connectionProps) {
-        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
-
-            @Override
-            protected Boolean doInBackground() throws Exception {
-                zooInspectorManager.setLastConnectionProps(connectionProps);
-                return zooInspectorManager.connect(connectionProps);
-            }
-
-            @Override
-            protected void done() {
-                try {
-                    if (get()) {
-                        treeViewer.refreshView();
-                        connectButton.setEnabled(false);
-                        disconnectButton.setEnabled(true);
-                        refreshButton.setEnabled(true);
-                        addNodeButton.setEnabled(true);
-                        deleteNodeButton.setEnabled(true);
-                    } else {
-                        JOptionPane.showMessageDialog(ZooInspectorPanel.this,
-                                "Unable to connect to zookeeper", "Error",
-                                JOptionPane.ERROR_MESSAGE);
-                    }
-                } catch (InterruptedException e) {
-                    LoggerFactory
-                            .getLogger()
-                            .error(
-                                    "Error occurred while connecting to ZooKeeper server",
-                                    e);
-                } catch (ExecutionException e) {
-                    LoggerFactory
-                            .getLogger()
-                            .error(
-                                    "Error occurred while connecting to ZooKeeper server",
-                                    e);
-                }
-            }
-
-        };
-        worker.execute();
-    }
-
-    /**
-	 * 
-	 */
-    public void disconnect() {
-        disconnect(false);
-    }
-
-    /**
-     * @param wait
-     *            - set this to true if the method should only return once the
-     *            application has successfully disconnected
-     */
-    public void disconnect(boolean wait) {
-        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
-
-            @Override
-            protected Boolean doInBackground() throws Exception {
-                return ZooInspectorPanel.this.zooInspectorManager.disconnect();
-            }
-
-            @Override
-            protected void done() {
-                try {
-                    if (get()) {
-                        treeViewer.clearView();
-                        connectButton.setEnabled(true);
-                        disconnectButton.setEnabled(false);
-                        refreshButton.setEnabled(false);
-                        addNodeButton.setEnabled(false);
-                        deleteNodeButton.setEnabled(false);
-                    }
-                } catch (InterruptedException e) {
-                    LoggerFactory
-                            .getLogger()
-                            .error(
-                                    "Error occurred while disconnecting from ZooKeeper server",
-                                    e);
-                } catch (ExecutionException e) {
-                    LoggerFactory
-                            .getLogger()
-                            .error(
-                                    "Error occurred while disconnecting from ZooKeeper server",
-                                    e);
-                }
-            }
-
-        };
-        worker.execute();
-        if (wait) {
-            while (!worker.isDone()) {
-                try {
-                    Thread.sleep(100);
-                } catch (InterruptedException e) {
-                    LoggerFactory
-                            .getLogger()
-                            .error(
-                                    "Error occurred while disconnecting from ZooKeeper server",
-                                    e);
-                }
-            }
-        }
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @seeorg.apache.zookeeper.inspector.gui.NodeViewersChangeListener#
-     * nodeViewersChanged(java.util.List)
-     */
-    public void nodeViewersChanged(List<ZooInspectorNodeViewer> newViewers) {
-        this.nodeViewersPanel.setNodeViewers(newViewers);
-    }
-
-    /**
-     * @param connectionProps
-     * @throws IOException
-     */
-    public void setdefaultConnectionProps(Properties connectionProps)
-            throws IOException {
-        this.zooInspectorManager.saveDefaultConnectionFile(connectionProps);
-    }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.inspector.gui;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JToolBar;
+import javax.swing.SwingWorker;
+
+import org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer;
+import org.apache.zookeeper.inspector.logger.LoggerFactory;
+import org.apache.zookeeper.inspector.manager.ZooInspectorManager;
+
+/**
+ * The parent {@link JPanel} for the whole application
+ */
+public class ZooInspectorPanel extends JPanel implements
+        NodeViewersChangeListener {
+    private final JButton refreshButton;
+    private final JButton disconnectButton;
+    private final JButton connectButton;
+    private final ZooInspectorNodeViewersPanel nodeViewersPanel;
+    private final ZooInspectorTreeViewer treeViewer;
+    private final ZooInspectorManager zooInspectorManager;
+    private final JButton addNodeButton;
+    private final JButton deleteNodeButton;
+    private final JButton nodeViewersButton;
+    private final JButton aboutButton;
+    private final List<NodeViewersChangeListener> listeners = new ArrayList<NodeViewersChangeListener>();
+    {
+        listeners.add(this);
+    }
+
+    /**
+     * @param zooInspectorManager
+     *            - the {@link ZooInspectorManager} for the application
+     */
+    public ZooInspectorPanel(final ZooInspectorManager zooInspectorManager) {
+        this.zooInspectorManager = zooInspectorManager;
+        final ArrayList<ZooInspectorNodeViewer> nodeViewers = new ArrayList<ZooInspectorNodeViewer>();
+        try {
+            List<String> defaultNodeViewersClassNames = this.zooInspectorManager
+                    .getDefaultNodeViewerConfiguration();
+            for (String className : defaultNodeViewersClassNames) {
+                nodeViewers.add((ZooInspectorNodeViewer) Class.forName(
+                        className).newInstance());
+            }
+        } catch (Exception ex) {
+            LoggerFactory.getLogger().error(
+                    "Error loading default node viewers.", ex);
+            JOptionPane.showMessageDialog(ZooInspectorPanel.this,
+                    "Error loading default node viewers: " + ex.getMessage(),
+                    "Error", JOptionPane.ERROR_MESSAGE);
+        }
+        nodeViewersPanel = new ZooInspectorNodeViewersPanel(
+                zooInspectorManager, nodeViewers);
+        treeViewer = new ZooInspectorTreeViewer(zooInspectorManager,
+                nodeViewersPanel);
+        this.setLayout(new BorderLayout());
+        JToolBar toolbar = new JToolBar();
+        toolbar.setFloatable(false);
+        connectButton = new JButton(ZooInspectorIconResources.getConnectIcon());
+        disconnectButton = new JButton(ZooInspectorIconResources
+                .getDisconnectIcon());
+        refreshButton = new JButton(ZooInspectorIconResources.getRefreshIcon());
+        addNodeButton = new JButton(ZooInspectorIconResources.getAddNodeIcon());
+        deleteNodeButton = new JButton(ZooInspectorIconResources
+                .getDeleteNodeIcon());
+        nodeViewersButton = new JButton(ZooInspectorIconResources
+                .getChangeNodeViewersIcon());
+        aboutButton = new JButton(ZooInspectorIconResources
+                .getInformationIcon());
+        toolbar.add(connectButton);
+        toolbar.add(disconnectButton);
+        toolbar.add(refreshButton);
+        toolbar.add(addNodeButton);
+        toolbar.add(deleteNodeButton);
+        toolbar.add(nodeViewersButton);
+        toolbar.add(aboutButton);
+        aboutButton.setEnabled(true);
+        connectButton.setEnabled(true);
+        disconnectButton.setEnabled(false);
+        refreshButton.setEnabled(false);
+        addNodeButton.setEnabled(false);
+        deleteNodeButton.setEnabled(false);
+        nodeViewersButton.setEnabled(true);
+        nodeViewersButton.setToolTipText("Change Node Viewers");
+        aboutButton.setToolTipText("About ZooInspector");
+        connectButton.setToolTipText("Connect");
+        disconnectButton.setToolTipText("Disconnect");
+        refreshButton.setToolTipText("Refresh");
+        addNodeButton.setToolTipText("Add Node");
+        deleteNodeButton.setToolTipText("Delete Node");
+        connectButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                ZooInspectorConnectionPropertiesDialog zicpd = new ZooInspectorConnectionPropertiesDialog(
+                        zooInspectorManager.getLastConnectionProps(),
+                        zooInspectorManager.getConnectionPropertiesTemplate(),
+                        ZooInspectorPanel.this);
+                zicpd.setVisible(true);
+            }
+        });
+        disconnectButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                disconnect();
+            }
+        });
+        refreshButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                treeViewer.refreshView();
+            }
+        });
+        addNodeButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                final List<String> selectedNodes = treeViewer
+                        .getSelectedNodes();
+                if (selectedNodes.size() == 1) {
+                    final String nodeName = JOptionPane.showInputDialog(
+                            ZooInspectorPanel.this,
+                            "Please Enter a name for the new node",
+                            "Create Node", JOptionPane.INFORMATION_MESSAGE);
+                    if (nodeName != null && nodeName.length() > 0) {
+                        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
+
+                            @Override
+                            protected Boolean doInBackground() throws Exception {
+                                return ZooInspectorPanel.this.zooInspectorManager
+                                        .createNode(selectedNodes.get(0),
+                                                nodeName);
+                            }
+
+                            @Override
+                            protected void done() {
+                                treeViewer.refreshView();
+                            }
+                        };
+                        worker.execute();
+                    }
+                } else {
+                    JOptionPane.showMessageDialog(ZooInspectorPanel.this,
+                            "Please select 1 parent node for the new node.");
+                }
+            }
+        });
+        deleteNodeButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                final List<String> selectedNodes = treeViewer
+                        .getSelectedNodes();
+                if (selectedNodes.size() == 0) {
+                    JOptionPane.showMessageDialog(ZooInspectorPanel.this,
+                            "Please select at least 1 node to be deleted");
+                } else {
+                    int answer = JOptionPane.showConfirmDialog(
+                            ZooInspectorPanel.this,
+                            "Are you sure you want to delete the selected nodes?"
+                                    + "(This action cannot be reverted)",
+                            "Confirm Delete", JOptionPane.YES_NO_OPTION,
+                            JOptionPane.WARNING_MESSAGE);
+                    if (answer == JOptionPane.YES_OPTION) {
+                        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
+
+                            @Override
+                            protected Boolean doInBackground() throws Exception {
+                                for (String nodePath : selectedNodes) {
+                                    ZooInspectorPanel.this.zooInspectorManager
+                                            .deleteNode(nodePath);
+                                }
+                                return true;
+                            }
+
+                            @Override
+                            protected void done() {
+                                treeViewer.refreshView();
+                            }
+                        };
+                        worker.execute();
+                    }
+                }
+            }
+        });
+        nodeViewersButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                ZooInspectorNodeViewersDialog nvd = new ZooInspectorNodeViewersDialog(
+                        JOptionPane.getRootFrame(), nodeViewers, listeners,
+                        zooInspectorManager);
+                nvd.setVisible(true);
+            }
+        });
+        aboutButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                ZooInspectorAboutDialog zicpd = new ZooInspectorAboutDialog(
+                        JOptionPane.getRootFrame());
+                zicpd.setVisible(true);
+            }
+        });
+        JScrollPane treeScroller = new JScrollPane(treeViewer);
+        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
+                treeScroller, nodeViewersPanel);
+        splitPane.setResizeWeight(0.25);
+        this.add(splitPane, BorderLayout.CENTER);
+        this.add(toolbar, BorderLayout.NORTH);
+    }
+
+    /**
+     * @param connectionProps
+     *            the {@link Properties} for connecting to the zookeeper
+     *            instance
+     */
+    public void connect(final Properties connectionProps) {
+        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
+
+            @Override
+            protected Boolean doInBackground() throws Exception {
+                zooInspectorManager.setLastConnectionProps(connectionProps);
+                return zooInspectorManager.connect(connectionProps);
+            }
+
+            @Override
+            protected void done() {
+                try {
+                    if (get()) {
+                        treeViewer.refreshView();
+                        connectButton.setEnabled(false);
+                        disconnectButton.setEnabled(true);
+                        refreshButton.setEnabled(true);
+                        addNodeButton.setEnabled(true);
+                        deleteNodeButton.setEnabled(true);
+                    } else {
+                        JOptionPane.showMessageDialog(ZooInspectorPanel.this,
+                                "Unable to connect to zookeeper", "Error",
+                                JOptionPane.ERROR_MESSAGE);
+                    }
+                } catch (InterruptedException e) {
+                    LoggerFactory
+                            .getLogger()
+                            .error(
+                                    "Error occurred while connecting to ZooKeeper server",
+                                    e);
+                } catch (ExecutionException e) {
+                    LoggerFactory
+                            .getLogger()
+                            .error(
+                                    "Error occurred while connecting to ZooKeeper server",
+                                    e);
+                }
+            }
+
+        };
+        worker.execute();
+    }
+
+    /**
+	 * 
+	 */
+    public void disconnect() {
+        disconnect(false);
+    }
+
+    /**
+     * @param wait
+     *            - set this to true if the method should only return once the
+     *            application has successfully disconnected
+     */
+    public void disconnect(boolean wait) {
+        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
+
+            @Override
+            protected Boolean doInBackground() throws Exception {
+                return ZooInspectorPanel.this.zooInspectorManager.disconnect();
+            }
+
+            @Override
+            protected void done() {
+                try {
+                    if (get()) {
+                        treeViewer.clearView();
+                        connectButton.setEnabled(true);
+                        disconnectButton.setEnabled(false);
+                        refreshButton.setEnabled(false);
+                        addNodeButton.setEnabled(false);
+                        deleteNodeButton.setEnabled(false);
+                    }
+                } catch (InterruptedException e) {
+                    LoggerFactory
+                            .getLogger()
+                            .error(
+                                    "Error occurred while disconnecting from ZooKeeper server",
+                                    e);
+                } catch (ExecutionException e) {
+                    LoggerFactory
+                            .getLogger()
+                            .error(
+                                    "Error occurred while disconnecting from ZooKeeper server",
+                                    e);
+                }
+            }
+
+        };
+        worker.execute();
+        if (wait) {
+            while (!worker.isDone()) {
+                try {
+                    Thread.sleep(100);
+                } catch (InterruptedException e) {
+                    LoggerFactory
+                            .getLogger()
+                            .error(
+                                    "Error occurred while disconnecting from ZooKeeper server",
+                                    e);
+                }
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @seeorg.apache.zookeeper.inspector.gui.NodeViewersChangeListener#
+     * nodeViewersChanged(java.util.List)
+     */
+    public void nodeViewersChanged(List<ZooInspectorNodeViewer> newViewers) {
+        this.nodeViewersPanel.setNodeViewers(newViewers);
+    }
+
+    /**
+     * @param connectionProps
+     * @throws IOException
+     */
+    public void setdefaultConnectionProps(Properties connectionProps)
+            throws IOException {
+        this.zooInspectorManager.saveDefaultConnectionFile(connectionProps);
+    }
+}

Propchange: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java (original)
+++ zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java Fri Apr  4 01:30:24 2014
@@ -1,362 +1,362 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.zookeeper.inspector.gui;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.swing.JMenuItem;
-import javax.swing.JPanel;
-import javax.swing.JPopupMenu;
-import javax.swing.JTree;
-import javax.swing.SwingWorker;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.DefaultTreeCellRenderer;
-import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.TreeNode;
-import javax.swing.tree.TreePath;
-
-import org.apache.zookeeper.inspector.manager.NodeListener;
-import org.apache.zookeeper.inspector.manager.ZooInspectorManager;
-
-import com.nitido.utils.toaster.Toaster;
-
-/**
- * A {@link JPanel} for showing the tree view of all the nodes in the zookeeper
- * instance
- */
-public class ZooInspectorTreeViewer extends JPanel implements NodeListener {
-    private final ZooInspectorManager zooInspectorManager;
-    private final JTree tree;
-    private final Toaster toasterManager;
-
-    /**
-     * @param zooInspectorManager
-     *            - the {@link ZooInspectorManager} for the application
-     * @param listener
-     *            - the {@link TreeSelectionListener} to listen for changes in
-     *            the selected node on the node tree
-     */
-    public ZooInspectorTreeViewer(
-            final ZooInspectorManager zooInspectorManager,
-            TreeSelectionListener listener) {
-        this.zooInspectorManager = zooInspectorManager;
-        this.setLayout(new BorderLayout());
-        final JPopupMenu popupMenu = new JPopupMenu();
-        final JMenuItem addNotify = new JMenuItem("Add Change Notification");
-        this.toasterManager = new Toaster();
-        this.toasterManager.setBorderColor(Color.BLACK);
-        this.toasterManager.setMessageColor(Color.BLACK);
-        this.toasterManager.setToasterColor(Color.WHITE);
-        addNotify.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                List<String> selectedNodes = getSelectedNodes();
-                zooInspectorManager.addWatchers(selectedNodes,
-                        ZooInspectorTreeViewer.this);
-            }
-        });
-        final JMenuItem removeNotify = new JMenuItem(
-                "Remove Change Notification");
-        removeNotify.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                List<String> selectedNodes = getSelectedNodes();
-                zooInspectorManager.removeWatchers(selectedNodes);
-            }
-        });
-        tree = new JTree(new DefaultMutableTreeNode());
-        tree.setCellRenderer(new ZooInspectorTreeCellRenderer());
-        tree.setEditable(false);
-        tree.getSelectionModel().addTreeSelectionListener(listener);
-        tree.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mouseClicked(MouseEvent e) {
-                if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON3) {
-                    // TODO only show add if a selected node isn't being
-                    // watched, and only show remove if a selected node is being
-                    // watched
-                    popupMenu.removeAll();
-                    popupMenu.add(addNotify);
-                    popupMenu.add(removeNotify);
-                    popupMenu.show(ZooInspectorTreeViewer.this, e.getX(), e
-                            .getY());
-                }
-            }
-        });
-        this.add(tree, BorderLayout.CENTER);
-    }
-
-    /**
-     * Refresh the tree view
-     */
-    public void refreshView() {
-        final Set<TreePath> expandedNodes = new LinkedHashSet<TreePath>();
-        int rowCount = tree.getRowCount();
-        for (int i = 0; i < rowCount; i++) {
-            TreePath path = tree.getPathForRow(i);
-            if (tree.isExpanded(path)) {
-                expandedNodes.add(path);
-            }
-        }
-        final TreePath[] selectedNodes = tree.getSelectionPaths();
-        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
-
-            @Override
-            protected Boolean doInBackground() throws Exception {
-                tree.setModel(new DefaultTreeModel(new ZooInspectorTreeNode(
-                        "/", null)));
-                return true;
-            }
-
-            @Override
-            protected void done() {
-                for (TreePath path : expandedNodes) {
-                    tree.expandPath(path);
-                }
-                tree.getSelectionModel().setSelectionPaths(selectedNodes);
-            }
-        };
-        worker.execute();
-    }
-
-    /**
-     * clear the tree view of all nodes
-     */
-    public void clearView() {
-        tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
-    }
-
-    /**
-     * @author Colin
-     * 
-     */
-    private static class ZooInspectorTreeCellRenderer extends
-            DefaultTreeCellRenderer {
-        public ZooInspectorTreeCellRenderer() {
-            setLeafIcon(ZooInspectorIconResources.getTreeLeafIcon());
-            setOpenIcon(ZooInspectorIconResources.getTreeOpenIcon());
-            setClosedIcon(ZooInspectorIconResources.getTreeClosedIcon());
-        }
-    }
-
-    /**
-     * @author Colin
-     * 
-     */
-    private class ZooInspectorTreeNode implements TreeNode {
-        private final String nodePath;
-        private final String nodeName;
-        private final ZooInspectorTreeNode parent;
-
-        public ZooInspectorTreeNode(String nodePath, ZooInspectorTreeNode parent) {
-            this.parent = parent;
-            this.nodePath = nodePath;
-            int index = nodePath.lastIndexOf("/");
-            if (index == -1) {
-                throw new IllegalArgumentException("Invalid node path"
-                        + nodePath);
-            }
-            this.nodeName = nodePath.substring(index + 1);
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.swing.tree.TreeNode#children()
-         */
-        public Enumeration<TreeNode> children() {
-            List<String> children = zooInspectorManager
-                    .getChildren(this.nodePath);
-            Collections.sort(children);
-            List<TreeNode> returnChildren = new ArrayList<TreeNode>();
-            for (String child : children) {
-                returnChildren.add(new ZooInspectorTreeNode((this.nodePath
-                        .equals("/") ? "" : this.nodePath)
-                        + "/" + child, this));
-            }
-            return Collections.enumeration(returnChildren);
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.swing.tree.TreeNode#getAllowsChildren()
-         */
-        public boolean getAllowsChildren() {
-            return zooInspectorManager.isAllowsChildren(this.nodePath);
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.swing.tree.TreeNode#getChildAt(int)
-         */
-        public TreeNode getChildAt(int childIndex) {
-            String child = zooInspectorManager.getNodeChild(this.nodePath,
-                    childIndex);
-            if (child != null) {
-                return new ZooInspectorTreeNode((this.nodePath.equals("/") ? ""
-                        : this.nodePath)
-                        + "/" + child, this);
-            }
-            return null;
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.swing.tree.TreeNode#getChildCount()
-         */
-        public int getChildCount() {
-            return zooInspectorManager.getNumChildren(this.nodePath);
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
-         */
-        public int getIndex(TreeNode node) {
-            return zooInspectorManager.getNodeIndex(this.nodePath);
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.swing.tree.TreeNode#getParent()
-         */
-        public TreeNode getParent() {
-            return this.parent;
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.swing.tree.TreeNode#isLeaf()
-         */
-        public boolean isLeaf() {
-            return !zooInspectorManager.hasChildren(this.nodePath);
-        }
-
-        @Override
-        public String toString() {
-            return this.nodeName;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + getOuterType().hashCode();
-            result = prime * result
-                    + ((nodePath == null) ? 0 : nodePath.hashCode());
-            result = prime * result
-                    + ((parent == null) ? 0 : parent.hashCode());
-            return result;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (this == obj)
-                return true;
-            if (obj == null)
-                return false;
-            if (getClass() != obj.getClass())
-                return false;
-            ZooInspectorTreeNode other = (ZooInspectorTreeNode) obj;
-            if (!getOuterType().equals(other.getOuterType()))
-                return false;
-            if (nodePath == null) {
-                if (other.nodePath != null)
-                    return false;
-            } else if (!nodePath.equals(other.nodePath))
-                return false;
-            if (parent == null) {
-                if (other.parent != null)
-                    return false;
-            } else if (!parent.equals(other.parent))
-                return false;
-            return true;
-        }
-
-        private ZooInspectorTreeViewer getOuterType() {
-            return ZooInspectorTreeViewer.this;
-        }
-
-    }
-
-    /**
-     * @return {@link List} of the currently selected nodes
-     */
-    public List<String> getSelectedNodes() {
-        TreePath[] paths = tree.getSelectionPaths();
-        List<String> selectedNodes = new ArrayList<String>();
-        if (paths != null) {
-            for (TreePath path : paths) {
-                StringBuilder sb = new StringBuilder();
-                Object[] pathArray = path.getPath();
-                for (Object o : pathArray) {
-                    String nodeName = o.toString();
-                    if (nodeName.length() > 0) {
-                        sb.append("/");
-                        sb.append(o.toString());
-                    }
-                }
-                selectedNodes.add(sb.toString());
-            }
-        }
-        return selectedNodes;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.zookeeper.inspector.manager.NodeListener#processEvent(java
-     * .lang.String, java.lang.String, java.util.Map)
-     */
-    public void processEvent(String nodePath, String eventType,
-            Map<String, String> eventInfo) {
-        StringBuilder sb = new StringBuilder();
-        sb.append("Node: ");
-        sb.append(nodePath);
-        sb.append("\nEvent: ");
-        sb.append(eventType);
-        if (eventInfo != null) {
-            for (Map.Entry<String, String> entry : eventInfo.entrySet()) {
-                sb.append("\n");
-                sb.append(entry.getKey());
-                sb.append(": ");
-                sb.append(entry.getValue());
-            }
-        }
-        this.toasterManager.showToaster(ZooInspectorIconResources
-                .getInformationIcon(), sb.toString());
-    }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.inspector.gui;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+import javax.swing.SwingWorker;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
+
+import org.apache.zookeeper.inspector.manager.NodeListener;
+import org.apache.zookeeper.inspector.manager.ZooInspectorManager;
+
+import com.nitido.utils.toaster.Toaster;
+
+/**
+ * A {@link JPanel} for showing the tree view of all the nodes in the zookeeper
+ * instance
+ */
+public class ZooInspectorTreeViewer extends JPanel implements NodeListener {
+    private final ZooInspectorManager zooInspectorManager;
+    private final JTree tree;
+    private final Toaster toasterManager;
+
+    /**
+     * @param zooInspectorManager
+     *            - the {@link ZooInspectorManager} for the application
+     * @param listener
+     *            - the {@link TreeSelectionListener} to listen for changes in
+     *            the selected node on the node tree
+     */
+    public ZooInspectorTreeViewer(
+            final ZooInspectorManager zooInspectorManager,
+            TreeSelectionListener listener) {
+        this.zooInspectorManager = zooInspectorManager;
+        this.setLayout(new BorderLayout());
+        final JPopupMenu popupMenu = new JPopupMenu();
+        final JMenuItem addNotify = new JMenuItem("Add Change Notification");
+        this.toasterManager = new Toaster();
+        this.toasterManager.setBorderColor(Color.BLACK);
+        this.toasterManager.setMessageColor(Color.BLACK);
+        this.toasterManager.setToasterColor(Color.WHITE);
+        addNotify.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                List<String> selectedNodes = getSelectedNodes();
+                zooInspectorManager.addWatchers(selectedNodes,
+                        ZooInspectorTreeViewer.this);
+            }
+        });
+        final JMenuItem removeNotify = new JMenuItem(
+                "Remove Change Notification");
+        removeNotify.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                List<String> selectedNodes = getSelectedNodes();
+                zooInspectorManager.removeWatchers(selectedNodes);
+            }
+        });
+        tree = new JTree(new DefaultMutableTreeNode());
+        tree.setCellRenderer(new ZooInspectorTreeCellRenderer());
+        tree.setEditable(false);
+        tree.getSelectionModel().addTreeSelectionListener(listener);
+        tree.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseClicked(MouseEvent e) {
+                if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON3) {
+                    // TODO only show add if a selected node isn't being
+                    // watched, and only show remove if a selected node is being
+                    // watched
+                    popupMenu.removeAll();
+                    popupMenu.add(addNotify);
+                    popupMenu.add(removeNotify);
+                    popupMenu.show(ZooInspectorTreeViewer.this, e.getX(), e
+                            .getY());
+                }
+            }
+        });
+        this.add(tree, BorderLayout.CENTER);
+    }
+
+    /**
+     * Refresh the tree view
+     */
+    public void refreshView() {
+        final Set<TreePath> expandedNodes = new LinkedHashSet<TreePath>();
+        int rowCount = tree.getRowCount();
+        for (int i = 0; i < rowCount; i++) {
+            TreePath path = tree.getPathForRow(i);
+            if (tree.isExpanded(path)) {
+                expandedNodes.add(path);
+            }
+        }
+        final TreePath[] selectedNodes = tree.getSelectionPaths();
+        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
+
+            @Override
+            protected Boolean doInBackground() throws Exception {
+                tree.setModel(new DefaultTreeModel(new ZooInspectorTreeNode(
+                        "/", null)));
+                return true;
+            }
+
+            @Override
+            protected void done() {
+                for (TreePath path : expandedNodes) {
+                    tree.expandPath(path);
+                }
+                tree.getSelectionModel().setSelectionPaths(selectedNodes);
+            }
+        };
+        worker.execute();
+    }
+
+    /**
+     * clear the tree view of all nodes
+     */
+    public void clearView() {
+        tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
+    }
+
+    /**
+     * @author Colin
+     * 
+     */
+    private static class ZooInspectorTreeCellRenderer extends
+            DefaultTreeCellRenderer {
+        public ZooInspectorTreeCellRenderer() {
+            setLeafIcon(ZooInspectorIconResources.getTreeLeafIcon());
+            setOpenIcon(ZooInspectorIconResources.getTreeOpenIcon());
+            setClosedIcon(ZooInspectorIconResources.getTreeClosedIcon());
+        }
+    }
+
+    /**
+     * @author Colin
+     * 
+     */
+    private class ZooInspectorTreeNode implements TreeNode {
+        private final String nodePath;
+        private final String nodeName;
+        private final ZooInspectorTreeNode parent;
+
+        public ZooInspectorTreeNode(String nodePath, ZooInspectorTreeNode parent) {
+            this.parent = parent;
+            this.nodePath = nodePath;
+            int index = nodePath.lastIndexOf("/");
+            if (index == -1) {
+                throw new IllegalArgumentException("Invalid node path"
+                        + nodePath);
+            }
+            this.nodeName = nodePath.substring(index + 1);
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.swing.tree.TreeNode#children()
+         */
+        public Enumeration<TreeNode> children() {
+            List<String> children = zooInspectorManager
+                    .getChildren(this.nodePath);
+            Collections.sort(children);
+            List<TreeNode> returnChildren = new ArrayList<TreeNode>();
+            for (String child : children) {
+                returnChildren.add(new ZooInspectorTreeNode((this.nodePath
+                        .equals("/") ? "" : this.nodePath)
+                        + "/" + child, this));
+            }
+            return Collections.enumeration(returnChildren);
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.swing.tree.TreeNode#getAllowsChildren()
+         */
+        public boolean getAllowsChildren() {
+            return zooInspectorManager.isAllowsChildren(this.nodePath);
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.swing.tree.TreeNode#getChildAt(int)
+         */
+        public TreeNode getChildAt(int childIndex) {
+            String child = zooInspectorManager.getNodeChild(this.nodePath,
+                    childIndex);
+            if (child != null) {
+                return new ZooInspectorTreeNode((this.nodePath.equals("/") ? ""
+                        : this.nodePath)
+                        + "/" + child, this);
+            }
+            return null;
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.swing.tree.TreeNode#getChildCount()
+         */
+        public int getChildCount() {
+            return zooInspectorManager.getNumChildren(this.nodePath);
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
+         */
+        public int getIndex(TreeNode node) {
+            return zooInspectorManager.getNodeIndex(this.nodePath);
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.swing.tree.TreeNode#getParent()
+         */
+        public TreeNode getParent() {
+            return this.parent;
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.swing.tree.TreeNode#isLeaf()
+         */
+        public boolean isLeaf() {
+            return !zooInspectorManager.hasChildren(this.nodePath);
+        }
+
+        @Override
+        public String toString() {
+            return this.nodeName;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + getOuterType().hashCode();
+            result = prime * result
+                    + ((nodePath == null) ? 0 : nodePath.hashCode());
+            result = prime * result
+                    + ((parent == null) ? 0 : parent.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            ZooInspectorTreeNode other = (ZooInspectorTreeNode) obj;
+            if (!getOuterType().equals(other.getOuterType()))
+                return false;
+            if (nodePath == null) {
+                if (other.nodePath != null)
+                    return false;
+            } else if (!nodePath.equals(other.nodePath))
+                return false;
+            if (parent == null) {
+                if (other.parent != null)
+                    return false;
+            } else if (!parent.equals(other.parent))
+                return false;
+            return true;
+        }
+
+        private ZooInspectorTreeViewer getOuterType() {
+            return ZooInspectorTreeViewer.this;
+        }
+
+    }
+
+    /**
+     * @return {@link List} of the currently selected nodes
+     */
+    public List<String> getSelectedNodes() {
+        TreePath[] paths = tree.getSelectionPaths();
+        List<String> selectedNodes = new ArrayList<String>();
+        if (paths != null) {
+            for (TreePath path : paths) {
+                StringBuilder sb = new StringBuilder();
+                Object[] pathArray = path.getPath();
+                for (Object o : pathArray) {
+                    String nodeName = o.toString();
+                    if (nodeName.length() > 0) {
+                        sb.append("/");
+                        sb.append(o.toString());
+                    }
+                }
+                selectedNodes.add(sb.toString());
+            }
+        }
+        return selectedNodes;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.zookeeper.inspector.manager.NodeListener#processEvent(java
+     * .lang.String, java.lang.String, java.util.Map)
+     */
+    public void processEvent(String nodePath, String eventType,
+            Map<String, String> eventInfo) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("Node: ");
+        sb.append(nodePath);
+        sb.append("\nEvent: ");
+        sb.append(eventType);
+        if (eventInfo != null) {
+            for (Map.Entry<String, String> entry : eventInfo.entrySet()) {
+                sb.append("\n");
+                sb.append(entry.getKey());
+                sb.append(": ");
+                sb.append(entry.getValue());
+            }
+        }
+        this.toasterManager.showToaster(ZooInspectorIconResources
+                .getInformationIcon(), sb.toString());
+    }
+}

Propchange: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html (original)
+++ zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html Fri Apr  4 01:30:24 2014
@@ -1,21 +1,21 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>ZooInspector v0.1</title>
-</head>
-<body>
-<p>ZooInspector was developed by Colin Goodheart-Smithe and is
-available under the Apache Software Licence v2.0.</p>
-<p>The Icons used were sourced from the Eclipse project (<a
-	href="http://www.eclipse.org">http://www.eclipse.org</a>) and licensed
-under the Eclipse Public Licence v1.0. [<a
-	href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</a>]
-</p>
-<p>ZooKeeper is available from <a
-	href="http://zookeeper.apache.org/">http://zookeeper.apache.org/</a>
-and is licensed under an Apache Software Licence v2.0</p>
-<p>The ApacheSoftware Licence v2.0 can be found at <a
-	href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a></p>
-</body>
-</html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>ZooInspector v0.1</title>
+</head>
+<body>
+<p>ZooInspector was developed by Colin Goodheart-Smithe and is
+available under the Apache Software Licence v2.0.</p>
+<p>The Icons used were sourced from the Eclipse project (<a
+	href="http://www.eclipse.org">http://www.eclipse.org</a>) and licensed
+under the Eclipse Public Licence v1.0. [<a
+	href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</a>]
+</p>
+<p>ZooKeeper is available from <a
+	href="http://zookeeper.apache.org/">http://zookeeper.apache.org/</a>
+and is licensed under an Apache Software Licence v2.0</p>
+<p>The ApacheSoftware Licence v2.0 can be found at <a
+	href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a></p>
+</body>
+</html>

Propchange: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java (original)
+++ zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java Fri Apr  4 01:30:24 2014
@@ -1,187 +1,187 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.zookeeper.inspector.gui.nodeviewer;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-
-import javax.swing.BorderFactory;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTextField;
-import javax.swing.SwingWorker;
-
-import org.apache.zookeeper.inspector.logger.LoggerFactory;
-import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager;
-
-/**
- * A node viewer for displaying the ACLs currently applied to the selected node
- */
-public class NodeViewerACL extends ZooInspectorNodeViewer {
-    private ZooInspectorNodeManager zooInspectorManager;
-    private final JPanel aclDataPanel;
-    private String selectedNode;
-
-    /**
-	 * 
-	 */
-    public NodeViewerACL() {
-        this.setLayout(new BorderLayout());
-        this.aclDataPanel = new JPanel();
-        this.aclDataPanel.setBackground(Color.WHITE);
-        JScrollPane scroller = new JScrollPane(this.aclDataPanel);
-        this.add(scroller, BorderLayout.CENTER);
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
-     * getTitle()
-     */
-    @Override
-    public String getTitle() {
-        return "Node ACLs";
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
-     * nodeSelectionChanged(java.util.Set)
-     */
-    @Override
-    public void nodeSelectionChanged(List<String> selectedNodes) {
-        this.aclDataPanel.removeAll();
-        if (selectedNodes.size() > 0) {
-            this.selectedNode = selectedNodes.get(0);
-            SwingWorker<List<Map<String, String>>, Void> worker = new SwingWorker<List<Map<String, String>>, Void>() {
-
-                @Override
-                protected List<Map<String, String>> doInBackground()
-                        throws Exception {
-                    return NodeViewerACL.this.zooInspectorManager
-                            .getACLs(NodeViewerACL.this.selectedNode);
-                }
-
-                @Override
-                protected void done() {
-                    List<Map<String, String>> acls = null;
-                    try {
-                        acls = get();
-                    } catch (InterruptedException e) {
-                        acls = new ArrayList<Map<String, String>>();
-                        LoggerFactory.getLogger().error(
-                                "Error retrieving ACL Information for node: "
-                                        + NodeViewerACL.this.selectedNode, e);
-                    } catch (ExecutionException e) {
-                        acls = new ArrayList<Map<String, String>>();
-                        LoggerFactory.getLogger().error(
-                                "Error retrieving ACL Information for node: "
-                                        + NodeViewerACL.this.selectedNode, e);
-                    }
-                    aclDataPanel.setLayout(new GridBagLayout());
-                    int j = 0;
-                    for (Map<String, String> data : acls) {
-                        int rowPos = 2 * j + 1;
-                        JPanel aclPanel = new JPanel();
-                        aclPanel.setBorder(BorderFactory
-                                .createLineBorder(Color.BLACK));
-                        aclPanel.setBackground(Color.WHITE);
-                        aclPanel.setLayout(new GridBagLayout());
-                        int i = 0;
-                        for (Map.Entry<String, String> entry : data.entrySet()) {
-                            int rowPosACL = 2 * i + 1;
-                            JLabel label = new JLabel(entry.getKey());
-                            JTextField text = new JTextField(entry.getValue());
-                            text.setEditable(false);
-                            GridBagConstraints c1 = new GridBagConstraints();
-                            c1.gridx = 1;
-                            c1.gridy = rowPosACL;
-                            c1.gridwidth = 1;
-                            c1.gridheight = 1;
-                            c1.weightx = 0;
-                            c1.weighty = 0;
-                            c1.anchor = GridBagConstraints.NORTHWEST;
-                            c1.fill = GridBagConstraints.BOTH;
-                            c1.insets = new Insets(5, 5, 5, 5);
-                            c1.ipadx = 0;
-                            c1.ipady = 0;
-                            aclPanel.add(label, c1);
-                            GridBagConstraints c2 = new GridBagConstraints();
-                            c2.gridx = 3;
-                            c2.gridy = rowPosACL;
-                            c2.gridwidth = 1;
-                            c2.gridheight = 1;
-                            c2.weightx = 0;
-                            c2.weighty = 0;
-                            c2.anchor = GridBagConstraints.NORTHWEST;
-                            c2.fill = GridBagConstraints.BOTH;
-                            c2.insets = new Insets(5, 5, 5, 5);
-                            c2.ipadx = 0;
-                            c2.ipady = 0;
-                            aclPanel.add(text, c2);
-                            i++;
-                        }
-                        GridBagConstraints c = new GridBagConstraints();
-                        c.gridx = 1;
-                        c.gridy = rowPos;
-                        c.gridwidth = 1;
-                        c.gridheight = 1;
-                        c.weightx = 1;
-                        c.weighty = 1;
-                        c.anchor = GridBagConstraints.NORTHWEST;
-                        c.fill = GridBagConstraints.NONE;
-                        c.insets = new Insets(5, 5, 5, 5);
-                        c.ipadx = 0;
-                        c.ipady = 0;
-                        aclDataPanel.add(aclPanel, c);
-                    }
-                    NodeViewerACL.this.aclDataPanel.revalidate();
-                    NodeViewerACL.this.aclDataPanel.repaint();
-                }
-            };
-            worker.execute();
-        }
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
-     * setZooInspectorManager
-     * (org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager)
-     */
-    @Override
-    public void setZooInspectorManager(
-            ZooInspectorNodeManager zooInspectorManager) {
-        this.zooInspectorManager = zooInspectorManager;
-    }
-
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.inspector.gui.nodeviewer;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+import javax.swing.SwingWorker;
+
+import org.apache.zookeeper.inspector.logger.LoggerFactory;
+import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager;
+
+/**
+ * A node viewer for displaying the ACLs currently applied to the selected node
+ */
+public class NodeViewerACL extends ZooInspectorNodeViewer {
+    private ZooInspectorNodeManager zooInspectorManager;
+    private final JPanel aclDataPanel;
+    private String selectedNode;
+
+    /**
+	 * 
+	 */
+    public NodeViewerACL() {
+        this.setLayout(new BorderLayout());
+        this.aclDataPanel = new JPanel();
+        this.aclDataPanel.setBackground(Color.WHITE);
+        JScrollPane scroller = new JScrollPane(this.aclDataPanel);
+        this.add(scroller, BorderLayout.CENTER);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
+     * getTitle()
+     */
+    @Override
+    public String getTitle() {
+        return "Node ACLs";
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
+     * nodeSelectionChanged(java.util.Set)
+     */
+    @Override
+    public void nodeSelectionChanged(List<String> selectedNodes) {
+        this.aclDataPanel.removeAll();
+        if (selectedNodes.size() > 0) {
+            this.selectedNode = selectedNodes.get(0);
+            SwingWorker<List<Map<String, String>>, Void> worker = new SwingWorker<List<Map<String, String>>, Void>() {
+
+                @Override
+                protected List<Map<String, String>> doInBackground()
+                        throws Exception {
+                    return NodeViewerACL.this.zooInspectorManager
+                            .getACLs(NodeViewerACL.this.selectedNode);
+                }
+
+                @Override
+                protected void done() {
+                    List<Map<String, String>> acls = null;
+                    try {
+                        acls = get();
+                    } catch (InterruptedException e) {
+                        acls = new ArrayList<Map<String, String>>();
+                        LoggerFactory.getLogger().error(
+                                "Error retrieving ACL Information for node: "
+                                        + NodeViewerACL.this.selectedNode, e);
+                    } catch (ExecutionException e) {
+                        acls = new ArrayList<Map<String, String>>();
+                        LoggerFactory.getLogger().error(
+                                "Error retrieving ACL Information for node: "
+                                        + NodeViewerACL.this.selectedNode, e);
+                    }
+                    aclDataPanel.setLayout(new GridBagLayout());
+                    int j = 0;
+                    for (Map<String, String> data : acls) {
+                        int rowPos = 2 * j + 1;
+                        JPanel aclPanel = new JPanel();
+                        aclPanel.setBorder(BorderFactory
+                                .createLineBorder(Color.BLACK));
+                        aclPanel.setBackground(Color.WHITE);
+                        aclPanel.setLayout(new GridBagLayout());
+                        int i = 0;
+                        for (Map.Entry<String, String> entry : data.entrySet()) {
+                            int rowPosACL = 2 * i + 1;
+                            JLabel label = new JLabel(entry.getKey());
+                            JTextField text = new JTextField(entry.getValue());
+                            text.setEditable(false);
+                            GridBagConstraints c1 = new GridBagConstraints();
+                            c1.gridx = 1;
+                            c1.gridy = rowPosACL;
+                            c1.gridwidth = 1;
+                            c1.gridheight = 1;
+                            c1.weightx = 0;
+                            c1.weighty = 0;
+                            c1.anchor = GridBagConstraints.NORTHWEST;
+                            c1.fill = GridBagConstraints.BOTH;
+                            c1.insets = new Insets(5, 5, 5, 5);
+                            c1.ipadx = 0;
+                            c1.ipady = 0;
+                            aclPanel.add(label, c1);
+                            GridBagConstraints c2 = new GridBagConstraints();
+                            c2.gridx = 3;
+                            c2.gridy = rowPosACL;
+                            c2.gridwidth = 1;
+                            c2.gridheight = 1;
+                            c2.weightx = 0;
+                            c2.weighty = 0;
+                            c2.anchor = GridBagConstraints.NORTHWEST;
+                            c2.fill = GridBagConstraints.BOTH;
+                            c2.insets = new Insets(5, 5, 5, 5);
+                            c2.ipadx = 0;
+                            c2.ipady = 0;
+                            aclPanel.add(text, c2);
+                            i++;
+                        }
+                        GridBagConstraints c = new GridBagConstraints();
+                        c.gridx = 1;
+                        c.gridy = rowPos;
+                        c.gridwidth = 1;
+                        c.gridheight = 1;
+                        c.weightx = 1;
+                        c.weighty = 1;
+                        c.anchor = GridBagConstraints.NORTHWEST;
+                        c.fill = GridBagConstraints.NONE;
+                        c.insets = new Insets(5, 5, 5, 5);
+                        c.ipadx = 0;
+                        c.ipady = 0;
+                        aclDataPanel.add(aclPanel, c);
+                    }
+                    NodeViewerACL.this.aclDataPanel.revalidate();
+                    NodeViewerACL.this.aclDataPanel.repaint();
+                }
+            };
+            worker.execute();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
+     * setZooInspectorManager
+     * (org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager)
+     */
+    @Override
+    public void setZooInspectorManager(
+            ZooInspectorNodeManager zooInspectorManager) {
+        this.zooInspectorManager = zooInspectorManager;
+    }
+
+}

Propchange: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message