'Refresh' after inserting element with AuthorDocumentController

Post here questions and problems related to oXygen frameworks/document types.
abhik
Posts: 17
Joined: Tue Sep 05, 2023 12:14 am

'Refresh' after inserting element with AuthorDocumentController

Post 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-1.png (52.56 KiB) Viewed 476 times
screenshot-2.png
screenshot-2.png (87.12 KiB) Viewed 476 times
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: 'Refresh' after inserting element with AuthorDocumentController

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
abhik
Posts: 17
Joined: Tue Sep 05, 2023 12:14 am

Re: 'Refresh' after inserting element with AuthorDocumentController

Post by abhik »

Hi Radu,
Thank you for the reply.
createNewDocumentFragmentInContext function is working perfectly fine for me.

Regards,
AbhiK
Post Reply