1 11 package org.eclipse.ui.internal.navigator; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.expressions.ElementHandler; 18 import org.eclipse.core.expressions.EvaluationResult; 19 import org.eclipse.core.expressions.Expression; 20 import org.eclipse.core.expressions.ExpressionConverter; 21 import org.eclipse.core.expressions.IEvaluationContext; 22 import org.eclipse.core.runtime.Assert; 23 import org.eclipse.core.runtime.CoreException; 24 import org.eclipse.core.runtime.IConfigurationElement; 25 import org.eclipse.core.runtime.IStatus; 26 27 32 public class CustomAndExpression extends Expression { 33 34 protected List fExpressions; 35 36 44 public CustomAndExpression(IConfigurationElement element) { 45 Assert.isNotNull(element); 46 47 IConfigurationElement[] children = element.getChildren(); 48 49 if (children.length > 0) { 50 fExpressions = new ArrayList (); 51 } 52 for (int i = 0; i < children.length; i++) { 53 try { 54 fExpressions.add(ElementHandler.getDefault().create( 55 ExpressionConverter.getDefault(), children[i])); 56 } catch (CoreException ce) { 57 NavigatorPlugin.log(IStatus.ERROR, 0, ce.getMessage(), ce); 58 } 59 } 60 } 61 62 public EvaluationResult evaluate(IEvaluationContext scope) 63 throws CoreException { 64 if (fExpressions == null) { 65 return EvaluationResult.TRUE; 66 } 67 EvaluationResult result = EvaluationResult.TRUE; 68 for (Iterator iter = fExpressions.iterator(); iter.hasNext();) { 69 Expression expression = (Expression) iter.next(); 70 result = result.and(expression.evaluate(scope)); 71 if (result == EvaluationResult.FALSE) { 74 return result; 75 } 76 } 77 return result; 78 } 79 80 } 81 | Popular Tags |