KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > filters > CommonFilterDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

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 /**
25  *
26  * Describes a <b>commonFilter</b> element under a
27  * <b>org.eclipse.ui.navigator.navigatorContent</b> extension.
28  *
29  * @since 3.2
30  *
31  */

32 public class CommonFilterDescriptor implements ICommonFilterDescriptor,
33         INavigatorContentExtPtConstants {
34
35     private IConfigurationElement element;
36
37     private Expression filterExpression;
38
39     private String JavaDoc 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 = ""; //$NON-NLS-1$
51
}
52         IConfigurationElement[] children = element
53                 .getChildren(TAG_FILTER_EXPRESSION);
54         if (children.length == 1) {
55             filterExpression = new CustomAndExpression(children[0]);
56         }
57     }
58
59     /**
60      *
61      * @return An identifier used to determine whether the filter is visible.
62      * May not be unique.
63      */

64     public String JavaDoc getId() {
65         return id;
66     }
67
68     /**
69      *
70      * @return A translated name to identify the filter
71      */

72     public String JavaDoc getName() {
73         return element.getAttribute(ATT_NAME);
74     }
75
76     /**
77      *
78      * @return A translated description to explain to the user what the defined
79      * filter will hide from the view.
80      */

81     public String JavaDoc getDescription() {
82         return element.getAttribute(ATT_DESCRIPTION);
83     }
84
85     /**
86      *
87      * @return Indicates the filter should be in an "Active" state by default.
88      */

89     public boolean isActiveByDefault() {
90         return Boolean.valueOf(element.getAttribute(ATT_ACTIVE_BY_DEFAULT))
91                 .booleanValue();
92     }
93
94     /**
95      *
96      * @return An instance of the ViewerFilter defined by the extension. Callers
97      * of this method are responsible for managing the instantiated
98      * filter.
99      */

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 " + //$NON-NLS-1$
111
element.getDeclaringExtension().getNamespaceIdentifier()
112                                             + " which specifies a \"class\" attribute and an Core Expression.\n" + //$NON-NLS-1$
113
"Only the Core Expression will be respected.", //$NON-NLS-1$
114
null);
115                 }
116
117                 return new CoreExpressionFilter(filterExpression);
118             }
119
120             return (ViewerFilter) element.createExecutableExtension(ATT_CLASS);
121         } catch (RuntimeException JavaDoc 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     /*
131      * (non-Javadoc)
132      *
133      * @see java.lang.Object#toString()
134      */

135     public String JavaDoc toString() {
136         return "CommonFilterDescriptor[" + getName() + " (" + getId() + ")]"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
137
}
138 }
139
Popular Tags