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

import java.io.ObjectInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Iterator;
import java.beans.PropertyChangeListener;

import org.openide.ServiceType;
import org.openide.util.HelpCtx;
import org.openide.util.Lookup;

import org.netbeans.tax.traversal.TreeNodeFilter;
import org.netbeans.modules.xml.tax.traversal.TreeNodeFilterHandle;

/**
 * @author  Libor Kramolis
 * @version 0.1
 */
public class NodeViewType extends ServiceType {

    /** Serial version UID. */
    private static final long serialVersionUID = -7806627125394259058L;


    public static final String PROP_NAME                       = "name"; // NOI18N
    public static final String PROP_SHORT_DESCRIPTION          = "shortDescription"; // NOI18N
    public static final String PROP_FILTER                     = "filter"; // NOI18N
    public static final String PROP_EXPAND_ENTITY_REFERENCES   = "expandEntityReferences"; // NOI18N
    public static final String PROP_MERGE_CHARACTER_DATA       = "mergeCharacterData"; // NOI18N
    public static final String PROP_SHOW_IGNORABLE_WHITESPACES = "showIgnorableWhitespaces"; // NOI18N
    public static final String PROP_GROUP_TYPES                = "groupTypes"; // NOI18N
    public static final String PROP_EXPAND_CONDITIONAL_SECTION = "expandConditionalSection"; // NOI18N


    /** */
    public static final Data GROUPED_DATA =
        new Data (Util.THIS.getString ("PROP_NodeViewType_defaultName"),
                  Util.THIS.getString ("PROP_NodeViewType_defaultShortDescription"),
                  TreeNodeFilter.SHOW_ALL_FILTER, false, false,
                  false, true, false);
    /** */
    public static final Data LINEAR_DATA =
        new Data (Util.THIS.getString ("PROP_NodeViewType_linearName"),
                  Util.THIS.getString ("PROP_NodeViewType_linearShortDescription"),
                  TreeNodeFilter.SHOW_ALL_FILTER, false, false,
                  true, false, false);
    /** */
    public static final Data DATA_ONLY_DATA =
        new Data (Util.THIS.getString ("PROP_NodeViewType_dataOnlyName"),
                  Util.THIS.getString ("PROP_NodeViewType_dataOnlyShortDescription"),
                  TreeNodeFilter.SHOW_DATA_ONLY_FILTER, false, false,
                  false, false, false);
    /** */
    public static final Data DEFAULT_DATA = GROUPED_DATA;


    /** Holds value of property shortDescription. */
    private String shortDescription;

    /** Holds value of property filter handler. */
    private TreeNodeFilterHandle filterHandler;

    /** Holds value of property expandEntityReferences. */
    private boolean expandEntityReferences;

    /** Holds value of property mergeCharacterData. */
    private boolean mergeCharacterData;

    /** Holds value of property showIgnorableWhitespaces. */
    private boolean showIgnorableWhitespaces;

    /** Holds value of property groupTypes. */
    private boolean groupTypes;

    /** Holds value of property expandConditionalSection. */
    private boolean expandConditionalSection;


    //
    // init
    //

    /** */
    public NodeViewType (String name, String shortDescription, TreeNodeFilter filter,
                         boolean expandEntityReferences, boolean mergeCharacterData,
                         boolean showIgnorableWhitespaces, boolean groupTypes, boolean expandConditionalSection) {
        setName (name);

        this.shortDescription         = shortDescription;
        this.filterHandler            = new TreeNodeFilterHandle (filter);
        this.expandEntityReferences   = expandEntityReferences;
        this.mergeCharacterData       = mergeCharacterData;
        this.showIgnorableWhitespaces = showIgnorableWhitespaces;
        this.groupTypes               = groupTypes;
        this.expandConditionalSection = expandConditionalSection;

        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\nNodeViewType [ " + this + " ] ::INIT: name = " + name);//, new RuntimeException()); // NOI18N
    }

    /** */
    public NodeViewType (Data nvtData) {
        this (nvtData.name, nvtData.shortDescription, nvtData.filter,
              nvtData.expandEntityReferences, nvtData.mergeCharacterData,
              nvtData.showIgnorableWhitespaces, nvtData.groupTypes, nvtData.expandConditionalSection);
    }


    /** */
    public NodeViewType () {
        this (DEFAULT_DATA);
    }


    //
    // itself
    //


    /** Getter for property shortDescription.
     * @return Value of property shortDescription.
     */
    public String getShortDescription () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::getShortDescription : " + shortDescription);//, new RuntimeException()); // NOI18N

        return shortDescription;
    }

    /** Setter for property shortDescription.
     * @param shortDescription New value of property shortDescription.
     */
    public void setShortDescription (String shortDescription) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::setShortDescription : " + shortDescription);//, new RuntimeException()); // NOI18N

        String oldShortDescription = this.shortDescription;
        this.shortDescription = shortDescription;
        firePropertyChange (PROP_SHORT_DESCRIPTION, oldShortDescription, shortDescription);
    }
    
    /** Getter for property filter.
     * @return Value of property filter.
     */
    public TreeNodeFilter getFilter () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::getFilter : " + filterHandler); // NOI18N

        return filterHandler.getNodeFilter();
    }

    /** Setter for property filter.
     * @param filter New value of property filter.
     */
    public void setFilter (TreeNodeFilter filter) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::setFilter : " + filter); // NOI18N

        TreeNodeFilter oldFilter = this.filterHandler.getNodeFilter();
        this.filterHandler = new TreeNodeFilterHandle (filter);

        firePropertyChange (PROP_FILTER, oldFilter, filter);
    }

    /** Getter for property expandEntityReferences.
     * @return Value of property expandEntityReferences.
     */
    public boolean isExpandEntityReferences () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::isExpandEntityReferences : " + expandEntityReferences); // NOI18N

        return expandEntityReferences;
    }

    /** Setter for property expandEntityReferences.
     * @param expandEntityReferences New value of property expandEntityReferences.
     */
    public void setExpandEntityReferences (boolean expandEntityReferences) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::setExpandEntityReferences : " + expandEntityReferences); // NOI18N

        boolean oldExpandEntityReferences = this.expandEntityReferences;
        this.expandEntityReferences = expandEntityReferences;
        firePropertyChange (PROP_EXPAND_ENTITY_REFERENCES, oldExpandEntityReferences ? Boolean.TRUE : Boolean.FALSE, expandEntityReferences ? Boolean.TRUE : Boolean.FALSE);
    }

    /** Getter for property mergeCharacterData.
     * @return Value of property mergeCharacterData.
     */
    public boolean isMergeCharacterData () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::isMergeCharacterData : " + mergeCharacterData); // NOI18N

        return mergeCharacterData;
    }

    /** Setter for property mergeCharacterData.
     * @param mergeCharacterData New value of property mergeCharacterData.
     */
    public void setMergeCharacterData (boolean mergeCharacterData) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::setMergeCharacterData : " + mergeCharacterData); // NOI18N

        boolean oldMergeCharacterData = this.mergeCharacterData;
        this.mergeCharacterData = mergeCharacterData;
        firePropertyChange (PROP_MERGE_CHARACTER_DATA, oldMergeCharacterData ? Boolean.TRUE : Boolean.FALSE, mergeCharacterData ? Boolean.TRUE : Boolean.FALSE);
    }

    /** Getter for property showIgnorableWhitespaces.
     * @return Value of property showIgnorableWhitespaces.
     */
    public boolean isShowIgnorableWhitespaces () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::isShowIgnorableWhitespaces : " + showIgnorableWhitespaces); // NOI18N

        return showIgnorableWhitespaces;
    }

    /** Setter for property showIgnorableWhitespaces.
     * @param showIgnorableWhitespaces New value of property showIgnorableWhitespaces.
     */
    public void setShowIgnorableWhitespaces (boolean showIgnorableWhitespaces) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::setShowIgnorableWhitespaces : " + showIgnorableWhitespaces); // NOI18N

        boolean oldShowIgnorableWhitespaces = this.showIgnorableWhitespaces;
        this.showIgnorableWhitespaces = showIgnorableWhitespaces;
        firePropertyChange (PROP_SHOW_IGNORABLE_WHITESPACES, oldShowIgnorableWhitespaces ? Boolean.TRUE : Boolean.FALSE, showIgnorableWhitespaces ? Boolean.TRUE : Boolean.FALSE);
    }

    /** Getter for property groupTypes.
     * @return Value of property groupTypes.
     */
    public boolean isGroupTypes () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::isGroupTypes : " + groupTypes); // NOI18N

        return groupTypes;
    }

    /** Setter for property groupTypes.
     * @param groupTypes New value of property groupTypes.
     */
    public void setGroupTypes (boolean groupTypes) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::setGroupTypes : " + groupTypes); // NOI18N

        boolean oldGroupTypes = this.groupTypes;
        this.groupTypes = groupTypes;
        firePropertyChange (PROP_GROUP_TYPES, oldGroupTypes ? Boolean.TRUE : Boolean.FALSE, groupTypes ? Boolean.TRUE : Boolean.FALSE);
    }

    /** Getter for property expandConditionalSection.
     * @return Value of property expandConditionalSection.
     */
    public boolean isExpandConditionalSection () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::isExpandConditionalSection : " + expandConditionalSection); // NOI18N

        return expandConditionalSection;
    }

    /** Setter for property expandConditionalSection.
     * @param expandConditionalSection New value of property expandConditionalSection.
     */
    public void setExpandConditionalSection (boolean expandConditionalSection) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("NodeViewType::setExpandConditionalSection : " + expandConditionalSection); // NOI18N

        boolean oldExpandConditionalSection = this.expandConditionalSection;
        this.expandConditionalSection = expandConditionalSection;
        firePropertyChange (PROP_EXPAND_CONDITIONAL_SECTION, oldExpandConditionalSection ? Boolean.TRUE : Boolean.FALSE, expandConditionalSection ? Boolean.TRUE : Boolean.FALSE);
    }


    //
    // utils
    //

    /** */
    public boolean equals (Object obj) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("|#=- NodeViewType.equals"); // NOI18N

        if ( obj == null )
            return false;
        if (!!! (obj instanceof NodeViewType) )
            return false;

        NodeViewType nvtObj = (NodeViewType)obj;

        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("     filter                  ? " + (this.getFilter().equals (nvtObj.getFilter()))); //NOI18N
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("     expandConditionalSection? " + (this.expandEntityReferences == nvtObj.expandEntityReferences)); //NOI18N
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("     mergeCharacterData      ? " + (this.mergeCharacterData == nvtObj.mergeCharacterData)); //NOI18N
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("     showIgnorableWhitespaces? " + (this.showIgnorableWhitespaces == nvtObj.showIgnorableWhitespaces)); //NOI18N
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("     groupTypes              ? " + (this.groupTypes == nvtObj.groupTypes)); //NOI18N
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("     expandConditionalSection? " + (this.expandConditionalSection == nvtObj.expandConditionalSection)); //NOI18N

        if ( !!! this.getFilter().equals (nvtObj.getFilter()) )
            return false;
        if ( this.expandEntityReferences != nvtObj.expandEntityReferences )
            return false;
        if ( this.mergeCharacterData != nvtObj.mergeCharacterData )
            return false;
        if ( this.showIgnorableWhitespaces != nvtObj.showIgnorableWhitespaces )
            return false;
        if ( this.groupTypes != nvtObj.groupTypes )
            return false;
        if ( this.expandConditionalSection != nvtObj.expandConditionalSection )
            return false;

        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("|#=- NodeViewType.equals: return TRUE"); //NOI18N

        return true;
    }


    /**
     */
    public final boolean isLinear () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\nNodeViewType::isLinear: nodeViewType.name = " + getName()); // NOI18N

        if ( !!! this.getFilter().equals (TreeNodeFilter.SHOW_ALL_FILTER) )
            return false;
        if ( this.expandEntityReferences != false )
            return false;
        if ( this.mergeCharacterData != false )
            return false;
        if ( this.showIgnorableWhitespaces != true )
            return false;
        if ( this.groupTypes != false )
            return false;
        if ( this.expandConditionalSection != false )
            return false;

        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\nNodeViewType::isLinear: nodeViewType.name: return TRUE"); // NOI18N

        return true;
    }


    /**
     * @return true if nodeViewType is in list of services
     *         or if there is no NodeViewType in list of available services, otherwise false.
     */
    public final static boolean isValid (NodeViewType nodeViewType) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\nNodeViewType::isValid: nodeViewType = " + nodeViewType); // NOI18N
        if ( nodeViewType != null ) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("            ::isValid: nodeViewType.name = " + nodeViewType.getName()); // NOI18N
        }

        if ( nodeViewType == null ) {
            return false;
        }

        Lookup.Template template = new Lookup.Template(NodeViewType.class);
        Iterator it = Lookup.getDefault().lookup(template).allInstances().iterator();

        while (it.hasNext()) {
            Object obj = it.next();

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("            ::isValid: next Object = " + obj); // NOI18N
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("            ::isValid: next Object.name = " + ((NodeViewType)obj).getName()); // NOI18N

            if ( obj == nodeViewType ) {
                if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("            ::isValid: RETURN *true*"); // NOI18N

                return true;
            }
        }
        return false;
    }

    /**
     */
    public final static NodeViewType getValid (NodeViewType nodeViewType) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\nNodeViewType::getValid: nodeViewType = " + nodeViewType); // NOI18N
        if ( nodeViewType != null ) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("            ::getValid: nodeViewType.name = " + nodeViewType.getName()); // NOI18N
        }

        NodeViewType candidat = null;

        Lookup.Template template = new Lookup.Template(NodeViewType.class);
        Iterator it = Lookup.getDefault().lookup(template).allInstances().iterator();

        while (it.hasNext()) {
            Object obj = it.next();

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("            ::getValid: next Object = " + obj); // NOI18N
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("            ::getValid: next Object.name = " + ((NodeViewType)obj).getName()); // NOI18N

            if ( obj == nodeViewType ) { // find same object
                return nodeViewType;
            }
            if ( obj.equals (nodeViewType) && ( candidat == null ) ) { // find first equal candidat
                candidat = (NodeViewType)obj;
            }
        }

        return candidat;
    }


    //
    // from ServiceType
    //

    /** Get context help for this service type.
     * @return context help
     */
    public HelpCtx getHelpCtx () {
        return new HelpCtx(NodeViewType.class);
    }


    /**
     */
    public String toString () {
        StringBuffer sb = new StringBuffer();

        sb.append (super.toString()).append (" [ "); //NOI18N
        sb.append ("name= ").append (getName()).append (" | "); //NOI18N
        sb.append ("shortDescription= ").append (shortDescription).append (" | "); //NOI18N
        sb.append ("filterHandler= ").append (filterHandler).append (" | "); //NOI18N
        if ( filterHandler != null ) {
            sb.append ("filter= ").append (filterHandler.getNodeFilter()).append (" | "); //NOI18N
        }
        sb.append ("expandEntityReferences= ").append (expandEntityReferences).append (" | "); //NOI18N
        sb.append ("mergeCharacterData= ").append (mergeCharacterData).append (" | "); //NOI18N
        sb.append ("showIgnorableWhitespaces= ").append (showIgnorableWhitespaces).append (" | "); //NOI18N
        sb.append ("groupTypes= ").append (groupTypes).append (" | "); //NOI18N
        sb.append ("expandConditionalSection= ").append (expandConditionalSection); //NOI18N
        sb.append (" ]"); //NOI18N

        return sb.toString();
    }

    /**
     */
    private void readObject (ObjectInputStream ois) throws IOException, ClassNotFoundException {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\n\n\n--> NodeViewType.readObject"); //NOI18N

//         ois.defaultReadObject();


        ObjectInputStream.GetField getField = ois.readFields();        

        // name
        try {
            String name = (String)getField.get ("name", null); //NOI18N
            if ( name != null ) {
                setName (name);
            }
        } catch (IllegalArgumentException exc) {
            // field *name* is not serialized -> OK, super class did it.
        }

        // shortDescription
        this.shortDescription = (String)getField.get ("shortDescription", DEFAULT_DATA.shortDescription); //NOI18N

        // filterHandler
        try {
            this.filterHandler = (TreeNodeFilterHandle)getField.get ("filterHandler", null); //NOI18N
        } catch (IllegalArgumentException exc) {
            // field *filterHandler* is not serialized -> OK, filter will be.
        }
        try {
            TreeNodeFilter filter = (TreeNodeFilter)getField.get ("filter", DEFAULT_DATA.filter); //NOI18N
            this.filterHandler = new TreeNodeFilterHandle (filter);
        } catch (IllegalArgumentException exc) {
            // field *filter* is not serialized -> OK, filterHandler will be.
        }
        if ( this.filterHandler == null ) {
            this.filterHandler = new TreeNodeFilterHandle (DEFAULT_DATA.filter);
        }

        // expandEntityReferences
        this.expandEntityReferences = getField.get ("expandEntityReferences", //NOI18N
                                                    DEFAULT_DATA.expandEntityReferences);

        // mergeCharacterData
        this.mergeCharacterData = getField.get ("mergeCharacterData", DEFAULT_DATA.mergeCharacterData); //NOI18N

        // showIgnorableWhitespaces
        this.showIgnorableWhitespaces = getField.get ("showIgnorableWhitespaces", //NOI18N
                                                      DEFAULT_DATA.showIgnorableWhitespaces);

        // groupTypes
        this.groupTypes = getField.get ("groupTypes", DEFAULT_DATA.groupTypes); //NOI18N

        // expandConditionalSection
        this.expandConditionalSection = getField.get ("expandConditionalSection", //NOI18N
                                                      DEFAULT_DATA.expandConditionalSection);

        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" ->   this.toString() = " + this.toString()); //NOI18N
    }
    

    //
    // interface Provider
    //

    /**
     *
     */
    public static interface Provider {
        
        /** */
        public static final String PROP_NODE_VIEW_TYPE = "nodeViewType"; // NOI18N

        /** */
        public NodeViewType getNodeViewType ();

        /** */
        public void setNodeViewType (NodeViewType nodeViewType);

        /** */
        public void addPropertyChangeListener (PropertyChangeListener l);

        /** */
        public void removePropertyChangeListener (PropertyChangeListener l);

    } // end: interface Provider


    //
    // class Data
    //

    /**
     *
     */
    public static class Data {
        /** Holds value of property name. */
        public final String name;
        
        /** Holds value of property shortDescription . */
        public final String shortDescription;

        /** Holds value of property filter. */
        public final TreeNodeFilter filter;
        
        /** Holds value of property expandEntityReferences. */
        public final boolean expandEntityReferences;
        
        /** Holds value of property mergeCharacterData. */
        public final boolean mergeCharacterData;

        /** Holds value of property showIgnorableWhitespaces. */
        public final boolean showIgnorableWhitespaces;
        
        /** Holds value of property groupTypes. */
        public final boolean groupTypes;
        
        /** Holds value of property expandConditionalSection. */
        public final boolean expandConditionalSection;
        
        /**
         */
        public Data (String name, String shortDescription, TreeNodeFilter filter,
                     boolean expandEntityReferences, boolean mergeCharacterData,
                     boolean showIgnorableWhitespaces, boolean groupTypes, boolean expandConditionalSection) {
            this.name                     = name;
            this.shortDescription         = shortDescription;
            this.filter                   = filter;
            this.expandEntityReferences   = expandEntityReferences;
            this.mergeCharacterData       = mergeCharacterData;
            this.showIgnorableWhitespaces = showIgnorableWhitespaces;
            this.groupTypes               = groupTypes;
            this.expandConditionalSection = expandConditionalSection;
        }
    } // end: class Data


    //
    // class Creator
    //

    /**
     *
     */
    public static class Creator {
        /**
         */
        public static NodeViewType createGroupedType () {
            return new NodeViewType (GROUPED_DATA);
        }

        /**
         */
        public static NodeViewType createLinearType () {
            return new NodeViewType (LINEAR_DATA);
        }

        /**
         */
        public static NodeViewType createDataOnlyType () {
            return new NodeViewType (DATA_ONLY_DATA);
        }
    } // end: class Creator

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