hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r920604 [2/3] - in /hadoop/zookeeper/trunk: ./ src/contrib/zooinspector/ src/contrib/zooinspector/config/ src/contrib/zooinspector/icons/ src/contrib/zooinspector/lib/ src/contrib/zooinspector/licences/ src/contrib/zooinspector/src/ src/con...
Date Tue, 09 Mar 2010 01:06:17 GMT
Added: hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorIconResources.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorIconResources.java?rev=920604&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorIconResources.java (added)
+++ hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorIconResources.java Tue Mar  9 01:06:15 2010
@@ -0,0 +1,118 @@
+/**
+ * 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 javax.swing.ImageIcon;
+
+/**
+ * A class containing static methods for retrieving {@link ImageIcon}s used in
+ * the application
+ */
+public class ZooInspectorIconResources {
+
+    /**
+     * @return file icon
+     */
+    public static ImageIcon getTreeLeafIcon() {
+        return new ImageIcon("icons/file_obj.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return folder open icon
+     */
+    public static ImageIcon getTreeOpenIcon() {
+        return new ImageIcon("icons/fldr_obj.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return folder closed icon
+     */
+    public static ImageIcon getTreeClosedIcon() {
+        return new ImageIcon("icons/fldr_obj.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return connect icon
+     */
+    public static ImageIcon getConnectIcon() {
+        return new ImageIcon("icons/launch_run.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return disconnect icon
+     */
+    public static ImageIcon getDisconnectIcon() {
+        return new ImageIcon("icons/launch_stop.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return save icon
+     */
+    public static ImageIcon getSaveIcon() {
+        return new ImageIcon("icons/save_edit.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return add icon
+     */
+    public static ImageIcon getAddNodeIcon() {
+        return new ImageIcon("icons/new_con.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return delete icon
+     */
+    public static ImageIcon getDeleteNodeIcon() {
+        return new ImageIcon("icons/trash.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return refresh icon
+     */
+    public static ImageIcon getRefreshIcon() {
+        return new ImageIcon("icons/refresh.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return information icon
+     */
+    public static ImageIcon getInformationIcon() {
+        return new ImageIcon("icons/info_obj.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return node viewers icon
+     */
+    public static ImageIcon getChangeNodeViewersIcon() {
+        return new ImageIcon("icons/edtsrclkup_co.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return up icon
+     */
+    public static ImageIcon getUpIcon() {
+        return new ImageIcon("icons/search_prev.gif"); //$NON-NLS-1$
+    }
+
+    /**
+     * @return down icon
+     */
+    public static ImageIcon getDownIcon() {
+        return new ImageIcon("icons/search_next.gif"); //$NON-NLS-1$
+    }
+}

Added: hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersDialog.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersDialog.java?rev=920604&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersDialog.java (added)
+++ hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersDialog.java Tue Mar  9 01:06:15 2010
@@ -0,0 +1,605 @@
+/**
+ * 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.Component;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.DefaultListModel;
+import javax.swing.DropMode;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+import javax.swing.ListSelectionModel;
+import javax.swing.TransferHandler;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+import org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer;
+import org.apache.zookeeper.inspector.logger.LoggerFactory;
+import org.apache.zookeeper.inspector.manager.ZooInspectorManager;
+
+/**
+ * A {@link JDialog} for configuring which {@link ZooInspectorNodeViewer}s to
+ * show in the application
+ */
+public class ZooInspectorNodeViewersDialog extends JDialog implements
+        ListSelectionListener {
+
+    private final JButton upButton;
+    private final JButton downButton;
+    private final JButton removeButton;
+    private final JButton addButton;
+    private final JList viewersList;
+    private final JButton saveFileButton;
+    private final JButton loadFileButton;
+    private final JButton setDefaultsButton;
+    private final JFileChooser fileChooser = new JFileChooser(new File("."));
+
+    /**
+     * @param frame
+     *            - the Frame from which the dialog is displayed
+     * @param currentViewers
+     *            - the {@link ZooInspectorNodeViewer}s to show
+     * @param listeners
+     *            - the {@link NodeViewersChangeListener}s which need to be
+     *            notified of changes to the node viewers configuration
+     * @param manager
+     *            - the {@link ZooInspectorManager} for the application
+     * 
+     */
+    public ZooInspectorNodeViewersDialog(Frame frame,
+            final List<ZooInspectorNodeViewer> currentViewers,
+            final Collection<NodeViewersChangeListener> listeners,
+            final ZooInspectorManager manager) {
+        super(frame);
+        final List<ZooInspectorNodeViewer> newViewers = new ArrayList<ZooInspectorNodeViewer>(
+                currentViewers);
+        this.setLayout(new BorderLayout());
+        this.setIconImage(ZooInspectorIconResources.getChangeNodeViewersIcon()
+                .getImage());
+        this.setTitle("About ZooInspector");
+        this.setModal(true);
+        this.setAlwaysOnTop(true);
+        this.setResizable(true);
+        final JPanel panel = new JPanel();
+        panel.setLayout(new GridBagLayout());
+        viewersList = new JList();
+        DefaultListModel model = new DefaultListModel();
+        for (ZooInspectorNodeViewer viewer : newViewers) {
+            model.addElement(viewer);
+        }
+        viewersList.setModel(model);
+        viewersList.setCellRenderer(new DefaultListCellRenderer() {
+            @Override
+            public Component getListCellRendererComponent(JList list,
+                    Object value, int index, boolean isSelected,
+                    boolean cellHasFocus) {
+                ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) value;
+                JLabel label = (JLabel) super.getListCellRendererComponent(
+                        list, value, index, isSelected, cellHasFocus);
+                label.setText(viewer.getTitle());
+                return label;
+            }
+        });
+        viewersList.setDropMode(DropMode.INSERT);
+        viewersList.enableInputMethods(true);
+        viewersList.setDragEnabled(true);
+        viewersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        viewersList.getSelectionModel().addListSelectionListener(this);
+        viewersList.setTransferHandler(new TransferHandler() {
+
+            @Override
+            public boolean canImport(TransferHandler.TransferSupport info) {
+                // we only import NodeViewers
+                if (!info
+                        .isDataFlavorSupported(ZooInspectorNodeViewer.nodeViewerDataFlavor)) {
+                    return false;
+                }
+
+                JList.DropLocation dl = (JList.DropLocation) info
+                        .getDropLocation();
+                if (dl.getIndex() == -1) {
+                    return false;
+                }
+                return true;
+            }
+
+            @Override
+            public boolean importData(TransferHandler.TransferSupport info) {
+                JList.DropLocation dl = (JList.DropLocation) info
+                        .getDropLocation();
+                DefaultListModel listModel = (DefaultListModel) viewersList
+                        .getModel();
+                int index = dl.getIndex();
+                boolean insert = dl.isInsert();
+                // Get the string that is being dropped.
+                Transferable t = info.getTransferable();
+                String data;
+                try {
+                    data = (String) t
+                            .getTransferData(ZooInspectorNodeViewer.nodeViewerDataFlavor);
+                } catch (Exception e) {
+                    return false;
+                }
+                try {
+                    ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) Class
+                            .forName(data).newInstance();
+                    if (listModel.contains(viewer)) {
+                        listModel.removeElement(viewer);
+                    }
+                    if (insert) {
+                        listModel.add(index, viewer);
+                    } else {
+                        listModel.set(index, viewer);
+                    }
+                    return true;
+                } catch (Exception e) {
+                    LoggerFactory.getLogger().error(
+                            "Error instantiating class: " + data, e);
+                    return false;
+                }
+
+            }
+
+            @Override
+            public int getSourceActions(JComponent c) {
+                return MOVE;
+            }
+
+            @Override
+            protected Transferable createTransferable(JComponent c) {
+                JList list = (JList) c;
+                ZooInspectorNodeViewer value = (ZooInspectorNodeViewer) list
+                        .getSelectedValue();
+                return value;
+            }
+        });
+        JScrollPane scroller = new JScrollPane(viewersList);
+        GridBagConstraints c1 = new GridBagConstraints();
+        c1.gridx = 0;
+        c1.gridy = 0;
+        c1.gridwidth = 3;
+        c1.gridheight = 3;
+        c1.weightx = 0;
+        c1.weighty = 1;
+        c1.anchor = GridBagConstraints.CENTER;
+        c1.fill = GridBagConstraints.BOTH;
+        c1.insets = new Insets(5, 5, 5, 5);
+        c1.ipadx = 0;
+        c1.ipady = 0;
+        panel.add(scroller, c1);
+        upButton = new JButton(ZooInspectorIconResources.getUpIcon());
+        downButton = new JButton(ZooInspectorIconResources.getDownIcon());
+        removeButton = new JButton(ZooInspectorIconResources
+                .getDeleteNodeIcon());
+        addButton = new JButton(ZooInspectorIconResources.getAddNodeIcon());
+        upButton.setEnabled(false);
+        downButton.setEnabled(false);
+        removeButton.setEnabled(false);
+        addButton.setEnabled(true);
+        upButton.setToolTipText("Move currently selected node viewer up");
+        downButton.setToolTipText("Move currently selected node viewer down");
+        removeButton.setToolTipText("Remove currently selected node viewer");
+        addButton.setToolTipText("Add node viewer");
+        final JTextField newViewerTextField = new JTextField();
+        GridBagConstraints c2 = new GridBagConstraints();
+        c2.gridx = 3;
+        c2.gridy = 0;
+        c2.gridwidth = 1;
+        c2.gridheight = 1;
+        c2.weightx = 0;
+        c2.weighty = 0;
+        c2.anchor = GridBagConstraints.NORTH;
+        c2.fill = GridBagConstraints.HORIZONTAL;
+        c2.insets = new Insets(5, 5, 5, 5);
+        c2.ipadx = 0;
+        c2.ipady = 0;
+        panel.add(upButton, c2);
+        GridBagConstraints c3 = new GridBagConstraints();
+        c3.gridx = 3;
+        c3.gridy = 2;
+        c3.gridwidth = 1;
+        c3.gridheight = 1;
+        c3.weightx = 0;
+        c3.weighty = 0;
+        c3.anchor = GridBagConstraints.NORTH;
+        c3.fill = GridBagConstraints.HORIZONTAL;
+        c3.insets = new Insets(5, 5, 5, 5);
+        c3.ipadx = 0;
+        c3.ipady = 0;
+        panel.add(downButton, c3);
+        GridBagConstraints c4 = new GridBagConstraints();
+        c4.gridx = 3;
+        c4.gridy = 1;
+        c4.gridwidth = 1;
+        c4.gridheight = 1;
+        c4.weightx = 0;
+        c4.weighty = 0;
+        c4.anchor = GridBagConstraints.NORTH;
+        c4.fill = GridBagConstraints.HORIZONTAL;
+        c4.insets = new Insets(5, 5, 5, 5);
+        c4.ipadx = 0;
+        c4.ipady = 0;
+        panel.add(removeButton, c4);
+        GridBagConstraints c5 = new GridBagConstraints();
+        c5.gridx = 0;
+        c5.gridy = 3;
+        c5.gridwidth = 3;
+        c5.gridheight = 1;
+        c5.weightx = 0;
+        c5.weighty = 0;
+        c5.anchor = GridBagConstraints.CENTER;
+        c5.fill = GridBagConstraints.BOTH;
+        c5.insets = new Insets(5, 5, 5, 5);
+        c5.ipadx = 0;
+        c5.ipady = 0;
+        panel.add(newViewerTextField, c5);
+        GridBagConstraints c6 = new GridBagConstraints();
+        c6.gridx = 3;
+        c6.gridy = 3;
+        c6.gridwidth = 1;
+        c6.gridheight = 1;
+        c6.weightx = 0;
+        c6.weighty = 0;
+        c6.anchor = GridBagConstraints.CENTER;
+        c6.fill = GridBagConstraints.BOTH;
+        c6.insets = new Insets(5, 5, 5, 5);
+        c6.ipadx = 0;
+        c6.ipady = 0;
+        panel.add(addButton, c6);
+        upButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                DefaultListModel listModel = (DefaultListModel) viewersList
+                        .getModel();
+                ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) viewersList
+                        .getSelectedValue();
+                int index = viewersList.getSelectedIndex();
+                if (listModel.contains(viewer)) {
+                    listModel.removeElementAt(index);
+                    listModel.insertElementAt(viewer, index - 1);
+                    viewersList.setSelectedValue(viewer, true);
+                }
+            }
+        });
+        downButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                DefaultListModel listModel = (DefaultListModel) viewersList
+                        .getModel();
+                ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) viewersList
+                        .getSelectedValue();
+                int index = viewersList.getSelectedIndex();
+                if (listModel.contains(viewer)) {
+                    listModel.removeElementAt(index);
+                    listModel.insertElementAt(viewer, index + 1);
+                    viewersList.setSelectedValue(viewer, true);
+                }
+            }
+        });
+        removeButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                DefaultListModel listModel = (DefaultListModel) viewersList
+                        .getModel();
+                ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) viewersList
+                        .getSelectedValue();
+                int index = viewersList.getSelectedIndex();
+                if (listModel.contains(viewer)) {
+                    listModel.removeElement(viewer);
+                    viewersList
+                            .setSelectedIndex(index == listModel.size() ? index - 1
+                                    : index);
+                }
+            }
+        });
+        addButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                String className = newViewerTextField.getText();
+                if (className == null || className.length() == 0) {
+                    JOptionPane
+                            .showMessageDialog(
+                                    ZooInspectorNodeViewersDialog.this,
+                                    "Please enter the full class name for a Node Viewer and click the add button",
+                                    "Input Error", JOptionPane.ERROR_MESSAGE);
+                } else {
+                    try {
+                        DefaultListModel listModel = (DefaultListModel) viewersList
+                                .getModel();
+                        ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) Class
+                                .forName(className).newInstance();
+                        if (listModel.contains(viewer)) {
+                            JOptionPane
+                                    .showMessageDialog(
+                                            ZooInspectorNodeViewersDialog.this,
+                                            "Node viewer already exists.  Each node viewer can only be added once.",
+                                            "Input Error",
+                                            JOptionPane.ERROR_MESSAGE);
+                        } else {
+                            listModel.addElement(viewer);
+                        }
+                    } catch (Exception ex) {
+                        LoggerFactory
+                                .getLogger()
+                                .error(
+                                        "An error occurred while instaniating the node viewer. ",
+                                        ex);
+                        JOptionPane.showMessageDialog(
+                                ZooInspectorNodeViewersDialog.this,
+                                "An error occurred while instaniating the node viewer: "
+                                        + ex.getMessage(), "Error",
+                                JOptionPane.ERROR_MESSAGE);
+                    }
+                }
+            }
+        });
+        saveFileButton = new JButton("Save");
+        loadFileButton = new JButton("Load");
+        setDefaultsButton = new JButton("Set As Defaults");
+        saveFileButton
+                .setToolTipText("Save current node viewer configuration to file");
+        loadFileButton
+                .setToolTipText("Load node viewer configuration frm file");
+        setDefaultsButton
+                .setToolTipText("Set current configuration asd defaults");
+        GridBagConstraints c7 = new GridBagConstraints();
+        c7.gridx = 0;
+        c7.gridy = 4;
+        c7.gridwidth = 1;
+        c7.gridheight = 1;
+        c7.weightx = 1;
+        c7.weighty = 0;
+        c7.anchor = GridBagConstraints.WEST;
+        c7.fill = GridBagConstraints.VERTICAL;
+        c7.insets = new Insets(5, 5, 5, 5);
+        c7.ipadx = 0;
+        c7.ipady = 0;
+        panel.add(saveFileButton, c7);
+        GridBagConstraints c8 = new GridBagConstraints();
+        c8.gridx = 1;
+        c8.gridy = 4;
+        c8.gridwidth = 1;
+        c8.gridheight = 1;
+        c8.weightx = 0;
+        c8.weighty = 0;
+        c8.anchor = GridBagConstraints.WEST;
+        c8.fill = GridBagConstraints.VERTICAL;
+        c8.insets = new Insets(5, 5, 5, 5);
+        c8.ipadx = 0;
+        c8.ipady = 0;
+        panel.add(loadFileButton, c8);
+        GridBagConstraints c9 = new GridBagConstraints();
+        c9.gridx = 2;
+        c9.gridy = 4;
+        c9.gridwidth = 1;
+        c9.gridheight = 1;
+        c9.weightx = 0;
+        c9.weighty = 0;
+        c9.anchor = GridBagConstraints.WEST;
+        c9.fill = GridBagConstraints.VERTICAL;
+        c9.insets = new Insets(5, 5, 5, 5);
+        c9.ipadx = 0;
+        c9.ipady = 0;
+        panel.add(setDefaultsButton, c9);
+        saveFileButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                int result = fileChooser
+                        .showSaveDialog(ZooInspectorNodeViewersDialog.this);
+                if (result == JFileChooser.APPROVE_OPTION) {
+                    File selectedFile = fileChooser.getSelectedFile();
+                    int answer = JOptionPane.YES_OPTION;
+                    if (selectedFile.exists()) {
+                        answer = JOptionPane
+                                .showConfirmDialog(
+                                        ZooInspectorNodeViewersDialog.this,
+                                        "The specified file already exists.  do you want to overwrite it?",
+                                        "Confirm Overwrite",
+                                        JOptionPane.YES_NO_OPTION,
+                                        JOptionPane.WARNING_MESSAGE);
+                    }
+                    if (answer == JOptionPane.YES_OPTION) {
+                        DefaultListModel listModel = (DefaultListModel) viewersList
+                                .getModel();
+                        List<String> nodeViewersClassNames = new ArrayList<String>();
+                        Object[] modelContents = listModel.toArray();
+                        for (Object o : modelContents) {
+                            nodeViewersClassNames
+                                    .add(((ZooInspectorNodeViewer) o)
+                                            .getClass().getCanonicalName());
+                        }
+                        try {
+                            manager.saveNodeViewersFile(selectedFile,
+                                    nodeViewersClassNames);
+                        } catch (IOException ex) {
+                            LoggerFactory
+                                    .getLogger()
+                                    .error(
+                                            "Error saving node veiwer configuration from file.",
+                                            ex);
+                            JOptionPane.showMessageDialog(
+                                    ZooInspectorNodeViewersDialog.this,
+                                    "Error saving node veiwer configuration from file: "
+                                            + ex.getMessage(), "Error",
+                                    JOptionPane.ERROR_MESSAGE);
+                        }
+                    }
+                }
+            }
+        });
+        loadFileButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                int result = fileChooser
+                        .showOpenDialog(ZooInspectorNodeViewersDialog.this);
+                if (result == JFileChooser.APPROVE_OPTION) {
+                    try {
+                        List<String> nodeViewersClassNames = manager
+                                .loadNodeViewersFile(fileChooser
+                                        .getSelectedFile());
+                        List<ZooInspectorNodeViewer> nodeViewers = new ArrayList<ZooInspectorNodeViewer>();
+                        for (String nodeViewersClassName : nodeViewersClassNames) {
+                            ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) Class
+                                    .forName(nodeViewersClassName)
+                                    .newInstance();
+                            nodeViewers.add(viewer);
+                        }
+                        DefaultListModel model = new DefaultListModel();
+                        for (ZooInspectorNodeViewer viewer : nodeViewers) {
+                            model.addElement(viewer);
+                        }
+                        viewersList.setModel(model);
+                        panel.revalidate();
+                        panel.repaint();
+                    } catch (Exception ex) {
+                        LoggerFactory
+                                .getLogger()
+                                .error(
+                                        "Error loading node veiwer configuration from file.",
+                                        ex);
+                        JOptionPane.showMessageDialog(
+                                ZooInspectorNodeViewersDialog.this,
+                                "Error loading node veiwer configuration from file: "
+                                        + ex.getMessage(), "Error",
+                                JOptionPane.ERROR_MESSAGE);
+                    }
+                }
+            }
+        });
+        setDefaultsButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                int answer = JOptionPane
+                        .showConfirmDialog(
+                                ZooInspectorNodeViewersDialog.this,
+                                "Are you sure you want to save this configuration as the default?",
+                                "Confirm Set Defaults",
+                                JOptionPane.YES_NO_OPTION,
+                                JOptionPane.WARNING_MESSAGE);
+                if (answer == JOptionPane.YES_OPTION) {
+                    DefaultListModel listModel = (DefaultListModel) viewersList
+                            .getModel();
+                    List<String> nodeViewersClassNames = new ArrayList<String>();
+                    Object[] modelContents = listModel.toArray();
+                    for (Object o : modelContents) {
+                        nodeViewersClassNames.add(((ZooInspectorNodeViewer) o)
+                                .getClass().getCanonicalName());
+                    }
+                    try {
+                        manager
+                                .setDefaultNodeViewerConfiguration(nodeViewersClassNames);
+                    } catch (IOException ex) {
+                        LoggerFactory
+                                .getLogger()
+                                .error(
+                                        "Error setting default node veiwer configuration.",
+                                        ex);
+                        JOptionPane.showMessageDialog(
+                                ZooInspectorNodeViewersDialog.this,
+                                "Error setting default node veiwer configuration: "
+                                        + ex.getMessage(), "Error",
+                                JOptionPane.ERROR_MESSAGE);
+                    }
+                }
+            }
+        });
+
+        JPanel buttonsPanel = new JPanel();
+        buttonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
+        JButton okButton = new JButton("OK");
+        okButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                ZooInspectorNodeViewersDialog.this.dispose();
+                DefaultListModel listModel = (DefaultListModel) viewersList
+                        .getModel();
+                newViewers.clear();
+                Object[] modelContents = listModel.toArray();
+                for (Object o : modelContents) {
+                    newViewers.add((ZooInspectorNodeViewer) o);
+                }
+                currentViewers.clear();
+                currentViewers.addAll(newViewers);
+                for (NodeViewersChangeListener listener : listeners) {
+                    listener.nodeViewersChanged(currentViewers);
+                }
+            }
+        });
+        buttonsPanel.add(okButton);
+        JButton cancelButton = new JButton("Cancel");
+        cancelButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                ZooInspectorNodeViewersDialog.this.dispose();
+            }
+        });
+        buttonsPanel.add(cancelButton);
+        this.add(panel, BorderLayout.CENTER);
+        this.add(buttonsPanel, BorderLayout.SOUTH);
+        this.pack();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event
+     * .ListSelectionEvent)
+     */
+    public void valueChanged(ListSelectionEvent e) {
+        int index = viewersList.getSelectedIndex();
+        if (index == -1) {
+            removeButton.setEnabled(false);
+            upButton.setEnabled(false);
+            downButton.setEnabled(false);
+        } else {
+            removeButton.setEnabled(true);
+            if (index == 0) {
+                upButton.setEnabled(false);
+            } else {
+                upButton.setEnabled(true);
+            }
+            if (index == ((DefaultListModel) viewersList.getModel()).getSize()) {
+                downButton.setEnabled(false);
+            } else {
+                downButton.setEnabled(true);
+            }
+        }
+    }
+}

Added: hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersPanel.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersPanel.java?rev=920604&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersPanel.java (added)
+++ hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersPanel.java Tue Mar  9 01:06:15 2010
@@ -0,0 +1,140 @@
+/**
+ * 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.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.TreePath;
+
+import org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer;
+import org.apache.zookeeper.inspector.manager.ZooInspectorManager;
+import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager;
+
+/**
+ * This is the {@link JPanel} which contains the {@link ZooInspectorNodeViewer}s
+ */
+public class ZooInspectorNodeViewersPanel extends JPanel implements
+        TreeSelectionListener, ChangeListener {
+
+    private final List<ZooInspectorNodeViewer> nodeVeiwers = new ArrayList<ZooInspectorNodeViewer>();
+    private final List<Boolean> needsReload = new ArrayList<Boolean>();
+    private final JTabbedPane tabbedPane;
+    private final List<String> selectedNodes = new ArrayList<String>();
+    private final ZooInspectorNodeManager zooInspectorManager;
+
+    /**
+     * @param zooInspectorManager
+     *            - the {@link ZooInspectorManager} for the application
+     * @param nodeVeiwers
+     *            - the {@link ZooInspectorNodeViewer}s to show
+     */
+    public ZooInspectorNodeViewersPanel(
+            ZooInspectorNodeManager zooInspectorManager,
+            List<ZooInspectorNodeViewer> nodeVeiwers) {
+        this.zooInspectorManager = zooInspectorManager;
+        this.setLayout(new BorderLayout());
+        tabbedPane = new JTabbedPane(JTabbedPane.TOP,
+                JTabbedPane.WRAP_TAB_LAYOUT);
+        setNodeViewers(nodeVeiwers);
+        tabbedPane.addChangeListener(this);
+        this.add(tabbedPane, BorderLayout.CENTER);
+        reloadSelectedViewer();
+    }
+
+    /**
+     * @param nodeViewers
+     *            - the {@link ZooInspectorNodeViewer}s to show
+     */
+    public void setNodeViewers(List<ZooInspectorNodeViewer> nodeViewers) {
+        this.nodeVeiwers.clear();
+        this.nodeVeiwers.addAll(nodeViewers);
+        needsReload.clear();
+        tabbedPane.removeAll();
+        for (ZooInspectorNodeViewer nodeViewer : nodeVeiwers) {
+            nodeViewer.setZooInspectorManager(zooInspectorManager);
+            needsReload.add(true);
+            tabbedPane.add(nodeViewer.getTitle(), nodeViewer);
+        }
+        this.revalidate();
+        this.repaint();
+    }
+
+    private void reloadSelectedViewer() {
+        int index = this.tabbedPane.getSelectedIndex();
+        if (index != -1 && this.needsReload.get(index)) {
+            ZooInspectorNodeViewer viewer = this.nodeVeiwers.get(index);
+            viewer.nodeSelectionChanged(selectedNodes);
+            this.needsReload.set(index, false);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event
+     * .TreeSelectionEvent)
+     */
+    public void valueChanged(TreeSelectionEvent e) {
+        TreePath[] paths = e.getPaths();
+        selectedNodes.clear();
+        for (TreePath path : paths) {
+            boolean appended = false;
+            StringBuilder sb = new StringBuilder();
+            Object[] pathArray = path.getPath();
+            for (Object o : pathArray) {
+                if (o != null) {
+                    String nodeName = o.toString();
+                    if (nodeName != null) {
+                        if (nodeName.length() > 0) {
+                            appended = true;
+                            sb.append("/"); //$NON-NLS-1$
+                            sb.append(o.toString());
+                        }
+                    }
+                }
+            }
+            if (appended) {
+                selectedNodes.add(sb.toString());
+            }
+        }
+        for (int i = 0; i < needsReload.size(); i++) {
+            this.needsReload.set(i, true);
+        }
+        reloadSelectedViewer();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent
+     * )
+     */
+    public void stateChanged(ChangeEvent e) {
+        reloadSelectedViewer();
+    }
+}

Added: hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java?rev=920604&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java (added)
+++ hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java Tue Mar  9 01:06:15 2010
@@ -0,0 +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);
+    }
+}

Added: hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java?rev=920604&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java (added)
+++ hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java Tue Mar  9 01:06:15 2010
@@ -0,0 +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());
+    }
+}

Added: hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html?rev=920604&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html (added)
+++ hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html Tue Mar  9 01:06:15 2010
@@ -0,0 +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://hadoop.apache.org/zookeeper/">http://hadoop.apache.org/zookeeper/</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>
\ No newline at end of file

Added: hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java?rev=920604&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java (added)
+++ hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java Tue Mar  9 01:06:15 2010
@@ -0,0 +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;
+    }
+
+}

Added: hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerData.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerData.java?rev=920604&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerData.java (added)
+++ hadoop/zookeeper/trunk/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerData.java Tue Mar  9 01:06:15 2010
@@ -0,0 +1,146 @@
+/**
+ * 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.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
+import javax.swing.JToolBar;
+import javax.swing.SwingWorker;
+
+import org.apache.zookeeper.inspector.gui.ZooInspectorIconResources;
+import org.apache.zookeeper.inspector.logger.LoggerFactory;
+import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager;
+
+/**
+ * A node viewer for displaying the data for the currently selected node
+ */
+public class NodeViewerData extends ZooInspectorNodeViewer {
+    private ZooInspectorNodeManager zooInspectorManager;
+    private final JTextPane dataArea;
+    private final JToolBar toolbar;
+    private String selectedNode;
+
+    /**
+	 * 
+	 */
+    public NodeViewerData() {
+        this.setLayout(new BorderLayout());
+        this.dataArea = new JTextPane();
+        this.toolbar = new JToolBar();
+        this.toolbar.setFloatable(false);
+        JScrollPane scroller = new JScrollPane(this.dataArea);
+        scroller
+                .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+        this.add(scroller, BorderLayout.CENTER);
+        this.add(this.toolbar, BorderLayout.NORTH);
+        JButton saveButton = new JButton(ZooInspectorIconResources
+                .getSaveIcon());
+        saveButton.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                if (selectedNode != null) {
+                    if (JOptionPane.showConfirmDialog(NodeViewerData.this,
+                            "Are you sure you want to save this node?"
+                                    + " (this action cannot be reverted)",
+                            "Confirm Save", JOptionPane.YES_NO_OPTION,
+                            JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
+                        zooInspectorManager.setData(selectedNode, dataArea
+                                .getText());
+                    }
+                }
+            }
+        });
+        this.toolbar.add(saveButton);
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
+     * getTitle()
+     */
+    @Override
+    public String getTitle() {
+        return "Node Data";
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
+     * nodeSelectionChanged(java.util.Set)
+     */
+    @Override
+    public void nodeSelectionChanged(List<String> selectedNodes) {
+        if (selectedNodes.size() > 0) {
+            this.selectedNode = selectedNodes.get(0);
+            SwingWorker<String, Void> worker = new SwingWorker<String, Void>() {
+
+                @Override
+                protected String doInBackground() throws Exception {
+                    return NodeViewerData.this.zooInspectorManager
+                            .getData(NodeViewerData.this.selectedNode);
+                }
+
+                @Override
+                protected void done() {
+                    String data = "";
+                    try {
+                        data = get();
+                    } catch (InterruptedException e) {
+                        LoggerFactory.getLogger().error(
+                                "Error retrieving data for node: "
+                                        + NodeViewerData.this.selectedNode, e);
+                    } catch (ExecutionException e) {
+                        LoggerFactory.getLogger().error(
+                                "Error retrieving data for node: "
+                                        + NodeViewerData.this.selectedNode, e);
+                    }
+                    NodeViewerData.this.dataArea.setText(data);
+                }
+            };
+            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;
+    }
+
+}



Mime
View raw message