1 11 12 package org.eclipse.ui.internal.menus; 13 14 import java.util.Collection ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 19 import org.eclipse.core.commands.common.NotDefinedException; 20 21 45 public final class SMenuLayout extends SPartMenuLayout { 46 47 57 static final SMenuLayout computeLayout(final Collection menuElements) { 58 final SMenuLayout layout = new SMenuLayout(); 59 60 final Iterator elementItr = menuElements.iterator(); 61 while (elementItr.hasNext()) { 62 final MenuElement element = (MenuElement) elementItr.next(); 63 try { 64 final SLocation[] locations = element.getLocations(); 65 for (int i = 0; i < locations.length; i++) { 66 final SLocation location = locations[i]; 67 final LocationElement locationElement = location.getPath(); 68 if (locationElement instanceof SBar) { 69 final SBar bar = (SBar) locationElement; 70 layout.addBar(element, location, bar); 71 72 } else if (locationElement instanceof SPopup) { 73 final SPopup popup = (SPopup) locationElement; 74 layout.addPopup(element, location, popup); 75 76 } else if (locationElement instanceof SPart) { 77 final SPart part = (SPart) locationElement; 78 layout.addPart(element, location, part); 79 80 } 81 } 82 } catch (final NotDefinedException e) { 83 } 85 } 86 87 return layout; 88 } 89 90 94 private final Map partsById; 95 96 99 SMenuLayout() { 100 this.partsById = new HashMap (); 101 } 102 103 118 private final void addPart(final MenuElement element, 119 final SLocation location, final SPart part) 120 throws NotDefinedException { 121 final String partIdOrType = part.getPart(); 122 SPartMenuLayout layout = (SPartMenuLayout) partsById.get(partIdOrType); 123 if (layout == null) { 124 layout = new SPartMenuLayout(); 125 partsById.put(partIdOrType, layout); 126 } 127 final LeafLocationElement locationElement = part.getLocation(); 128 if (locationElement instanceof SBar) { 129 final SBar bar = (SBar) locationElement; 130 layout.addBar(element, location, bar); 131 132 } else if (locationElement instanceof SPopup) { 133 final SPopup popup = (SPopup) locationElement; 134 layout.addPopup(element, location, popup); 135 136 } 137 } 138 139 143 public final String toString() { 144 final StringBuffer buffer = new StringBuffer (); 145 Iterator entryItr; 146 147 buffer.append(" ***** TOP-LEVEL BARS ***** \n"); entryItr = getBarsByType().entrySet().iterator(); 150 while (entryItr.hasNext()) { 151 final Map.Entry entry = (Map.Entry ) entryItr.next(); 152 final String type = (String ) entry.getKey(); 153 buffer.append(type); 154 buffer.append('\n'); 155 LayoutNode node = (LayoutNode) entry.getValue(); 156 printNode(node, buffer, 2); 157 } 158 159 buffer.append(" ***** PART-SPECIFIC BARS ***** \n"); entryItr = partsById.entrySet().iterator(); 162 while (entryItr.hasNext()) { 163 final Map.Entry entry = (Map.Entry ) entryItr.next(); 164 final String partId = (String ) entry.getKey(); 165 buffer.append(partId); 166 buffer.append('\n'); 167 final SPartMenuLayout layout = (SPartMenuLayout) entry.getValue(); 168 buffer.append(layout.toString()); 169 } 170 171 buffer.append(" ***** CONTEXT MENUS ***** \n"); entryItr = getPopupsById().entrySet().iterator(); 174 while (entryItr.hasNext()) { 175 final Map.Entry entry = (Map.Entry ) entryItr.next(); 176 final String id = (String ) entry.getKey(); 177 buffer.append(id); 178 buffer.append('\n'); 179 LayoutNode node = (LayoutNode) entry.getValue(); 180 printNode(node, buffer, 2); 181 } 182 183 return buffer.toString(); 184 } 185 } 186 | Popular Tags |