Matt Flaherty wrote:
> Hi Hussein,
>
> I've come up with a cheat to accomplish my desired ability to set node trees
> as readonly using css. You may be able to tell me whether this is inadvisable
> or na?ve. I think perhaps it is at least a bit na?ve in that it assumes the
> context node is an alement, so it wouldn't work for comments or attibutes.
> With a bit more time I could probably solve that. I created a stylesheet
> extension that looks like this:
>
> package com.pgs.xxe.css;
>
> import com.xmlmind.xmledit.doc.Element;
> import com.xmlmind.xmledit.doc.Node;
> import com.xmlmind.xmledit.styledview.StyledViewFactory;
> import com.xmlmind.xmledit.stylesheet.StyleSpecsBase;
> import com.xmlmind.xmledit.stylesheet.StyleValue;
>
> public class StyleSheetExtension extends StyleSpecsBase {
>
> public StyleSheetExtension(String[]args, StyledViewFactory
> styledviewfactory) {
>
> }
>
> public StyleValue readonly(StyleValue[] args, Node contextNode,
> StyledViewFactory viewFactory) {
> Element element = (Element) contextNode;
> element.setReadOnly(true);
> return null;
> }
> }
>
> And I created a css rule that looks like this:
>
> content: invoke("readonly");
>
>
> Because the readonly method returns a null StyleValue, it has no effect on
> the element content. As far as I can tell it's working, but it seems so
> simple that it couldn't possibly be covering everything, could it?
>
Clever hack. Congratulations.
I couldn't have suggested to do that because styling an element isn't
supposed to have side-effects on this element.
The only drawback I see (a big one) is that element.setReadOnly(true)
will clear the Undo stack more often that you would like. (Why? Imagine
you edit an element, mark it as read-only, then undo your edit.)
setReadOnly was supposed to be used like this:
[1] Open the document.
[2] Using an OpenedDocumentHook, mark subtrees as read-only using
setReadOnly(true)
[3] Possibly mark descendants of the above read-only subtrees as
editable using setReadOnly(false) (this feature is new in XXE v4).
This is supposed to restrict some users to editable islands in the
middle of a read-only ocean.