Search in sources :

Example 1 with ExpressionConverter

use of org.eclipse.core.expressions.ExpressionConverter in project eclipse.platform.text by eclipse.

the class GenericContentTypeRelatedExtension method buildEnabledWhen.

/**
 * Returns the expression {@link Expression} declared in the
 * <code>enabledWhen</code> element.
 *
 * @param configElement the configuration element
 * @return the expression {@link Expression} declared in the enabledWhen
 *         element.
 * @throws CoreException when enabledWhen expression is not valid.
 */
private static Expression buildEnabledWhen(IConfigurationElement configElement) throws CoreException {
    final IConfigurationElement[] children = configElement.getChildren(ENABLED_WHEN_ATTRIBUTE);
    if (children.length > 0) {
        IConfigurationElement[] subChildren = children[0].getChildren();
        if (subChildren.length != 1) {
            throw new CoreException(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, // $NON-NLS-1$
            "One <enabledWhen> element is accepted. Disabling " + configElement.getAttribute(ID_ATTRIBUTE)));
        }
        final ElementHandler elementHandler = ElementHandler.getDefault();
        final ExpressionConverter converter = ExpressionConverter.getDefault();
        return elementHandler.create(converter, subChildren[0]);
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ExpressionConverter(org.eclipse.core.expressions.ExpressionConverter) ElementHandler(org.eclipse.core.expressions.ElementHandler) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 2 with ExpressionConverter

use of org.eclipse.core.expressions.ExpressionConverter in project eclipse.platform.text by eclipse.

the class CodeMiningProviderDescriptor method createEnabledWhen.

/**
 * Returns the expression {@link Expression} declared in the
 * <code>enabledWhen</code> element.
 *
 * @param configElement
 *            the configuration element
 * @param id
 *            the id of the codemining provider.
 * @return the expression {@link Expression} declared in the enabledWhen
 *         element.
 * @throws CoreException
 *             when enabledWhen expression is not valid.
 */
private static Expression createEnabledWhen(IConfigurationElement configElement, String id) throws CoreException {
    final IConfigurationElement[] children = configElement.getChildren(ENABLED_WHEN_ATTR);
    if (children.length > 0) {
        IConfigurationElement[] subChildren = children[0].getChildren();
        if (subChildren.length != 1) {
            throw new CoreException(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, // $NON-NLS-1$
            "One <enabledWhen> element is accepted. Disabling " + id));
        }
        final ElementHandler elementHandler = ElementHandler.getDefault();
        final ExpressionConverter converter = ExpressionConverter.getDefault();
        return elementHandler.create(converter, subChildren[0]);
    }
    throw new CoreException(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, // $NON-NLS-1$
    "<enabledWhen> element is required. Disabling " + id));
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ExpressionConverter(org.eclipse.core.expressions.ExpressionConverter) ElementHandler(org.eclipse.core.expressions.ElementHandler) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Aggregations

ElementHandler (org.eclipse.core.expressions.ElementHandler)2 ExpressionConverter (org.eclipse.core.expressions.ExpressionConverter)2 CoreException (org.eclipse.core.runtime.CoreException)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2