简体   繁体   中英

Eclipse RCP update a View after changes in the editor

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM