Page 1 of 1

List of attributes for a node

Posted: Tue Nov 22, 2011 12:42 pm
by maxim.kovalev
How can I get a list of attributes for a node?
I found this way. Get a node on the spot where the cursor is positioned. The following is a AuthorNode AuthorElement. And call the AuthorElement.getAttributeAtIndex(i);
However, this method returns only attributes that are installed. And how can you get a complete list of attributes that are possible for this node (as in panel attributes).

Re: List of attributes for a node

Posted: Tue Nov 22, 2011 3:41 pm
by mihaela
Hi Maxim,

To find all the possible attributes for a node you have to get the WhatAttributesCanGoHereContext from the document schema manager and then ask the schema manager what attributes are available in this context.
The following code sample list the names of all attributes available for the element at caret position:

Code: Select all


  int caretOffset = authorAcess.getEditorAccess().getCaretOffset();

AuthorDocumentController controller = authorAcess.getDocumentController();
// Get the node at caret position
AuthorNode node = controller.getNodeAtOffset(caretOffset);

if (node instanceof AuthorElement) {
AuthorSchemaManager authorSchemaManager = controller.getAuthorSchemaManager();
// From schema manager get the current context
WhatAttributesCanGoHereContext context = authorSchemaManager.createWhatAttributesCanGoHereContext((AuthorElement) node);
// Find the list of all possible attributes for the current context
List<CIAttribute> possibleAttrs = authorSchemaManager.whatAttributesCanGoHere(context);
if (possibleAttrs != null) {
for (CIAttribute ciAttribute : possibleAttrs) {
System.out.println("Attr: " + ciAttribute.getName());
}
}
}
Regards,
Mihaela

Re: List of attributes for a node

Posted: Tue Nov 22, 2011 4:43 pm
by maxim.kovalev
mihaela wrote:Hi Maxim,

To find all the possible attributes for a node you have to get the WhatAttributesCanGoHereContext from the document schema manager and then ask the schema manager what attributes are available in this context.
The following code sample list the names of all attributes available for the element at caret position:

Code: Select all


  int caretOffset = authorAcess.getEditorAccess().getCaretOffset();

AuthorDocumentController controller = authorAcess.getDocumentController();
// Get the node at caret position
AuthorNode node = controller.getNodeAtOffset(caretOffset);

if (node instanceof AuthorElement) {
AuthorSchemaManager authorSchemaManager = controller.getAuthorSchemaManager();
// From schema manager get the current context
WhatAttributesCanGoHereContext context = authorSchemaManager.createWhatAttributesCanGoHereContext((AuthorElement) node);
// Find the list of all possible attributes for the current context
List<CIAttribute> possibleAttrs = authorSchemaManager.whatAttributesCanGoHere(context);
if (possibleAttrs != null) {
for (CIAttribute ciAttribute : possibleAttrs) {
System.out.println("Attr: " + ciAttribute.getName());
}
}
}
Regards,
Mihaela
Cool, thanks