Description/Implementation
IExtensionStateModel is a fairly useful feature in Common Navigator Framework that we could make use of when dealing with multiple content provider.
It allows clients to coordinate state across components that are part of the same logical extension.[1]
That is, a content provider might vary how it exposes its content based on the state of a specific property in the model. Interested parties may add themselves as IPropertyChangeListener to track changes in the state model.
For example, if we want multiple content provider to take instant adjustments and refresh themselves within a specific scope of tree structure and based on a centralized state change, say a Boolean value on one extension, we could simply register a Boolean value to a specific IExtensionStateModel of the sharing content service
public void init(IViewPart view) {
this.view = view;if (view instanceof CommonNavigator) {IExtensionStateModel stateModel = ((CommonNavigator)view).getNavigatorContentService().findStateModel(DSEPlugin.SERVERS_VIEW_CONTENT_EXTENSION_ID);stateModel.setBooleanProperty(DSEPlugin.PROP_SHOW_CATEGORIES,currentState);}}/** The state model stores properties associated with the extension. Each* content extension has its own contained state model. Components of the* extension (content provider, label provider, action providers, etc) may* attach themselves as listeners to the model* and respond to changes to the values of the properties.** @param anExtensionId* The extension id defined by a navigatorContent* extension.* @return The state model for the given extension id.*/IExtensionStateModel findStateModel(String anExtensionId);
Then IPropertyChangeListener could be added from another contentProvider to receive notification on the state model change, and take corresponding adjustments.
private IPropertyChangeListener mPropertyChangeListener = new IPropertyChangeListener() {public void propertyChange(PropertyChangeEvent event) {//DO something}};if (mViewer instanceof CommonViewer) {IExtensionStateModel stateModel = ((CommonViewer) mViewer).getNavigatorContentService().findStateModel(DSE_VIEW_CONTENT_EXTENSION_ID);stateModel.addPropertyChangeListener(mPropertyChangeListener);}
[1] Eclipse Platform API specification – IExtensionStateModel