1 11 12 package org.eclipse.ui.internal.menus; 13 14 import org.eclipse.jface.util.Util; 15 16 40 public final class SPopup extends LeafLocationElement { 41 42 46 private final String id; 47 48 60 public SPopup(final String id, final String path) { 61 super(path); 62 63 this.id = id; 64 } 65 66 public final LocationElement createChild(final String id) { 67 final String parentPath = getPath(); 68 final String path; 69 if (parentPath == null) { 70 path = id; 71 } else { 72 path = parentPath + PATH_SEPARATOR + id; 73 } 74 return new SPopup(getId(), path); 75 } 76 77 84 public final String getId() { 85 return id; 86 } 87 88 public final ILocationElementTokenizer getTokenizer() { 89 return new ILocationElementTokenizer() { 90 String remainingPath = getPath(); 91 92 String parsedPath = null; 93 94 public final LocationElementToken nextToken() { 95 final SLocation location = new SLocation(new SPopup(getId(), 96 parsedPath)); 97 final int separator = remainingPath 98 .indexOf(LeafLocationElement.PATH_SEPARATOR); 99 final String id; 100 if (separator == -1) { 101 id = remainingPath; 102 remainingPath = null; 103 } else { 104 id = remainingPath.substring(0, separator); 105 remainingPath = remainingPath.substring(separator + 1); 106 } 107 parsedPath = parsedPath + id; 108 return new LocationElementToken(location, id); 109 } 110 111 public final boolean hasMoreTokens() { 112 return remainingPath != null; 113 } 114 }; 115 } 116 117 public final String toString() { 118 final StringBuffer buffer = new StringBuffer (); 119 buffer.append("SPopup("); buffer.append(id); 121 buffer.append(','); 122 buffer.append(getPath()); 123 buffer.append(')'); 124 return buffer.toString(); 125 } 126 127 130 public boolean equals(Object obj) { 131 if (this==obj) { 132 return true; 133 } 134 if (obj instanceof SPopup) { 135 SPopup popup = (SPopup) obj; 136 return Util.equals(id, popup.id) && super.equals(obj); 137 } 138 return false; 139 } 140 141 144 public int hashCode() { 145 return Util.hashCode(id) + super.hashCode(); 146 } 147 } 148 | Popular Tags |