KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > rulers > RulerColumnTarget


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 package org.eclipse.ui.internal.texteditor.rulers;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.core.runtime.content.IContentType;
16
17 /**
18  * Describes the target of a contribution to the <code>org.eclipse.ui.texteditor.rulerColumns</code>
19  * extension point.
20  *
21  * @since 3.3
22  */

23 public abstract class RulerColumnTarget {
24     public abstract boolean matchesEditorId(String JavaDoc editorId);
25     public abstract boolean matchesContentType(IContentType contentType);
26     public abstract boolean matchesClass(Class JavaDoc clazz);
27
28     /* package visible */
29     RulerColumnTarget() {
30     }
31
32     public static RulerColumnTarget createAllTarget() {
33         return new AllTarget();
34     }
35
36     public static RulerColumnTarget createOrTarget(RulerColumnTarget either, RulerColumnTarget or) {
37         Assert.isLegal(or != null || either != null);
38         if (either == null)
39             return or;
40         if (or == null)
41             return either;
42         return new OrTarget(either, or);
43     }
44
45     public static RulerColumnTarget createContentTypeTarget(String JavaDoc contentTypeId) {
46         return new ContentTypeTarget(contentTypeId);
47     }
48
49     public static RulerColumnTarget createEditorIdTarget(String JavaDoc editorId) {
50         return new EditorIdTarget(editorId);
51     }
52
53     public static RulerColumnTarget createClassTarget(String JavaDoc className) {
54         return new ClassTarget(className);
55     }
56 }
57
58 final class AllTarget extends RulerColumnTarget {
59     AllTarget() {
60     }
61
62     public boolean matchesContentType(IContentType contentType) {
63         return true;
64     }
65
66     public boolean matchesEditorId(String JavaDoc editorId) {
67         return true;
68     }
69
70     public boolean matchesClass(Class JavaDoc clazz) {
71         return true;
72     }
73
74     public String JavaDoc toString() {
75         return "All"; //$NON-NLS-1$
76
}
77 }
78
79 final class OrTarget extends RulerColumnTarget {
80     private final RulerColumnTarget fEither;
81     private final RulerColumnTarget fOr;
82
83     OrTarget(RulerColumnTarget either, RulerColumnTarget or) {
84         fEither= either;
85         fOr= or;
86         Assert.isLegal(either != null);
87         Assert.isLegal(or != null);
88     }
89
90     public boolean matchesContentType(IContentType contentType) {
91         return fEither.matchesContentType(contentType) || fOr.matchesContentType(contentType);
92     }
93
94     public boolean matchesEditorId(String JavaDoc editorId) {
95         return fEither.matchesEditorId(editorId) || fOr.matchesEditorId(editorId);
96     }
97
98     public boolean matchesClass(Class JavaDoc clazz) {
99         return fEither.matchesClass(clazz) || fOr.matchesClass(clazz);
100     }
101
102     public String JavaDoc toString() {
103         return fEither.toString() + " || " + fOr.toString(); //$NON-NLS-1$
104
}
105 }
106
107 final class EditorIdTarget extends RulerColumnTarget {
108     private final String JavaDoc fEditorId;
109
110     EditorIdTarget(String JavaDoc id) {
111         Assert.isLegal(id != null);
112         fEditorId= id;
113     }
114
115     public boolean matchesContentType(IContentType contentType) {
116         return false;
117     }
118
119     public boolean matchesEditorId(String JavaDoc editorId) {
120         return fEditorId.equals(editorId);
121     }
122
123     public boolean matchesClass(Class JavaDoc clazz) {
124         return false;
125     }
126
127     public String JavaDoc toString() {
128         return "editorID=" + fEditorId; //$NON-NLS-1$
129
}
130 }
131
132 final class ClassTarget extends RulerColumnTarget {
133     private final String JavaDoc fClassName;
134
135     ClassTarget(String JavaDoc className) {
136         Assert.isLegal(className != null);
137         fClassName= className;
138     }
139
140     public boolean matchesContentType(IContentType contentType) {
141         return false;
142     }
143
144     public boolean matchesEditorId(String JavaDoc editorId) {
145         return false;
146     }
147
148     public boolean matchesClass(Class JavaDoc clazz) {
149         Assert.isLegal(clazz != null);
150         
151         do {
152             if (clazz.getName().equals(fClassName))
153                 return true;
154             clazz= clazz.getSuperclass();
155         } while (clazz != null);
156
157         return false;
158     }
159
160     public String JavaDoc toString() {
161         return "class=" + fClassName; //$NON-NLS-1$
162
}
163 }
164
165 final class ContentTypeTarget extends RulerColumnTarget {
166     private final IContentType fContentType;
167
168     ContentTypeTarget(String JavaDoc contentTypeId) {
169         Assert.isLegal(contentTypeId != null);
170         fContentType= Platform.getContentTypeManager().getContentType(contentTypeId);
171     }
172
173     public boolean matchesContentType(IContentType contentType) {
174         return fContentType != null && contentType != null && contentType.isKindOf(fContentType);
175     }
176
177     public boolean matchesEditorId(String JavaDoc editorId) {
178         return false;
179     }
180
181     public boolean matchesClass(Class JavaDoc clazz) {
182         return false;
183     }
184
185     public String JavaDoc toString() {
186         return "contentType=" + fContentType; //$NON-NLS-1$
187
}
188 }
189
Popular Tags