Search in sources :

Example 1 with NavigatorContentDescriptor

use of org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor 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 2 with NavigatorContentDescriptor

use of org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor 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 3 with NavigatorContentDescriptor

use of org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor 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 4 with NavigatorContentDescriptor

use of org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor 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 5 with NavigatorContentDescriptor

use of org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor in project polymap4-core by Polymap4.

the class NavigatorContentService method restoreState.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.internal.navigator.INavigatorContentService#restoreState
	 * (org.eclipse.ui.IMemento)
	 */
public void restoreState(final IMemento aMemento) {
    synchronized (this) {
        for (Iterator extensionItr = getExtensions().iterator(); extensionItr.hasNext(); ) {
            final NavigatorContentExtension element = (NavigatorContentExtension) extensionItr.next();
            SafeRunner.run(new NavigatorSafeRunnable(((NavigatorContentDescriptor) element.getDescriptor()).getConfigElement()) {

                public void run() throws Exception {
                    element.restoreState(aMemento);
                }
            });
        }
    }
}
Also used : NavigatorContentExtension(org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension) INavigatorContentExtension(org.eclipse.ui.navigator.INavigatorContentExtension) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) INavigatorContentDescriptor(org.eclipse.ui.navigator.INavigatorContentDescriptor) NavigatorContentDescriptor(org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Aggregations

NavigatorContentDescriptor (org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor)17 INavigatorContentDescriptor (org.eclipse.ui.navigator.INavigatorContentDescriptor)17 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Iterator (java.util.Iterator)6 Set (java.util.Set)5 NavigatorContentExtension (org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension)5 HashSet (java.util.HashSet)4 ListIterator (java.util.ListIterator)4 INavigatorContentExtension (org.eclipse.ui.navigator.INavigatorContentExtension)4 LinkedHashSet (java.util.LinkedHashSet)3 SortedSet (java.util.SortedSet)3 TreeSet (java.util.TreeSet)3 SaveablesProvider (org.eclipse.ui.navigator.SaveablesProvider)3 ListenerList (org.eclipse.core.runtime.ListenerList)2 BackingStoreException (org.osgi.service.prefs.BackingStoreException)2 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 Saveable (org.eclipse.ui.Saveable)1