1 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 23 public abstract class RulerColumnTarget { 24 public abstract boolean matchesEditorId(String editorId); 25 public abstract boolean matchesContentType(IContentType contentType); 26 public abstract boolean matchesClass(Class clazz); 27 28 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 contentTypeId) { 46 return new ContentTypeTarget(contentTypeId); 47 } 48 49 public static RulerColumnTarget createEditorIdTarget(String editorId) { 50 return new EditorIdTarget(editorId); 51 } 52 53 public static RulerColumnTarget createClassTarget(String 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 editorId) { 67 return true; 68 } 69 70 public boolean matchesClass(Class clazz) { 71 return true; 72 } 73 74 public String toString() { 75 return "All"; } 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 editorId) { 95 return fEither.matchesEditorId(editorId) || fOr.matchesEditorId(editorId); 96 } 97 98 public boolean matchesClass(Class clazz) { 99 return fEither.matchesClass(clazz) || fOr.matchesClass(clazz); 100 } 101 102 public String toString() { 103 return fEither.toString() + " || " + fOr.toString(); } 105 } 106 107 final class EditorIdTarget extends RulerColumnTarget { 108 private final String fEditorId; 109 110 EditorIdTarget(String 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 editorId) { 120 return fEditorId.equals(editorId); 121 } 122 123 public boolean matchesClass(Class clazz) { 124 return false; 125 } 126 127 public String toString() { 128 return "editorID=" + fEditorId; } 130 } 131 132 final class ClassTarget extends RulerColumnTarget { 133 private final String fClassName; 134 135 ClassTarget(String 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 editorId) { 145 return false; 146 } 147 148 public boolean matchesClass(Class 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 toString() { 161 return "class=" + fClassName; } 163 } 164 165 final class ContentTypeTarget extends RulerColumnTarget { 166 private final IContentType fContentType; 167 168 ContentTypeTarget(String 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 editorId) { 178 return false; 179 } 180 181 public boolean matchesClass(Class clazz) { 182 return false; 183 } 184 185 public String toString() { 186 return "contentType=" + fContentType; } 188 } 189 | Popular Tags |