1 11 12 package org.eclipse.ui.internal.navigator.sorters; 13 14 import org.eclipse.core.expressions.EvaluationContext; 15 import org.eclipse.core.expressions.EvaluationResult; 16 import org.eclipse.core.expressions.Expression; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.jface.viewers.ViewerSorter; 20 import org.eclipse.ui.internal.navigator.CustomAndExpression; 21 import org.eclipse.ui.internal.navigator.NavigatorPlugin; 22 import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants; 23 24 31 public class CommonSorterDescriptor implements INavigatorContentExtPtConstants { 32 33 private IConfigurationElement element; 34 35 private Expression parentExpression; 36 37 private String id; 38 39 protected CommonSorterDescriptor(IConfigurationElement anElement) { 40 element = anElement; 41 init(); 42 } 43 44 private void init() { 45 id = element.getAttribute(ATT_ID); 46 if (id == null) { 47 id = ""; } 49 IConfigurationElement[] children = element 50 .getChildren(TAG_PARENT_EXPRESSION); 51 if (children.length == 1) { 52 parentExpression = new CustomAndExpression(children[0]); 53 } 54 } 55 56 61 public String getId() { 62 return id; 63 } 64 65 72 public boolean isEnabledForParent(Object aParent) { 73 if(aParent == null) { 74 return false; 75 } 76 77 if (parentExpression != null) { 78 EvaluationContext context = new EvaluationContext(null, aParent); 79 context.setAllowPluginActivation(true); 80 try { 81 return parentExpression.evaluate(context) == EvaluationResult.TRUE; 82 } catch (CoreException e) { 83 NavigatorPlugin.logError(0, e.getMessage(), e); 84 } 85 } 86 return true; 87 } 88 89 95 public ViewerSorter createSorter() { 96 try { 97 return (ViewerSorter) element.createExecutableExtension(ATT_CLASS); 98 } catch (RuntimeException re) { 99 NavigatorPlugin.logError(0, re.getMessage(), re); 100 } catch (CoreException e) { 101 NavigatorPlugin.logError(0, e.getMessage(), e); 102 } 103 return SkeletonViewerSorter.INSTANCE; 104 } 105 106 111 public String toString() { 112 return "CommonSorterDescriptor[" + getId() + "]"; } 114 } 115 | Popular Tags |