Access the editorOpened method via framework

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
aujunior
Posts: 29
Joined: Thu Feb 16, 2023 11:00 pm

Access the editorOpened method via framework

Post by aujunior »

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?

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:
image.png
image.png (69.3 KiB) Viewed 190 times
Every time we open a file, the system adds a new listener and all listeners are called in a row.
cristi_talau
Posts: 499
Joined: Thu Sep 04, 2014 4:22 pm

Re: Access the editorOpened method via framework

Post by cristi_talau »

Hello,

An alternative to AuthorExtensionStateListener is WebappEditingSessionLifecycleListener. You need to implement "editingSessionStarted(String, AuthorDocumentModel)" and "editingSessionClosed(String, AuthorDocumentModel)". To install the filter you can like this: "authorDocumentModel.getWSEditor.addValidationProblemsFilter(...)"
We'll investigate why AuthorExtensionStateListener.deactivate isn't called.

Best,
Cristian
Post Reply