|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2003, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2003, 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 13-22
Link Here
|
| 13 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
| 14 |
import java.util.List; |
14 |
import java.util.List; |
| 15 |
|
15 |
|
|
|
16 |
import org.eclipse.core.expressions.*; |
| 16 |
import org.eclipse.core.resources.IProject; |
17 |
import org.eclipse.core.resources.IProject; |
|
|
18 |
import org.eclipse.core.runtime.CoreException; |
| 17 |
import org.eclipse.core.runtime.IConfigurationElement; |
19 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 18 |
import org.eclipse.core.runtime.IProgressMonitor; |
20 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 19 |
|
|
|
| 20 |
import org.eclipse.wst.server.core.IModule; |
21 |
import org.eclipse.wst.server.core.IModule; |
| 21 |
import org.eclipse.wst.server.core.IModuleType; |
22 |
import org.eclipse.wst.server.core.IModuleType; |
| 22 |
import org.eclipse.wst.server.core.model.InternalInitializer; |
23 |
import org.eclipse.wst.server.core.model.InternalInitializer; |
|
Lines 28-33
Link Here
|
| 28 |
private IConfigurationElement element; |
29 |
private IConfigurationElement element; |
| 29 |
public ModuleFactoryDelegate delegate; |
30 |
public ModuleFactoryDelegate delegate; |
| 30 |
private List<IModuleType> moduleTypes; |
31 |
private List<IModuleType> moduleTypes; |
|
|
32 |
private Expression fContextualLaunchExpr = null; |
| 31 |
|
33 |
|
| 32 |
/** |
34 |
/** |
| 33 |
* ModuleFactory constructor comment. |
35 |
* ModuleFactory constructor comment. |
|
Lines 137-142
Link Here
|
| 137 |
return new IModule[0]; |
139 |
return new IModule[0]; |
| 138 |
} |
140 |
} |
| 139 |
} |
141 |
} |
|
|
142 |
|
| 143 |
/** |
| 144 |
* Returns an expression that represents the enablement logic for the |
| 145 |
* contextual project of this module factory <code>null</code> if none. |
| 146 |
* @return an evaluatable expression or <code>null</code> |
| 147 |
* @throws CoreException if the configuration element can't be |
| 148 |
* converted. Reasons include: (a) no handler is available to |
| 149 |
* cope with a certain configuration element or (b) the XML |
| 150 |
* expression tree is malformed. |
| 151 |
*/ |
| 152 |
protected Expression getContextualLaunchEnablementExpression() throws CoreException { |
| 153 |
if (fContextualLaunchExpr == null) { |
| 154 |
IConfigurationElement[] elements = element.getChildren(ExpressionTagNames.ENABLEMENT); |
| 155 |
IConfigurationElement enablement = (elements != null && elements.length > 0) ? elements[0] : null; |
| 156 |
|
| 157 |
if (enablement != null) |
| 158 |
fContextualLaunchExpr = ExpressionConverter.getDefault().perform(enablement); |
| 159 |
} |
| 160 |
return fContextualLaunchExpr; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Evaluate the given expression within the given context and return |
| 165 |
* the result. Returns <code>true</code> if result is either TRUE or NOT_LOADED. |
| 166 |
* This allows optimistic inclusion before plugins are loaded. |
| 167 |
* Returns <code>true</code> if exp is <code>null</code>. |
| 168 |
* |
| 169 |
* @param exp the enablement expression to evaluate or <code>null</code> |
| 170 |
* @param context the context of the evaluation. |
| 171 |
* @return the result of evaluating the expression |
| 172 |
* @throws CoreException |
| 173 |
*/ |
| 174 |
protected boolean evalEnablementExpression(IEvaluationContext context, Expression exp) throws CoreException { |
| 175 |
// for compatibility with the current behaviour, if the exp == null we return true. Meaning that the factory doesn't |
| 176 |
// implement an expression and should be enabled for all cases. |
| 177 |
return (exp != null) ? ((exp.evaluate(context)) != EvaluationResult.FALSE) : true; |
| 178 |
} |
| 179 |
|
| 180 |
public boolean isEnabled(IProject project, IProgressMonitor monitor) { |
| 181 |
try { |
| 182 |
IEvaluationContext context = new EvaluationContext(null, project); |
| 183 |
context.addVariable("project", project); |
| 184 |
|
| 185 |
return evalEnablementExpression(context, getContextualLaunchEnablementExpression()); |
| 186 |
} catch (Throwable t) { |
| 187 |
Trace.trace(Trace.SEVERE, "Error calling delegate " + toString(), t); |
| 188 |
return false; |
| 189 |
} |
| 190 |
} |
| 140 |
|
191 |
|
| 141 |
/* |
192 |
/* |
| 142 |
* @see ModuleFactoryDelegate#findModule(String) |
193 |
* @see ModuleFactoryDelegate#findModule(String) |