KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > console > ConsolePageParticipantExtension


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.console;
12
13 import org.eclipse.core.expressions.EvaluationContext;
14 import org.eclipse.core.expressions.EvaluationResult;
15 import org.eclipse.core.expressions.Expression;
16 import org.eclipse.core.expressions.ExpressionConverter;
17 import org.eclipse.core.expressions.ExpressionTagNames;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IConfigurationElement;
20 import org.eclipse.ui.IPluginContribution;
21 import org.eclipse.ui.console.IConsole;
22 import org.eclipse.ui.console.IConsolePageParticipant;
23
24 public class ConsolePageParticipantExtension implements 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 JavaDoc 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 JavaDoc 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().evaluate(context);
50         return evaluationResult == EvaluationResult.TRUE;
51     }
52     
53     public Expression getEnablementExpression() throws CoreException {
54         if (fEnablementExpression == null) {
55             IConfigurationElement[] elements = fConfig.getChildren(ExpressionTagNames.ENABLEMENT);
56             IConfigurationElement enablement = elements.length > 0 ? elements[0] : null;
57
58             if (enablement != null) {
59                 fEnablementExpression = ExpressionConverter.getDefault().perform(enablement);
60             }
61         }
62         return fEnablementExpression;
63     }
64
65     public IConsolePageParticipant createDelegate() throws CoreException {
66         return (IConsolePageParticipant) fConfig.createExecutableExtension("class"); //$NON-NLS-1$;
67
}
68
69 }
70
Popular Tags