1 11 12 package org.eclipse.ui.internal.navigator.filters; 13 14 import org.eclipse.core.expressions.Expression; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.jface.viewers.ViewerFilter; 19 import org.eclipse.ui.internal.navigator.CustomAndExpression; 20 import org.eclipse.ui.internal.navigator.NavigatorPlugin; 21 import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants; 22 import org.eclipse.ui.navigator.ICommonFilterDescriptor; 23 24 32 public class CommonFilterDescriptor implements ICommonFilterDescriptor, 33 INavigatorContentExtPtConstants { 34 35 private IConfigurationElement element; 36 37 private Expression filterExpression; 38 39 private String id; 40 41 protected CommonFilterDescriptor(IConfigurationElement anElement) { 42 43 element = anElement; 44 init(); 45 } 46 47 private void init() { 48 id = element.getAttribute(ATT_ID); 49 if (id == null) { 50 id = ""; } 52 IConfigurationElement[] children = element 53 .getChildren(TAG_FILTER_EXPRESSION); 54 if (children.length == 1) { 55 filterExpression = new CustomAndExpression(children[0]); 56 } 57 } 58 59 64 public String getId() { 65 return id; 66 } 67 68 72 public String getName() { 73 return element.getAttribute(ATT_NAME); 74 } 75 76 81 public String getDescription() { 82 return element.getAttribute(ATT_DESCRIPTION); 83 } 84 85 89 public boolean isActiveByDefault() { 90 return Boolean.valueOf(element.getAttribute(ATT_ACTIVE_BY_DEFAULT)) 91 .booleanValue(); 92 } 93 94 100 public ViewerFilter createFilter() { 101 try { 102 103 if (filterExpression != null) { 104 105 if (element.getAttribute(ATT_CLASS) != null) { 106 NavigatorPlugin 107 .log( 108 IStatus.WARNING, 109 0, 110 "A \"commonFilter\" was specified in " + element.getDeclaringExtension().getNamespaceIdentifier() 112 + " which specifies a \"class\" attribute and an Core Expression.\n" + "Only the Core Expression will be respected.", null); 115 } 116 117 return new CoreExpressionFilter(filterExpression); 118 } 119 120 return (ViewerFilter) element.createExecutableExtension(ATT_CLASS); 121 } catch (RuntimeException re) { 122 NavigatorPlugin.logError(0, re.getMessage(), re); 123 } catch (CoreException e) { 124 NavigatorPlugin.logError(0, e.getMessage(), e); 125 } 126 127 return SkeletonViewerFilter.INSTANCE; 128 } 129 130 135 public String toString() { 136 return "CommonFilterDescriptor[" + getName() + " (" + getId() + ")]"; } 138 } 139 | Popular Tags |