Re: Custom Editor/Tree for XML Docs...

Rich Unger <[email protected]> Wed, 03 Nov 2004 11:10:59 -0800
Newsgroups gmane.comp.java.netbeans.modules.xml.devel
Message-ID <[email protected]>
The tree editor isn't really going away. It's just not being actively 
supported by sun anymore. You can do what you're asking, though.

The way I do it, is to declare my own data loader:

public class VoiceXMLDataLoader extends UniFileLoader
{
   public VoiceXMLDataLoader() {
       //super("org.netbeans.modules.xml.core.XMLDataObject");
       
super("com.nuance.tools.voicexml.VoiceXMLDataLoader$DummyDataObject");
   }

   protected String defaultDisplayName () {
       return "VoiceXML Data Loader";
   }

   protected void initialize () {
      
       super.initialize();
      
       ExtensionList extensions = new ExtensionList();
       extensions.addMimeType(VOICEXML_MIME_TYPE);
       setExtensions(extensions);
   }

   protected SystemAction[] defaultActions () {
       return new SystemAction[] {
// put node actions here
       };
   }

   protected MultiDataObject createMultiObject (FileObject primaryFile)
       throws DataObjectExistsException
   {
       return new XMLDataObject(primaryFile, this);
   }

   protected FileObject findPrimaryFile (FileObject fo)
   {
       if (fo.isFolder())
           return null;
      
       if( fo.getMIMEType().equals(VOICEXML_MIME_TYPE) )
           return fo;

       // not recognized
       return null;
   }

   /**
    * Use this for determining DataLoader ordering, to avoid cyclical
    * dependencies on XMLDataObject.
    */
   static class DummyDataObject extends org.openide.loaders.XMLDataObject
   {
       public DummyDataObject(FileObject fo, MultiFileLoader loader)
             throws DataObjectExistsException
       {
           super(fo,loader);
       }
   }

   public static final String VOICEXML_MIME_TYPE = 
"application/voicexml+xml";

   private static final long serialVersionUID = -6880743747133875374L;
}

Then, in the layer file, you need to:
1. declare a MIMEResolver
2. provide a mapping from tag name to icon/customizer, i.e.:
   <folder name="Hidden">
       <file name="com-nuance-tools-voicexml-tagmap.instance">
           <attr name="instanceClass" 
stringvalue="org.netbeans.modules.xml.tree.nodes.DoctypeElementMap"/>
           <attr name="instanceCreate" 
methodvalue="org.netbeans.modules.xml.tree.nodes.DoctypeElementMap.configure"/>
           <attr name="map" 
urlvalue="nbresloc:/com/nuance/tools/voicexml/resources/VoiceXMLMap.xml"/>
       </file>
   </folder>

The contents of VoiceXMLMap.xml is:
<doctype publicID="-//Nuance/DTD VoiceXML 2.0//EN"
        nsURI="http://www.w3.org/2001/vxml">
   <element name="vxml"
            text="vxml {application,{application},}"
            iconbase="com/nuance/tools/voicexml/resources/icons/vxml_16">
       <customizer 
class="org.netbeans.modules.xml.tree.nodes.propertysheet.PropertySheetCustomizer">
       </customizer>
   </element>

   <element name="meta"
            text="meta {name,{content,{name}={content}   ,{name} 
},{content,{content}   , }}{http-equiv,{http-equiv},}"
            iconbase="com/nuance/tools/voicexml/resources/icons/meta_16">
       <customizer 
class="org.netbeans.modules.xml.tree.nodes.propertysheet.PropertySheetCustomizer">
       </customizer>
   </element>

   <element name="prompt"
            text="prompt {bargein,bargein={bargein}  , 
}{count,count={count}  , }{cond,{cond}  , }"
            iconbase="com/nuance/tools/voicexml/resources/icons/prompt_16">
       <customizer 
class="org.netbeans.modules.xml.tree.nodes.propertysheet.PropertySheetCustomizer">
       </customizer>
   </element>

...etc, etc.

The text attribute is optional, and provides a way of customizing the 
text that goes with the node.  It uses a basic java text formatter, with 
the format
{attribute}
or
{attribute, text if attribute is non-null, text otherwise}

For example, the <vxml> element above uses the node text "vxml" if the 
'application' attribute is empty, or "vxml applicationValue" if it is not.

The <customizer> element is also optional.  If unspecified, it will look 
like the basic xml tree editor.  The provided PropertySheetCustomizer 
presents a tabbed customizer with the main tab being a property sheet 
with each attribute being a row.  You can specify children of the 
<customizer> element to provide additional tabs.  Look at the source to 
see what I mean.  There are javadocs there to help you.

Hope this helps.

Cheers,
Rich


Neuman, Ben J., A&M IRM wrote:

>I am interested in creating custom editors/trees for various XML Doctypes.
>Browsing through previous posts, I noticed there was some work done on
>creating custom tree editors with the XML Tree Editor module. Is this effort
>dead along with the Tree Editor Module? If not, are there any examples or
>documents to get me started? Rich mentioned something about a custom web.xml
>implementation he was working on. 
> 
>If the Tree Editor Module is going away, what is the best way to go about
>this? Create my own dataloader, dataobject and editor/tree capabilities?
> 
>Thanks for your help. 
>Ben
> 
>DRC/Impact Innovations Group, LLC
>Software Developer
>OASD(PA)-IRM
>703 428-0239
> <mailto:[email protected]> [email protected]
> 
>
>  
>