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-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.xml.tree.nodes;

import java.beans.*;

import org.openide.nodes.*;
import org.openide.util.WeakListener;

import org.netbeans.tax.*;

/**
 *
 * @author  Libor Kramolis
 * @version 0.1
 */
public class ConditionalSectionNode extends AbstractParentNode {

    /** */
    private static final String NODE_TYPE = "#conditional-section"; // NOI18N

    /** */
    private static final Class[] GROUP_TYPES = new Class[] {
        TreeElementDecl.class,
        TreeAttlistDecl.class,
        TreeEntityDecl.class,
        TreeNotationDecl.class,
    };

    /** */
    private static final String INCLUDE_NAME = "INCLUDE"; // NOI18N
    /** */
    private static final String IGNORE_NAME  = "IGNORE"; // NOI18N
    

    /** */
    private InnerListener listener;


    //
    // init
    //

    /** */
    public ConditionalSectionNode (TreeConditionalSection treeCondSect) throws IntrospectionException {
        super (treeCondSect, GROUP_TYPES, getIconBase (treeCondSect));

        init (treeCondSect);
    }

    /** 
     */
    private void init (TreeConditionalSection peer) {
        listener = new InnerListener();
        peer.addPropertyChangeListener (WeakListener.propertyChange (listener, peer));
    }


    //
    // itself
    //

    protected final TreeConditionalSection getConditionalSection () {
        return (TreeConditionalSection) getTreeObject();
    }

    //
    // icon
    //

    /**
     */
    private static String getIconBase (TreeConditionalSection treeCondSect) {
        if ( treeCondSect.isInclude() ) {
            return "condSectionIncludeNode"; // NOI18N
        } else {
            return "condSectionIgnoreNode"; // NOI18N
        }        
    }

    /**
     */
    private void updateIconBase () {
        updateIconBase (getIconBase (getConditionalSection()));
    }


    //
    // from AbstractObjectNode
    //

    /** Name of property used as node name. Used to listen on it.
     */
    protected final String getPresentableNamePropertyName () {
        return TreeConditionalSection.PROP_INCLUDE;
    }

    /**
     */
    protected final void setPresentableNameProperty (String name) throws TreeException {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\n+++ ConditionalSectionNode::setPresentableNameProperty: new name = '" + name + "'"); // NOI18N
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("+++                       ::setPresentableNameProperty: boolean value = '" + (Boolean.valueOf (name)).booleanValue() + "'"); // NOI18N

        getConditionalSection().setInclude (name2boolean (name));
    }

    /**
     */
    protected final String createName () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("+++ ConditionalSectionNode::createName: return name = " + getConditionalSection().isInclude()); // NOI18N

        return boolean2name (getConditionalSection().isInclude());
    }


    /**
     */
    protected final String createNodePreview () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("+++ ConditionalSectionNode::createNodePreview"); // NOI18N

        StringBuffer sb = new StringBuffer();

        sb.append (""); // NOI18N
        
        return sb.toString();
    }

    /**
     */
    protected final String getNodeTypePrefix () {
        return NODE_TYPE;
    }


    //
    // util
    //

    /**
     */
    private static boolean name2boolean (String includeName) {
        return (INCLUDE_NAME.equals (includeName));
    }

    /**
     */
    private static String boolean2name (boolean include) {
        return ( include ? INCLUDE_NAME : IGNORE_NAME );
    }


    //
    // class InnerListener
    //

    /**
     * class InnerListener listen on
     */
    private class InnerListener implements PropertyChangeListener {

        /** */
        public void propertyChange (PropertyChangeEvent pche) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("ConditionalSectionNode::InnerListener::propertyChange: propertyName = '" + pche.getPropertyName() + "'"); // NOI18N

            if (TreeConditionalSection.PROP_INCLUDE.equals (pche.getPropertyName())) {
                ConditionalSectionNode.this.updateIconBase();
            }
        }

    } // end: class InnerListener

}
... 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.