1 11 12 package org.eclipse.ui.internal.menus; 13 14 37 public final class SPart implements LocationElement { 38 39 42 public static final int TYPE_CLASS = 0; 43 44 48 public static final int TYPE_ID = 1; 49 50 53 private final LeafLocationElement location; 54 55 60 private final String part; 61 62 65 private final int type; 66 67 79 public SPart(final String part, final int type, 80 final LeafLocationElement location) { 81 if (part == null) { 82 throw new NullPointerException ("A part needs a class or id"); } 84 if ((type < TYPE_CLASS) || (type > TYPE_ID)) { 85 throw new IllegalArgumentException ( 86 "The part must be either a class or an identifier"); } 88 if (location == null) { 89 throw new NullPointerException ( 90 "A part needs a location for the menu element to appear"); } 92 93 this.part = part; 94 this.type = type; 95 this.location = location; 96 } 97 98 public final LocationElement createChild(final String id) { 99 final LeafLocationElement childPath = (LeafLocationElement) getLocation() 100 .createChild(id); 101 return new SPart(getPart(), getType(), childPath); 102 } 103 104 111 public final LeafLocationElement getLocation() { 112 return location; 113 } 114 115 121 public final String getPart() { 122 return part; 123 } 124 125 131 public final int getType() { 132 return type; 133 } 134 135 public final String toString() { 136 final StringBuffer buffer = new StringBuffer (); 137 buffer.append("SPart("); switch (type) { 139 case TYPE_CLASS: 140 buffer.append("class"); break; 142 case TYPE_ID: 143 buffer.append("id"); break; 145 default: 146 buffer.append("unknown"); } 148 buffer.append(','); 149 buffer.append(part); 150 buffer.append(','); 151 buffer.append(location); 152 buffer.append(')'); 153 return buffer.toString(); 154 } 155 } 156 | Popular Tags |