问题
i am new to Eclipse RCP and have the following Scenario:
- One plugin which is the Application
- Another witch is a view and does show some Data
- And a third which is the editor.
in the view I can right click on a record and choose edit what does open the Editor and lets me change the data.
No I'd like to refresh the View when I save the Editor. I think this is a classical scenario to implement a Whiteboard pattern. Unfortunately I am not really familiar with it, may be some one could show a simple example how to implement it in Eclipse RCP.
Thanks in Advance Johannes
回答1:
Your view needs to implements IPartListener2 (http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IPartListener2.html)
you can override the method partInputChanged(IWorkbenchPartReference partRef) to refresh thw view in two ways: 1) If the plug-in with view has dependency to plugin with editor
If (partRef instanceOf YourEditorClass){
YourData yourData = editor.getInput().getxxx();
}
2) If the plug-in with view doesn't have dependency to plugin with editor you need to use an adapter. You override the getAdapter method in the editor to return the Data that you need and the view get the data from the adapter
If (partRef instanceOf EditorPart){
YourData yourData = Platform.getAdapterManager().getAdapter(this, YourData.class);
}
Two codes are just an example to show the idea!
I hope I helped you
回答2:
The view has to listen to the editor or - even better - to the edited model. If it listens to the editor, look for some "save" events. Personally I would make the model itself observable and notify listeners (like your view) of actual changes.
The view then needs some logic to extract its information from the model. So instead of a whitboard - the observer pattern should be the right choice for your design.
This is worth a try: add an IPropertyListener to the IEditorPart instance of your editor and wait for property changes. The IEditorPart.PROP_DIRTY property should change from "is dirty" to "is not dirty" after a save. Snippets/code example for eclipse rcp stuff are hard to develop and to communicate. Use the buzzwords from my answer for some searches on the eclipse help, API and on google. And: good luck ;) - btw, consider buying some good books on eclipse plugin/rcp development, they're worth every €/$ spent.
来源:https://stackoverflow.com/questions/3829797/eclipse-rcp-update-a-view-after-changes-in-the-editor