Page 1 of 1

Elments tab with java api

Posted: Fri Feb 14, 2014 12:16 am
by hmida
Hi,

I use WhatAttributesCanGoHereContext class to obtain a list of possible insert after the node elements, but the list is not identical with the items displayed in the tab element (after).

how I can have just the list of elements to be inserted after the node (as in the Elements tab) ?

here is my code :

Code: Select all


WhatElementsCanGoHereContext whatElementsCanGoHereContext = authorSchemaManager
.createWhatElementsCanGoHereContext(authorPageAccess.getCaretOffset());
if (whatElementsCanGoHereContext != null) {
List<CIElement> whatElementsCanGoHere = authorSchemaManager
.whatElementsCanGoHere(whatElementsCanGoHereContext);
if (whatElementsCanGoHere != null) {

for (CIElement ciElement : whatElementsCanGoHere) {
if("PAR_ET".equals(ciElement))
boolean find = true;
}
Best regards,
Hmida.

Re: Elments tab with java api

Posted: Fri Feb 14, 2014 9:53 am
by Radu
Hi Hmida,

If you want to know the list of elements which can be inserted after the current element you need to create the context based on a caret offset which is after the element, something like:

Code: Select all

      AuthorNode nodeAtOffset = authorAccess.getDocumentController().getNodeAtOffset(authorPage.getCaretOffset());
int offsetAfter = nodeAtOffset.getEndOffset() + 1;
WhatElementsCanGoHereContext contextAfter = authorSchemaManager.createWhatElementsCanGoHereContext(offsetAfter);
Regards,
Radu

Re: Elments tab with java api

Posted: Sat Feb 15, 2014 12:55 pm
by hmida
Hi Radu,
This code work fine :

Code: Select all


if(position != null && position.equals("BEFOR")){
whatElementsCanGoHere = authorSchemaManager
.createWhatElementsCanGoHereContext(authorAccess
.getEditorAccess().getSelectionStart());
}else if(position != null && position.equals("AFTER")){
whatElementsCanGoHere = authorSchemaManager
.createWhatElementsCanGoHereContext(authorAccess
.getEditorAccess().getSelectionEnd());
}

if (whatElementsCanGoHere != null) {
List<CIElement> elements = authorSchemaManager.whatElementsCanGoHere(whatElementsCanGoHere);

if (elements != null) {

for (CIElement ciElement : elements) {
if(elementName != null && elementName.equals(ciElement.toString())){
canGoHere = true;
}
}}}
my xml doc :

Code: Select all


<Tag0>
<a>
<b> (user select this node)
<c>
<d>
</Tag0>
How can I initialize the context dynamically :
When the user select the node '<b>', I want to know if it can insert an element at the end of the section (between <d> and </ Tag0>).

Regards,
Hmida.

Re: Elments tab with java api

Posted: Mon Feb 17, 2014 10:56 am
by Radu
Hi Hmida,
How can I initialize the context dynamically :
When the user select the node '<b>', I want to know if it can insert an element at the end of the section (between <d> and </ Tag0>).
I'm sorry but I do not understand.

You also have the API:

ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPageBase.getFullySelectedNode()

to give you the node which is currently fully selected by the user.

Each node has getParent(), getStartOffset() and getEndOffset() methods.
Each parent node has a ro.sync.ecss.extensions.api.node.AuthorParentNode.getContentNodes() method which can be used to iterate child nodes.

The general AuthorNode architecture which is exposed via the API looks like this:

http://www.oxygenxml.com/InstData/Edito ... ecture.gif

You have a hierarchy of nodes which point to a common sequence containing all the text nodes from the XML document.

Regards,
Radu