XML Editor in Source View of MultiView Component (Part 2)

Let's extend the XML source editor in our multiview component to support XML checking and XML validation. The end result will be like this:

Thanks to Toni Epple and Enrico Scantamburlo, I came up with the following solution, which requires a dependency on the "XML Tools" module.

Note in particular the parts in bold below:

public class AbcDataObject extends XMLDataObject implements Lookup.Provider {

    final InstanceContent ic;

    private AbstractLookup lookup;

    public AbcDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
        super(pf, loader);
        ic = new InstanceContent();
        lookup = new AbstractLookup(ic);
        InputSource is = DataObjectAdapters.inputSource(this);
        Source source = DataObjectAdapters.source(this);
        ic.add(new CheckXMLSupport(is));
        ic.add(new ValidateXMLSupport(is));
        ic.add(new TransformableSupport(source));
        ic.add(AbcEditorSupport.create(this));
    }

    @Override
    protected Node createNodeDelegate() {
        return new MyDataNode(this);
    }

    public class MyDataNode extends DataNode implements Node.Cookie {
        public MyDataNode(AbcDataObject obj) {
            super(obj, Children.LEAF, lookup);
            ic.add(this);
            setIconBaseWithExtension("org/myorg/abcfiletype/Datasource.gif");
        }
    }

    @Override
    public Lookup getLookup() {
        return lookup;
    }

    @Override
    public Node.Cookie getCookie(Class type){
        Object o = lookup.lookup(type);
        return o instanceof Node.Cookie ? (Node.Cookie)o: null;
    }

}

And now you should have XML checking and validation enabled in the XML editor of your multiview component!

In other news. Now continue to part 3 of this series!

Comments:

Congratulations! Another great (and very useful) post!

I have a question: have you tested NB's reaction when user changes the DOCTYPE or the root element?

Posted by Eduardo Costa on May 04, 2010 at 11:20 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today