Search in sources :

Example 1 with Priority

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

the class NavigatorContentDescriptor method init.

/**
 * Parses the configuration element.
 *
 * @throws WorkbenchException
 *             if the configuration element could not be parsed. Reasons
 *             include:
 *             <ul>
 *             <li>A required attribute is missing.</li>
 *             <li>More elements are define than is allowed.</li>
 *             </ul>
 */
private void init() throws WorkbenchException {
    id = configElement.getAttribute(ATT_ID);
    name = configElement.getAttribute(ATT_NAME);
    String priorityString = configElement.getAttribute(ATT_PRIORITY);
    icon = configElement.getAttribute(ATT_ICON);
    String activeByDefaultString = configElement.getAttribute(ATT_ACTIVE_BY_DEFAULT);
    activeByDefault = (activeByDefaultString != null && activeByDefaultString.length() > 0) ? Boolean.valueOf(activeByDefaultString).booleanValue() : true;
    String providesSaveablesString = configElement.getAttribute(ATT_PROVIDES_SAVEABLES);
    providesSaveables = (providesSaveablesString != null && providesSaveablesString.length() > 0) ? Boolean.valueOf(providesSaveablesString).booleanValue() : false;
    appearsBeforeId = configElement.getAttribute(ATT_APPEARS_BEFORE);
    if (priorityString != null) {
        try {
            Priority p = Priority.get(priorityString);
            priority = p != null ? p.getValue() : Priority.NORMAL_PRIORITY_VALUE;
        } catch (NumberFormatException exception) {
            priority = Priority.NORMAL_PRIORITY_VALUE;
        }
    }
    // We start with this because the sort ExtensionPriorityComparator works
    // from the sequenceNumber
    sequenceNumber = priority;
    String sortOnlyString = configElement.getAttribute(ATT_SORT_ONLY);
    sortOnly = (sortOnlyString != null && sortOnlyString.length() > 0) ? Boolean.valueOf(sortOnlyString).booleanValue() : false;
    if (id == null) {
        throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { ATT_ID, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
    }
    contribution = new IPluginContribution() {

        public String getLocalId() {
            return getId();
        }

        public String getPluginId() {
            return configElement.getDeclaringExtension().getNamespaceIdentifier();
        }
    };
    IConfigurationElement[] children;
    children = configElement.getChildren(TAG_INITIAL_ACTIVATION);
    if (children.length > 0) {
        if (children.length == 1) {
            initialActivation = new CustomAndExpression(children[0]);
        } else {
            throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { TAG_INITIAL_ACTIVATION, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
        }
    }
    if (sortOnly)
        return;
    children = configElement.getChildren(TAG_ENABLEMENT);
    if (children.length == 0) {
        children = configElement.getChildren(TAG_TRIGGER_POINTS);
        if (children.length == 1) {
            enablement = new CustomAndExpression(children[0]);
        } else {
            throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { TAG_TRIGGER_POINTS, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
        }
        children = configElement.getChildren(TAG_POSSIBLE_CHILDREN);
        if (children.length == 1) {
            possibleChildren = new CustomAndExpression(children[0]);
        } else if (children.length > 1) {
            throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { TAG_POSSIBLE_CHILDREN, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
        }
    } else if (children.length == 1) {
        try {
            enablement = ElementHandler.getDefault().create(ExpressionConverter.getDefault(), children[0]);
        } catch (CoreException e) {
            NavigatorPlugin.log(IStatus.ERROR, 0, e.getMessage(), e);
        }
    } else if (children.length > 1) {
        throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { TAG_ENABLEMENT, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
    }
    children = configElement.getChildren(TAG_OVERRIDE);
    if (children.length == 0) {
        overridePolicy = OverridePolicy.get(OverridePolicy.InvokeAlwaysRegardlessOfSuppressedExt_LITERAL);
    } else if (children.length == 1) {
        suppressedExtensionId = children[0].getAttribute(ATT_SUPPRESSED_EXT_ID);
        overridePolicy = OverridePolicy.get(children[0].getAttribute(ATT_POLICY));
    } else if (children.length > 1) {
        throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Too_many_elements_Warning, new Object[] { TAG_OVERRIDE, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
    }
}
Also used : CustomAndExpression(org.eclipse.ui.internal.navigator.CustomAndExpression) CoreException(org.eclipse.core.runtime.CoreException) Priority(org.eclipse.ui.navigator.Priority) IPluginContribution(org.eclipse.ui.IPluginContribution) WorkbenchException(org.eclipse.ui.WorkbenchException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IPluginContribution (org.eclipse.ui.IPluginContribution)1 WorkbenchException (org.eclipse.ui.WorkbenchException)1 CustomAndExpression (org.eclipse.ui.internal.navigator.CustomAndExpression)1 Priority (org.eclipse.ui.navigator.Priority)1