Page 1 of 1

'Refresh' after inserting element with AuthorDocumentController

Posted: Tue Sep 05, 2023 1:16 am
by abhik
Hello Team,

I am trying to implement custom AuthorDnDListener.
On authorDrop(), I am creating new element and adding to the document.
After adding element, it is not displaying properly in Author page. Check screenshot-1 for reference. Here I have added xref element and image element using DnD operation. Link icon is not available for xref element and image element is not rendering with image.

But after doing 'save' and 'refresh' operation, it is displaying properly. Check screenshot-2 for reference. Link icon is available with xref and image is displaying for image element.

I am calling authorDocumentController.refreshNodeReferences() and authorEditorPage.refresh(), but it is not working.
Please check code snippet for more details.

Code: Select all

    public boolean authorDrop(Transferable transferable, DropTargetDropEvent event) {
        String path = (String) transferable.getTransferData(DataFlavor.stringFlavor);
        WSEditorPage editorPage = editorAccess.getCurrentPage();
        WSAuthorEditorPage authorEditorPage = (WSAuthorEditorPage) editorPage;
        int position = authorEditorPage.getCaretOffset();
        AuthorDocumentController authorDocumentController = authorEditorPage.getDocumentController();
        AuthorElement element = authorDocumentController.createElement("xref");
        authorDocumentController.insertElement(position, element);
        authorDocumentController.setAttribute("href", new AttrValue(path), element);
        AuthorNode rootNode = authorDocumentController.getAuthorDocumentNode();

        // Refresh operation
        authorDocumentController.refreshNodeReferences(rootNode);
        authorDocumentController.refreshNodeReferences(element);
        SwingUtilities.invokeLater(() -> {
            authorEditorPage.refresh(element);
            authorEditorPage.refresh();
        });
        return true;
    }
How to properly refresh the Author page after inserting the element?
How can I achieve results as per screenshot-2 programmatically (without doing manual 'save' and 'refresh' operation) ?

Thanks,
AbhiK
screenshot-1.png
screenshot-2.png

Re: 'Refresh' after inserting element with AuthorDocumentController

Posted: Tue Sep 05, 2023 7:34 am
by Radu
Hi,
The DITA "xref" element has default attributes with default values like the DITA @class attribute. And these default attributes do not get computed if you create the element just with the name.
I suggest this replacement code instead:

Code: Select all

    AuthorDocumentFragment frag = authorDocumentController.createNewDocumentFragmentInContext("<xref href=\"" + path + "\"/>", position);
    authorDocumentController.insertFragment(position, frag);
Regards,
Radu

Re: 'Refresh' after inserting element with AuthorDocumentController

Posted: Wed Sep 06, 2023 11:24 pm
by abhik
Hi Radu,
Thank you for the reply.
createNewDocumentFragmentInContext function is working perfectly fine for me.

Regards,
AbhiK