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.nodes;

import java.io.IOException;
import java.io.ObjectStreamException;
import java.util.List;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyDescriptor;
import java.beans.EventSetDescriptor;
import java.beans.MethodDescriptor;
import java.awt.Image;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;

import org.openide.ServiceType;
import org.openide.nodes.*;
import org.openide.util.Utilities;
import org.openide.util.WeakListener;
import org.openide.util.datatransfer.NewType;
import org.openide.util.datatransfer.PasteType;
import org.openide.util.datatransfer.ExTransferable;

import org.netbeans.tax.*;
import org.netbeans.modules.xml.tree.settings.NodeViewType;
import org.netbeans.modules.xml.tree.settings.NodeViewTypeBeanInfo;
import org.netbeans.modules.xml.tree.children.ObjectListChildren;
import org.netbeans.modules.xml.tree.lib.GuiUtil;

import org.w3c.dom.Element;
import org.w3c.dom.Comment;
import org.w3c.dom.Text;

/**
 *
 * @author  Libor Kramolis
 * @version 0.1
 */
public abstract class AbstractParentNode extends AbstractObjectNode implements NodeViewType.Provider {

    /** */
    public static final String VIEW_SHEET_SET = "view"; // NOI18N

    /** */
    private static final NodeViewType NO_NODE_VIEW_TYPE = new NoNodeViewType();

    /** */
    private NodeViewType nodeViewType;
    /** */
    private static final NodeViewType linearNodeViewType = new NodeViewType (NodeViewType.LINEAR_DATA);

    /** */
    private final NodeViewTypeListener nvtListener;
    private PropertyChangeListener weakNVTListener;
    /** */
    private final ParentNodeListener   pnListener;
    
    /** */
    private IndexSupportImpl indexSupport;


    //
    // init
    //

    /** */
    protected AbstractParentNode (TreeObject treeObject, ObjectListChildren children, String iconName) throws IntrospectionException {
        super (treeObject, children, iconName);

        // init listeners        
        nvtListener = new NodeViewTypeListener();
        pnListener = new ParentNodeListener();

        this.addPropertyChangeListener (nvtListener); //NodeViewType.Provider.PROP_NODE_VIEW_TYPE
        this.addNodeListener (pnListener); //Node.PROP_PARENT_NODE
        
        init();
    }

    /** */
    protected AbstractParentNode (TreeParentNode treeParent, Class[] groupTypes, String iconName) throws IntrospectionException {
        this (treeParent, new ObjectListChildren (treeParent.getChildNodes(), groupTypes), iconName);
    }


    /**
     */
    private void init () {

        // init cookies
        CookieSet set = getCookieSet();
        CookieSet.Factory factory = new CookieFactory();

        set.add (Index.class, factory);
    }


    //
    // Sheet
    //

    /**
     */
    private Node.Property createViewTypeProperty () {
        PropertySupport.Reflection property = null;

        try {
            class NVTProperty extends PropertySupport.Reflection {
                public NVTProperty (Object bean) throws NoSuchMethodException {
                    super (bean, NodeViewType.class, "nodeViewType"); // NOI18N
                }
                public java.beans.PropertyEditor getPropertyEditor () {
                    return java.beans.PropertyEditorManager.findEditor (ServiceType.class);
                }
            }
            property = new NVTProperty (this);
            property.setValue ("superClass", NodeViewType.class); // NOI18N
            property.setValue ("noneServiceClass", NO_NODE_VIEW_TYPE); // NOI18N

            property.setName ("nodeViewType"); // NOI18N
            property.setDisplayName (Util.THIS.getString ("PROP_Node_View_Type"));
            property.setShortDescription (Util.THIS.getString ("HINT_Node_View_Type"));
        } catch (NoSuchMethodException exc) {
            GuiUtil.notifyException (exc);
        }
        
        return property;
    }


    /**
     */
    protected void createProperties (Object bean, BeanInfo info) {
        // super createProperties
        super.createProperties (bean, info);

        // get Sheet
        Sheet sheet = getSheet();

        // add VIEW set to sheet
        sheet.put (createViewSet());
    }


    /**
     */
    protected final Sheet.Set createViewSet () {
        // create new VIEW set
        Sheet.Set viewSet = new Sheet.Set ();
        viewSet.setName (VIEW_SHEET_SET);
        viewSet.setDisplayName (Util.THIS.getString ("PROP_view_sheet_set"));
        viewSet.setShortDescription (Util.THIS.getString ("HINT_view_sheet_set"));
        viewSet.setValue ("helpID", AbstractParentNode.class.getName() + "[NodeViewType]"); // NOI18N
        
        // fill view set
        viewSet.put (createViewTypeProperty());

        return viewSet;
    }
    

    //
    // itself
    //

    /**
     */
    protected final ObjectListChildren getObjectListChildren () {
        return (ObjectListChildren)getChildren();
    }

    /**
     */
    protected boolean canAddTreeObject (TreeObject newObject) {
        return getObjectListChildren().getObjectList().isAssignableObject (newObject);
    }

    /**
     */
    protected boolean addTreeObject (TreeObject newObject) {
        try {
            getObjectListChildren().getObjectList().add (newObject);

            return true;
	} catch (ClassCastException exc) {
	    GuiUtil.notifyWarning (exc.getMessage());

            return false;
        }        
    }

    //
    // from NodeViewType.Provider
    //

    /**
     */
    public NodeViewType getNodeViewType () {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("AbstractParentNode::getNodeViewType: this = " + this); // NOI18N
        if ( nodeViewType != null ) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::getNodeViewType: nodeViewType.name = " + nodeViewType.getName()); // NOI18N
        }
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::getNodeViewType: nodeViewType = " + nodeViewType); // NOI18N

        if (nodeViewType != null)
            return nodeViewType;

        NodeViewType.Provider nodeViewTypeProvider = (NodeViewType.Provider)getParentNode();

        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::getNodeViewType: parentNode = " + getParentNode()); // NOI18N
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::getNodeViewType: parentNode == NULL");//, new RuntimeException()); // NOI18N

        if ( nodeViewTypeProvider == null ) {
//                  if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("***                   ::getNodeViewType: parentNode == NULL", new RuntimeException()); // NOI18N

            return null;
        }

        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::getNodeViewType: RETURN " + nodeViewTypeProvider.getNodeViewType()); // NOI18N

        return nodeViewTypeProvider.getNodeViewType();
    }
    
    /**
     */
    public final void setNodeViewType (NodeViewType nodeViewType) {
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("AbstractParentNode::setNodeViewType: this = " + this); // NOI18N
        if ( nodeViewType != null ) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::setNodeViewType: NEW nodeViewType.name = " + nodeViewType.getName()); // NOI18N
        }
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::setNodeViewType: NEW nodeViewType = " + nodeViewType);//, new RuntimeException()); // NOI18N

        if ( nodeViewType instanceof NoNodeViewType ) {
            nodeViewType = null;
        }

        if ( (this.nodeViewType == nodeViewType) &&
             (getNodeViewType() == nodeViewType) ) {
            return;
        }

        if (weakNVTListener != null) {
            getNodeViewType().removePropertyChangeListener (weakNVTListener);
        }

        NodeViewType oldNodeViewType = this.nodeViewType;
        this.nodeViewType = nodeViewType;

        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::setNodeViewType: OLD nodeViewType = " + oldNodeViewType); // NOI18N

        NodeViewType view = getNodeViewType();
        weakNVTListener = WeakListener.propertyChange(nvtListener, view);
        view.addPropertyChangeListener (weakNVTListener);
        getObjectListChildren().setNodeViewType (view);

        firePropertyChange (PROP_NODE_VIEW_TYPE, oldNodeViewType, this.nodeViewType);
    }

    
    //
    // NewTypes
    //

    /**
     *  Can return either a Tree Classes or Tree Object.
     */
    protected Object[] getNewTypesTypes () {
        return null;
    }


    /** Support for new types that can be created in this node.
     * @return array of new type operations that are allowed
     */
    public final NewType[] getNewTypes () {

        Object[] newTypesTypes = getNewTypesTypes();
        if( newTypesTypes == null )
        { 
            return new NewType[0];
        }

        boolean addedByClass = false;
        List newTypesList = new java.util.ArrayList(newTypesTypes.length);
        for (int i = 0; i < newTypesTypes.length; i++) {
            if (newTypesTypes[i] instanceof Class) {
                addedByClass = true;
            }
            addNewType(newTypesList, newTypesTypes[i]);
        }

        // TODO: remove these when we can query for them in ElementNode
        // properly

        String sName;
        if (newTypesTypes.length == 0) { // no grammat hint exists
             sName = Util.THIS.getString( "PROP_xmlNewElement");
             newTypesList.add(addNewTypeHelper(sName, TreeElement.class));
        }

        // it's default, TODO: It can be implemented as polymorphics getNewTypesTypes
        if (addedByClass == false) {
             sName = Util.THIS.getString( "PROP_xmlNewCDATA");
             newTypesList.add(addNewTypeHelper(sName, TreeCDATASection.class));
             sName = Util.THIS.getString( "PROP_xmlNewText");
             newTypesList.add(addNewTypeHelper(sName, TreeText.class));
             sName = Util.THIS.getString( "PROP_xmlNewCharRef");
             newTypesList.add(addNewTypeHelper(sName, TreeCharacterReference.class));
             sName = Util.THIS.getString( "PROP_xmlNewGeneralEntityRef");
             newTypesList.add(addNewTypeHelper(sName, TreeGeneralEntityReference.class));
             sName = Util.THIS.getString( "PROP_xmlNewComment");
             newTypesList.add(addNewTypeHelper(sName, TreeComment.class));
        }

        NewType[] newTypes = new NewType [newTypesList.size()];
        return (NewType[])newTypesList.toArray(newTypes);
    }
    

    /**
     * @param type A DOM entity type (Element, PCData, Comment, etc)
     */
    protected void addNewType( List newTypesList, final Object type ) {

        if (type instanceof Class) {

            Class klass = (Class) type;
            newTypesList.add(addNewTypeHelper(getTypeNameForClass(klass), klass));

        } else if( type instanceof Element )
        { 
            Element element = (Element)type;
            final String sName = element.getTagName();
            final String sLabel = '<' + sName + '>';

            NewType newElementType = new NewType() { 
                public String getName() { 
                    return sLabel;
                } 

                public void create() throws IOException { 
                    try
                    { 
                        TreeElement elmt = new TreeElement(sName);
                        AbstractParentNode.this.addTreeObject(elmt);
                    } catch( InvalidArgumentException ex ) {} 
                } 
            };

            newTypesList.add(newElementType);
        } 
        else if( type instanceof Text )
        { 
             // if we can accept Text nodes, then we can add:
             // text, CDATA, character ref, entity ref
             String sName;
             sName = Util.THIS.getString( "PROP_xmlNewCDATA");
             newTypesList.add(addNewTypeHelper(sName, TreeCDATASection.class));
             sName = Util.THIS.getString( "PROP_xmlNewText");
             newTypesList.add(addNewTypeHelper(sName, TreeText.class));
             sName = Util.THIS.getString( "PROP_xmlNewCharRef");
             newTypesList.add(addNewTypeHelper(sName, TreeCharacterReference.class));
             sName = Util.THIS.getString( "PROP_xmlNewGeneralEntityRef");
             newTypesList.add(addNewTypeHelper(sName, TreeGeneralEntityReference.class));
        }
        else if( type instanceof Comment )
        {
            String sName = Util.THIS.getString( "PROP_xmlNewComment");
            newTypesList.add(addNewTypeHelper(sName, TreeComment.class));
        } 
    }

    /**
     * Translate New type class to proper display name.
     */
    private static String getTypeNameForClass(Class type) {
        String name = null;

        if ( type == TreeAttribute.class ) {
            name = Util.THIS.getString ("PROP_xmlNewAttribute");
        } else if ( type == TreeCDATASection.class ) {
            name = Util.THIS.getString ("PROP_xmlNewCDATA");
        } else if ( type == TreeCharacterReference.class ) {
            name = Util.THIS.getString ("PROP_xmlNewCharRef");
        } else if ( type == TreeComment.class ) {
            name = Util.THIS.getString ("PROP_xmlNewComment");
        } else if ( type == TreeElement.class ) {
            name = Util.THIS.getString ("PROP_xmlNewElement");
        } else if ( type == TreeGeneralEntityReference.class ) {
            name = Util.THIS.getString ("PROP_xmlNewGeneralEntityRef");
        } else if ( type == TreeProcessingInstruction.class ) {
            name = Util.THIS.getString ("PROP_xmlNewPI");
        } else if ( type == TreeText.class ) {
            name = Util.THIS.getString ("PROP_xmlNewText");
        } else if ( type == TreeDocumentType.class ) {
            name = Util.THIS.getString ("PROP_xmlNewDoctype");
        }

       return name;
    }

    protected NewType addNewTypeHelper( final String name, final Class type )
    { 
        return new NewType () { 
            public String getName () { 
                return name;
            } 

            public void create() throws IOException { 
                TreeObject newObject = NodeFactory.createTreeObjectDialog(
                        type, AbstractParentNode.this, true);
                if( newObject != null )
                { 
                    AbstractParentNode.this.addTreeObject( newObject );
                } 
            } 
        };
    } 


    //
    // clipboard
    //

    /**
     */
    protected void createPasteTypes (Transferable t, List s) {
        TreeObject treeObject = null;
        boolean cutFlavor = false;

        try {
            if (t.isDataFlavorSupported (XML_NODE_COPY_FLAVOR)) {
                treeObject = (TreeObject)t.getTransferData (XML_NODE_COPY_FLAVOR);
            } else if (t.isDataFlavorSupported (XML_NODE_CUT_FLAVOR)) {
                treeObject = (TreeObject)t.getTransferData (XML_NODE_CUT_FLAVOR);
                cutFlavor = true;
            }
        } catch (UnsupportedFlavorException exc) {
            /* do nothing -> treeObject is still null */
        } catch (IOException exc) {
            /* do nothing -> treeObject is still null */
        }

        if ( treeObject == null ) {
            return; // not supported data flavor
        }

        if ( ( (this instanceof ElementNode) == false) &&
             ( (this instanceof ElementAttributesNode) == false) &&
             ( (this instanceof DocumentNode) == false) ) {
            return; // paste is supported on not dtd nodes only
        }

        if ( cutFlavor ) {
            if (getTreeObject() == treeObject) {
                return; // cannot *cut* *itself to itself*
            } else
                if ( ( treeObject instanceof TreeParentNode ) &&
                     ( getTreeObject() instanceof TreeChild ) &&
                     ((TreeChild)getTreeObject()).isDescendantOf ((TreeParentNode)treeObject)
                     ) {
                    return; // cannot *cut* *ancestor to its descendant*
                } else 
                    if ( ( treeObject instanceof TreeNamedObjectMap ) &&
                         ( getTreeObject() instanceof TreeElement ) &&
                         ( ((TreeElement)getTreeObject()).getAttributes() == treeObject )
                         ) {
                        return; // cannot *cut* attlist to owner element
                    }
        }

        if ( canAddTreeObject (treeObject) ) {
            s.add (new XMLPaste (t));
        }
    }

    
    //
    // class XMLPaste
    //

    /** Paste types for data objects.
     */
    private final class XMLPaste extends PasteType {
        /** */
        private Transferable transferable;

        //
        // init
        //

        /** */
        public XMLPaste (Transferable t) {
            this.transferable = t;
        }

        //
        // itself
        //

        /**
         */
        public Transferable paste () throws IOException {
            // debug
            clipboardEM.log ("Paste transferable [ " + System.identityHashCode (transferable) + " ] = " + transferable);

            Transferable transferOut = null;
            try {
                if (transferable.isDataFlavorSupported (XML_NODE_CUT_FLAVOR)) {
                    if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::XMLPaste::paste: XML_NODE_CUT_FLAVOR: " + XML_NODE_CUT_FLAVOR); // NOI18N
                    
                    TreeObject treeObject = (TreeObject)transferable.getTransferData (XML_NODE_CUT_FLAVOR);

                    // because we are working with active treeObject, it is important to check if this was not removed after insert to clipboard
                    if ( treeObject.isInContext() ) {
                        TreeObject cloneTreeObject = (TreeObject)treeObject.clone();
                        if ( addTreeObject (cloneTreeObject) ) {
                            try {
                                treeObject.removeFromContext();
                                transferOut = ExTransferable.create (new XMLTransferable (XML_NODE_COPY_FLAVOR, (TreeObject)treeObject.clone()));
                            } catch (ReadOnlyException exc) {
                                GuiUtil.notifyTreeException (exc);
                            }
                        }
                    }
                } else if (transferable.isDataFlavorSupported (XML_NODE_COPY_FLAVOR)) {
                    if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::XMLPaste::paste: XML_NODE_COPY_FLAVOR: " + XML_NODE_COPY_FLAVOR); // NOI18N

                    TreeObject treeObject = (TreeObject)transferable.getTransferData (XML_NODE_COPY_FLAVOR);
                    addTreeObject ((TreeObject)treeObject.clone());
                }
            } catch (IOException e) {
            } catch (UnsupportedFlavorException e) {
            }

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::XMLPaste::paste: transferOut = " + transferOut); // NOI18N

            return transferOut;
        }

    } // end: class XMLPaste



    //
    // NodeViewTypeListener
    //

    /**
     *
     */
    private class NodeViewTypeListener implements PropertyChangeListener {

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

            if ( NodeViewType.Provider.PROP_NODE_VIEW_TYPE.equals (pche.getPropertyName())) {
                Node parent = getParentNode();

                if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::NodeViewTypeListener::propertyChange: parent = " + parent); // NOI18N
                if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::NodeViewTypeListener::propertyChange: event source = " + pche.getSource()); // NOI18N
                
                if ( pche.getSource() == parent ) {
                    if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::NodeViewTypeListener::propertyChange: SOURCE == PARENT  =>  this.setNodeViewType (null)"); // NOI18N

                    AbstractParentNode.this.setNodeViewType (null); // reset own node view type cache to support parent set
                }
            }
        }

    } // end: class NodeViewTypeListener


    //
    // ParentNodeListener
    //

    /**
     *
     */
    private class ParentNodeListener implements NodeListener {

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

            if ( Node.PROP_PARENT_NODE.equals (pche.getPropertyName())) {
                Node parent = getParentNode();

                if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::ParentNodeListener::propertyChange: parent = " + parent); // NOI18N
                
                if ( parent != null ) {
                    ((NodeViewType.Provider)parent).addPropertyChangeListener (WeakListener.propertyChange (AbstractParentNode.this.nvtListener, parent));
                }
            }
        }

        /** Fired when a set of new children is added.
         * @param ev event describing the action
         */
        public void childrenAdded (NodeMemberEvent ev) {
        }
        
        /** Fired when a set of children is removed.
         * @param ev event describing the action
         */
        public void childrenRemoved (NodeMemberEvent ev) {
        }
        
        /** Fired when the order of children is changed.
         * @param ev event describing the change
         */
        public void childrenReordered (NodeReorderEvent ev) {
        }
        
        /** Fired when the node is deleted.
         * @param ev event describing the node
         */
        public void nodeDestroyed (NodeEvent ev) {
        }

    } // end: class ParentNodeListener



    //
    // class IndexSupportImpl
    //

    /** Index support for reordering of nodes.
     */
    protected class IndexSupportImpl extends Index.Support {
        /** */
        ObjectListChildren children;

        //
        // init
        //

        /** */
        public IndexSupportImpl (ObjectListChildren children) {
            super();

            this.children = children;
        }

        //
        // itself
        //


        public int indexOf (Node node) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("IndexSupportImpl.indexOf: node = " + node); // NOI18N

            int index = super.indexOf (node);

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("IndexSupportImpl.indexOf: return " + index); // NOI18N

            return index;
        }


        /**
         */
        public Node[] getNodes () {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("IndexSupportImpl.getNodes: children = " + children); // NOI18N
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("IndexSupportImpl.getNodes: this.getObjectListChildren = " + AbstractParentNode.this.getObjectListChildren()); // NOI18N

            NodeViewType oldNodeViewType = children.getNodeViewType();
            children.setNodeViewType (linearNodeViewType);

            Node[] src = children.getNodes();

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("IndexSupportImpl.getNodes: nodes = " + java.util.Arrays.asList (src)); // NOI18N

            children.setNodeViewType (oldNodeViewType);

            TreeObjectList toList = children.getObjectList();
            int size = toList.size();

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("AbstractParentNode::IndexSupportImpl::getNodes: this = " + AbstractParentNode.this); // NOI18N
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::IndexSupportImpl::getNodes: src.length = " + src.length); // NOI18N
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::IndexSupportImpl::getNodes: children.getObjectList().size() = " + size); // NOI18N

            if ( size > src.length ) { // data was more nodes than presentation node
                return new Node[0];
            }

            Node[] nodes = new Node [size];
            int j = 0;
            for (int i = 0; i < src.length; i++) {
                AbstractObjectNode aoNode = (AbstractObjectNode)src[i];
                if ( toList.contains (aoNode.getTreeObject()) ) {
                    nodes[j++] = src[i];
                }
            }

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::IndexSupportImpl::getNodes: j = " + j); // NOI18N

            if ( j != size ) { // number of nodes which can be reordered is not same as number of data nodes
                return new Node[0];
            }

            return nodes;
        }

        /** Get the node count. Subclasses must provide this.
         * @return the count
         */
        public int getNodesCount () {
            int count = getNodes().length; //children.getNodesCount();

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("AbstractParentNode::IndexSupportImpl::getNodesCount: this = " + AbstractParentNode.this); // NOI18N
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::IndexSupportImpl::getNodesCount: return " + count); // NOI18N

            return count;
        }

        /** Reorder by permutation. Subclasses must provide this.
         * @param perm the permutation
         */
        public void reorder (int[] perm) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("AbstractParentNode::IndexSupportImpl::reorder1: this = " + AbstractParentNode.this); // NOI18N
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < perm.length; i++) {
                sb.append (" ").append (perm[i]); // NOI18N
            }
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::IndexSupportImpl::reorder1: perm =" + sb.toString()); // NOI18N

            try {
                children.getObjectList().reorder (perm);
            } catch (TreeException exc) {
                GuiUtil.notifyTreeException (exc);
            }
        }

        /**
         */
        public void reorder () {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("AbstractParentNode::IndexSupportImpl::reorder2: this = " + AbstractParentNode.this); // NOI18N
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("                  ::IndexSupportImpl::reorder2"); // NOI18N

            IndexedCustomizer ic = new IndexedCustomizer();
            ic.setTitle (ic.getTitle() + Util.THIS.getString ("TITLE_notFilteredView"));
            ic.setImmediateReorder (false);
            ic.setObject (this);

            ic.show();
        }

    } // end: class IndexSupportImpl



    //
    // NoNodeViewType
    //
    
    /**
     *
     */
    public static final class NoNodeViewType extends NodeViewType {

        private static final long serialVersionUID =-7616356712664686962L;
        
        /**
         */
        public String getName () {
            return Util.THIS.getString ("LAB_NoNodeViewType");
        }

        /**
         */
        private Object readResolve () throws ObjectStreamException {
            return NO_NODE_VIEW_TYPE;
        }
        
    } // end: class NoNodeViewType


    //
    // NoNodeViewTypeBeanInfo
    //
    
    /**
     *
     */
    public static final class NoNodeViewTypeBeanInfo extends NodeViewTypeBeanInfo {

        /**
         */
        public Image getIcon (int iconKind) {
            switch ( iconKind ) {
            case ICON_COLOR_16x16:
                return Utilities.loadImage ("org/netbeans/modules/xml/tree/resources/noNodeViewSettings.gif"); // NOI18N
            default:
                return super.getIcon (iconKind);
            }
        }

        /**
         */
        public PropertyDescriptor[] getPropertyDescriptors () {
            return new PropertyDescriptor[0];
        }
        
        /**
         */
        public EventSetDescriptor[] getEventSetDescriptors() {
            return new EventSetDescriptor[0];
        }

        /**
         */
        public MethodDescriptor[] getMethodDescriptors() {
            return new MethodDescriptor[0];
        }

    } // end: class NoNodeViewTypeBeanInfo


    //
    // class CookieFactory
    //

    /**
     *
     */
    private class CookieFactory implements CookieSet.Factory {

        /** Creates new Cookie */
        public Node.Cookie createCookie (Class clazz) {
            if ( (clazz == Index.class) &&
                 AbstractParentNode.this.canChangeOrder() ) {
                return new IndexSupportImpl (AbstractParentNode.this.getObjectListChildren());
            }

            return null;
        }
        
    }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.