Page 1 of 1

beforeAttributeChange and attributeChanged in the AuthorListener

Posted: Mon Jan 30, 2012 11:02 am
by SSC
Hello,

there are several ways to change attributes of a certain tag element.
Internally I guess they are all changed by the

Code: Select all

documentController.setAttribute(attrName, new AttrValue(attrValue), authorElement);
Is the AuthorListener with its attributeChanged event the correct listener for the setAttribute method of the AuthorDocumentController?
When exactly are the beforeAttributeChange and attributeChanged methods are invoked?

Thanks in advance

Simon

Re: beforeAttributeChange and attributeChanged in the AuthorListener

Posted: Mon Jan 30, 2012 12:04 pm
by Radu
Hi Simon,

So you are referring to this listener class:

ro.sync.ecss.dom.AuthorDocumentListenerExt

It should receive events before and after an attribute was added/removed/changed either through the Attributes Table (or in-place Attributes viewer) provided by Oxygen or when some API call to the document controller is made either by the Oxygen code or by a developer's extension.

What exactly are you trying to accomplish?
If you want to alter the value which is set I would suggest the document filter approach:

ro.sync.ecss.extensions.api.AuthorDocumentFilter.setAttribute(AuthorDocumentFilterBypass, String, AttrValue, AuthorElement)

Regards,
Radu

Re: beforeAttributeChange and attributeChanged in the AuthorListener

Posted: Mon Jan 30, 2012 1:17 pm
by SSC
I was not referring to the ro.sync.ecss.dom.AuthorDocumentListenerExt, but to the ro.sync.ecss.extensions.api.AuthorListener.

I am not able to find the ro.sync.ecss.dom.AuthorDocumentListenerExt class. Maybe it is obfuscated.

How do I get the ro.sync.ecss.extensions.api.AuthorDocumentFilter, you mentioned?

For the usual AuthorDocumentController I use the following method :

Code: Select all

	private AuthorDocumentController getDocumentController() {
IEditorPart activeEditor = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (activeEditor instanceof WSEditor) {
WSEditorPage currentPage = ((WSEditor) activeEditor)
.getCurrentPage();
if (currentPage instanceof WSAuthorEditorPage) {
return ((WSAuthorEditorPage) currentPage)
.getDocumentController();
}
}
return null;
}
Regards,

Simon

Re: beforeAttributeChange and attributeChanged in the AuthorListener

Posted: Mon Jan 30, 2012 1:41 pm
by Radu
Hi Simon,

You are right, I meant this listener:

ro.sync.ecss.extensions.api.AuthorListener

Once you gain access to the AuthorDocumentController you can do the following:

Code: Select all

    documentController.setDocumentFilter(new AuthorDocumentFilter() {
/**
* @see ro.sync.ecss.extensions.api.AuthorDocumentFilter#setAttribute(ro.sync.ecss.extensions.api.AuthorDocumentFilterBypass, java.lang.String, ro.sync.ecss.extensions.api.node.AttrValue, ro.sync.ecss.extensions.api.node.AuthorElement)
*/
@Override
public void setAttribute(AuthorDocumentFilterBypass filterBypass, String attributeName,
AttrValue value, AuthorElement element) {
//Here you can modify the attribute name and/or value before delegating to super.
//TODO your code here
// Delegate to super to perform the default operation on the attribute value and name.
super.setAttribute(filterBypass, attributeName, value, element);
}
});
Regards,
Radu