下面列出了org.eclipse.ui.handlers.IHandlerActivation#org.eclipse.core.expressions.Expression 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ViewInstanceDescriptor ( final String id, final String parentId, final ViewInstanceFactory factory, final URI uri, final String name, final int order, final boolean defaultInstance, final Boolean zooming, final Expression lazyExpression, final Expression visibleExpression, final Expression defaultInstanceExpression, final String summaryConnectionId, final String summaryItemId, final boolean mainView, final Map<String, String> properties )
{
super ();
this.id = id;
this.parentId = parentId;
this.factory = factory;
this.uri = uri;
this.name = name;
this.properties = properties;
this.order = order;
this.defaultInstance = defaultInstance;
this.zooming = zooming;
this.lazyExpression = lazyExpression;
this.visibleExpression = visibleExpression;
this.defaultInstanceExpression = defaultInstanceExpression;
this.summaryConnectionId = summaryConnectionId;
this.summaryItemId = summaryItemId;
this.mainView = mainView;
}
public boolean matches(IJavaProject javaProject) {
if (fStatus != null) {
return fStatus.booleanValue();
}
IConfigurationElement[] children= fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT);
if (children.length == 1) {
try {
ExpressionConverter parser= ExpressionConverter.getDefault();
Expression expression= parser.perform(children[0]);
EvaluationContext evalContext= new EvaluationContext(null, javaProject);
evalContext.addVariable("project", javaProject); //$NON-NLS-1$
evalContext.addVariable("sourceLevel", javaProject.getOption(JavaCore.COMPILER_SOURCE, true)); //$NON-NLS-1$
return expression.evaluate(evalContext) == EvaluationResult.TRUE;
} catch (CoreException e) {
JavaPlugin.log(e);
}
return false;
}
fStatus= Boolean.FALSE;
return false;
}
public static EditPart createEditPart( EditPart context, Object model )
{
EvaluationContext econtext = new EvaluationContext( null, model );
for ( Iterator<Expression> iterator = extensionMap.keySet( ).iterator( ); iterator.hasNext( ); )
{
try
{
Expression expression = iterator.next( );
if ( expression.evaluate( econtext ) == EvaluationResult.TRUE )
{
EditPart editPart = (EditPart) extensionMap.get( expression )
.createExecutableExtension( "type" ); //$NON-NLS-1$
editPart.setModel( model );
return editPart;
}
}
catch ( CoreException e )
{
logger.log( Level.SEVERE, e.getMessage( ), e );
}
}
return null;
}
/** Verify that a node is a valid expression. */
protected static Expression checkExpression(Element expression) {
try {
Expression converted = ExpressionConverter.getDefault().perform(expression);
Assert.assertNotNull(converted);
return converted;
} catch (CoreException ex) {
throw new AssertionError("failed to convert to core expression", ex);
}
}
@Test
public void testNavigatorContentTriggerExpression_normalProject() throws CoreException {
Element triggerPoints =
findElement(
"//plugin/extension[@point='org.eclipse.ui.navigator.navigatorContent']"
+ "/navigatorContent[@id='com.google.cloud.tools.eclipse.appengine.navigator']"
+ "/triggerPoints/*");
Expression triggerExpression = checkExpression(triggerPoints);
assertEquals(
EvaluationResult.FALSE,
triggerExpression.evaluate(new EvaluationContext(null, projectCreator.getProject())));
}
@Test
public void testNavigatorContentTriggerExpression_appEngineStandardJavaProject()
throws CoreException {
Element triggerPoints =
findElement(
"//plugin/extension[@point='org.eclipse.ui.navigator.navigatorContent']"
+ "/navigatorContent[@id='com.google.cloud.tools.eclipse.appengine.navigator']"
+ "/triggerPoints/*");
Expression triggerExpression = checkExpression(triggerPoints);
projectCreator.withFacets(
AppEngineStandardFacet.JRE7, JavaFacet.VERSION_1_7, WebFacetUtils.WEB_25);
assertEquals(
EvaluationResult.TRUE,
triggerExpression.evaluate(new EvaluationContext(null, projectCreator.getProject())));
}
@Test
public void testNavigatorContentTriggerExpression_appEngineFlexibleWarJavaProject()
throws CoreException {
Element triggerPoints =
findElement(
"//plugin/extension[@point='org.eclipse.ui.navigator.navigatorContent']"
+ "/navigatorContent[@id='com.google.cloud.tools.eclipse.appengine.navigator']"
+ "/triggerPoints/*");
Expression triggerExpression = checkExpression(triggerPoints);
projectCreator.withFacets(
AppEngineFlexWarFacet.FACET_VERSION, JavaFacet.VERSION_1_8, WebFacetUtils.WEB_31);
assertEquals(
EvaluationResult.TRUE,
triggerExpression.evaluate(new EvaluationContext(null, projectCreator.getProject())));
}
@Test
public void testNavigatorContentTriggerExpression_appEngineFlexibleJarJavaProject()
throws CoreException {
Element triggerPoints =
findElement(
"//plugin/extension[@point='org.eclipse.ui.navigator.navigatorContent']"
+ "/navigatorContent[@id='com.google.cloud.tools.eclipse.appengine.navigator']"
+ "/triggerPoints/*");
Expression triggerExpression = checkExpression(triggerPoints);
projectCreator.withFacets(AppEngineFlexJarFacet.FACET_VERSION, JavaFacet.VERSION_1_8);
assertEquals(
EvaluationResult.TRUE,
triggerExpression.evaluate(new EvaluationContext(null, projectCreator.getProject())));
}
@Test
public void testNavigatorContentActionProvider() throws CoreException {
Element actionProvider =
findElement(
"//plugin/extension[@point='org.eclipse.ui.navigator.navigatorContent']"
+ "/navigatorContent[@id='com.google.cloud.tools.eclipse.appengine.navigator']"
+ "/actionProvider");
assertEquals(AppEngineActionProvider.class.getName(), actionProvider.getAttribute("class"));
assertEquals(
"com.google.cloud.tools.eclipse.appengine.facets.ui.navigator.actions",
actionProvider.getAttribute("id"));
Element actionProviderEnablement = findElement("enablement/*", actionProvider);
Expression enablementExpression = checkExpression(actionProviderEnablement);
assertEquals(
EvaluationResult.TRUE,
enablementExpression.evaluate(
new EvaluationContext(null, mock(AppEngineProjectElement.class))));
assertEquals(
EvaluationResult.TRUE,
enablementExpression.evaluate(new EvaluationContext(null, mock(CronDescriptor.class))));
assertEquals(
EvaluationResult.TRUE,
enablementExpression.evaluate(
new EvaluationContext(null, mock(DenialOfServiceDescriptor.class))));
assertEquals(
EvaluationResult.TRUE,
enablementExpression.evaluate(
new EvaluationContext(null, mock(DispatchRoutingDescriptor.class))));
assertEquals(
EvaluationResult.TRUE,
enablementExpression.evaluate(
new EvaluationContext(null, mock(DatastoreIndexesDescriptor.class))));
assertEquals(
EvaluationResult.TRUE,
enablementExpression.evaluate(
new EvaluationContext(null, mock(TaskQueuesDescriptor.class))));
}
private boolean matches(ICompilationUnit cunit) {
if (fRequiredSourceLevel != null) {
String current= cunit.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true);
if (JavaModelUtil.isVersionLessThan(current, fRequiredSourceLevel)) {
return false;
}
}
if (fStatus != null) {
return fStatus.booleanValue();
}
IConfigurationElement[] children= fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT);
if (children.length == 1) {
try {
ExpressionConverter parser= ExpressionConverter.getDefault();
Expression expression= parser.perform(children[0]);
EvaluationContext evalContext= new EvaluationContext(null, cunit);
evalContext.addVariable("compilationUnit", cunit); //$NON-NLS-1$
IJavaProject javaProject= cunit.getJavaProject();
String[] natures= javaProject.getProject().getDescription().getNatureIds();
evalContext.addVariable("projectNatures", Arrays.asList(natures)); //$NON-NLS-1$
evalContext.addVariable("sourceLevel", javaProject.getOption(JavaCore.COMPILER_SOURCE, true)); //$NON-NLS-1$
return expression.evaluate(evalContext) == EvaluationResult.TRUE;
} catch (CoreException e) {
JavaPlugin.log(e);
}
return false;
}
fStatus= Boolean.FALSE;
return false;
}
public Expression getDefaultInstanceExpression ()
{
return this.defaultInstanceExpression;
}
public Expression getLazyExpression ()
{
return this.lazyExpression;
}
public Expression getVisibleExpression ()
{
return this.visibleExpression;
}
public Expression getExpression( )
{
return expression;
}
public void setExpression( Expression expression )
{
this.expression = expression;
}
/**
* Returns the enablement element of the described extension.
*
* @return the enablement expression or <code>null</code> if it is not specified
* @since 3.8.1
*/
Expression getEnablementExpression() {
return fEnablementExpression;
}