Elments tab with java api

Having trouble installing Oxygen? Got a bug to report? Post it all here.
hmida
Posts: 2
Joined: Thu Feb 13, 2014 11:32 pm

Elments tab with java api

Post 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.
Radu
Posts: 9449
Joined: Fri Jul 09, 2004 5:18 pm

Re: Elments tab with java api

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
hmida
Posts: 2
Joined: Thu Feb 13, 2014 11:32 pm

Re: Elments tab with java api

Post 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.
Radu
Posts: 9449
Joined: Fri Jul 09, 2004 5:18 pm

Re: Elments tab with java api

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply