As you work to develop a plugin here are a few things to consider while working with the currently loaded document. ...
When working with the currently active Rich Document, it may be handy to have a helper method, that returns the Currently Loaded Document.
Note: It is attached in CodeSnippet.txt. If you are in a SideShelf, you'll want to follow the Wiki Article on how to get the currently active view from the SideShelf
How to gain access to the current document when loaded in a ViewPart / SideShelf?
Test what type of Document is loaded, and be sure to simplify the code by getting the UNO Model prior to launching into the If Then Else Statement
As a consideration, if you are going to manipulate the document for the user, consider forcing a Save prior to your work, as the user then can revert.
It's a design choice.
If you are going to dispatch a long job, consider using IJob so the User does not think the client is frozen while it completes an operation.
Using Jobs and UIJobs with SWT Components (See attached file: CodeSnippet.txt)