1 11 package org.eclipse.ui.internal.console; 12 13 import java.net.URL ; 14 15 import org.eclipse.core.expressions.EvaluationContext; 16 import org.eclipse.core.expressions.EvaluationResult; 17 import org.eclipse.core.expressions.Expression; 18 import org.eclipse.core.expressions.ExpressionConverter; 19 import org.eclipse.core.expressions.ExpressionTagNames; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.FileLocator; 22 import org.eclipse.core.runtime.IConfigurationElement; 23 import org.eclipse.core.runtime.Path; 24 import org.eclipse.core.runtime.Platform; 25 import org.eclipse.jface.resource.ImageDescriptor; 26 import org.eclipse.ui.IPluginContribution; 27 import org.eclipse.ui.console.ConsolePlugin; 28 import org.eclipse.ui.console.IConsoleFactory; 29 import org.osgi.framework.Bundle; 30 31 34 public class ConsoleFactoryExtension implements IPluginContribution { 35 36 private IConfigurationElement fConfig; 37 private Expression fEnablementExpression; 38 private String fLabel; 39 private ImageDescriptor fImageDescriptor; 40 private IConsoleFactory fFactory; 41 42 ConsoleFactoryExtension(IConfigurationElement config) { 43 fConfig = config; 44 } 45 46 49 public String getLocalId() { 50 return fConfig.getAttribute("id"); } 52 53 56 public String getPluginId() { 57 return fConfig.getContributor().getName(); 58 } 59 60 public boolean isEnabled() { 61 try { 62 Expression enablementExpression = getEnablementExpression(); 63 if (enablementExpression == null) { 64 return true; 65 } 66 EvaluationContext context = new EvaluationContext(null, this); 67 EvaluationResult evaluationResult = enablementExpression.evaluate(context); 68 return evaluationResult != EvaluationResult.FALSE; 69 } catch (CoreException e) { 70 ConsolePlugin.log(e); 71 return false; 72 } 73 } 74 75 public Expression getEnablementExpression() throws CoreException { 76 if (fEnablementExpression == null) { 77 IConfigurationElement[] elements = fConfig.getChildren(ExpressionTagNames.ENABLEMENT); 78 IConfigurationElement enablement = elements.length > 0 ? elements[0] : null; 79 80 if (enablement != null) { 81 fEnablementExpression = ExpressionConverter.getDefault().perform(enablement); 82 } 83 } 84 return fEnablementExpression; 85 } 86 87 public String getLabel() { 88 if (fLabel == null) { 89 fLabel = fConfig.getAttribute("label"); } 91 return fLabel; 92 } 93 94 97 public ImageDescriptor getImageDescriptor() { 98 if (fImageDescriptor == null) { 99 String path = fConfig.getAttribute("icon"); if (path != null) { 101 Bundle bundle = Platform.getBundle(getPluginId()); 102 URL url = FileLocator.find(bundle, new Path(path), null); 103 if (url != null) { 104 fImageDescriptor = ImageDescriptor.createFromURL(url); 105 } 106 } 107 } 108 return fImageDescriptor; 109 } 110 111 115 public IConsoleFactory createFactory() throws CoreException { 116 if (fFactory == null) { 117 fFactory = (IConsoleFactory) fConfig.createExecutableExtension("class"); } 119 return fFactory; 120 } 121 } 122 | Popular Tags |