|
Link Here
|
| 25 |
import org.eclipse.e4.core.services.events.IEventBroker; |
25 |
import org.eclipse.e4.core.services.events.IEventBroker; |
| 26 |
import org.eclipse.e4.core.services.log.Logger; |
26 |
import org.eclipse.e4.core.services.log.Logger; |
| 27 |
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer; |
27 |
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer; |
| 28 |
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; |
|
|
| 29 |
import org.eclipse.e4.ui.model.application.MApplication; |
28 |
import org.eclipse.e4.ui.model.application.MApplication; |
| 30 |
import org.eclipse.e4.ui.model.application.ui.MContext; |
29 |
import org.eclipse.e4.ui.model.application.ui.MCoreExpression; |
| 31 |
import org.eclipse.e4.ui.model.application.ui.MElementContainer; |
30 |
import org.eclipse.e4.ui.model.application.ui.MElementContainer; |
| 32 |
import org.eclipse.e4.ui.model.application.ui.MUIElement; |
31 |
import org.eclipse.e4.ui.model.application.ui.MUIElement; |
| 33 |
import org.eclipse.e4.ui.model.application.ui.MUILabel; |
32 |
import org.eclipse.e4.ui.model.application.ui.MUILabel; |
|
Link Here
|
| 39 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; |
38 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; |
| 40 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
39 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
| 41 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator; |
40 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator; |
|
|
41 |
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenu; |
| 42 |
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem; |
| 42 |
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; |
43 |
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; |
|
|
44 |
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; |
| 43 |
import org.eclipse.e4.ui.workbench.IResourceUtilities; |
45 |
import org.eclipse.e4.ui.workbench.IResourceUtilities; |
| 44 |
import org.eclipse.e4.ui.workbench.UIEvents; |
46 |
import org.eclipse.e4.ui.workbench.UIEvents; |
| 45 |
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; |
47 |
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; |
|
Link Here
|
| 48 |
import org.eclipse.emf.ecore.EObject; |
50 |
import org.eclipse.emf.ecore.EObject; |
| 49 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
51 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
| 50 |
import org.eclipse.jface.action.AbstractGroupMarker; |
52 |
import org.eclipse.jface.action.AbstractGroupMarker; |
|
|
53 |
import org.eclipse.jface.action.ContributionItem; |
| 51 |
import org.eclipse.jface.action.GroupMarker; |
54 |
import org.eclipse.jface.action.GroupMarker; |
| 52 |
import org.eclipse.jface.action.IContributionItem; |
55 |
import org.eclipse.jface.action.IContributionItem; |
| 53 |
import org.eclipse.jface.action.IMenuListener; |
|
|
| 54 |
import org.eclipse.jface.action.IMenuManager; |
| 55 |
import org.eclipse.jface.action.MenuManager; |
56 |
import org.eclipse.jface.action.MenuManager; |
| 56 |
import org.eclipse.jface.action.Separator; |
57 |
import org.eclipse.jface.action.Separator; |
| 57 |
import org.eclipse.jface.resource.ImageDescriptor; |
58 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
|
59 |
import org.eclipse.swt.SWT; |
| 58 |
import org.eclipse.swt.events.DisposeEvent; |
60 |
import org.eclipse.swt.events.DisposeEvent; |
| 59 |
import org.eclipse.swt.events.DisposeListener; |
61 |
import org.eclipse.swt.events.DisposeListener; |
| 60 |
import org.eclipse.swt.widgets.Control; |
62 |
import org.eclipse.swt.widgets.Control; |
| 61 |
import org.eclipse.swt.widgets.Decorations; |
63 |
import org.eclipse.swt.widgets.Decorations; |
|
|
64 |
import org.eclipse.swt.widgets.Display; |
| 62 |
import org.eclipse.swt.widgets.Menu; |
65 |
import org.eclipse.swt.widgets.Menu; |
| 63 |
import org.osgi.service.event.Event; |
66 |
import org.osgi.service.event.Event; |
| 64 |
import org.osgi.service.event.EventHandler; |
67 |
import org.osgi.service.event.EventHandler; |
|
Link Here
|
| 72 |
private Map<MMenu, MenuManager> modelToManager = new HashMap<MMenu, MenuManager>(); |
75 |
private Map<MMenu, MenuManager> modelToManager = new HashMap<MMenu, MenuManager>(); |
| 73 |
private Map<MenuManager, MMenu> managerToModel = new HashMap<MenuManager, MMenu>(); |
76 |
private Map<MenuManager, MMenu> managerToModel = new HashMap<MenuManager, MMenu>(); |
| 74 |
|
77 |
|
| 75 |
private Map<MMenuItem, IContributionItem> modelToContribution = new HashMap<MMenuItem, IContributionItem>(); |
78 |
private Map<MMenuElement, IContributionItem> modelToContribution = new HashMap<MMenuElement, IContributionItem>(); |
|
|
79 |
private Map<IContributionItem, MMenuElement> contributionToModel = new HashMap<IContributionItem, MMenuElement>(); |
| 76 |
|
80 |
|
| 77 |
private Map<MMenuElement, ContributionRecord> modelContributionToRecord = new HashMap<MMenuElement, ContributionRecord>(); |
81 |
private Map<MMenuElement, ContributionRecord> modelContributionToRecord = new HashMap<MMenuElement, ContributionRecord>(); |
| 78 |
|
82 |
|
|
Link Here
|
| 126 |
modelProcessSwitch(parent, itemModel); |
130 |
modelProcessSwitch(parent, itemModel); |
| 127 |
} |
131 |
} |
| 128 |
} else { |
132 |
} else { |
| 129 |
IContributionItem ici = modelToContribution |
133 |
IContributionItem ici = getContribution(itemModel); |
| 130 |
.remove(itemModel); |
134 |
clearModelToContribution(itemModel, ici); |
| 131 |
if (ici != null && parent != null) { |
135 |
if (ici != null && parent != null) { |
| 132 |
parent.remove(ici); |
136 |
parent.remove(ici); |
| 133 |
} |
137 |
} |
|
Link Here
|
| 145 |
return; |
149 |
return; |
| 146 |
} |
150 |
} |
| 147 |
manager.setVisible(menuModel.isVisible()); |
151 |
manager.setVisible(menuModel.isVisible()); |
|
|
152 |
if (manager.getParent() != null) { |
| 153 |
manager.getParent().markDirty(); |
| 154 |
} |
| 148 |
} else if (element instanceof MMenuElement) { |
155 |
} else if (element instanceof MMenuElement) { |
| 149 |
MMenuElement itemModel = (MMenuElement) element; |
156 |
MMenuElement itemModel = (MMenuElement) element; |
| 150 |
IContributionItem ici = getContribution(itemModel); |
157 |
Object obj = getContribution(itemModel); |
| 151 |
if (ici == null) { |
158 |
if (!(obj instanceof ContributionItem)) { |
| 152 |
return; |
159 |
return; |
| 153 |
} |
160 |
} |
| 154 |
ici.setVisible(itemModel.isVisible()); |
161 |
ContributionItem item = (ContributionItem) obj; |
|
|
162 |
item.setVisible(itemModel.isVisible()); |
| 163 |
if (item.getParent() != null) { |
| 164 |
item.getParent().markDirty(); |
| 165 |
} |
| 155 |
} |
166 |
} |
| 156 |
} |
167 |
} |
| 157 |
} |
168 |
} |
|
Link Here
|
| 165 |
|
176 |
|
| 166 |
MMenuItem itemModel = (MMenuItem) event |
177 |
MMenuItem itemModel = (MMenuItem) event |
| 167 |
.getProperty(UIEvents.EventTags.ELEMENT); |
178 |
.getProperty(UIEvents.EventTags.ELEMENT); |
| 168 |
IContributionItem ici = modelToContribution.get(itemModel); |
179 |
IContributionItem ici = getContribution(itemModel); |
| 169 |
if (ici != null) { |
180 |
if (ici != null) { |
| 170 |
ici.update(); |
181 |
ici.update(); |
| 171 |
} |
182 |
} |
|
Link Here
|
| 180 |
|
191 |
|
| 181 |
MMenuItem itemModel = (MMenuItem) event |
192 |
MMenuItem itemModel = (MMenuItem) event |
| 182 |
.getProperty(UIEvents.EventTags.ELEMENT); |
193 |
.getProperty(UIEvents.EventTags.ELEMENT); |
| 183 |
IContributionItem ici = modelToContribution.get(itemModel); |
194 |
IContributionItem ici = getContribution(itemModel); |
| 184 |
if (ici != null) { |
195 |
if (ici != null) { |
| 185 |
ici.update(); |
196 |
ici.update(); |
| 186 |
} |
197 |
} |
| 187 |
} |
198 |
} |
| 188 |
}; |
199 |
}; |
| 189 |
|
200 |
|
| 190 |
private IMenuListener visibilityCalculationListener = new IMenuListener() { |
201 |
private MenuManagerRendererFilter rendererFilter; |
| 191 |
public void menuAboutToShow(IMenuManager manager) { |
|
|
| 192 |
MenuManager menuManager = (MenuManager) manager; |
| 193 |
if (menuManager.getMenu() == null) { |
| 194 |
return; |
| 195 |
} |
| 196 |
MMenu menuModel = getMenuModel(menuManager); |
| 197 |
if (menuModel == null) { |
| 198 |
Menu menu = menuManager.getMenu(); |
| 199 |
Object obj = menu.getData(AbstractPartRenderer.OWNING_ME); |
| 200 |
if (obj == null && menu.getParentItem() != null) { |
| 201 |
obj = menu.getParentItem().getData( |
| 202 |
AbstractPartRenderer.OWNING_ME); |
| 203 |
} |
| 204 |
if (!(obj instanceof MMenu)) { |
| 205 |
return; |
| 206 |
} |
| 207 |
menuModel = (MMenu) obj; |
| 208 |
} else if (menuModel.getWidget() == null) { |
| 209 |
bindWidget(menuModel, menuManager.getMenu()); |
| 210 |
} |
| 211 |
final IEclipseContext evalContext; |
| 212 |
if (menuModel instanceof MContext) { |
| 213 |
evalContext = ((MContext) menuModel).getContext(); |
| 214 |
} else { |
| 215 |
evalContext = modelService.getContainingContext(menuModel); |
| 216 |
} |
| 217 |
HashSet<ContributionRecord> records = new HashSet<ContributionRecord>(); |
| 218 |
for (MMenuElement element : menuModel.getChildren()) { |
| 219 |
ContributionRecord record = modelContributionToRecord |
| 220 |
.get(element); |
| 221 |
if (record != null && records.add(record)) { |
| 222 |
record.updateVisibility(evalContext); |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
}; |
| 227 |
|
202 |
|
| 228 |
@PostConstruct |
203 |
@PostConstruct |
| 229 |
public void init() { |
204 |
public void init() { |
|
Link Here
|
| 237 |
eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC), |
212 |
eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC), |
| 238 |
toBeRenderedUpdater); |
213 |
toBeRenderedUpdater); |
| 239 |
|
214 |
|
|
|
215 |
context.set(MenuManagerRenderer.class, this); |
| 216 |
Display display = context.get(Display.class); |
| 217 |
rendererFilter = ContextInjectionFactory.make( |
| 218 |
MenuManagerRendererFilter.class, context); |
| 219 |
display.addFilter(SWT.Show, rendererFilter); |
| 220 |
display.addFilter(SWT.Hide, rendererFilter); |
| 221 |
display.addFilter(SWT.Dispose, rendererFilter); |
| 222 |
context.set(MenuManagerRendererFilter.class, rendererFilter); |
| 223 |
|
| 240 |
} |
224 |
} |
| 241 |
|
225 |
|
| 242 |
@PreDestroy |
226 |
@PreDestroy |
|
Link Here
|
| 245 |
eventBroker.unsubscribe(selectionUpdater); |
229 |
eventBroker.unsubscribe(selectionUpdater); |
| 246 |
eventBroker.unsubscribe(enabledUpdater); |
230 |
eventBroker.unsubscribe(enabledUpdater); |
| 247 |
eventBroker.unsubscribe(toBeRenderedUpdater); |
231 |
eventBroker.unsubscribe(toBeRenderedUpdater); |
|
|
232 |
|
| 233 |
context.remove(MenuManagerRendererFilter.class); |
| 234 |
Display display = context.get(Display.class); |
| 235 |
if (display != null && !display.isDisposed() && rendererFilter != null) { |
| 236 |
display.removeFilter(SWT.Show, rendererFilter); |
| 237 |
display.removeFilter(SWT.Hide, rendererFilter); |
| 238 |
display.removeFilter(SWT.Dispose, rendererFilter); |
| 239 |
} |
| 240 |
if (rendererFilter != null) { |
| 241 |
ContextInjectionFactory.uninject(rendererFilter, context); |
| 242 |
rendererFilter = null; |
| 243 |
} |
| 244 |
context.remove(MenuManagerRenderer.class); |
| 248 |
} |
245 |
} |
| 249 |
|
246 |
|
| 250 |
/* |
247 |
/* |
|
Link Here
|
| 261 |
|
258 |
|
| 262 |
final MMenu menuModel = (MMenu) element; |
259 |
final MMenu menuModel = (MMenu) element; |
| 263 |
Menu newMenu = null; |
260 |
Menu newMenu = null; |
|
|
261 |
MenuManager menuManager = null; |
| 264 |
boolean menuBar = false; |
262 |
boolean menuBar = false; |
| 265 |
|
263 |
|
| 266 |
if (parent instanceof Decorations) { |
264 |
if (parent instanceof Decorations) { |
| 267 |
MUIElement container = (MUIElement) ((EObject) element) |
265 |
MUIElement container = (MUIElement) ((EObject) element) |
| 268 |
.eContainer(); |
266 |
.eContainer(); |
| 269 |
if (container instanceof MWindow) { |
267 |
if (container instanceof MWindow) { |
| 270 |
MenuManager menuBarManager = getManager(menuModel); |
268 |
menuManager = getManager(menuModel); |
| 271 |
if (menuBarManager == null) { |
269 |
if (menuManager == null) { |
| 272 |
menuBarManager = new MenuManager(NO_LABEL, |
270 |
menuManager = new MenuManager(NO_LABEL, |
| 273 |
menuModel.getElementId()); |
271 |
menuModel.getElementId()); |
| 274 |
linkModelToManager(menuModel, menuBarManager); |
272 |
linkModelToManager(menuModel, menuManager); |
| 275 |
} |
273 |
} |
| 276 |
newMenu = menuBarManager.createMenuBar((Decorations) parent); |
274 |
newMenu = menuManager.createMenuBar((Decorations) parent); |
| 277 |
((Decorations) parent).setMenuBar(newMenu); |
275 |
((Decorations) parent).setMenuBar(newMenu); |
| 278 |
newMenu.setData(menuBarManager); |
276 |
newMenu.setData(menuManager); |
| 279 |
menuBar = true; |
277 |
menuBar = true; |
| 280 |
} else { |
278 |
} else { |
| 281 |
MenuManager popupManager = getManager(menuModel); |
279 |
menuManager = getManager(menuModel); |
| 282 |
if (popupManager == null) { |
280 |
if (menuManager == null) { |
| 283 |
popupManager = new MenuManager(NO_LABEL, |
281 |
menuManager = new MenuManager(NO_LABEL, |
| 284 |
menuModel.getElementId()); |
282 |
menuModel.getElementId()); |
| 285 |
linkModelToManager(menuModel, popupManager); |
283 |
linkModelToManager(menuModel, menuManager); |
| 286 |
} |
284 |
} |
| 287 |
newMenu = popupManager.createContextMenu((Control) parent); |
285 |
newMenu = menuManager.createContextMenu((Control) parent); |
| 288 |
((Control) parent).setMenu(newMenu); |
286 |
// we can't be sure this is the correct parent. |
| 289 |
newMenu.setData(popupManager); |
287 |
// ((Control) parent).setMenu(newMenu); |
|
|
288 |
newMenu.setData(menuManager); |
| 290 |
} |
289 |
} |
| 291 |
} else if (parent instanceof Menu) { |
290 |
} else if (parent instanceof Menu) { |
| 292 |
// Object data = ((Menu) parent).getData(); |
291 |
// Object data = ((Menu) parent).getData(); |
| 293 |
logger.debug(new Exception(), "Trying to render a sub menu " //$NON-NLS-1$ |
292 |
logger.debug(new Exception(), "Trying to render a sub menu " //$NON-NLS-1$ |
| 294 |
+ menuModel + "\n\t" + parent); //$NON-NLS-1$ |
293 |
+ menuModel + "\n\t" + parent); //$NON-NLS-1$ |
|
|
294 |
return null; |
| 295 |
|
295 |
|
| 296 |
} else if (parent instanceof Control) { |
296 |
} else if (parent instanceof Control) { |
| 297 |
MenuManager popupManager = getManager(menuModel); |
297 |
menuManager = getManager(menuModel); |
| 298 |
if (popupManager == null) { |
298 |
if (menuManager == null) { |
| 299 |
popupManager = new MenuManager(NO_LABEL, |
299 |
menuManager = new MenuManager(NO_LABEL, |
| 300 |
menuModel.getElementId()); |
300 |
menuModel.getElementId()); |
| 301 |
linkModelToManager(menuModel, popupManager); |
301 |
linkModelToManager(menuModel, menuManager); |
| 302 |
} |
302 |
} |
| 303 |
newMenu = popupManager.createContextMenu((Control) parent); |
303 |
newMenu = menuManager.createContextMenu((Control) parent); |
| 304 |
((Control) parent).setMenu(newMenu); |
304 |
// we can't be sure this is the correct parent. |
| 305 |
newMenu.setData(popupManager); |
305 |
// ((Control) parent).setMenu(newMenu); |
|
|
306 |
newMenu.setData(menuManager); |
| 307 |
} |
| 308 |
if (!menuManager.getRemoveAllWhenShown()) { |
| 309 |
processContributions(menuModel, menuBar); |
| 306 |
} |
310 |
} |
| 307 |
processContributions(menuModel, menuBar); |
|
|
| 308 |
if (newMenu != null) { |
311 |
if (newMenu != null) { |
| 309 |
newMenu.addDisposeListener(new DisposeListener() { |
312 |
newMenu.addDisposeListener(new DisposeListener() { |
| 310 |
public void widgetDisposed(DisposeEvent e) { |
313 |
public void widgetDisposed(DisposeEvent e) { |
|
Link Here
|
| 318 |
/** |
321 |
/** |
| 319 |
* @param menuModel |
322 |
* @param menuModel |
| 320 |
*/ |
323 |
*/ |
| 321 |
protected void cleanUp(MMenu menuModel) { |
324 |
public void cleanUp(MMenu menuModel) { |
| 322 |
Collection<ContributionRecord> vals = modelContributionToRecord |
325 |
Collection<ContributionRecord> vals = modelContributionToRecord |
| 323 |
.values(); |
326 |
.values(); |
| 324 |
for (ContributionRecord record : vals |
327 |
for (ContributionRecord record : vals |
|
Link Here
|
| 336 |
copyManager.dispose(); |
339 |
copyManager.dispose(); |
| 337 |
} |
340 |
} |
| 338 |
} else { |
341 |
} else { |
| 339 |
IContributionItem ici = modelToContribution |
342 |
IContributionItem ici = getContribution(copy); |
| 340 |
.remove(copy); |
343 |
clearModelToContribution(copy, ici); |
| 341 |
if (ici != null) { |
344 |
if (ici != null) { |
| 342 |
record.manager.remove(ici); |
345 |
record.manager.remove(ici); |
| 343 |
} |
346 |
} |
|
Link Here
|
| 352 |
* @param menuModel |
355 |
* @param menuModel |
| 353 |
* @param menuBar |
356 |
* @param menuBar |
| 354 |
*/ |
357 |
*/ |
| 355 |
private void processContributions(MMenu menuModel, boolean menuBar) { |
358 |
public void processContributions(MMenu menuModel, boolean menuBar) { |
| 356 |
final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); |
359 |
final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); |
| 357 |
ContributionsAnalyzer.XXXgatherMenuContributions(menuModel, |
360 |
ContributionsAnalyzer.XXXgatherMenuContributions(menuModel, |
| 358 |
application.getMenuContributions(), menuModel.getElementId(), |
361 |
application.getMenuContributions(), menuModel.getElementId(), |
|
Link Here
|
| 500 |
boolean isVisible = ContributionsAnalyzer.isVisible( |
503 |
boolean isVisible = ContributionsAnalyzer.isVisible( |
| 501 |
menuContribution, exprContext); |
504 |
menuContribution, exprContext); |
| 502 |
for (MMenuElement item : generatedElements) { |
505 |
for (MMenuElement item : generatedElements) { |
| 503 |
item.setVisible(isVisible); |
506 |
if (isVisible && item.getVisibleWhen() != null) { |
|
|
507 |
MenuManagerRenderer.updateVisibility(manager, item, |
| 508 |
exprContext); |
| 509 |
} else { |
| 510 |
item.setVisible(isVisible); |
| 511 |
} |
| 504 |
} |
512 |
} |
| 505 |
manager.markDirty(); |
513 |
manager.markDirty(); |
| 506 |
} |
514 |
} |
|
Link Here
|
| 564 |
* @param menuModel |
572 |
* @param menuModel |
| 565 |
*/ |
573 |
*/ |
| 566 |
private void processMenu(MenuManager parentManager, MMenu menuModel) { |
574 |
private void processMenu(MenuManager parentManager, MMenu menuModel) { |
| 567 |
String menuText = getText(menuModel); |
575 |
MenuManager menuManager = getManager(menuModel); |
| 568 |
ImageDescriptor desc = getImageDescriptor(menuModel); |
576 |
if (menuManager == null) { |
| 569 |
MenuManager menuManager = new MenuManager(menuText, desc, |
577 |
String menuText = getText(menuModel); |
| 570 |
menuModel.getElementId()); |
578 |
ImageDescriptor desc = getImageDescriptor(menuModel); |
| 571 |
linkModelToManager(menuModel, menuManager); |
579 |
menuManager = new MenuManager(menuText, desc, |
| 572 |
menuManager.setVisible(menuModel.isVisible()); |
580 |
menuModel.getElementId()); |
| 573 |
parentManager.add(menuManager); |
581 |
linkModelToManager(menuModel, menuManager); |
|
|
582 |
menuManager.setVisible(menuModel.isVisible()); |
| 583 |
parentManager.add(menuManager); |
| 584 |
} |
| 574 |
processContributions(menuModel, false); |
585 |
processContributions(menuModel, false); |
| 575 |
List<MMenuElement> parts = menuModel.getChildren(); |
586 |
List<MMenuElement> parts = menuModel.getChildren(); |
| 576 |
if (parts != null) { |
587 |
if (parts != null) { |
|
Link Here
|
| 600 |
} else if (childME instanceof MMenuSeparator) { |
611 |
} else if (childME instanceof MMenuSeparator) { |
| 601 |
MMenuSeparator sep = (MMenuSeparator) childME; |
612 |
MMenuSeparator sep = (MMenuSeparator) childME; |
| 602 |
processSeparator(menuManager, sep); |
613 |
processSeparator(menuManager, sep); |
|
|
614 |
} else if (childME instanceof MOpaqueMenu) { |
| 615 |
// I'm not sure what to do here. |
| 603 |
} else if (childME instanceof MMenu) { |
616 |
} else if (childME instanceof MMenu) { |
| 604 |
MMenu itemModel = (MMenu) childME; |
617 |
MMenu itemModel = (MMenu) childME; |
| 605 |
processMenu(menuManager, itemModel); |
618 |
processMenu(menuManager, itemModel); |
|
Link Here
|
| 632 |
*/ |
645 |
*/ |
| 633 |
void processDirectItem(MenuManager parentManager, |
646 |
void processDirectItem(MenuManager parentManager, |
| 634 |
MDirectMenuItem itemModel, String id) { |
647 |
MDirectMenuItem itemModel, String id) { |
|
|
648 |
IContributionItem ici = getContribution(itemModel); |
| 649 |
if (ici != null) { |
| 650 |
return; |
| 651 |
} |
| 635 |
final IEclipseContext lclContext = getContext(itemModel); |
652 |
final IEclipseContext lclContext = getContext(itemModel); |
| 636 |
DirectContributionItem ci = ContextInjectionFactory.make( |
653 |
DirectContributionItem ci = ContextInjectionFactory.make( |
| 637 |
DirectContributionItem.class, lclContext); |
654 |
DirectContributionItem.class, lclContext); |
| 638 |
ci.setModel(itemModel); |
655 |
ci.setModel(itemModel); |
| 639 |
ci.setVisible(itemModel.isVisible()); |
656 |
ci.setVisible(itemModel.isVisible()); |
| 640 |
parentManager.add(ci); |
657 |
parentManager.add(ci); |
| 641 |
modelToContribution.put(itemModel, ci); |
658 |
linkModelToContribution(itemModel, ci); |
| 642 |
} |
659 |
} |
| 643 |
|
660 |
|
| 644 |
/** |
661 |
/** |
|
Link Here
|
| 647 |
*/ |
664 |
*/ |
| 648 |
void processHandledItem(MenuManager parentManager, |
665 |
void processHandledItem(MenuManager parentManager, |
| 649 |
MHandledMenuItem itemModel) { |
666 |
MHandledMenuItem itemModel) { |
|
|
667 |
IContributionItem ici = getContribution(itemModel); |
| 668 |
if (ici != null) { |
| 669 |
return; |
| 670 |
} |
| 650 |
final IEclipseContext lclContext = getContext(itemModel); |
671 |
final IEclipseContext lclContext = getContext(itemModel); |
| 651 |
HandledContributionItem ci = ContextInjectionFactory.make( |
672 |
HandledContributionItem ci = ContextInjectionFactory.make( |
| 652 |
HandledContributionItem.class, lclContext); |
673 |
HandledContributionItem.class, lclContext); |
| 653 |
ci.setModel(itemModel); |
674 |
ci.setModel(itemModel); |
| 654 |
ci.setVisible(itemModel.isVisible()); |
675 |
ci.setVisible(itemModel.isVisible()); |
| 655 |
parentManager.add(ci); |
676 |
parentManager.add(ci); |
| 656 |
modelToContribution.put(itemModel, ci); |
677 |
linkModelToContribution(itemModel, ci); |
| 657 |
} |
678 |
} |
| 658 |
|
679 |
|
| 659 |
private String getText(MMenu menuModel) { |
680 |
private String getText(MMenu menuModel) { |
|
Link Here
|
| 686 |
public void linkModelToManager(MMenu model, MenuManager manager) { |
707 |
public void linkModelToManager(MMenu model, MenuManager manager) { |
| 687 |
modelToManager.put(model, manager); |
708 |
modelToManager.put(model, manager); |
| 688 |
managerToModel.put(manager, model); |
709 |
managerToModel.put(manager, model); |
| 689 |
manager.addMenuListener(visibilityCalculationListener); |
|
|
| 690 |
} |
710 |
} |
| 691 |
|
711 |
|
| 692 |
public void clearModelToManager(MMenu model, MenuManager manager) { |
712 |
public void clearModelToManager(MMenu model, MenuManager manager) { |
| 693 |
modelToManager.remove(model); |
713 |
modelToManager.remove(model); |
| 694 |
managerToModel.remove(manager); |
714 |
managerToModel.remove(manager); |
| 695 |
if (manager != null) { |
|
|
| 696 |
manager.removeMenuListener(visibilityCalculationListener); |
| 697 |
} |
| 698 |
} |
715 |
} |
| 699 |
|
716 |
|
| 700 |
public IContributionItem getContribution(MMenuElement model) { |
717 |
public IContributionItem getContribution(MMenuElement model) { |
| 701 |
return modelToContribution.get(model); |
718 |
return modelToContribution.get(model); |
| 702 |
} |
719 |
} |
|
|
720 |
|
| 721 |
public MMenuElement getMenuElement(IContributionItem item) { |
| 722 |
return contributionToModel.get(item); |
| 723 |
} |
| 724 |
|
| 725 |
public void linkModelToContribution(MMenuElement model, |
| 726 |
IContributionItem item) { |
| 727 |
modelToContribution.put(model, item); |
| 728 |
contributionToModel.put(item, model); |
| 729 |
} |
| 730 |
|
| 731 |
public void clearModelToContribution(MMenuElement model, |
| 732 |
IContributionItem item) { |
| 733 |
modelToContribution.remove(model); |
| 734 |
contributionToModel.remove(item); |
| 735 |
} |
| 736 |
|
| 737 |
public ContributionRecord getContributionRecord(MMenuElement element) { |
| 738 |
return modelContributionToRecord.get(element); |
| 739 |
} |
| 740 |
|
| 741 |
/** |
| 742 |
* @param menuManager |
| 743 |
* @param menuModel |
| 744 |
*/ |
| 745 |
public void reconcileManagerToModel(MenuManager menuManager, MMenu menuModel) { |
| 746 |
List<MMenuElement> modelChildren = menuModel.getChildren(); |
| 747 |
|
| 748 |
HashSet<MOpaqueMenuItem> oldModelItems = new HashSet<MOpaqueMenuItem>(); |
| 749 |
HashSet<MOpaqueMenu> oldMenus = new HashSet<MOpaqueMenu>(); |
| 750 |
for (MMenuElement itemModel : modelChildren) { |
| 751 |
if (itemModel instanceof MOpaqueMenuItem) { |
| 752 |
oldModelItems.add((MOpaqueMenuItem) itemModel); |
| 753 |
} else if (itemModel instanceof MOpaqueMenu) { |
| 754 |
oldMenus.add((MOpaqueMenu) itemModel); |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
IContributionItem[] items = menuManager.getItems(); |
| 759 |
for (int src = 0, dest = 0; src < items.length; src++, dest++) { |
| 760 |
IContributionItem item = items[src]; |
| 761 |
if (item instanceof MenuManager) { |
| 762 |
MenuManager childManager = (MenuManager) item; |
| 763 |
MMenu childModel = getMenuModel(childManager); |
| 764 |
if (childModel == null) { |
| 765 |
MMenu legacyModel = MenuFactoryImpl.eINSTANCE |
| 766 |
.createOpaqueMenu(); |
| 767 |
legacyModel.setElementId(childManager.getId()); |
| 768 |
legacyModel.setVisible(childManager.isVisible()); |
| 769 |
linkModelToManager(legacyModel, childManager); |
| 770 |
modelChildren.add(dest, legacyModel); |
| 771 |
} else { |
| 772 |
if (childModel instanceof MOpaqueMenu) { |
| 773 |
oldMenus.remove(childModel); |
| 774 |
} |
| 775 |
if (modelChildren.size() > dest) { |
| 776 |
if (modelChildren.get(dest) != childModel) { |
| 777 |
modelChildren.remove(childModel); |
| 778 |
modelChildren.add(dest, childModel); |
| 779 |
} |
| 780 |
} else { |
| 781 |
modelChildren.add(childModel); |
| 782 |
} |
| 783 |
} |
| 784 |
} else { |
| 785 |
MMenuElement menuElement = getMenuElement(item); |
| 786 |
if (menuElement == null) { |
| 787 |
MOpaqueMenuItem legacyItem = MenuFactoryImpl.eINSTANCE |
| 788 |
.createOpaqueMenuItem(); |
| 789 |
legacyItem.setElementId(item.getId()); |
| 790 |
legacyItem.setVisible(item.isVisible()); |
| 791 |
legacyItem.setOpaqueItem(item); |
| 792 |
linkModelToContribution(legacyItem, item); |
| 793 |
modelChildren.add(dest, legacyItem); |
| 794 |
} else if (menuElement instanceof MOpaqueMenuItem) { |
| 795 |
MOpaqueMenuItem legacyItem = (MOpaqueMenuItem) menuElement; |
| 796 |
oldModelItems.remove(legacyItem); |
| 797 |
if (modelChildren.size() > dest) { |
| 798 |
if (modelChildren.get(dest) != legacyItem) { |
| 799 |
modelChildren.remove(legacyItem); |
| 800 |
modelChildren.add(dest, legacyItem); |
| 801 |
} |
| 802 |
} else { |
| 803 |
modelChildren.add(legacyItem); |
| 804 |
} |
| 805 |
} |
| 806 |
} |
| 807 |
} |
| 808 |
if (!oldModelItems.isEmpty()) { |
| 809 |
modelChildren.removeAll(oldModelItems); |
| 810 |
for (MOpaqueMenuItem model : oldModelItems) { |
| 811 |
clearModelToContribution(model, |
| 812 |
(IContributionItem) model.getOpaqueItem()); |
| 813 |
} |
| 814 |
} |
| 815 |
if (!oldMenus.isEmpty()) { |
| 816 |
modelChildren.removeAll(oldMenus); |
| 817 |
for (MOpaqueMenu oldMenu : oldMenus) { |
| 818 |
MenuManager oldManager = getManager(oldMenu); |
| 819 |
clearModelToManager(oldMenu, oldManager); |
| 820 |
} |
| 821 |
} |
| 822 |
} |
| 823 |
|
| 824 |
/** |
| 825 |
* @param menuManager |
| 826 |
* @param element |
| 827 |
* @param evalContext |
| 828 |
*/ |
| 829 |
public static void updateVisibility(MenuManager menuManager, |
| 830 |
MMenuElement element, ExpressionContext evalContext) { |
| 831 |
if (!(element.getVisibleWhen() instanceof MCoreExpression)) { |
| 832 |
return; |
| 833 |
} |
| 834 |
boolean val = ContributionsAnalyzer.isVisible( |
| 835 |
(MCoreExpression) element.getVisibleWhen(), evalContext); |
| 836 |
if (val != element.isVisible()) { |
| 837 |
element.setVisible(val); |
| 838 |
menuManager.markDirty(); |
| 839 |
} |
| 840 |
} |
| 703 |
} |
841 |
} |