Access the editorOpened method via framework
Posted: Wed Apr 10, 2024 8:26 pm
Hello!
We created a framework in Oxygem Web that allows us to perform updates and checks on our XML files.
We create an ExtensionsBundle and inside it we call an AuthorExtensionStateListener.
This way we were able to create our uniqueAttributesRecognizer method and call webWorkspace.addEditorChangeListener and webWorkspace.addEditingSessionLifecycleListener.
However, we noticed that the extensionBundle is adding a Listener each time it is called when opening a file. This is generating several validation problems. We also noticed that the deactivate method is not being called so that we can remove the listeners.
We saw that including addValidationProblemsFilter is very simple to do via plugin, however, we don't know the correct place to create these listeners and validators via the framework.
Can you please tell us what is the best way to access the workspace and add listeners via framework?
Result: Every time we open a file, the system adds a new listener and all listeners are called in a row.
We created a framework in Oxygem Web that allows us to perform updates and checks on our XML files.
We create an ExtensionsBundle and inside it we call an AuthorExtensionStateListener.
This way we were able to create our uniqueAttributesRecognizer method and call webWorkspace.addEditorChangeListener and webWorkspace.addEditingSessionLifecycleListener.
However, we noticed that the extensionBundle is adding a Listener each time it is called when opening a file. This is generating several validation problems. We also noticed that the deactivate method is not being called so that we can remove the listeners.
We saw that including addValidationProblemsFilter is very simple to do via plugin, however, we don't know the correct place to create these listeners and validators via the framework.
Can you please tell us what is the best way to access the workspace and add listeners via framework?
Code: Select all
public class AuthorExtensionStateListenerTPMS implements AuthorExtensionStateListener {
private AuthorAccess authorAccess;
AttributesRecognizer uniqueAttributesRecognizer;
protected static final Logger logger = LoggerFactory.getLogger(AuthorExtensionStateListenerTPMS.class);
public void activated(final AuthorAccess authorAccess) {
this.authorAccess = authorAccess;
WebappPluginWorkspace webWorkspace = (WebappPluginWorkspace) PluginWorkspaceProvider.getPluginWorkspace();
this.uniqueAttributesRecognizer = new AttributesRecognizer();
// Primeiramente ativo a classe para reconhecer os padroes TPMS
this.uniqueAttributesRecognizer.activated(authorAccess);
// Depois chamo o metodo para criar os IDs
this.uniqueAttributesRecognizer.assignUniqueIDs(0,
authorAccess.getDocumentController().getAuthorDocumentNode().getLength(), true);
webWorkspace.addEditorChangeListener(new WSEditorChangeListenerTPMS(authorAccess, webWorkspace), 0);
webWorkspace.addEditingSessionLifecycleListener(new WebappEditingSessionLifecycleListenerTPMS());
logger.error("AuthorExtensionStateListenerTPMS > activated");
}
public void deactivated(AuthorAccess authorAccess) {
uniqueAttributesRecognizer.deactivated(authorAccess);
//should remove listeners on deactivate?
logger.error("AuthorExtensionStateListenerTPMS > deactivated");
}
Code: Select all
public class WSEditorChangeListenerTPMS extends WSEditorChangeListener {
AuthorAccess authorAccess;
PluginWorkspace workspace;
protected static final Logger logger = LoggerFactory.getLogger(WSEditorChangeListenerTPMS.class);
@Override
public void editorOpened(URL editorLocation) {
WSEditor editor = workspace.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
WSAuthorEditorPage authorEditorPage = (WSAuthorEditorPage) editor.getCurrentPage();
authorEditorPage.getAuthorAccess().getDocumentController()
.setDocumentFilter(new AuthorDocumentFilterTPMS(this.authorAccess));
editor.addValidationProblemsFilter(new CheckCompletenessFilter(authorEditorPage));
logger.error("WSEditorChangeListenerTPMS > editorOpened");
super.editorOpened(editorLocation);
}
Result: Every time we open a file, the system adds a new listener and all listeners are called in a row.