| 
What this is
 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.beans.*;
import java.util.ArrayList;
import java.util.List;
import org.openide.nodes.*;
import org.netbeans.tax.*;
import org.netbeans.modules.xml.tree.children.ObjectListChildren;
import org.netbeans.modules.xml.tree.lib.GuiUtil;
/**
 *
 * @author  Libor Kramolis
 * @version 0.1
 */
public class DocumentNode extends AbstractRootNode {
    /** */
    private static final String NODE_TYPE = "#document"; // NOI18N
    //
    // init
    //
    /** */
    public DocumentNode (TreeDocument treeDocument) throws IntrospectionException {
        super (treeDocument, (Class[])null, "xmlObject"); // NOI18N
        setShortDescription (Util.THIS.getString ("PROP_DocumentNode_description"));
    }
    
    //
    // itself
    //
    /**
     */
    protected final TreeDocument getDocument () {
        return (TreeDocument) getTreeObject();
    }
    /**
     */
    protected final boolean addTreeObject (TreeObject newObject) {
        if ( newObject instanceof TreeDocumentType ) {
            return setDocumentType ((TreeDocumentType)newObject);
        } else if ( newObject instanceof TreeElement ) {
            return setDocumentElement ((TreeElement)newObject);
        } else {
            return super.addTreeObject (newObject);
        }
    }
    protected Object[] getNewTypesTypes() {
        List list = new ArrayList(4);
        TreeElement root = getDocument().getDocumentElement();
        if (root == null) {  //??? such tree probably does not exist at all
            list.add(TreeElement.class);
        }
        TreeDocumentType type = getDocument().getDocumentType();
        if (type == null) {
            list.add(TreeDocumentType.class);
        }
        list.add(TreeProcessingInstruction.class);
        list.add(TreeComment.class);
        return list.toArray();
    }
    /**
     */
    public final boolean setDocumentType (TreeDocumentType documentType) {
        try {
            TreeDocument doc = getDocument();
            boolean toSet = true;
            TreeDocumentType oldDoctype = doc.getDocumentType();
            if ( oldDoctype != null ) {
                toSet = GuiUtil.confirmAction (Util.THIS.getString ("MSG_replace_document_type"));
            }
            if ( toSet ) {
                doc.setDocumentType ((TreeDocumentType)documentType);
                return true;
            }
	} catch (TreeException exc) {
	    GuiUtil.notifyTreeException (exc);
        }        
        return false;
    }
    /**
     */
    public final boolean setDocumentElement (TreeElement element) {
        try {
            TreeDocument doc = getDocument();
            boolean toSet = true;
            TreeElement oldElement = doc.getDocumentElement();
            if ( oldElement != null ) {
                toSet = GuiUtil.confirmAction (Util.THIS.getString ("MSG_replace_root_element"));
            }
            if ( toSet ) {
                doc.setDocumentElement ((TreeElement)element);
                return true;
            }
	} catch (TreeException exc) {
	    GuiUtil.notifyTreeException (exc);
        }        
        return false;
    }
    //
    // name support
    //
    /**
     */
    protected final String getNodeTypePrefix () {
        return NODE_TYPE;
    }
}
 | 
| ... this post is sponsored by my books ... | |
         
           #1 New Release!  | 
      
         
           FP Best Seller  | 
  
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.