use of org.eclipse.ui.navigator.SaveablesProvider in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method getSaveable.
/**
* @param element
* @return the saveable associated with the given element
*/
private Saveable getSaveable(Object element) {
if (saveablesProviderMap == null) {
// has the side effect of recomputing saveablesProviderMap:
getSaveablesProviders();
}
for (Iterator sItr = saveablesProviderMap.keySet().iterator(); sItr.hasNext(); ) {
NavigatorContentDescriptor descriptor = (NavigatorContentDescriptor) sItr.next();
if (descriptor.isTriggerPoint(element) || descriptor.isPossibleChild(element)) {
SaveablesProvider provider = (SaveablesProvider) saveablesProviderMap.get(descriptor);
Saveable saveable = provider.getSaveable(element);
if (saveable != null) {
return saveable;
}
}
}
return null;
}
use of org.eclipse.ui.navigator.SaveablesProvider in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method createSaveablesProvider.
/**
* @param descriptor
* @return the SaveablesProvider, or null
*/
private SaveablesProvider createSaveablesProvider(NavigatorContentDescriptor descriptor) {
NavigatorContentExtension extension = contentService.getExtension(descriptor, true);
// Use getContentProvider to get the client objects, this is important
// for the adaptation below. See bug 306545
ITreeContentProvider contentProvider = extension.getContentProvider();
return (SaveablesProvider) AdaptabilityUtility.getAdapter(contentProvider, SaveablesProvider.class);
}
use of org.eclipse.ui.navigator.SaveablesProvider in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method updateSaveablesProviders.
/**
* @param startedBundleId
*/
private void updateSaveablesProviders(String startedBundleId) {
List result = new ArrayList(Arrays.asList(saveablesProviders));
List descriptors = (List) inactivePluginsWithSaveablesProviders.get(startedBundleId);
for (Iterator it = descriptors.iterator(); it.hasNext(); ) {
NavigatorContentDescriptor descriptor = (NavigatorContentDescriptor) it.next();
SaveablesProvider saveablesProvider = createSaveablesProvider(descriptor);
if (saveablesProvider != null) {
saveablesProvider.init(saveablesLifecycleListener);
result.add(saveablesProvider);
saveablesProviderMap.put(descriptor, saveablesProvider);
}
}
saveablesProviders = (SaveablesProvider[]) result.toArray(new SaveablesProvider[result.size()]);
}
use of org.eclipse.ui.navigator.SaveablesProvider in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method getSaveablesProviders.
/**
* @return all SaveablesProvider objects
*/
private SaveablesProvider[] getSaveablesProviders() {
// TODO optimize this
if (saveablesProviders == null) {
inactivePluginsWithSaveablesProviders = new HashMap();
saveablesProviderMap = new TreeMap(ExtensionSequenceNumberComparator.INSTANCE);
INavigatorContentDescriptor[] descriptors = contentService.getActiveDescriptorsWithSaveables();
List result = new ArrayList();
for (int i = 0; i < descriptors.length; i++) {
NavigatorContentDescriptor descriptor = (NavigatorContentDescriptor) descriptors[i];
String pluginId = ((NavigatorContentDescriptor) descriptor).getContribution().getPluginId();
if (Platform.getBundle(pluginId).getState() != Bundle.ACTIVE) {
List inactiveDescriptors = (List) inactivePluginsWithSaveablesProviders.get(pluginId);
if (inactiveDescriptors == null) {
inactiveDescriptors = new ArrayList();
inactivePluginsWithSaveablesProviders.put(pluginId, inactiveDescriptors);
}
inactiveDescriptors.add(descriptor);
} else {
SaveablesProvider saveablesProvider = createSaveablesProvider(descriptor);
if (saveablesProvider != null) {
saveablesProvider.init(saveablesLifecycleListener);
result.add(saveablesProvider);
saveablesProviderMap.put(descriptor, saveablesProvider);
}
}
}
saveablesProviders = (SaveablesProvider[]) result.toArray(new SaveablesProvider[result.size()]);
}
return saveablesProviders;
}
use of org.eclipse.ui.navigator.SaveablesProvider in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method computeSaveables.
/**
* helper to compute the saveables for which elements are part of the tree.
* Must be called from a synchronized method.
*
* @return the saveables
*/
private Saveable[] computeSaveables() {
ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
boolean isTreepathContentProvider = contentProvider instanceof ITreePathContentProvider;
Object viewerInput = viewer.getInput();
List result = new ArrayList();
Set roots = new HashSet(Arrays.asList(contentProvider.getElements(viewerInput)));
SaveablesProvider[] saveablesProviders = getSaveablesProviders();
for (int i = 0; i < saveablesProviders.length; i++) {
SaveablesProvider saveablesProvider = saveablesProviders[i];
Saveable[] saveables = saveablesProvider.getSaveables();
for (int j = 0; j < saveables.length; j++) {
Saveable saveable = saveables[j];
Object[] elements = saveablesProvider.getElements(saveable);
// the saveable is added to the result if at least one of the
// elements representing the saveable appears in the tree, i.e.
// if its parent chain leads to a root node.
boolean foundRoot = false;
for (int k = 0; !foundRoot && k < elements.length; k++) {
Object element = elements[k];
if (roots.contains(element)) {
result.add(saveable);
foundRoot = true;
} else if (isTreepathContentProvider) {
ITreePathContentProvider treePathContentProvider = (ITreePathContentProvider) contentProvider;
TreePath[] parentPaths = treePathContentProvider.getParents(element);
for (int l = 0; !foundRoot && l < parentPaths.length; l++) {
TreePath parentPath = parentPaths[l];
for (int m = 0; !foundRoot && m < parentPath.getSegmentCount(); m++) {
if (roots.contains(parentPath.getSegment(m))) {
result.add(saveable);
foundRoot = true;
}
}
}
} else {
while (!foundRoot && element != null) {
if (roots.contains(element)) {
// found a parent chain leading to a root. The
// saveable is part of the tree.
result.add(saveable);
foundRoot = true;
} else {
element = contentProvider.getParent(element);
}
}
}
}
}
}
return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
Aggregations