01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.console;
11:
12: import org.eclipse.core.expressions.EvaluationContext;
13: import org.eclipse.core.expressions.EvaluationResult;
14: import org.eclipse.core.expressions.Expression;
15: import org.eclipse.core.expressions.ExpressionConverter;
16: import org.eclipse.core.expressions.ExpressionTagNames;
17: import org.eclipse.core.runtime.CoreException;
18: import org.eclipse.core.runtime.IConfigurationElement;
19: import org.eclipse.ui.IPluginContribution;
20: import org.eclipse.ui.console.IConsole;
21: import org.eclipse.ui.console.IConsolePageParticipant;
22:
23: public class ConsolePageParticipantExtension implements
24: IPluginContribution {
25:
26: private IConfigurationElement fConfig;
27: private Expression fEnablementExpression;
28:
29: public ConsolePageParticipantExtension(IConfigurationElement config) {
30: fConfig = config;
31: }
32:
33: /* (non-Javadoc)
34: * @see org.eclipse.ui.IPluginContribution#getLocalId()
35: */
36: public String getLocalId() {
37: return fConfig.getAttribute("id"); //$NON-NLS-1$
38: }
39:
40: /* (non-Javadoc)
41: * @see org.eclipse.ui.IPluginContribution#getPluginId()
42: */
43: public String getPluginId() {
44: return fConfig.getContributor().getName();
45: }
46:
47: public boolean isEnabledFor(IConsole console) throws CoreException {
48: EvaluationContext context = new EvaluationContext(null, console);
49: EvaluationResult evaluationResult = getEnablementExpression()
50: .evaluate(context);
51: return evaluationResult == EvaluationResult.TRUE;
52: }
53:
54: public Expression getEnablementExpression() throws CoreException {
55: if (fEnablementExpression == null) {
56: IConfigurationElement[] elements = fConfig
57: .getChildren(ExpressionTagNames.ENABLEMENT);
58: IConfigurationElement enablement = elements.length > 0 ? elements[0]
59: : null;
60:
61: if (enablement != null) {
62: fEnablementExpression = ExpressionConverter
63: .getDefault().perform(enablement);
64: }
65: }
66: return fEnablementExpression;
67: }
68:
69: public IConsolePageParticipant createDelegate()
70: throws CoreException {
71: return (IConsolePageParticipant) fConfig
72: .createExecutableExtension("class"); //$NON-NLS-1$;
73: }
74:
75: }
|