Page 1 of 1

Modify Link Action

Posted: Wed Jan 07, 2015 1:23 pm
by mu258770
Hi Alex,

We are working in one more functionality as "Modify inserted Link" in oxygen eclipse. What is required is if user select a link and by selecting "Modify Link" option from menu or toolbar, he should get the link in the proper text box and he should be able to edit it. This is similar to "Edit Attributes", but difference is our link is a mixture of many fields.

For eg :- Consider the link is as below,

<xref topicname#sectionname>

Now user selects Modify Link from toolbar (this we have done using framework changes), then we need to get 'topicname' in one field and 'sectionname' in another.

How can we do this. How can we read character from the editor using java code.

Regards,
Shabeer

Re: Modify Link Action

Posted: Wed Jan 07, 2015 5:14 pm
by alex_jitianu
Hi,

I suspect that there is an href attribute there, that contains the topicName#sectionName value, right? You can get it and set it back like this:

Code: Select all

int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorNode xrefNode = authorAccess.getDocumentController().getNodeAtOffset(caretOffset);
if (xrefNode.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement authorElement = (AuthorElement) xrefNode;

// How to get/set an attribute value
AttrValue attribute = authorElement.getAttribute("href");

String[] topicNameAndSection = attribute.getValue().split("#");
// TODO ......
// To set the value back you must use the controller
authorAccess.getDocumentController().setAttribute("href", new AttrValue("newValue"), authorElement);
}
You can learn more about the Author document model by reading about the AuthorNode and AuthorElement.

best regards,
Alex