How to handle DomElement becoming invalid

Hi,

I've created a dedicated editor for an XML file. Different panels in this editor contain specialized editors for sections of the XML file. Some of these panels are bound to DomElements that are part of an XML collection. These panels extend BasicDomElementComponent.

The problem is that when I delete or add a tag in that section the underlying DomElement of the panel becomes invalid. I can see a CollectionElementRemovedEvent and a CollectionElementAddedEvent that indicate that the DomElement that was bound to the panel is removed, and a new one is attached to the containing collection element.

How do I handle the fact that the DomElement underlying my panel becomes invalid? How do I attach the panel to the new DomElement?

4 comments

Ok , I figured it out: In the constructor of the BasicDomElementComponent subclass I do:

public BDESubClass(DomElement element)
{
super(element.createStableCopy());
bindPropeties();
}

This solves my problem

0

I'd suggest you not to create a stable copy, but rather use
DomManager.createStableValue() whenever possible. Stable copies only
remember the XPath to the element. So if, for example, a collection element
is added before your stable-copied one, the stable element will in fact
change. In your case undo functionality may sometimes be broken. I'd suggest
you to remember the indices of your underlying elements in the containing
panel, and rebuild it according to the events (or on any change, if it isn't
too slow).

"Jan Arend Jansen" <no_mail@jetbrains.com> wrote in message
news:30109718.1160334018415.JavaMail.itn@is.intellij.net...

Ok , I figured it out: In the constructor of the BasicDomElementComponent
subclass I do:

>

public BDESubClass(DomElement element)
{
super(element.createStableCopy());
bindPropeties();
}

>

This solves my problem



0

I was trying to implement what you suggested. This approach needs an implementation for the Factory]]> interface. Is there a default implementation for DomElements or do I write one myself? If the latter, how would this look?

0

No default implementation. It's just a way for you to get the right
DomElement if the former one has become invalid. Usually it's something like
taking a definite child from its parent (which is stable itself).

"Jan Arend Jansen" wrote in message news:26956272.1160834540973.JavaMail.itn@is.intellij.net... >I was trying to implement what you suggested. This approach needs an >implementation for the Factory interface. Is there a default >implementation for DomElements or do I write one myself? If the latter, how >]]>would this look?


0

Please sign in to leave a comment.