1 11 12 package org.eclipse.ui.internal.menus; 13 14 import org.eclipse.jface.util.Util; 15 import org.eclipse.ui.internal.misc.Policy; 16 17 37 public final class SBar extends LeafLocationElement { 38 39 42 public static final String TYPE_MENU = "menu"; 44 47 public static final String TYPE_TRIM = "trim"; 49 52 private final String type; 53 54 59 public SBar() { 60 this(TYPE_MENU, null); 61 } 62 63 73 public SBar(final String path) { 74 this(TYPE_MENU, path); 75 } 76 77 90 public SBar(final String type, final String path) { 91 super(path); 92 this.type = type; 93 } 94 95 public final LocationElement createChild(final String id) { 96 final String parentPath = getPath(); 97 final String path; 98 if (parentPath == null) { 99 path = id; 100 } else { 101 path = parentPath + PATH_SEPARATOR + id; 102 } 103 return new SBar(getType(), path); 104 } 105 106 public final ILocationElementTokenizer getTokenizer() { 107 if (Policy.EXPERIMENTAL_MENU && getPath() != null 108 && getPath().indexOf(LeafLocationElement.BREAKPOINT_PATH) > -1) { 109 System.err.println("getTokenizer: " + getPath()); } 111 return new ILocationElementTokenizer() { 112 String remainingPath = getPath(); 113 114 String parsedPath = null; 115 116 public final LocationElementToken nextToken() { 117 final SLocation location = new SLocation(new SBar(getType(), 118 parsedPath)); 119 final int separator = remainingPath 120 .indexOf(LeafLocationElement.PATH_SEPARATOR); 121 final String id; 122 if (separator == -1) { 123 id = remainingPath; 124 remainingPath = null; 125 } else { 126 id = remainingPath.substring(0, separator); 127 remainingPath = remainingPath.substring(separator + 1); 128 if (remainingPath.length()==0) { 129 remainingPath = null; 130 } 131 } 132 if (parsedPath==null) { 133 parsedPath = id; 134 } else { 135 parsedPath = parsedPath + '/' + id; 136 } 137 return new LocationElementToken(location, id); 138 } 139 140 public final boolean hasMoreTokens() { 141 return remainingPath != null; 142 } 143 }; 144 } 145 146 151 public final String getType() { 152 return type; 153 } 154 155 public final String toString() { 156 final StringBuffer buffer = new StringBuffer (); 157 buffer.append("SBar("); buffer.append(type); 159 buffer.append(','); 160 buffer.append(getPath()); 161 buffer.append(')'); 162 return buffer.toString(); 163 } 164 165 168 public boolean equals(Object obj) { 169 if (this==obj) { 170 return true; 171 } 172 if (obj instanceof SBar) { 173 SBar bar = (SBar) obj; 174 return Util.equals(type, bar.type) && super.equals(obj); 175 } 176 return false; 177 } 178 179 182 public int hashCode() { 183 return Util.hashCode(type) + super.hashCode(); 184 } 185 } 186 | Popular Tags |