The problem:
Finding a mechanism to keep the same Tabbed Properties view for more than one active view without fighting Eclipse.
Use case example:
Consider 3 views: one that provides a meaningful selection (a tree view for example), one that does not (a graph or a chart associated with the selected item), and a tabbed properties view for the selected item. The chart and the properties need to be visible simultaneously.
Navigating the tree produces the expected results: both other views change accordingly. However, once the tree view becomes inactive (click on the chart) the properties change to "Properties are not available"
Details:
For the views to stay consistent the adapter for IPropertySheetPage.class key from both views needs to be (or refer to) the same instance of TabbedPropertySheetPage. Merely instantiating a new TabbedPropertySheetPage with the same contributor is not sufficient because each instance will keep its own tab selection state, which can result in tab selection changing depending on which view (tree or chart) is active.
Returning the same (cached) instance of TabbedPropertySheetPage from getAdapter() more than once breaks the code because init() and createControl() get called on the adapter every time it's returned.
TabbedPropertySheetPage does not have a shallow clone() that could be a potential solution, depending of course on how clone() is implemented. TabbedPropertySheetPage is not Cloneable at all.
A kludge:
Here is an implementation of getAdapter() method for the tree and for the chart that does the trick, but has a distinct taste of fighting the workbench:
Tree:
private TabbedPropertySheetPage properties;
public TabbedPropertySheetPage getProperties() {
return properties;
}
public Object getAdapter(Class key) {
if (key == IPropertySheetPage.class) {
properties = new TabbedPropertySheetPage(this) {
boolean initialized = false;
public void init(IPageSite site) {
if (!initialized) {
super.init(site);
}
}
public void createControl(Composite parent) {
if (!initialized) {
super.createControl(parent);
initialized = true;
}
}
};
return properties;
}
return super.getAdapter(key);
}
Chart:
public Object getAdapter(Class key) {
if (key == IPropertySheetPage.class) {
return getTreeViewOneWayOrAnother().getProperties();
}
return super.getAdapter(key);
}
Question:
Is there an Eclipse idiom that would accomplish the same thing in a more graceful way?
Thanks!