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 Rich Unger. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.xml.tree.nodes;

import org.openide.nodes.Node;
import org.openide.loaders.DataObject;
import org.openide.filesystems.FileObject;
import org.netbeans.modules.xml.tree.nodes.ElementNode;
import org.netbeans.tax.TreeElement;
import org.netbeans.tax.TreeAttribute;

/**
 * Interface for all XML tree editor customizers.
 *
 * @author  Rich Unger
 */
public abstract class ElementCustomizer extends javax.swing.JTabbedPane 
  implements java.beans.Customizer
{
    /** Gets a FileObject representing the page this customizer is editing */
    public FileObject getFileObject()
    {
        Node.Cookie cookie = m_node.getCookie( DataObject.class );
        DataObject dObj = (DataObject)cookie;
        return dObj.getPrimaryFile();
    }

    public ElementNode getNode()
    {
        return m_node;
    }

    /** Customizer interface.  Will be called when the DoctypeMap properties file is read */
    public void setObject( Object obj )
    {
        m_node = (ElementNode)obj;
    }

    /**
     * convenience method for setting attributes in TreeElement.
     * For more info on the issues surrounding this, see:
     * http://www.netbeans.org/issues/show_bug.cgi?id=17699
     */
    public void setAttribute( String sName, String sValue )
    {
        TreeElement element = m_node.getElement();

        synchronized( element )
        {
            try
            {
                if ( sValue == null || sValue.trim().length() == 0) {
                    element.removeAttribute(sName);
                }
                else if( !element.hasAttribute(sName) )
                {
                    element.addAttribute(sName, sValue);
                }
                else
                {
                    TreeAttribute attr = element.getAttribute( sName );
                    attr.setValue( sValue );
                }
            }
            catch( org.netbeans.tax.ReadOnlyException ex )
            {
                // voicexml doesn't declare any read-only attributes
            }
            catch( org.netbeans.tax.InvalidArgumentException ex )
            {
            }
        }
    }

    public String getAttribute(String sName)
    {
        if (sName != null && sName.length() > 0) {
            TreeElement element = m_node.getElement();
            if (element != null) {
                TreeAttribute ta = element.getAttribute(sName);
                if (ta != null) {
                    return ta.getValue();
                }
            }
        }
        return null;
    }

    protected ElementNode m_node;
}
... 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.