Search in sources :

Example 6 with INavigatorContentDescriptor

use of org.eclipse.ui.navigator.INavigatorContentDescriptor in project polymap4-core by Polymap4.

the class NavigatorActivationService method revertExtensionActivations.

private void revertExtensionActivations() {
    IEclipsePreferences prefs = NavigatorContentService.getPreferencesRoot();
    String activatedExtensionsString = prefs.get(getPreferenceKey(), null);
    if (activatedExtensionsString != null && activatedExtensionsString.length() > 0) {
        String[] contentExtensionIds = activatedExtensionsString.split(DELIM);
        String id = null;
        String booleanString = null;
        int indx = 0;
        for (int i = 0; i < contentExtensionIds.length; i++) {
            if ((indx = contentExtensionIds[i].indexOf(EQUALS)) > -1) {
                // up to but not including the equals
                id = contentExtensionIds[i].substring(0, indx);
                booleanString = contentExtensionIds[i].substring(indx + 1, contentExtensionIds[i].length());
                activatedExtensionsMap.put(id, Boolean.valueOf(booleanString));
            } else {
                // IS THIS THE RIGHT WAY TO HANDLE THIS CASE?
                NavigatorContentDescriptor descriptor = CONTENT_DESCRIPTOR_REGISTRY.getContentDescriptor(contentExtensionIds[i]);
                if (descriptor != null)
                    activatedExtensionsMap.put(id, Boolean.valueOf(descriptor.isActiveByDefault()));
            }
        }
    } else {
        /*
			 * We add the default activation of every known extension, even
			 * though some may not be bound to the associated content service;
			 * this is because they could be bound at a later time through the
			 * programmatic binding mechanism in INavigatorContentService.
			 */
        INavigatorContentDescriptor[] contentDescriptors = CONTENT_DESCRIPTOR_REGISTRY.getAllContentDescriptors();
        for (int i = 0; i < contentDescriptors.length; i++) {
            if (contentDescriptors[i].isActiveByDefault()) {
                activatedExtensionsMap.put(contentDescriptors[i].getId(), Boolean.TRUE);
            }
        }
    }
}
Also used : INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) NavigatorContentDescriptor(org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor)

Example 7 with INavigatorContentDescriptor

use of org.eclipse.ui.navigator.INavigatorContentDescriptor in project polymap4-core by Polymap4.

the class NavigatorActivationService method deactivateExtensions.

public INavigatorContentDescriptor[] deactivateExtensions(String[] extensionIds, boolean toEnableAllOthers) {
    Set activatedDescriptors = new HashSet();
    setActive(extensionIds, false);
    if (toEnableAllOthers) {
        NavigatorContentDescriptor[] descriptors = CONTENT_DESCRIPTOR_REGISTRY.getAllContentDescriptors();
        List descriptorList = new ArrayList(Arrays.asList(descriptors));
        for (int descriptorIndx = 0; descriptorIndx < descriptors.length; descriptorIndx++) {
            for (int extId = 0; extId < extensionIds.length; extId++) {
                if (descriptors[descriptorIndx].getId().equals(extensionIds[extId])) {
                    descriptorList.remove(descriptors[descriptorIndx]);
                }
            }
        }
        String[] activatedExtensions = new String[descriptorList.size()];
        for (int i = 0; i < descriptorList.size(); i++) {
            NavigatorContentDescriptor descriptor = (NavigatorContentDescriptor) descriptorList.get(i);
            activatedExtensions[i] = descriptor.getId();
            activatedDescriptors.add(descriptor);
        }
        setActive(activatedExtensions, true);
    }
    if (activatedDescriptors.size() == 0) {
        return NO_DESCRIPTORS;
    }
    return (INavigatorContentDescriptor[]) activatedDescriptors.toArray(new NavigatorContentDescriptor[activatedDescriptors.size()]);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ListenerList(org.eclipse.core.runtime.ListenerList) ArrayList(java.util.ArrayList) List(java.util.List) NavigatorContentDescriptor(org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) HashSet(java.util.HashSet)

Example 8 with INavigatorContentDescriptor

use of org.eclipse.ui.navigator.INavigatorContentDescriptor in project polymap4-core by Polymap4.

the class NavigatorContentService method getExtension.

/**
 * @param aDescriptorKey
 * @param toLoadIfNecessary
 *            True if the extension should be loaded if it is not already.
 * @return The instance of the extension for the given descriptor key.
 */
public final NavigatorContentExtension getExtension(INavigatorContentDescriptor aDescriptorKey, boolean toLoadIfNecessary) {
    /* Query and return the relevant descriptor instance */
    NavigatorContentExtension extension = (NavigatorContentExtension) contentExtensions.get(aDescriptorKey);
    if (extension != null || !toLoadIfNecessary) {
        return extension;
    }
    /*
		 * If the descriptor instance hasn't been created yet, then we need to
		 * (1) verify that it wasn't added by another thread, (2) create and add
		 * the result into the map
		 */
    synchronized (this) {
        extension = (NavigatorContentExtension) contentExtensions.get(aDescriptorKey);
        if (extension == null) {
            contentExtensions.put(aDescriptorKey, (extension = new NavigatorContentExtension((NavigatorContentDescriptor) aDescriptorKey, this, structuredViewerManager)));
            notifyListeners(extension);
        }
    }
    return extension;
}
Also used : NavigatorContentExtension(org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension) INavigatorContentExtension(org.eclipse.ui.navigator.INavigatorContentExtension) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) NavigatorContentDescriptor(org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor)

Example 9 with INavigatorContentDescriptor

use of org.eclipse.ui.navigator.INavigatorContentDescriptor in project polymap4-core by Polymap4.

the class NavigatorContentService method getVisibleExtensions.

public INavigatorContentDescriptor[] getVisibleExtensions() {
    List visibleDescriptors = new ArrayList();
    NavigatorContentDescriptor[] descriptors = CONTENT_DESCRIPTOR_REGISTRY.getAllContentDescriptors();
    for (int i = 0; i < descriptors.length; i++) {
        if (assistant.isVisible(descriptors[i].getId())) {
            visibleDescriptors.add(descriptors[i]);
        }
    }
    if (visibleDescriptors.isEmpty()) {
        return NO_DESCRIPTORS;
    }
    return (INavigatorContentDescriptor[]) visibleDescriptors.toArray(new INavigatorContentDescriptor[visibleDescriptors.size()]);
}
Also used : INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) NavigatorContentDescriptor(org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor)

Example 10 with INavigatorContentDescriptor

use of org.eclipse.ui.navigator.INavigatorContentDescriptor in project polymap4-core by Polymap4.

the class NavigatorContentServiceContentProvider method internalGetChildren.

private Object[] internalGetChildren(final Object aParentElement, final Object aParentElementOrPath, final Set enabledExtensions, final boolean elements) {
    if (enabledExtensions.size() == 0) {
        return NO_CHILDREN;
    }
    final Set finalSet = new LinkedHashSet();
    final ContributorTrackingSet localSet = new ContributorTrackingSet(contentService);
    for (final Iterator itr = enabledExtensions.iterator(); itr.hasNext(); ) {
        SafeRunner.run(new NavigatorSafeRunnable() {

            NavigatorContentExtension foundExtension = (NavigatorContentExtension) itr.next();

            Object[] contributedChildren = null;

            NavigatorContentExtension[] overridingExtensions;

            public void run() throws Exception {
                if (!isOverridingExtensionInSet(foundExtension.getDescriptor(), enabledExtensions)) {
                    if (elements)
                        contributedChildren = foundExtension.internalGetContentProvider().getElements(aParentElementOrPath);
                    else
                        contributedChildren = foundExtension.internalGetContentProvider().getChildren(aParentElementOrPath);
                    overridingExtensions = foundExtension.getOverridingExtensionsForTriggerPoint(aParentElement);
                    INavigatorContentDescriptor foundDescriptor = foundExtension.getDescriptor();
                    localSet.setContributor(foundDescriptor, foundDescriptor);
                    localSet.setContents(contributedChildren);
                    if (overridingExtensions.length > 0) {
                        pipelineChildren(aParentElement, overridingExtensions, foundDescriptor, localSet, elements);
                    }
                    finalSet.addAll(localSet);
                }
            }

            public void handleException(Throwable e) {
                NavigatorPlugin.logError(0, NLS.bind(CommonNavigatorMessages.Exception_Invoking_Extension, new Object[] { foundExtension.getDescriptor().getId(), aParentElement }), e);
            }
        });
    }
    return finalSet.toArray();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) NavigatorContentExtension(org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension) Iterator(java.util.Iterator)

Aggregations

INavigatorContentDescriptor (org.eclipse.ui.navigator.INavigatorContentDescriptor)23 Set (java.util.Set)10 NavigatorContentDescriptor (org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor)10 ArrayList (java.util.ArrayList)7 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 HashSet (java.util.HashSet)6 Iterator (java.util.Iterator)6 SortedSet (java.util.SortedSet)4 TreeSet (java.util.TreeSet)4 ListIterator (java.util.ListIterator)3 NavigatorContentExtension (org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension)3 INavigatorContentExtension (org.eclipse.ui.navigator.INavigatorContentExtension)3 ListenerList (org.eclipse.core.runtime.ListenerList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TableItem (org.eclipse.swt.widgets.TableItem)2 ICommonFilterDescriptor (org.eclipse.ui.navigator.ICommonFilterDescriptor)2 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1