Hello,

I want to insert (at specific bookmark location) several generated sub
documents, into a global document.
For the first subdocument, all is ok, but for all others ... it insert the
first !
I think the XTransferable is not up to date, so how can I refresh the
XTransferable ?

I write the following java code :

public static final void insertSubDocument(XComponent xComponent_sourceDoc,
XComponent xComponent_targetDoc, XNameAccess xNamedBookmarks, String
bookmarkName) throws UnsupportedFlavorException
{
    XTextDocument xTextDocument_sourceDoc = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xComponent_sourceDoc);

    XTextDocument xTextDocument_targetDoc = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xComponent_targetDoc);
    
System.out.println(xTextDocument_sourceDoc.getText().getString());
//all sub doc are ok here

    // the controllers
    XController xController_sourceDoc =
xTextDocument_sourceDoc.getCurrentController();
    XController xController_targetDoc =
xTextDocument_targetDoc.getCurrentController();

    // the cursor for the source document
    XTextViewCursorSupplier xViewCursorSupplier_sourceDoc =
(XTextViewCursorSupplier)
UnoRuntime.queryInterface(XTextViewCursorSupplier.class,
xController_sourceDoc);

    // selecting the whole source document
    XTextViewCursor xTextViewCursor_sourceDoc =
xViewCursorSupplier_sourceDoc.getViewCursor();
    xTextViewCursor_sourceDoc.gotoEnd(true);
    
    // getting the data supplier of our source doc
    XTransferableSupplier xTransferableSupplier_sourceDoc =
(XTransferableSupplier)
UnoRuntime.queryInterface(XTransferableSupplier.class,
xController_sourceDoc);
    
    // saving the selected contents
    XTransferable xTransferable =
xTransferableSupplier_sourceDoc.getTransferable();

    // getting the data supplier of our target doc
    XTransferableSupplier xTransferableSupplier_targetDoc =
(XTransferableSupplier)
UnoRuntime.queryInterface(XTransferableSupplier.class,
xController_targetDoc);

    // the cursor for the target document
    XTextViewCursorSupplier xViewCursorSupplier_targetDoc =
(XTextViewCursorSupplier)
UnoRuntime.queryInterface(XTextViewCursorSupplier.class,
xController_targetDoc);
    // going to the end of the source document

    try
    {
        // find the bookmark named bookmarkName
        Object bookmark = xNamedBookmarks.getByName(bookmarkName);

        // we need its XTextRange which is available from getAnchor(),
        // so query for XTextContent
        XTextContent xBookmarkContent = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class, bookmark);

        // get the anchor of the bookmark (its XTextRange)
        XTextRange xBookmarkRange = xBookmarkContent.getAnchor();

        XTextViewCursor xTextViewCursor_targetDoc =
xViewCursorSupplier_targetDoc.getViewCursor();
        xTextViewCursor_targetDoc.gotoRange(xBookmarkRange, false);

        // inserting the source document there
        xTransferableSupplier_targetDoc.insertTransferable(xTransferable);
    }
    catch (NoSuchElementException e)
    {
        // nothing
    }
    catch (WrappedTargetException e)
    {
        // nothing
    }
}
-- 
View this message in context: 
http://www.nabble.com/sub-document-insertion-bug-tf3591129.html#a10036493
Sent from the openoffice - api dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to