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.
 */

/*
 * ConfigBeanNode.java
 *
 * Created on August 15, 2001, 4:29 PM
 */

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

import org.openide.ErrorManager;
import org.openide.nodes.*;
import org.openide.util.HelpCtx;
import org.openide.util.actions.*;
import org.netbeans.modules.j2ee.deployment.config.*;
import org.netbeans.modules.j2ee.deployment.plugins.api.DConfigBeanProperties;

import java.util.*;
import java.beans.*;
import java.awt.Image;
import java.awt.Component;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import javax.enterprise.deploy.spi.DConfigBean;

/**
 *
 * @author  gfink
 * @author  Jeri Lockhart
 * @version
 */
public class ConfigBeanNode extends AbstractNode {
    
    final ConfigBeanStorage bean;
    final BeanInfo info;
    final DConfigBeanProperties extraProps;
    
    public ConfigBeanNode(ConfigBeanStorage bean) {
        super(new ConfigChildren(bean));
        this.bean = bean;
        info = ConfigUtils.createBeanInfo(bean.getConfigBean());
        extraProps = bean.getStorage().getServer().getDConfigBeanProperties(bean.getConfigBean());
        bean.addChildrenChangeListener((ConfigChildren) getChildren());
    }
    
    public void updateKeys() {
        ((ConfigChildren)getChildren()).updateKeys();
    }
    
    public void updateKey(Object key) {
        ((ConfigChildren)getChildren()).updateKey(key);
    }
    
    public String getDisplayName() {
        if(extraProps != null) return extraProps.getDisplayName();
        if(info == null) return bean.getClass().toString();
        return info.getBeanDescriptor().getDisplayName();
    }
    
    private static final javax.swing.Action[] EMPTY_ACTIONS = new javax.swing.Action[0];
    public javax.swing.Action[] getActions(boolean context) {
        return EMPTY_ACTIONS;
    }
    
    public HelpCtx getHelpCtx() {
        if(extraProps != null) {
            String helpId = extraProps.getHelpId();
            if(helpId != null) return new HelpCtx(helpId);
        }
        return HelpCtx.DEFAULT_HELP;
    }
    
    public Image getIcon(int type) {
        if(info != null) {
            Image icon = info.getIcon(type);
            if(icon != null) return icon;
        }
        return super.getIcon(type);
    }
    
    public Image getOpenedIcon(int type) {
        if(info != null) {
            Image icon = info.getIcon(type);
            if(icon != null) return icon;
        }
        return super.getOpenedIcon(type);
    }
    
    public Sheet createSheet() {
        Sheet ret = new Sheet();
        Sheet.Set set = ConfigUtils.createSheet(bean);
        set.setName(getDisplayName());
        ret.put(set);
        return ret;
    }
    
    public DConfigBean getBean() {
        return bean.getConfigBean();
    }
    
    /** Get the customizer.
     * @return null in the default implementation
     *
     */
    public Component getCustomizer() {
        Component comp = null;
        if (!hasCustomizer()) {
            return null;
        }
        try {
            // If there isn't such a customizer, try the default constructor
            return (java.awt.Component) info.getBeanDescriptor().getCustomizerClass().newInstance();
        }catch (Exception e) {
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
        }
        return comp;
    }
    
    /** Does this node have a customizer?
     * @return false
     *
     */
    public boolean hasCustomizer() {
        return info.getBeanDescriptor().getCustomizerClass() != null;
    }
    
    public static class ConfigChildren extends Children.Keys implements ConfigBeanStorage.ChildrenChangeListener {
        ConfigBeanStorage bean;
        ConfigChildren(ConfigBeanStorage bean) {
            this.bean = bean;
        }
        protected void addNotify() {
            updateKeys();
        }
        void updateKeys() {
            setKeys(bean.childMap.keySet());
        }
        void updateKey(Object key) {
            refreshKey(key);
        }
        protected Node[] createNodes(Object key) {
            Collection nodeSet = (Collection) bean.childMap.get(key);
            Node[] ret = new Node[nodeSet.size()];
            Iterator i = nodeSet.iterator();
            for(int c = 0; i.hasNext(); c++) {
                ConfigBeanStorage cbs = (ConfigBeanStorage) i.next();
                ret[c] = cbs.getNode();
            }
            return ret;
        }
        public void childBeanAdded(ConfigBeanStorage childStorage) {
            updateKeys();
            refreshKey(childStorage.getConfigBean().getDDBean().getXpath());
        }
        public void childBeanRemoved(ConfigBeanStorage childStorage) {
            updateKey(childStorage.getConfigBean().getDDBean().getXpath());
        }
    }
}
... 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.