Search in sources :

Example 1 with SaveablesProvider

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;
}
Also used : Saveable(org.eclipse.ui.Saveable) Iterator(java.util.Iterator) NavigatorContentDescriptor(org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) SaveablesProvider(org.eclipse.ui.navigator.SaveablesProvider)

Example 2 with SaveablesProvider

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);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) NavigatorContentExtension(org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension) SaveablesProvider(org.eclipse.ui.navigator.SaveablesProvider)

Example 3 with SaveablesProvider

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()]);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) NavigatorContentDescriptor(org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) SaveablesProvider(org.eclipse.ui.navigator.SaveablesProvider)

Example 4 with SaveablesProvider

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;
}
Also used : INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) NavigatorContentDescriptor(org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) SaveablesProvider(org.eclipse.ui.navigator.SaveablesProvider)

Example 5 with SaveablesProvider

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()]);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Saveable(org.eclipse.ui.Saveable) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) TreePath(org.eclipse.jface.viewers.TreePath) ITreePathContentProvider(org.eclipse.jface.viewers.ITreePathContentProvider) ArrayList(java.util.ArrayList) List(java.util.List) SaveablesProvider(org.eclipse.ui.navigator.SaveablesProvider) HashSet(java.util.HashSet)

Aggregations

SaveablesProvider (org.eclipse.ui.navigator.SaveablesProvider)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NavigatorContentDescriptor (org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor)3 INavigatorContentDescriptor (org.eclipse.ui.navigator.INavigatorContentDescriptor)3 Iterator (java.util.Iterator)2 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)2 Saveable (org.eclipse.ui.Saveable)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 ITreePathContentProvider (org.eclipse.jface.viewers.ITreePathContentProvider)1 TreePath (org.eclipse.jface.viewers.TreePath)1 NavigatorContentExtension (org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension)1