Page 1 of 1
PlugIn: Go to certain location within document
Posted: Tue Oct 19, 2010 6:30 pm
by ckirchho
Hello,
I would like to write a PlugIn that does some tests on an xml document and reports errors. I would like to log the errors in a dialog window.
My question is: Would the following scenario be possible? The dialog lists the problems found in a list or a table (internally I might store a character position and a length). When the user clicks on an entry in the list/row in the table, the cursor jumps to the proper position in the document window and selects a certain amount of characters (Similar to what happens when you do a search).
I know that I can get the frame with context.getFrame() (when it is a DocumentPluginExtension). But is there any possibility to go from the frame to the window that contains the document, and then remotely control that window?
Best regards,
Christian Kirchhoff
Re: PlugIn: Go to certain location within document
Posted: Wed Oct 20, 2010 9:06 am
by Radu
Dear Christian,
I assume you already know where to find our plugins development kit:
http://www.oxygenxml.com/developer.html#Plugins
The type of plugin that you should look into is the "Workspace Access" plugin. We have a sample in the plugins development kit for such a plugin implementation which should be useful to you.
This kind of plugin can register actions on the toolbar and main menu.
You can also access the current selected editor using the
StandalonePluginWorkspace API, get access to methods which can be used to create a
Reader over the selected
WSEditor editor.
Then you can check in what page the editor is opened: Text, Grid or Author and using the
WSTextBasedEditorPage API perform modifications to it or move the caret to certain positions.
If you want you can write us an email to our support email address with more details and I'll try to provide a sample implementation of a Workspace Access plugin.
Regards,
Radu
Re: PlugIn: Go to certain location within document
Posted: Wed Oct 20, 2010 11:21 am
by ckirchho
Hello Radu,
thanks for the quick response. Yes I have the plugins development kit and I started with a document plugin. With that I was able to parse the document's contents and log problems. I will take a closer look at the Workspace Access plugin example. If I have further questions, I will get back to you.
Thanks again
Christian
Re: PlugIn: Go to certain location within document
Posted: Wed Oct 20, 2010 3:29 pm
by ckirchho
Just one additional question: Which is the minimal Oxygen version that supports Workspace Access PlugIns?
Re: PlugIn: Go to certain location within document
Posted: Wed Oct 20, 2010 3:35 pm
by Radu
Hi Christian,
The Workspace Access plugin and API was added in Oxygen 11.2.
From Oxygen 11.0 or 11.1 the upgrade to 11.2 is free.
If you have Oxygen 10.x or older maybe we can find a workaround using the older API. In what page do you want to present the errors? In the Text page?
Regards,
Radu
Re: PlugIn: Go to certain location within document
Posted: Wed Oct 20, 2010 5:18 pm
by ckirchho
The presentation of the errors should be in an external window (just as the Conversion example in the Development Kit opens in a new window).
That windows will either contain a list or a table. Clicking on an entry in that list or a row in that table should reult in the xml document being moved to a certain position (if possible).
Re: PlugIn: Go to certain location within document
Posted: Thu Oct 21, 2010 11:19 am
by Radu
Hi,
The most that you can accomplish using the older plugins API is to try and get access to the JTextArea in which the XML is edited like:
Code: Select all
/**
* Process context.
*
*@param context Selection context.
*@return Selection plugin result.
*/
public SelectionPluginResult process(SelectionPluginContext context) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//This the JTextArea from the Oxygen Text page.
JTextArea currentEditor = (JTextArea) KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
//TODO perform your own code here.
}
});
return null;
}
You have to invoke later on the AWT the code so that the focus is transfered back to the JTextArea after the action is invoked.
Regards,
Radu
Re: PlugIn: Go to certain location within document
Posted: Mon Oct 25, 2010 12:05 pm
by ckirchho
Dear Radu,
that worked perfectly, thank you very much! Nevertheless I'll try to upgrade and check the Workspace Access plugin, too.
Best regards,
Christian