[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.webtools] Re: Questions about building on top of the XML Editor

Nitin,

Could you elaborate a bit more regarding the function of the PropagatingAdapterFactory?

I want to get notified when any part of the DOM tree is changed. I then have some code that processes the low-level DOM events into high-level changes that the UI can deal with. The UI layer is not aware of DOM at all.

I ended up writing the following function. It gets called upon initialization of the Document node. It also gets called any time an ADD event is received...

    private static void initNodeAdapter( final Node node )
    {
        ( (INodeNotifier) node ).getAdapterFor( NodeAdapterImpl.class );

        final NodeList children = node.getChildNodes();

        for( int i = 0, n = children.getLength(); i < n; i++ )
        {
            initNodeAdapter( children.item( i ) );
        }

        if( node instanceof Element )
        {
            final Element element = (Element) node;
            final NamedNodeMap attributes = element.getAttributes();

            for( int i = 0, n = attributes.getLength(); i < n; i++ )
            {
                initNodeAdapter( attributes.item( i ) );
            }
        }
    }

The above is probably not the best way of getting this accomplished, but at least it makes sure that I am able to see all the changes.

The other part of the puzzle that I do not understand is the purpose of the IStructuredModel and it's relationship to the DOM instance. When I started writing the editor, I found the following code for getting at the DOM instance that I can then modify:

ISourceEditingTextTools sourceEditingTextTools
= (ISourceEditingTextTools) this.sourceEditor.getAdapter( ISourceEditingTextTools.class );


IDOMSourceEditingTextTools domSourceEditingTextTools
  = (IDOMSourceEditingTextTools) sourceEditingTextTools;

Document doc = domSourceEditingTextTools.getDOMDocument();

Then, in order to listen for changes, I had to get the model to register the adapter factory...

IDocument idoc = this.sourceEditor.getDocumentProvider().getDocument( getEditorInput() );

IStructuredModel model = StructuredModelManager.getModelManager().getModelForWrite( (IStructuredDocument) idoc );

So...

1. What is the relationship between IStructuredModel and the DOM instance?

2. When should getModelForEdit() and releaseFromEdit() methods be called? Right around factory registration code or should I not release the model until the editor is closed?

3. Is there anything else I should be doing with the model? Right now I only use it for registering the adapter factory. All changes just modify the DOM instance.

- Konstantin