1 11 12 package org.eclipse.ui.internal.intro.impl.model; 13 14 import org.eclipse.core.runtime.IConfigurationElement; 15 import org.eclipse.ui.internal.intro.impl.model.util.BundleUtil; 16 import org.eclipse.ui.internal.intro.impl.util.StringUtil; 17 import org.osgi.framework.Bundle; 18 import org.w3c.dom.Element ; 19 20 40 public abstract class AbstractIntroElement implements Cloneable { 41 42 45 public static final int MODEL_ROOT = 1; 46 47 50 public static final int PRESENTATION = 1 << 1; 51 52 55 public static final int HOME_PAGE = 1 << 2; 56 57 60 public static final int PAGE = 1 << 3; 61 62 65 public static final int ABSTRACT_PAGE = HOME_PAGE | PAGE; 66 67 70 public static final int GROUP = 1 << 4; 71 72 75 public static final int ABSTRACT_CONTAINER = ABSTRACT_PAGE | GROUP 76 | MODEL_ROOT; 77 78 81 public static final int HTML = 1 << 5; 82 83 86 public static final int LINK = 1 << 6; 87 88 91 public static final int IMAGE = 1 << 7; 92 93 96 public static final int INCLUDE = 1 << 8; 97 98 101 public static final int TEXT = 1 << 9; 102 103 106 public static final int CONTAINER_EXTENSION = 1 << 10; 107 108 111 public static final int HEAD = 1 << 11; 112 113 116 public static final int PAGE_TITLE = 1 << 12; 117 118 121 public static final int ANCHOR = 1 << 13; 122 123 126 public static final int CONTENT_PROVIDER = 1 << 14; 127 128 131 public static final int LAUNCH_BAR = 1 << 15; 132 133 136 public static final int LAUNCH_BAR_SHORTCUT = 1 << 16; 137 138 141 public static final int INJECTED_IFRAME = 1 << 17; 142 143 146 public static final int THEME = 1 << 18; 147 148 151 public static final int HR = 1 << 19; 152 153 154 157 public static final int ABSTRACT_TEXT = HTML | LINK | CONTENT_PROVIDER; 158 159 162 public static final int BASE_ELEMENT = ABSTRACT_CONTAINER | ABSTRACT_TEXT 163 | IMAGE | TEXT | PAGE_TITLE; 164 165 170 public static final int ID_ELEMENT = BASE_ELEMENT | ANCHOR; 171 172 175 public static final int ELEMENT = ID_ELEMENT | CONTAINER_EXTENSION | HEAD 176 | INCLUDE | PRESENTATION | LAUNCH_BAR | LAUNCH_BAR_SHORTCUT; 177 178 179 180 private AbstractIntroElement parent; 181 private Object cfgElement; 182 private Bundle bundle; 183 private String mixinStyle; 184 185 186 189 AbstractIntroElement(IConfigurationElement element) { 190 cfgElement = element; 191 bundle = BundleUtil.getBundleFromConfigurationElement(element); 192 } 193 194 195 203 AbstractIntroElement(Element element, Bundle bundle) { 204 this.cfgElement = element; 205 this.bundle = bundle; 206 } 207 208 209 221 AbstractIntroElement(Element element, Bundle bundle, String base) { 222 this(element, bundle); 223 } 224 225 226 227 228 235 public IConfigurationElement getCfgElement() { 236 return cfgElement instanceof IConfigurationElement?(IConfigurationElement)cfgElement:null; 237 } 238 239 public Element getElement() { 240 return cfgElement instanceof Element?(Element)cfgElement:null; 241 } 242 243 252 protected String getAttribute(Element element, String att) { 253 if (element.hasAttribute(att)) { 254 String value = element.getAttribute(att); 255 if (value!=null) { 256 IntroModelRoot root = getModelRoot(); 257 if (root!=null) 258 return root.resolveVariables(value); 259 return value; 260 } 261 } 262 return null; 263 } 264 265 272 protected String [] getAttributeList(Element element, String att) { 273 if (element.hasAttribute(att)) { 274 String value = element.getAttribute(att); 275 if (value!=null) { 276 IntroModelRoot root = getModelRoot(); 277 if (root!=null) 278 value = root.resolveVariables(value); 279 return StringUtil.split(value, ","); } 281 } 282 286 return null; 287 } 288 289 protected void loadFromParent() { 290 } 291 292 293 300 public Bundle getBundle() { 301 return bundle; 302 } 303 304 305 306 312 public abstract int getType(); 313 314 315 334 public AbstractIntroElement getParent() { 335 return parent; 336 } 337 338 342 public void setParent(AbstractIntroElement parent) { 343 this.parent = parent; 344 if (parent!=null) 345 loadFromParent(); 346 } 347 348 public void setBundle(Bundle bundle) { 349 this.bundle = bundle; 350 } 351 352 365 public AbstractIntroPage getParentPage() { 366 if (isOfType(AbstractIntroElement.ABSTRACT_PAGE)) 368 return (AbstractIntroPage) this; 369 370 AbstractIntroElement parent = getParent(); 371 if (parent == null) 372 return null; 373 374 while (parent != null && parent.getParent() != null 375 && !parent.isOfType(AbstractIntroElement.ABSTRACT_PAGE)) 376 parent = parent.getParent(); 377 if (parent.isOfType(ABSTRACT_PAGE)) 378 return (AbstractIntroPage) parent; 379 return null; 380 } 381 382 public IntroModelRoot getModelRoot() { 383 if (isOfType(AbstractIntroElement.MODEL_ROOT)) 385 return (IntroModelRoot) this; 386 387 AbstractIntroElement parent = getParent(); 388 if (parent == null) 389 return null; 390 391 while (parent != null && parent.getParent() != null 392 && !parent.isOfType(AbstractIntroElement.MODEL_ROOT)) 393 parent = parent.getParent(); 394 if (parent.isOfType(MODEL_ROOT)) 395 return (IntroModelRoot) parent; 396 return null; 397 } 398 399 400 415 public boolean isOfType(int elementMask) { 416 return (getType() & elementMask) != 0; 417 } 418 419 432 public static final boolean allElementsAreOfType( 433 AbstractIntroElement[] elements, int elementMask) { 434 if (elements.length == 0) 436 return false; 437 438 for (int i = 0; i < elements.length; i++) { 439 AbstractIntroElement element = elements[i]; 440 if (!element.isOfType(elementMask)) 441 return false; 442 } 443 return true; 444 } 445 446 452 public Object clone() throws CloneNotSupportedException { 453 return super.clone(); 454 } 455 456 457 458 public String getMixinStyle() { 459 return mixinStyle; 460 } 461 462 463 464 public void setMixinStyle(String mixinStyle) { 465 this.mixinStyle = mixinStyle; 466 } 467 468 469 470 } | Popular Tags |