alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

/*
 * ConfigBeanPanelView.java
 *
 * Created on March 6, 2003, 2:13 PM
 */

package org.netbeans.modules.j2ee.deployment.config.ui;

import java.awt.Component;
import java.awt.CardLayout;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JPanel;
import java.beans.Customizer;

import com.sun.tools.j2ee.editor.PanelView;
import org.openide.nodes.Node;
import org.openide.nodes.Children;
import org.openide.explorer.propertysheet.PropertySheetView;

/**
 *
 * @author  Jeri Lockhart
 */
public class ConfigBeanPanelView extends PanelView {


    private CardLayout deck = new CardLayout();
    private Map map = new HashMap();
    private JPanel blankPanel = new JPanel();
    private static String BLANK_PANEL = "ConfigBeanPanelView_blank_panel";

    /** Creates a new instance of ConfigBeanPanelView */
    public ConfigBeanPanelView(Node root) {
        setRoot(root);
        initComponents();
    }


    protected void initComponents() {
        setLayout(deck);
        setPopupAllowed(true);
        blankPanel.setName(BLANK_PANEL);
        add(BLANK_PANEL, blankPanel);
    }

    /** Called when explorer manager has changed the current selection.
     * The view should display the panel corresponding to the selected nodes
     *
     * @param nodes the nodes used to update the view
     *
     */
    public void showSelection(Node[] nodes) {
        // Sanity check
        if (nodes == null || nodes.length==0)
            return;

        //  lookup panel to show
        Node selNode = (Node) nodes[0];
        Component nodePanel = getPanel(selNode);
        if (nodePanel != null) {
		if (nodePanel == blankPanel) {
				deck.show(this,BLANK_PANEL);
			}
			else {
            	deck.show(this,String.valueOf(nodePanel.hashCode()));
            }
        }
    }

    public Component getPanel(Node selNode){
        // Lookup panel from node
        Component panel = null;
        ConfigBeanNode node = null;
        if (selNode instanceof ConfigBeanNode) {
            node = (ConfigBeanNode) selNode;
        }
        else {
            return blankPanel; // Show blank panel
        }
        panel = (Component)map.get(selNode);
        // found a panel, return it
        if (panel!=null) {
            if(panel instanceof Customizer)
                ((Customizer)panel).setObject(node.getBean());
            return panel;
        }

        // no current panel, use the nodes customizer instead and cache it
        // after milestone 2, this should change to reuse the same panel instead of 1 customizer per method
        //
        panel = node.getCustomizer();
        if (panel!=null) {
            // add nodeListener so we can clean up when the node goes away
            //
            map.put(node,panel);
            add(String.valueOf(panel.hashCode()),panel);
            //            node.addNodeListener(this);
            ((Customizer)panel).setObject(node.getBean());
            return panel;
        }
        else {
            PropertySheetView propSheetView = new PropertySheetView();
            propSheetView.setNodes(new Node[] {node});
            map.put(node, propSheetView);
            propSheetView.setName(node.getDisplayName());
            add(String.valueOf(propSheetView.hashCode()), propSheetView);
            return propSheetView;
        }
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.