How to refresh the properties view in Eclipse RCP?
I am using the properties view in RCP, i.e org.eclipse.ui.views.properties.PropertySheet
.
I want to be able to refresh the content of these properties programmatically. It seems RCP is geared towards the use case where this changes only when a selection changes.
Is there any way I can fire a dummy event to get开发者_运维问答 this to refresh (without having ugly UI artifacts such as visibly switching between parts) ?
The main problem is that the API hides all the pages (PropertySheetPage) and therefore viewers (PropertySheetViewer) within the properties view.
Good news is, you can tell the properties view to use a page of your desire. So I supply the page that it would normally use by default (PropertySheetPage), except when I supply it, I keep a reference to it (obviously), and then you can call propertySheetPageRef.refresh()
to update the model (thankfully this method is public).
public Object getAdapter(Class adapter) {
if (adapter == IPropertySource.class) {
return resultProvider;
} else if (adapter == IPropertySheetPage.class) {
return propertySheetPage;
}
return null;
}
Correction on geejay's answer: the getAdapter method is in the view (not in the object you are showing properties for).
Sample implementation (in your view's class):
//IPropertySheetPage doesn't implement refresh()
private PropertySheetPage propertyPage;
/**
* If called from UI thread, refreshes property page from model
* (an IPropertySource). If called from non-UI thread, does nothing.
*/
public void refreshPropertyPage() {
if (propertyPage != null) {
propertyPage.refresh();
}
}
@Override
public Object getAdapter(Class adapter) {
if (adapter == IPropertySheetPage.class) {
if (propertyPage == null) {
propertyPage = new PropertySheetPage();
}
return propertyPage;
}
//use platform's adapter manager for other classes
return super.getAdapter(adapter);
}
精彩评论