Page 1 of 3

oXygene Editor Events

Posted: Wed Jun 10, 2009 4:33 pm
by Max
Does oXygene support other than standard DOM events?
Basically we need to access the Click and on KeyPress events, knowing what node has been clicked.

Re: oXygene Editor Events

Posted: Thu Jun 11, 2009 10:22 am
by sorin_ristache
Hello,

Do you need to know the current node in Author editing mode and run a custom Author action on the node? The Author API which you can find in the Author SDK (on the Developer page) defines the method AuthorOperation.doOperation() for custom user actions. It receives an AuthorAccess parameter which helps you to find and process the current node of the Author document.

If this is not what you want please give more details about what you need to do.


Regards,
Sorin

Re: oXygene Editor Events

Posted: Thu Jun 11, 2009 3:45 pm
by Max
Hello Sorin.
Thanx for a quick response. Basically we need to perform different actions but for now the problem is to create handlers to specifick Click and KeyPress events.
As a sample imagine a task to display a cliked word in a separate dialog?
To do this we need to handle the Click event, then identify the clicked node and get it's text content.
Please help.

Re: oXygene Editor Events

Posted: Thu Jun 11, 2009 4:52 pm
by sorin_ristache
Hello,

We will add in the next version (10.3) the possibility to register a mouse listener for receiving mouse events (that includes mouse click events) on the current Author document. The Author API which enables registering the listener allows you to find and process the current node of the document. Version 10.3 will be released in a couple of weeks.


Regards,
Sorin

Re: oXygene Editor Events

Posted: Tue Jun 16, 2009 2:01 pm
by Max
Hi Sorin,

I just came across a post offering 10.3 for alpha tests. I also can participate

Re: oXygene Editor Events

Posted: Tue Jun 16, 2009 2:04 pm
by sorin_ristache
Hello,

On what platform do you use Oxygen? I can send you the download URL for a Windows kit or for an All Platforms kit.


Regards,
Sorin

Re: oXygene Editor Events

Posted: Tue Jun 16, 2009 2:06 pm
by Max
For Windows please

Re: oXygene Editor Events

Posted: Tue Jun 16, 2009 3:00 pm
by sorin_ristache
I sent the download URL to your email address. You can post here any suggestions that you have or any bugs that you find. Do you want to test something particularly?


Thank you,
Sorin

Re: oXygene Editor Events

Posted: Tue Jun 16, 2009 3:41 pm
by Max
We are willing to test API in its part of handling Click and KeyPress events of the built in editor

Regards,
Max

Re: oXygene Editor Events

Posted: Tue Jun 16, 2009 3:51 pm
by Max
by the way.. do you have any documentation for that already?

Re: oXygene Editor Events

Posted: Tue Jun 16, 2009 4:09 pm
by Max
And do you happen to have the new SDK for this version already?

Regards,
Max

Re: oXygene Editor Events

Posted: Tue Jun 16, 2009 4:14 pm
by sorin_ristache
There is a new SDK for testing.


Regards,
Sorin

Re: oXygene Editor Events

Posted: Thu Jun 18, 2009 5:15 pm
by Max
Thanx to the new marvelous update we can handle click events, identify the clicked coords and get the clicked node and its offset.

AuthorViewToModelInfo modelInfo = m_Context.viewToModel(event.X,event.Y);
AuthorNode m_Anode = modelInfo.getAuthorNode();
int m_ClickOffset = modelInfo.getOffset();

for further development we need to enumerate the child elements of that node.
apparently only the element interface allsows us to enumerate children
aList = aElem.getContentNodes();
how do we cast the node interface to the element one?

Re: oXygene Editor Events

Posted: Fri Jun 19, 2009 12:03 pm
by sorin_ristache
By casting ro.sync.ecss.extensions.api.node.AuthorNode to ro.sync.ecss.extensions.api.node.AuthorElement.


Regards,
Sorin

Re: oXygene Editor Events

Posted: Tue Jun 23, 2009 3:03 pm
by Max
Thanx.
How do we create new children for the located nodes... just like the DOM does?

Re: oXygene Editor Events

Posted: Tue Jun 23, 2009 4:29 pm
by sorin_ristache
You use one of the insert or create methods of ro.sync.ecss.extensions.api.AuthorDocumentController: createDocumentFragment, insertFragment, insertXMLFragment, insertMultipleElements, insertText.


Regards,
Sorin

Re: oXygene Editor Events

Posted: Wed Jun 24, 2009 3:56 pm
by Max
Hello Sorin.

We are using the following set of functions to insert new tags into the document
createDocumentFragment
insertFragment
insertXMLFragment
insertMultipleElements
insertText

Unfortunately we cannot achive the desired result.
In brief: instead of text BEFORE, we nee to get the text AFTER.

BEFORE=======================
<section><title>XML</title>
<para>Firsrt Line. In this section of the book <b>shall</b> I will explain different XML applications.</para>
<para>Second Line. In this section of the book <b>shall</b> I will explain different XML applications.</para>
</section>
==============================

AFTER=========================
<section><title>XML</title>
<para>Firsrt Line. In this <MyTag1>section</MyTag1> of the book <MyTag2><b>shall</b><MyTag2> I will explain different XML applications.</para>
<para>Second Line. In this <MyTag3>section</MyTag3> of the book <MyTag4><b>shall</b> I will</MyTag4> <MyTag5>explain</MyTag5> different <MyTag6>XML</MyTag6> applications.</para>
</section>
==============================

Please advise how can we achieve the desired behaviour using those funstions (or any other)?

Regards,
Max

Re: oXygene Editor Events

Posted: Wed Jun 24, 2009 5:57 pm
by sorin_ristache
Hello,

You should find the offset of the insert location and call AuthorDocumentController.insertXMLFragment(). For finding the offset (relative to the start of the edited document) for example if you have an AuthorNode reference just call AuthorNode.getStartOffset() or AuthorNode.getEndOffset().

How did you try to insert the new AuthorElement / AuthorNode objects in the Author document?


Regards,
Sorin

Re: oXygene Editor Events

Posted: Thu Jun 25, 2009 3:56 pm
by Max
Hello Sorin.

1. We have a problem with calculatiing the offset. Basically we are counting symbols to get the offset. The problem is that inline tags (e.g. <b>) have width = 1.
But if we fetch text via getTextContent(), it returns pure text without the inline tags which means that if we calculate the offset by counting characters, we'll get shifted by the amount of stripped inline tags.

2. We use insertXMLFragment("<myTag1/>", offset)
or
insertMultipleElements( ....)

Regards,
Max

Re: oXygene Editor Events

Posted: Thu Jun 25, 2009 5:54 pm
by sorin_ristache
As you can read in the javadoc of the class AuthorNode the string returned by AuthorNode.getTextContent() is a concatenation of all text child nodes of that AuthorNode object. You should not use only this string in offset computations / offset parameters to Author API calls because the offset takes into account the XML tag markers: each tag marker is counted as one character, for example <myTag1/> is counted as one character, the same for <myTag1> and </myTag1>.


Regards,
Sorin

Re: oXygene Editor Events

Posted: Thu Jun 25, 2009 6:04 pm
by Max
so what method to calculate the offset do you suggest as best?

Re: oXygene Editor Events

Posted: Fri Jun 26, 2009 10:09 am
by sorin_ristache
Any call that returns an offset is good and you should use the one that is appropriate in your context. For example if you want to find the offset of the current Author node (the node where the cursor is located currently) you should use AuthorNode.getStartOffset() or AuthorNode.getEndOffset(), if you have an XPath expression for the node and you need the offset you should use AuthorDocumentController.getXPathLocationOffset().


Regards,
Sorin

Re: oXygene Editor Events

Posted: Mon Jun 29, 2009 3:30 pm
by Max
Hello Sorin.
Thanx for the quick reply!

The result we are willing to get is on the following picture. How can we reach this?
Image

Best regards,
Max

Re: oXygene Editor Events

Posted: Tue Jul 07, 2009 5:22 pm
by sorin_ristache
Hello,

You cannot get a list that includes the text represented as separate nodes. You have the selected text with start offset and end offset (as index into a string that represents the whole document content) and also you have the current node with start offset and end offset. For example in your case for transforming

Code: Select all

<para>First line. In this section of the book <b>shall</b> I will explain different XML applications.</para>
in

Code: Select all

<para>First line. In this <MyTag1>section</MyTag1>of the book <MyTag2><b>shall</b></MyTag2> I will explain different XML applications.</para>
when the Author user selects the word section and double clicks on it and selects shall and double clicks on it you can use the following AuthorOperation.doOperation() implementation:

Code: Select all

public void doOperation(AuthorAccess authorAccess, ArgumentsMap arguments)
throws IllegalArgumentException, AuthorOperationException {
AuthorEditorAccess editorAccess = authorAccess.getEditorAccess();
int start = editorAccess.getSelectionStart();
int end = editorAccess.getSelectionEnd();
String selection = editorAccess.getSelectedText();

try {
AuthorDocumentController controller = authorAccess.getDocumentController();
AuthorNode currentNode = controller.getNodeAtOffset(editorAccess.getCaretOffset());

if (currentNode.getTextContent().equals(selection)) {
// The case "<b>shall</b>"
AuthorDocumentFragment selectionAsAFragment = controller.createDocumentFragment(start, end);
String selectionAsXML = controller.serializeFragmentToXML(selectionAsAFragment);
controller.deleteNode(currentNode);
controller.insertXMLFragment("<MyTag2>" + selectionAsXML + "</MyTag2>", editorAccess.getCaretOffset());
} else {
// The case "section"
controller.delete(start, end);
controller.insertXMLFragment("<MyTag1>" + selection + "</MyTag1>", start);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}

Regards,
Sorin

Re: oXygene Editor Events

Posted: Wed Jul 08, 2009 7:22 pm
by Max
Hello Sorin,
Thank you for the solution given. We've already solved the problem ourselves, but we found useful for us elements in your solution.
We have such a question:
Does the editor differentiate the tags <MyTag></MyTag> and <MyTag/>? How can we differ them in the editor?

To take into account the offset if node has Children we use the following formula:
Correction = NumberOfChilds * 2;
i.e. tags <MyTag>some text...</MyTag> with the length = 1.

But we can't catch how to take into acount such tags as <MyTag></MyTag> (empty tag) and <MyTag/>.

What width do they have?

Best regards,
Max

Re: oXygene Editor Events

Posted: Wed Jul 08, 2009 7:26 pm
by Max
Formula:
Correction = NumberOfChildren * 2;

Re: oXygene Editor Events

Posted: Thu Jul 09, 2009 11:54 am
by sorin_ristache
Max wrote:Does the editor differentiate the tags <MyTag></MyTag> and <MyTag/>? How can we differ them in the editor?
In Author mode there is no difference between the two forms. Both <MyTag></MyTag> and <MyTag/> take two 0 (zero) characters in the string with the document content. Every XML tag takes one 0 (zero) character.
Max wrote:But we can't catch how to take into acount such tags as <MyTag></MyTag> (empty tag) and <MyTag/>.

What width do they have?
<MyTag> has width 1, </MyTag> has width 1, <MyTag/> has width 2 (as for the equivalent form <MyTag></MyTag>).


Regards,
Sorin

Re: oXygene Editor Events

Posted: Thu Jul 09, 2009 12:12 pm
by Max
Hello Sorin,

Thanx for detailed answer!

We have tested our plugin on simple xml (Elements + Text Nodes).

Now it crashes on comments nodes (<!-- some text -->),
because when we are trying to enumerate children this code raises exception:

Code: Select all

((AuthorElement)aList.get(aIndex)).getType();
((AuthorElement)aList.get(aIndex)).getName();
How to cast<> a list item and how to get its type?

Regards,
Max

Re: oXygene Editor Events

Posted: Thu Jul 09, 2009 12:26 pm
by sorin_ristache
Why do you try to cast an XML comment to an XML element? An XML comment is not an XML element. It is just a node. You find the type with the getType() method:

Code: Select all

if (AuthorNode.NODE_TYPE_COMMENT == ((AuthorNode)aList.get(aIndex)).getType())  ...

Regards,
Sorin

Re: oXygene Editor Events

Posted: Thu Jul 09, 2009 3:59 pm
by Max
Thanx Sorin,

Now our plugin successfully processes XML comments.

We've tested the plugin on the following example: samples\dita\flowers\tasks\pruning.xml.

Unfortunately it works increadibly slow: highlight each word with a different color in this short text takes approx 15 seconds (!!)
We need to optimize it somehow.
After investgating the problem we discovered this function
insertMultipleElements(AuthorElement parentElement, java.lang.String[] elementNames, int[] offsets, java.lang.String namespace)

The function inserts multiple elements at the given offsets.
Do you think it is worth digging further and it will give us a nice speedup?
Or you may suggest alternative ways of highlighting words, with e.g. Processing Instructions?


Source:
<para>First line. In this section of the book <b>shall</b> I will explain different XML applications.</para>

Target:
<para>First line. In <MyTag1>this</MyTag1> section of the <MyTag1>book</MyTag1> <MyTag1><b>shall</b></MyTag1> I will explain <MyTag1>different</MyTag1> XML applications.</para>

Regards,
Max