Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Questions about building on top of the XML Editor
Questions about building on top of the XML Editor [message #213952] Sat, 17 May 2008 00:05 Go to next message
Eclipse UserFriend
Originally posted by: kosta.bea.com

I am in the process of writing a form-based editor for an XML file and I
want to use WTP's XML editor as the source view. I found a way to get at
the XML DOM of the editor and I am able to push changes from the
form-based editor to the source view.

Couple of questions...

1. How does one listen for changes to the DOM (in order to update the
form-based UI)?

2. Is there a trick/utility for handling formatting when creating
content? I know how to do it manually by adding various whitespace
sections to the DOM tree, but I'd rather not re-invent the wheel if the
wheel already exists. :)

Thanks,

- Konstantin
Re: Questions about building on top of the XML Editor [message #213961 is a reply to message #213952] Sat, 17 May 2008 03:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Konstantin Komissarchik wrote:
> I am in the process of writing a form-based editor for an XML file and I
> want to use WTP's XML editor as the source view. I found a way to get at
> the XML DOM of the editor and I am able to push changes from the
> form-based editor to the source view.
>
> Couple of questions...
>
> 1. How does one listen for changes to the DOM (in order to update the
> form-based UI)?

You might want to check out the XSD and WSDL editor code to see how they
do it, as well as the code from the XMLMultiPage Editor. I believe you
have to tell the StructuredDocument who is listening for it's events.

>
> 2. Is there a trick/utility for handling formatting when creating
> content? I know how to do it manually by adding various whitespace
> sections to the DOM tree, but I'd rather not re-invent the wheel if the
> wheel already exists. :)

Konstantin: if you just want a pretty formatted document, you could
programmatically have it execut the SSE formatter to format the document.

Again the best examples are probably the existing XML, XSD, and WSDL
editors.
Re: Questions about building on top of the XML Editor [message #213969 is a reply to message #213961] Sat, 17 May 2008 04:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kosta.bea.com

Yeah, I've been sifting through all that code, but without having a real
good grasp about what all the pieces are, what they are called and how
they are put together, it's a bit like looking for a needle in the haystack.

I did find IStructuredDocument.addDocumentChangedListener() api, but
that isn't the right level of abstraction for me since it deals with
document regions. I am looking for something that deals with DOM nodes.

Regarding the formatting question, I am not looking for a way to format
an existing document, but rather for something that will create
well-formatted structure (in localized manner) as new content is added
to the document.

- Konstantin
Re: Questions about building on top of the XML Editor [message #213976 is a reply to message #213952] Sat, 17 May 2008 04:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kosta.bea.com

Just found org.w3c.dom.events.EventTarget interface from DOM Level 2.
Hopefully this part of Level 2 spec is implemented by the xml editor's
DOM. Will give that a try next week.

- Konstantin
Re: Questions about building on top of the XML Editor [message #213983 is a reply to message #213969] Mon, 19 May 2008 13:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Konstantin Komissarchik wrote:
> Yeah, I've been sifting through all that code, but without having a real
> good grasp about what all the pieces are, what they are called and how
> they are put together, it's a bit like looking for a needle in the
> haystack.
>
> I did find IStructuredDocument.addDocumentChangedListener() api, but
> that isn't the right level of abstraction for me since it deals with
> document regions. I am looking for something that deals with DOM nodes.
>

As for some of the DOM nodes, you might want to look at the
EMFDOMAdaptor, which I think will get you in the direction you want to
go, as it keeps an EMF Model and DOM model in synch, so that changes to
one get propopogated into the other. Might be able to do something
similar in your situation, or at least it might give you some ideas.

> Regarding the formatting question, I am not looking for a way to format
> an existing document, but rather for something that will create
> well-formatted structure (in localized manner) as new content is added
> to the document.

I believe that is taken care of for you automatically, but I could be
mistaken.
Re: Questions about building on top of the XML Editor [message #213991 is a reply to message #213976] Mon, 19 May 2008 16:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kosta.bea.com

Nope. The XML editor infrastructure does not implement
org.w3c.dom.events.* interfaces. I did find an example plugin from an
old EclipseCon talk and from there was able to figure out that the
relevant listener interfaces are apparently INodeNotifier and
INodeAdapter. Getting them configured properly for notification was a
pain, but at least I am now getting events.

- Konstantin
Re: Questions about building on top of the XML Editor [message #213999 is a reply to message #213991] Mon, 19 May 2008 17:37 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Konstantin Komissarchik wrote:
> Nope. The XML editor infrastructure does not implement
> org.w3c.dom.events.* interfaces. I did find an example plugin from an
> old EclipseCon talk and from there was able to figure out that the
> relevant listener interfaces are apparently INodeNotifier and
> INodeAdapter. Getting them configured properly for notification was a
> pain, but at least I am now getting events.

Correct, the DOM Nodes all implement INodeNotifier and tell their
registered INodeAdapters of changes to attributes and children. The
adapters are created by INodeAdapterFactory instances.

So it's actually not that painful for adding *UI*
functionality--once you have the model, you can add your own adapter
factory through its FactoryRegistry object. This is usually done
when the model is first set as the input on a viewer. Your factory
will then be asked to lazily create an adapter when someone, meaning
your UI code, attempts to get that adapter from the Node using
INodeNotifier.getAdapterFor(Object). Under extreme circumstances,
you may also get the factory for the PropagatingAdapterFactory.class
type and add your factory to its list. This will exchange some
performance when Nodes are created for your factory being called
right then.

--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Questions about building on top of the XML Editor [message #214006 is a reply to message #213991] Mon, 19 May 2008 17:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Konstantin Komissarchik wrote:
> Nope. The XML editor infrastructure does not implement
> org.w3c.dom.events.* interfaces. I did find an example plugin from an
> old EclipseCon talk and from there was able to figure out that the
> relevant listener interfaces are apparently INodeNotifier and
> INodeAdapter. Getting them configured properly for notification was a
> pain, but at least I am now getting events.
>
> - Konstantin

Konstantin, you might be interested in adding your comments to the
following bugs:

231990 - DOM Level 2 Support
231992 - DOM Level 3 Support

Dave
Re: Questions about building on top of the XML Editor [message #214020 is a reply to message #213999] Mon, 19 May 2008 18:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kosta.bea.com

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
Re: Questions about building on top of the XML Editor [message #217183 is a reply to message #214020] Wed, 09 July 2008 11:53 Go to previous message
Eclipse UserFriend
Originally posted by: renhart.gittens.ouls.ox.ac.uk

Hi Konstantin,

I'm also in the process of writing a form-based editor for an XML files
controlled by XSD schemas. Would you be willing to share what you've
learned with me. I would really appreciate sight of your model etc as you
appear to have already explored the areas I'm finding difficulty with.
I've looked at the PDE Schema editor but I really need the model to run
from the DOM as you appear to.

Many thanks
Renhart
Previous Topic:Language packs for WTP 2.0.x ?
Next Topic:Need org.eclipse.wst.server plugin
Goto Forum:
  


Current Time: Tue Apr 16 09:53:56 GMT 2024

Powered by FUDForum. Page generated in 0.12740 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top