Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 325392 | Differences between
and this patch

Collapse All | Expand All

(-)model/UIElements.ecore (+9 lines)
Lines 316-321 Link Here
316
        <eStructuralFeatures xsi:type="ecore:EAttribute" name="contributionItem" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaObject"
316
        <eStructuralFeatures xsi:type="ecore:EAttribute" name="contributionItem" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaObject"
317
            transient="true"/>
317
            transient="true"/>
318
      </eClassifiers>
318
      </eClassifiers>
319
      <eClassifiers xsi:type="ecore:EClass" name="OpaqueMenuItem" eSuperTypes="#//ui/menu/MenuItem">
320
        <eStructuralFeatures xsi:type="ecore:EAttribute" name="opaqueItem" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaObject"
321
            transient="true"/>
322
      </eClassifiers>
323
      <eClassifiers xsi:type="ecore:EClass" name="OpaqueMenuSeparator" eSuperTypes="#//ui/menu/MenuSeparator">
324
        <eStructuralFeatures xsi:type="ecore:EAttribute" name="opaqueItem" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaObject"
325
            transient="true"/>
326
      </eClassifiers>
327
      <eClassifiers xsi:type="ecore:EClass" name="OpaqueMenu" eSuperTypes="#//ui/menu/Menu"/>
319
    </eSubpackages>
328
    </eSubpackages>
320
    <eSubpackages name="basic" nsURI="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic"
329
    <eSubpackages name="basic" nsURI="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic"
321
        nsPrefix="basic">
330
        nsPrefix="basic">
(-)src/org/eclipse/e4/ui/model/application/ui/menu/MMenuFactory.java (+27 lines)
Lines 171-174 Link Here
171
	 */
171
	 */
172
	MRenderedMenuItem createRenderedMenuItem();
172
	MRenderedMenuItem createRenderedMenuItem();
173
173
174
	/**
175
	 * Returns a new object of class '<em>Opaque Menu Item</em>'.
176
	 * <!-- begin-user-doc -->
177
	 * <!-- end-user-doc -->
178
	 * @return a new object of class '<em>Opaque Menu Item</em>'.
179
	 * @generated
180
	 */
181
	MOpaqueMenuItem createOpaqueMenuItem();
182
183
	/**
184
	 * Returns a new object of class '<em>Opaque Menu Separator</em>'.
185
	 * <!-- begin-user-doc -->
186
	 * <!-- end-user-doc -->
187
	 * @return a new object of class '<em>Opaque Menu Separator</em>'.
188
	 * @generated
189
	 */
190
	MOpaqueMenuSeparator createOpaqueMenuSeparator();
191
192
	/**
193
	 * Returns a new object of class '<em>Opaque Menu</em>'.
194
	 * <!-- begin-user-doc -->
195
	 * <!-- end-user-doc -->
196
	 * @return a new object of class '<em>Opaque Menu</em>'.
197
	 * @generated
198
	 */
199
	MOpaqueMenu createOpaqueMenu();
200
174
} //MMenuFactory
201
} //MMenuFactory
(-)src/org/eclipse/e4/ui/model/application/ui/menu/MOpaqueMenu.java (+24 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *      IBM Corporation - initial API and implementation
10
 */
11
package org.eclipse.e4.ui.model.application.ui.menu;
12
13
14
/**
15
 * <!-- begin-user-doc -->
16
 * A representation of the model object '<em><b>Opaque Menu</b></em>'.
17
 * <!-- end-user-doc -->
18
 *
19
 *
20
 * @model
21
 * @generated
22
 */
23
public interface MOpaqueMenu extends MMenu {
24
} // MOpaqueMenu
(-)src/org/eclipse/e4/ui/model/application/ui/menu/MOpaqueMenuItem.java (+55 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *      IBM Corporation - initial API and implementation
10
 */
11
package org.eclipse.e4.ui.model.application.ui.menu;
12
13
14
/**
15
 * <!-- begin-user-doc -->
16
 * A representation of the model object '<em><b>Opaque Menu Item</b></em>'.
17
 * <!-- end-user-doc -->
18
 *
19
 * <p>
20
 * The following features are supported:
21
 * <ul>
22
 *   <li>{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem#getOpaqueItem <em>Opaque Item</em>}</li>
23
 * </ul>
24
 * </p>
25
 *
26
 * @model
27
 * @generated
28
 */
29
public interface MOpaqueMenuItem extends MMenuItem {
30
	/**
31
	 * Returns the value of the '<em><b>Opaque Item</b></em>' attribute.
32
	 * <!-- begin-user-doc -->
33
	 * <p>
34
	 * If the meaning of the '<em>Opaque Item</em>' attribute isn't clear,
35
	 * there really should be more of a description here...
36
	 * </p>
37
	 * <!-- end-user-doc -->
38
	 * @return the value of the '<em>Opaque Item</em>' attribute.
39
	 * @see #setOpaqueItem(Object)
40
	 * @model transient="true"
41
	 * @generated
42
	 */
43
	Object getOpaqueItem();
44
45
	/**
46
	 * Sets the value of the '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem#getOpaqueItem <em>Opaque Item</em>}' attribute.
47
	 * <!-- begin-user-doc -->
48
	 * <!-- end-user-doc -->
49
	 * @param value the new value of the '<em>Opaque Item</em>' attribute.
50
	 * @see #getOpaqueItem()
51
	 * @generated
52
	 */
53
	void setOpaqueItem(Object value);
54
55
} // MOpaqueMenuItem
(-)src/org/eclipse/e4/ui/model/application/ui/menu/MOpaqueMenuSeparator.java (+55 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *      IBM Corporation - initial API and implementation
10
 */
11
package org.eclipse.e4.ui.model.application.ui.menu;
12
13
14
/**
15
 * <!-- begin-user-doc -->
16
 * A representation of the model object '<em><b>Opaque Menu Separator</b></em>'.
17
 * <!-- end-user-doc -->
18
 *
19
 * <p>
20
 * The following features are supported:
21
 * <ul>
22
 *   <li>{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator#getOpaqueItem <em>Opaque Item</em>}</li>
23
 * </ul>
24
 * </p>
25
 *
26
 * @model
27
 * @generated
28
 */
29
public interface MOpaqueMenuSeparator extends MMenuSeparator {
30
31
	/**
32
	 * Returns the value of the '<em><b>Opaque Item</b></em>' attribute.
33
	 * <!-- begin-user-doc -->
34
	 * <p>
35
	 * If the meaning of the '<em>Opaque Item</em>' attribute isn't clear,
36
	 * there really should be more of a description here...
37
	 * </p>
38
	 * <!-- end-user-doc -->
39
	 * @return the value of the '<em>Opaque Item</em>' attribute.
40
	 * @see #setOpaqueItem(Object)
41
	 * @model transient="true"
42
	 * @generated
43
	 */
44
	Object getOpaqueItem();
45
46
	/**
47
	 * Sets the value of the '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator#getOpaqueItem <em>Opaque Item</em>}' attribute.
48
	 * <!-- begin-user-doc -->
49
	 * <!-- end-user-doc -->
50
	 * @param value the new value of the '<em>Opaque Item</em>' attribute.
51
	 * @see #getOpaqueItem()
52
	 * @generated
53
	 */
54
	void setOpaqueItem(Object value);
55
} // MOpaqueMenuSeparator
(-)src/org/eclipse/e4/ui/model/application/ui/menu/impl/MenuFactoryImpl.java (+33 lines)
Lines 104-109 Link Here
104
			case MenuPackageImpl.TOOL_BAR_CONTRIBUTION: return (EObject)createToolBarContribution();
104
			case MenuPackageImpl.TOOL_BAR_CONTRIBUTION: return (EObject)createToolBarContribution();
105
			case MenuPackageImpl.TRIM_CONTRIBUTION: return (EObject)createTrimContribution();
105
			case MenuPackageImpl.TRIM_CONTRIBUTION: return (EObject)createTrimContribution();
106
			case MenuPackageImpl.RENDERED_MENU_ITEM: return (EObject)createRenderedMenuItem();
106
			case MenuPackageImpl.RENDERED_MENU_ITEM: return (EObject)createRenderedMenuItem();
107
			case MenuPackageImpl.OPAQUE_MENU_ITEM: return (EObject)createOpaqueMenuItem();
108
			case MenuPackageImpl.OPAQUE_MENU_SEPARATOR: return (EObject)createOpaqueMenuSeparator();
109
			case MenuPackageImpl.OPAQUE_MENU: return (EObject)createOpaqueMenu();
107
			default:
110
			default:
108
				throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); //$NON-NLS-1$ //$NON-NLS-2$
111
				throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); //$NON-NLS-1$ //$NON-NLS-2$
109
		}
112
		}
Lines 304-309 Link Here
304
	 * <!-- end-user-doc -->
307
	 * <!-- end-user-doc -->
305
	 * @generated
308
	 * @generated
306
	 */
309
	 */
310
	public MOpaqueMenuItem createOpaqueMenuItem() {
311
		OpaqueMenuItemImpl opaqueMenuItem = new OpaqueMenuItemImpl();
312
		return opaqueMenuItem;
313
	}
314
315
	/**
316
	 * <!-- begin-user-doc -->
317
	 * <!-- end-user-doc -->
318
	 * @generated
319
	 */
320
	public MOpaqueMenuSeparator createOpaqueMenuSeparator() {
321
		OpaqueMenuSeparatorImpl opaqueMenuSeparator = new OpaqueMenuSeparatorImpl();
322
		return opaqueMenuSeparator;
323
	}
324
325
	/**
326
	 * <!-- begin-user-doc -->
327
	 * <!-- end-user-doc -->
328
	 * @generated
329
	 */
330
	public MOpaqueMenu createOpaqueMenu() {
331
		OpaqueMenuImpl opaqueMenu = new OpaqueMenuImpl();
332
		return opaqueMenu;
333
	}
334
335
	/**
336
	 * <!-- begin-user-doc -->
337
	 * <!-- end-user-doc -->
338
	 * @generated
339
	 */
307
	public ItemType createItemTypeFromString(EDataType eDataType, String initialValue) {
340
	public ItemType createItemTypeFromString(EDataType eDataType, String initialValue) {
308
		ItemType result = ItemType.get(initialValue);
341
		ItemType result = ItemType.get(initialValue);
309
		if (result == null) throw new IllegalArgumentException("The value '" + initialValue + "' is not a valid enumerator of '" + eDataType.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
342
		if (result == null) throw new IllegalArgumentException("The value '" + initialValue + "' is not a valid enumerator of '" + eDataType.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
(-)src/org/eclipse/e4/ui/model/application/ui/menu/impl/MenuPackageImpl.java (-1 / +781 lines)
Lines 29-34 Link Here
29
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
29
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
30
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
30
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
31
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
31
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
32
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenu;
33
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem;
34
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator;
32
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
35
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
33
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu;
36
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu;
34
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenuItem;
37
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenuItem;
Lines 4481-4486 Link Here
4481
	public static final int RENDERED_MENU_ITEM_FEATURE_COUNT = MENU_ITEM_FEATURE_COUNT + 1;
4484
	public static final int RENDERED_MENU_ITEM_FEATURE_COUNT = MENU_ITEM_FEATURE_COUNT + 1;
4482
4485
4483
	/**
4486
	/**
4487
	 * The meta object id for the '{@link org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuItemImpl <em>Opaque Menu Item</em>}' class.
4488
	 * <!-- begin-user-doc -->
4489
	 * <!-- end-user-doc -->
4490
	 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuItemImpl
4491
	 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl#getOpaqueMenuItem()
4492
	 * @generated
4493
	 */
4494
	public static final int OPAQUE_MENU_ITEM = 25;
4495
4496
	/**
4497
	 * The feature id for the '<em><b>Element Id</b></em>' attribute.
4498
	 * <!-- begin-user-doc -->
4499
	 * <!-- end-user-doc -->
4500
	 * @generated
4501
	 * @ordered
4502
	 */
4503
	public static final int OPAQUE_MENU_ITEM__ELEMENT_ID = MENU_ITEM__ELEMENT_ID;
4504
4505
	/**
4506
	 * The feature id for the '<em><b>Tags</b></em>' attribute list.
4507
	 * <!-- begin-user-doc -->
4508
	 * <!-- end-user-doc -->
4509
	 * @generated
4510
	 * @ordered
4511
	 */
4512
	public static final int OPAQUE_MENU_ITEM__TAGS = MENU_ITEM__TAGS;
4513
4514
	/**
4515
	 * The feature id for the '<em><b>Widget</b></em>' attribute.
4516
	 * <!-- begin-user-doc -->
4517
	 * <!-- end-user-doc -->
4518
	 * @generated
4519
	 * @ordered
4520
	 */
4521
	public static final int OPAQUE_MENU_ITEM__WIDGET = MENU_ITEM__WIDGET;
4522
4523
	/**
4524
	 * The feature id for the '<em><b>Renderer</b></em>' attribute.
4525
	 * <!-- begin-user-doc -->
4526
	 * <!-- end-user-doc -->
4527
	 * @generated
4528
	 * @ordered
4529
	 */
4530
	public static final int OPAQUE_MENU_ITEM__RENDERER = MENU_ITEM__RENDERER;
4531
4532
	/**
4533
	 * The feature id for the '<em><b>To Be Rendered</b></em>' attribute.
4534
	 * <!-- begin-user-doc -->
4535
	 * <!-- end-user-doc -->
4536
	 * @generated
4537
	 * @ordered
4538
	 */
4539
	public static final int OPAQUE_MENU_ITEM__TO_BE_RENDERED = MENU_ITEM__TO_BE_RENDERED;
4540
4541
	/**
4542
	 * The feature id for the '<em><b>On Top</b></em>' attribute.
4543
	 * <!-- begin-user-doc -->
4544
	 * <!-- end-user-doc -->
4545
	 * @generated
4546
	 * @ordered
4547
	 */
4548
	public static final int OPAQUE_MENU_ITEM__ON_TOP = MENU_ITEM__ON_TOP;
4549
4550
	/**
4551
	 * The feature id for the '<em><b>Visible</b></em>' attribute.
4552
	 * <!-- begin-user-doc -->
4553
	 * <!-- end-user-doc -->
4554
	 * @generated
4555
	 * @ordered
4556
	 */
4557
	public static final int OPAQUE_MENU_ITEM__VISIBLE = MENU_ITEM__VISIBLE;
4558
4559
	/**
4560
	 * The feature id for the '<em><b>Parent</b></em>' container reference.
4561
	 * <!-- begin-user-doc -->
4562
	 * <!-- end-user-doc -->
4563
	 * @generated
4564
	 * @ordered
4565
	 */
4566
	public static final int OPAQUE_MENU_ITEM__PARENT = MENU_ITEM__PARENT;
4567
4568
	/**
4569
	 * The feature id for the '<em><b>Container Data</b></em>' attribute.
4570
	 * <!-- begin-user-doc -->
4571
	 * <!-- end-user-doc -->
4572
	 * @generated
4573
	 * @ordered
4574
	 */
4575
	public static final int OPAQUE_MENU_ITEM__CONTAINER_DATA = MENU_ITEM__CONTAINER_DATA;
4576
4577
	/**
4578
	 * The feature id for the '<em><b>Cur Shared Ref</b></em>' reference.
4579
	 * <!-- begin-user-doc -->
4580
	 * <!-- end-user-doc -->
4581
	 * @generated
4582
	 * @ordered
4583
	 */
4584
	public static final int OPAQUE_MENU_ITEM__CUR_SHARED_REF = MENU_ITEM__CUR_SHARED_REF;
4585
4586
	/**
4587
	 * The feature id for the '<em><b>Visible When</b></em>' containment reference.
4588
	 * <!-- begin-user-doc -->
4589
	 * <!-- end-user-doc -->
4590
	 * @generated
4591
	 * @ordered
4592
	 */
4593
	public static final int OPAQUE_MENU_ITEM__VISIBLE_WHEN = MENU_ITEM__VISIBLE_WHEN;
4594
4595
	/**
4596
	 * The feature id for the '<em><b>Accessibility Phrase</b></em>' attribute.
4597
	 * <!-- begin-user-doc -->
4598
	 * <!-- end-user-doc -->
4599
	 * @generated
4600
	 * @ordered
4601
	 */
4602
	public static final int OPAQUE_MENU_ITEM__ACCESSIBILITY_PHRASE = MENU_ITEM__ACCESSIBILITY_PHRASE;
4603
4604
	/**
4605
	 * The feature id for the '<em><b>Label</b></em>' attribute.
4606
	 * <!-- begin-user-doc -->
4607
	 * <!-- end-user-doc -->
4608
	 * @generated
4609
	 * @ordered
4610
	 */
4611
	public static final int OPAQUE_MENU_ITEM__LABEL = MENU_ITEM__LABEL;
4612
4613
	/**
4614
	 * The feature id for the '<em><b>Icon URI</b></em>' attribute.
4615
	 * <!-- begin-user-doc -->
4616
	 * <!-- end-user-doc -->
4617
	 * @generated
4618
	 * @ordered
4619
	 */
4620
	public static final int OPAQUE_MENU_ITEM__ICON_URI = MENU_ITEM__ICON_URI;
4621
4622
	/**
4623
	 * The feature id for the '<em><b>Tooltip</b></em>' attribute.
4624
	 * <!-- begin-user-doc -->
4625
	 * <!-- end-user-doc -->
4626
	 * @generated
4627
	 * @ordered
4628
	 */
4629
	public static final int OPAQUE_MENU_ITEM__TOOLTIP = MENU_ITEM__TOOLTIP;
4630
4631
	/**
4632
	 * The feature id for the '<em><b>Local Label</b></em>' attribute.
4633
	 * <!-- begin-user-doc -->
4634
	 * <!-- end-user-doc -->
4635
	 * @generated
4636
	 * @ordered
4637
	 */
4638
	public static final int OPAQUE_MENU_ITEM__LOCAL_LABEL = MENU_ITEM__LOCAL_LABEL;
4639
4640
	/**
4641
	 * The feature id for the '<em><b>Local Tooltip</b></em>' attribute.
4642
	 * <!-- begin-user-doc -->
4643
	 * <!-- end-user-doc -->
4644
	 * @generated
4645
	 * @ordered
4646
	 */
4647
	public static final int OPAQUE_MENU_ITEM__LOCAL_TOOLTIP = MENU_ITEM__LOCAL_TOOLTIP;
4648
4649
	/**
4650
	 * The feature id for the '<em><b>Local Image</b></em>' attribute.
4651
	 * <!-- begin-user-doc -->
4652
	 * <!-- end-user-doc -->
4653
	 * @generated
4654
	 * @ordered
4655
	 */
4656
	public static final int OPAQUE_MENU_ITEM__LOCAL_IMAGE = MENU_ITEM__LOCAL_IMAGE;
4657
4658
	/**
4659
	 * The feature id for the '<em><b>Enabled</b></em>' attribute.
4660
	 * <!-- begin-user-doc -->
4661
	 * <!-- end-user-doc -->
4662
	 * @generated
4663
	 * @ordered
4664
	 */
4665
	public static final int OPAQUE_MENU_ITEM__ENABLED = MENU_ITEM__ENABLED;
4666
4667
	/**
4668
	 * The feature id for the '<em><b>Selected</b></em>' attribute.
4669
	 * <!-- begin-user-doc -->
4670
	 * <!-- end-user-doc -->
4671
	 * @generated
4672
	 * @ordered
4673
	 */
4674
	public static final int OPAQUE_MENU_ITEM__SELECTED = MENU_ITEM__SELECTED;
4675
4676
	/**
4677
	 * The feature id for the '<em><b>Type</b></em>' attribute.
4678
	 * <!-- begin-user-doc -->
4679
	 * <!-- end-user-doc -->
4680
	 * @generated
4681
	 * @ordered
4682
	 */
4683
	public static final int OPAQUE_MENU_ITEM__TYPE = MENU_ITEM__TYPE;
4684
4685
	/**
4686
	 * The feature id for the '<em><b>Mnemonics</b></em>' attribute.
4687
	 * <!-- begin-user-doc -->
4688
	 * <!-- end-user-doc -->
4689
	 * @generated
4690
	 * @ordered
4691
	 */
4692
	public static final int OPAQUE_MENU_ITEM__MNEMONICS = MENU_ITEM__MNEMONICS;
4693
4694
	/**
4695
	 * The feature id for the '<em><b>Opaque Item</b></em>' attribute.
4696
	 * <!-- begin-user-doc -->
4697
	 * <!-- end-user-doc -->
4698
	 * @generated
4699
	 * @ordered
4700
	 */
4701
	public static final int OPAQUE_MENU_ITEM__OPAQUE_ITEM = MENU_ITEM_FEATURE_COUNT + 0;
4702
4703
	/**
4704
	 * The number of structural features of the '<em>Opaque Menu Item</em>' class.
4705
	 * <!-- begin-user-doc -->
4706
	 * <!-- end-user-doc -->
4707
	 * @generated
4708
	 * @ordered
4709
	 */
4710
	public static final int OPAQUE_MENU_ITEM_FEATURE_COUNT = MENU_ITEM_FEATURE_COUNT + 1;
4711
4712
	/**
4713
	 * The meta object id for the '{@link org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuSeparatorImpl <em>Opaque Menu Separator</em>}' class.
4714
	 * <!-- begin-user-doc -->
4715
	 * <!-- end-user-doc -->
4716
	 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuSeparatorImpl
4717
	 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl#getOpaqueMenuSeparator()
4718
	 * @generated
4719
	 */
4720
	public static final int OPAQUE_MENU_SEPARATOR = 26;
4721
4722
	/**
4723
	 * The feature id for the '<em><b>Element Id</b></em>' attribute.
4724
	 * <!-- begin-user-doc -->
4725
	 * <!-- end-user-doc -->
4726
	 * @generated
4727
	 * @ordered
4728
	 */
4729
	public static final int OPAQUE_MENU_SEPARATOR__ELEMENT_ID = MENU_SEPARATOR__ELEMENT_ID;
4730
4731
	/**
4732
	 * The feature id for the '<em><b>Tags</b></em>' attribute list.
4733
	 * <!-- begin-user-doc -->
4734
	 * <!-- end-user-doc -->
4735
	 * @generated
4736
	 * @ordered
4737
	 */
4738
	public static final int OPAQUE_MENU_SEPARATOR__TAGS = MENU_SEPARATOR__TAGS;
4739
4740
	/**
4741
	 * The feature id for the '<em><b>Widget</b></em>' attribute.
4742
	 * <!-- begin-user-doc -->
4743
	 * <!-- end-user-doc -->
4744
	 * @generated
4745
	 * @ordered
4746
	 */
4747
	public static final int OPAQUE_MENU_SEPARATOR__WIDGET = MENU_SEPARATOR__WIDGET;
4748
4749
	/**
4750
	 * The feature id for the '<em><b>Renderer</b></em>' attribute.
4751
	 * <!-- begin-user-doc -->
4752
	 * <!-- end-user-doc -->
4753
	 * @generated
4754
	 * @ordered
4755
	 */
4756
	public static final int OPAQUE_MENU_SEPARATOR__RENDERER = MENU_SEPARATOR__RENDERER;
4757
4758
	/**
4759
	 * The feature id for the '<em><b>To Be Rendered</b></em>' attribute.
4760
	 * <!-- begin-user-doc -->
4761
	 * <!-- end-user-doc -->
4762
	 * @generated
4763
	 * @ordered
4764
	 */
4765
	public static final int OPAQUE_MENU_SEPARATOR__TO_BE_RENDERED = MENU_SEPARATOR__TO_BE_RENDERED;
4766
4767
	/**
4768
	 * The feature id for the '<em><b>On Top</b></em>' attribute.
4769
	 * <!-- begin-user-doc -->
4770
	 * <!-- end-user-doc -->
4771
	 * @generated
4772
	 * @ordered
4773
	 */
4774
	public static final int OPAQUE_MENU_SEPARATOR__ON_TOP = MENU_SEPARATOR__ON_TOP;
4775
4776
	/**
4777
	 * The feature id for the '<em><b>Visible</b></em>' attribute.
4778
	 * <!-- begin-user-doc -->
4779
	 * <!-- end-user-doc -->
4780
	 * @generated
4781
	 * @ordered
4782
	 */
4783
	public static final int OPAQUE_MENU_SEPARATOR__VISIBLE = MENU_SEPARATOR__VISIBLE;
4784
4785
	/**
4786
	 * The feature id for the '<em><b>Parent</b></em>' container reference.
4787
	 * <!-- begin-user-doc -->
4788
	 * <!-- end-user-doc -->
4789
	 * @generated
4790
	 * @ordered
4791
	 */
4792
	public static final int OPAQUE_MENU_SEPARATOR__PARENT = MENU_SEPARATOR__PARENT;
4793
4794
	/**
4795
	 * The feature id for the '<em><b>Container Data</b></em>' attribute.
4796
	 * <!-- begin-user-doc -->
4797
	 * <!-- end-user-doc -->
4798
	 * @generated
4799
	 * @ordered
4800
	 */
4801
	public static final int OPAQUE_MENU_SEPARATOR__CONTAINER_DATA = MENU_SEPARATOR__CONTAINER_DATA;
4802
4803
	/**
4804
	 * The feature id for the '<em><b>Cur Shared Ref</b></em>' reference.
4805
	 * <!-- begin-user-doc -->
4806
	 * <!-- end-user-doc -->
4807
	 * @generated
4808
	 * @ordered
4809
	 */
4810
	public static final int OPAQUE_MENU_SEPARATOR__CUR_SHARED_REF = MENU_SEPARATOR__CUR_SHARED_REF;
4811
4812
	/**
4813
	 * The feature id for the '<em><b>Visible When</b></em>' containment reference.
4814
	 * <!-- begin-user-doc -->
4815
	 * <!-- end-user-doc -->
4816
	 * @generated
4817
	 * @ordered
4818
	 */
4819
	public static final int OPAQUE_MENU_SEPARATOR__VISIBLE_WHEN = MENU_SEPARATOR__VISIBLE_WHEN;
4820
4821
	/**
4822
	 * The feature id for the '<em><b>Accessibility Phrase</b></em>' attribute.
4823
	 * <!-- begin-user-doc -->
4824
	 * <!-- end-user-doc -->
4825
	 * @generated
4826
	 * @ordered
4827
	 */
4828
	public static final int OPAQUE_MENU_SEPARATOR__ACCESSIBILITY_PHRASE = MENU_SEPARATOR__ACCESSIBILITY_PHRASE;
4829
4830
	/**
4831
	 * The feature id for the '<em><b>Label</b></em>' attribute.
4832
	 * <!-- begin-user-doc -->
4833
	 * <!-- end-user-doc -->
4834
	 * @generated
4835
	 * @ordered
4836
	 */
4837
	public static final int OPAQUE_MENU_SEPARATOR__LABEL = MENU_SEPARATOR__LABEL;
4838
4839
	/**
4840
	 * The feature id for the '<em><b>Icon URI</b></em>' attribute.
4841
	 * <!-- begin-user-doc -->
4842
	 * <!-- end-user-doc -->
4843
	 * @generated
4844
	 * @ordered
4845
	 */
4846
	public static final int OPAQUE_MENU_SEPARATOR__ICON_URI = MENU_SEPARATOR__ICON_URI;
4847
4848
	/**
4849
	 * The feature id for the '<em><b>Tooltip</b></em>' attribute.
4850
	 * <!-- begin-user-doc -->
4851
	 * <!-- end-user-doc -->
4852
	 * @generated
4853
	 * @ordered
4854
	 */
4855
	public static final int OPAQUE_MENU_SEPARATOR__TOOLTIP = MENU_SEPARATOR__TOOLTIP;
4856
4857
	/**
4858
	 * The feature id for the '<em><b>Local Label</b></em>' attribute.
4859
	 * <!-- begin-user-doc -->
4860
	 * <!-- end-user-doc -->
4861
	 * @generated
4862
	 * @ordered
4863
	 */
4864
	public static final int OPAQUE_MENU_SEPARATOR__LOCAL_LABEL = MENU_SEPARATOR__LOCAL_LABEL;
4865
4866
	/**
4867
	 * The feature id for the '<em><b>Local Tooltip</b></em>' attribute.
4868
	 * <!-- begin-user-doc -->
4869
	 * <!-- end-user-doc -->
4870
	 * @generated
4871
	 * @ordered
4872
	 */
4873
	public static final int OPAQUE_MENU_SEPARATOR__LOCAL_TOOLTIP = MENU_SEPARATOR__LOCAL_TOOLTIP;
4874
4875
	/**
4876
	 * The feature id for the '<em><b>Local Image</b></em>' attribute.
4877
	 * <!-- begin-user-doc -->
4878
	 * <!-- end-user-doc -->
4879
	 * @generated
4880
	 * @ordered
4881
	 */
4882
	public static final int OPAQUE_MENU_SEPARATOR__LOCAL_IMAGE = MENU_SEPARATOR__LOCAL_IMAGE;
4883
4884
	/**
4885
	 * The feature id for the '<em><b>Opaque Item</b></em>' attribute.
4886
	 * <!-- begin-user-doc -->
4887
	 * <!-- end-user-doc -->
4888
	 * @generated
4889
	 * @ordered
4890
	 */
4891
	public static final int OPAQUE_MENU_SEPARATOR__OPAQUE_ITEM = MENU_SEPARATOR_FEATURE_COUNT + 0;
4892
4893
	/**
4894
	 * The number of structural features of the '<em>Opaque Menu Separator</em>' class.
4895
	 * <!-- begin-user-doc -->
4896
	 * <!-- end-user-doc -->
4897
	 * @generated
4898
	 * @ordered
4899
	 */
4900
	public static final int OPAQUE_MENU_SEPARATOR_FEATURE_COUNT = MENU_SEPARATOR_FEATURE_COUNT + 1;
4901
4902
	/**
4903
	 * The meta object id for the '{@link org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuImpl <em>Opaque Menu</em>}' class.
4904
	 * <!-- begin-user-doc -->
4905
	 * <!-- end-user-doc -->
4906
	 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuImpl
4907
	 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl#getOpaqueMenu()
4908
	 * @generated
4909
	 */
4910
	public static final int OPAQUE_MENU = 27;
4911
4912
	/**
4913
	 * The feature id for the '<em><b>Element Id</b></em>' attribute.
4914
	 * <!-- begin-user-doc -->
4915
	 * <!-- end-user-doc -->
4916
	 * @generated
4917
	 * @ordered
4918
	 */
4919
	public static final int OPAQUE_MENU__ELEMENT_ID = MENU__ELEMENT_ID;
4920
4921
	/**
4922
	 * The feature id for the '<em><b>Tags</b></em>' attribute list.
4923
	 * <!-- begin-user-doc -->
4924
	 * <!-- end-user-doc -->
4925
	 * @generated
4926
	 * @ordered
4927
	 */
4928
	public static final int OPAQUE_MENU__TAGS = MENU__TAGS;
4929
4930
	/**
4931
	 * The feature id for the '<em><b>Widget</b></em>' attribute.
4932
	 * <!-- begin-user-doc -->
4933
	 * <!-- end-user-doc -->
4934
	 * @generated
4935
	 * @ordered
4936
	 */
4937
	public static final int OPAQUE_MENU__WIDGET = MENU__WIDGET;
4938
4939
	/**
4940
	 * The feature id for the '<em><b>Renderer</b></em>' attribute.
4941
	 * <!-- begin-user-doc -->
4942
	 * <!-- end-user-doc -->
4943
	 * @generated
4944
	 * @ordered
4945
	 */
4946
	public static final int OPAQUE_MENU__RENDERER = MENU__RENDERER;
4947
4948
	/**
4949
	 * The feature id for the '<em><b>To Be Rendered</b></em>' attribute.
4950
	 * <!-- begin-user-doc -->
4951
	 * <!-- end-user-doc -->
4952
	 * @generated
4953
	 * @ordered
4954
	 */
4955
	public static final int OPAQUE_MENU__TO_BE_RENDERED = MENU__TO_BE_RENDERED;
4956
4957
	/**
4958
	 * The feature id for the '<em><b>On Top</b></em>' attribute.
4959
	 * <!-- begin-user-doc -->
4960
	 * <!-- end-user-doc -->
4961
	 * @generated
4962
	 * @ordered
4963
	 */
4964
	public static final int OPAQUE_MENU__ON_TOP = MENU__ON_TOP;
4965
4966
	/**
4967
	 * The feature id for the '<em><b>Visible</b></em>' attribute.
4968
	 * <!-- begin-user-doc -->
4969
	 * <!-- end-user-doc -->
4970
	 * @generated
4971
	 * @ordered
4972
	 */
4973
	public static final int OPAQUE_MENU__VISIBLE = MENU__VISIBLE;
4974
4975
	/**
4976
	 * The feature id for the '<em><b>Parent</b></em>' container reference.
4977
	 * <!-- begin-user-doc -->
4978
	 * <!-- end-user-doc -->
4979
	 * @generated
4980
	 * @ordered
4981
	 */
4982
	public static final int OPAQUE_MENU__PARENT = MENU__PARENT;
4983
4984
	/**
4985
	 * The feature id for the '<em><b>Container Data</b></em>' attribute.
4986
	 * <!-- begin-user-doc -->
4987
	 * <!-- end-user-doc -->
4988
	 * @generated
4989
	 * @ordered
4990
	 */
4991
	public static final int OPAQUE_MENU__CONTAINER_DATA = MENU__CONTAINER_DATA;
4992
4993
	/**
4994
	 * The feature id for the '<em><b>Cur Shared Ref</b></em>' reference.
4995
	 * <!-- begin-user-doc -->
4996
	 * <!-- end-user-doc -->
4997
	 * @generated
4998
	 * @ordered
4999
	 */
5000
	public static final int OPAQUE_MENU__CUR_SHARED_REF = MENU__CUR_SHARED_REF;
5001
5002
	/**
5003
	 * The feature id for the '<em><b>Visible When</b></em>' containment reference.
5004
	 * <!-- begin-user-doc -->
5005
	 * <!-- end-user-doc -->
5006
	 * @generated
5007
	 * @ordered
5008
	 */
5009
	public static final int OPAQUE_MENU__VISIBLE_WHEN = MENU__VISIBLE_WHEN;
5010
5011
	/**
5012
	 * The feature id for the '<em><b>Accessibility Phrase</b></em>' attribute.
5013
	 * <!-- begin-user-doc -->
5014
	 * <!-- end-user-doc -->
5015
	 * @generated
5016
	 * @ordered
5017
	 */
5018
	public static final int OPAQUE_MENU__ACCESSIBILITY_PHRASE = MENU__ACCESSIBILITY_PHRASE;
5019
5020
	/**
5021
	 * The feature id for the '<em><b>Label</b></em>' attribute.
5022
	 * <!-- begin-user-doc -->
5023
	 * <!-- end-user-doc -->
5024
	 * @generated
5025
	 * @ordered
5026
	 */
5027
	public static final int OPAQUE_MENU__LABEL = MENU__LABEL;
5028
5029
	/**
5030
	 * The feature id for the '<em><b>Icon URI</b></em>' attribute.
5031
	 * <!-- begin-user-doc -->
5032
	 * <!-- end-user-doc -->
5033
	 * @generated
5034
	 * @ordered
5035
	 */
5036
	public static final int OPAQUE_MENU__ICON_URI = MENU__ICON_URI;
5037
5038
	/**
5039
	 * The feature id for the '<em><b>Tooltip</b></em>' attribute.
5040
	 * <!-- begin-user-doc -->
5041
	 * <!-- end-user-doc -->
5042
	 * @generated
5043
	 * @ordered
5044
	 */
5045
	public static final int OPAQUE_MENU__TOOLTIP = MENU__TOOLTIP;
5046
5047
	/**
5048
	 * The feature id for the '<em><b>Local Label</b></em>' attribute.
5049
	 * <!-- begin-user-doc -->
5050
	 * <!-- end-user-doc -->
5051
	 * @generated
5052
	 * @ordered
5053
	 */
5054
	public static final int OPAQUE_MENU__LOCAL_LABEL = MENU__LOCAL_LABEL;
5055
5056
	/**
5057
	 * The feature id for the '<em><b>Local Tooltip</b></em>' attribute.
5058
	 * <!-- begin-user-doc -->
5059
	 * <!-- end-user-doc -->
5060
	 * @generated
5061
	 * @ordered
5062
	 */
5063
	public static final int OPAQUE_MENU__LOCAL_TOOLTIP = MENU__LOCAL_TOOLTIP;
5064
5065
	/**
5066
	 * The feature id for the '<em><b>Local Image</b></em>' attribute.
5067
	 * <!-- begin-user-doc -->
5068
	 * <!-- end-user-doc -->
5069
	 * @generated
5070
	 * @ordered
5071
	 */
5072
	public static final int OPAQUE_MENU__LOCAL_IMAGE = MENU__LOCAL_IMAGE;
5073
5074
	/**
5075
	 * The feature id for the '<em><b>Children</b></em>' containment reference list.
5076
	 * <!-- begin-user-doc -->
5077
	 * <!-- end-user-doc -->
5078
	 * @generated
5079
	 * @ordered
5080
	 */
5081
	public static final int OPAQUE_MENU__CHILDREN = MENU__CHILDREN;
5082
5083
	/**
5084
	 * The feature id for the '<em><b>Selected Element</b></em>' reference.
5085
	 * <!-- begin-user-doc -->
5086
	 * <!-- end-user-doc -->
5087
	 * @generated
5088
	 * @ordered
5089
	 */
5090
	public static final int OPAQUE_MENU__SELECTED_ELEMENT = MENU__SELECTED_ELEMENT;
5091
5092
	/**
5093
	 * The feature id for the '<em><b>Enabled</b></em>' attribute.
5094
	 * <!-- begin-user-doc -->
5095
	 * <!-- end-user-doc -->
5096
	 * @generated
5097
	 * @ordered
5098
	 */
5099
	public static final int OPAQUE_MENU__ENABLED = MENU__ENABLED;
5100
5101
	/**
5102
	 * The number of structural features of the '<em>Opaque Menu</em>' class.
5103
	 * <!-- begin-user-doc -->
5104
	 * <!-- end-user-doc -->
5105
	 * @generated
5106
	 * @ordered
5107
	 */
5108
	public static final int OPAQUE_MENU_FEATURE_COUNT = MENU_FEATURE_COUNT + 0;
5109
5110
	/**
4484
	 * The meta object id for the '{@link org.eclipse.e4.ui.model.application.ui.menu.ItemType <em>Item Type</em>}' enum.
5111
	 * The meta object id for the '{@link org.eclipse.e4.ui.model.application.ui.menu.ItemType <em>Item Type</em>}' enum.
4485
	 * <!-- begin-user-doc -->
5112
	 * <!-- begin-user-doc -->
4486
	 * <!-- end-user-doc -->
5113
	 * <!-- end-user-doc -->
Lines 4488-4494 Link Here
4488
	 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl#getItemType()
5115
	 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl#getItemType()
4489
	 * @generated
5116
	 * @generated
4490
	 */
5117
	 */
4491
	public static final int ITEM_TYPE = 25;
5118
	public static final int ITEM_TYPE = 28;
4492
5119
4493
	/**
5120
	/**
4494
	 * <!-- begin-user-doc -->
5121
	 * <!-- begin-user-doc -->
Lines 4670-4675 Link Here
4670
	 * <!-- end-user-doc -->
5297
	 * <!-- end-user-doc -->
4671
	 * @generated
5298
	 * @generated
4672
	 */
5299
	 */
5300
	private EClass opaqueMenuItemEClass = null;
5301
5302
	/**
5303
	 * <!-- begin-user-doc -->
5304
	 * <!-- end-user-doc -->
5305
	 * @generated
5306
	 */
5307
	private EClass opaqueMenuSeparatorEClass = null;
5308
5309
	/**
5310
	 * <!-- begin-user-doc -->
5311
	 * <!-- end-user-doc -->
5312
	 * @generated
5313
	 */
5314
	private EClass opaqueMenuEClass = null;
5315
5316
	/**
5317
	 * <!-- begin-user-doc -->
5318
	 * <!-- end-user-doc -->
5319
	 * @generated
5320
	 */
4673
	private EEnum itemTypeEEnum = null;
5321
	private EEnum itemTypeEEnum = null;
4674
5322
4675
	/**
5323
	/**
Lines 5351-5356 Link Here
5351
5999
5352
6000
5353
	/**
6001
	/**
6002
	 * Returns the meta object for class '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem <em>Opaque Menu Item</em>}'.
6003
	 * <!-- begin-user-doc -->
6004
	 * <!-- end-user-doc -->
6005
	 * @return the meta object for class '<em>Opaque Menu Item</em>'.
6006
	 * @see org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem
6007
	 * @generated
6008
	 */
6009
	public EClass getOpaqueMenuItem() {
6010
		return opaqueMenuItemEClass;
6011
	}
6012
6013
6014
	/**
6015
	 * Returns the meta object for the attribute '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem#getOpaqueItem <em>Opaque Item</em>}'.
6016
	 * <!-- begin-user-doc -->
6017
	 * <!-- end-user-doc -->
6018
	 * @return the meta object for the attribute '<em>Opaque Item</em>'.
6019
	 * @see org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem#getOpaqueItem()
6020
	 * @see #getOpaqueMenuItem()
6021
	 * @generated
6022
	 */
6023
	public EAttribute getOpaqueMenuItem_OpaqueItem() {
6024
		return (EAttribute)opaqueMenuItemEClass.getEStructuralFeatures().get(0);
6025
	}
6026
6027
6028
	/**
6029
	 * Returns the meta object for class '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator <em>Opaque Menu Separator</em>}'.
6030
	 * <!-- begin-user-doc -->
6031
	 * <!-- end-user-doc -->
6032
	 * @return the meta object for class '<em>Opaque Menu Separator</em>'.
6033
	 * @see org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator
6034
	 * @generated
6035
	 */
6036
	public EClass getOpaqueMenuSeparator() {
6037
		return opaqueMenuSeparatorEClass;
6038
	}
6039
6040
6041
	/**
6042
	 * Returns the meta object for the attribute '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator#getOpaqueItem <em>Opaque Item</em>}'.
6043
	 * <!-- begin-user-doc -->
6044
	 * <!-- end-user-doc -->
6045
	 * @return the meta object for the attribute '<em>Opaque Item</em>'.
6046
	 * @see org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator#getOpaqueItem()
6047
	 * @see #getOpaqueMenuSeparator()
6048
	 * @generated
6049
	 */
6050
	public EAttribute getOpaqueMenuSeparator_OpaqueItem() {
6051
		return (EAttribute)opaqueMenuSeparatorEClass.getEStructuralFeatures().get(0);
6052
	}
6053
6054
6055
	/**
6056
	 * Returns the meta object for class '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenu <em>Opaque Menu</em>}'.
6057
	 * <!-- begin-user-doc -->
6058
	 * <!-- end-user-doc -->
6059
	 * @return the meta object for class '<em>Opaque Menu</em>'.
6060
	 * @see org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenu
6061
	 * @generated
6062
	 */
6063
	public EClass getOpaqueMenu() {
6064
		return opaqueMenuEClass;
6065
	}
6066
6067
6068
	/**
5354
	 * Returns the meta object for enum '{@link org.eclipse.e4.ui.model.application.ui.menu.ItemType <em>Item Type</em>}'.
6069
	 * Returns the meta object for enum '{@link org.eclipse.e4.ui.model.application.ui.menu.ItemType <em>Item Type</em>}'.
5355
	 * <!-- begin-user-doc -->
6070
	 * <!-- begin-user-doc -->
5356
	 * <!-- end-user-doc -->
6071
	 * <!-- end-user-doc -->
Lines 5463-5468 Link Here
5463
		renderedMenuItemEClass = createEClass(RENDERED_MENU_ITEM);
6178
		renderedMenuItemEClass = createEClass(RENDERED_MENU_ITEM);
5464
		createEAttribute(renderedMenuItemEClass, RENDERED_MENU_ITEM__CONTRIBUTION_ITEM);
6179
		createEAttribute(renderedMenuItemEClass, RENDERED_MENU_ITEM__CONTRIBUTION_ITEM);
5465
6180
6181
		opaqueMenuItemEClass = createEClass(OPAQUE_MENU_ITEM);
6182
		createEAttribute(opaqueMenuItemEClass, OPAQUE_MENU_ITEM__OPAQUE_ITEM);
6183
6184
		opaqueMenuSeparatorEClass = createEClass(OPAQUE_MENU_SEPARATOR);
6185
		createEAttribute(opaqueMenuSeparatorEClass, OPAQUE_MENU_SEPARATOR__OPAQUE_ITEM);
6186
6187
		opaqueMenuEClass = createEClass(OPAQUE_MENU);
6188
5466
		// Create enums
6189
		// Create enums
5467
		itemTypeEEnum = createEEnum(ITEM_TYPE);
6190
		itemTypeEEnum = createEEnum(ITEM_TYPE);
5468
	}
6191
	}
Lines 5553-5558 Link Here
5553
		g1.getETypeArguments().add(g2);
6276
		g1.getETypeArguments().add(g2);
5554
		trimContributionEClass.getEGenericSuperTypes().add(g1);
6277
		trimContributionEClass.getEGenericSuperTypes().add(g1);
5555
		renderedMenuItemEClass.getESuperTypes().add(this.getMenuItem());
6278
		renderedMenuItemEClass.getESuperTypes().add(this.getMenuItem());
6279
		opaqueMenuItemEClass.getESuperTypes().add(this.getMenuItem());
6280
		opaqueMenuSeparatorEClass.getESuperTypes().add(this.getMenuSeparator());
6281
		opaqueMenuEClass.getESuperTypes().add(this.getMenu());
5556
6282
5557
		// Initialize classes and features; add operations and parameters
6283
		// Initialize classes and features; add operations and parameters
5558
		initEClass(itemEClass, MItem.class, "Item", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
6284
		initEClass(itemEClass, MItem.class, "Item", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
Lines 5626-5631 Link Here
5626
		initEClass(renderedMenuItemEClass, MRenderedMenuItem.class, "RenderedMenuItem", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
6352
		initEClass(renderedMenuItemEClass, MRenderedMenuItem.class, "RenderedMenuItem", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
5627
		initEAttribute(getRenderedMenuItem_ContributionItem(), ecorePackage.getEJavaObject(), "contributionItem", null, 0, 1, MRenderedMenuItem.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
6353
		initEAttribute(getRenderedMenuItem_ContributionItem(), ecorePackage.getEJavaObject(), "contributionItem", null, 0, 1, MRenderedMenuItem.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
5628
6354
6355
		initEClass(opaqueMenuItemEClass, MOpaqueMenuItem.class, "OpaqueMenuItem", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
6356
		initEAttribute(getOpaqueMenuItem_OpaqueItem(), ecorePackage.getEJavaObject(), "opaqueItem", null, 0, 1, MOpaqueMenuItem.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
6357
6358
		initEClass(opaqueMenuSeparatorEClass, MOpaqueMenuSeparator.class, "OpaqueMenuSeparator", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
6359
		initEAttribute(getOpaqueMenuSeparator_OpaqueItem(), ecorePackage.getEJavaObject(), "opaqueItem", null, 0, 1, MOpaqueMenuSeparator.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
6360
6361
		initEClass(opaqueMenuEClass, MOpaqueMenu.class, "OpaqueMenu", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
6362
5629
		// Initialize enums and add enum literals
6363
		// Initialize enums and add enum literals
5630
		initEEnum(itemTypeEEnum, ItemType.class, "ItemType"); //$NON-NLS-1$
6364
		initEEnum(itemTypeEEnum, ItemType.class, "ItemType"); //$NON-NLS-1$
5631
		addEEnumLiteral(itemTypeEEnum, ItemType.PUSH);
6365
		addEEnumLiteral(itemTypeEEnum, ItemType.PUSH);
Lines 6065-6070 Link Here
6065
		public static final EAttribute RENDERED_MENU_ITEM__CONTRIBUTION_ITEM = eINSTANCE.getRenderedMenuItem_ContributionItem();
6799
		public static final EAttribute RENDERED_MENU_ITEM__CONTRIBUTION_ITEM = eINSTANCE.getRenderedMenuItem_ContributionItem();
6066
6800
6067
		/**
6801
		/**
6802
		 * The meta object literal for the '{@link org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuItemImpl <em>Opaque Menu Item</em>}' class.
6803
		 * <!-- begin-user-doc -->
6804
		 * <!-- end-user-doc -->
6805
		 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuItemImpl
6806
		 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl#getOpaqueMenuItem()
6807
		 * @generated
6808
		 */
6809
		public static final EClass OPAQUE_MENU_ITEM = eINSTANCE.getOpaqueMenuItem();
6810
6811
		/**
6812
		 * The meta object literal for the '<em><b>Opaque Item</b></em>' attribute feature.
6813
		 * <!-- begin-user-doc -->
6814
		 * <!-- end-user-doc -->
6815
		 * @generated
6816
		 */
6817
		public static final EAttribute OPAQUE_MENU_ITEM__OPAQUE_ITEM = eINSTANCE.getOpaqueMenuItem_OpaqueItem();
6818
6819
		/**
6820
		 * The meta object literal for the '{@link org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuSeparatorImpl <em>Opaque Menu Separator</em>}' class.
6821
		 * <!-- begin-user-doc -->
6822
		 * <!-- end-user-doc -->
6823
		 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuSeparatorImpl
6824
		 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl#getOpaqueMenuSeparator()
6825
		 * @generated
6826
		 */
6827
		public static final EClass OPAQUE_MENU_SEPARATOR = eINSTANCE.getOpaqueMenuSeparator();
6828
6829
		/**
6830
		 * The meta object literal for the '<em><b>Opaque Item</b></em>' attribute feature.
6831
		 * <!-- begin-user-doc -->
6832
		 * <!-- end-user-doc -->
6833
		 * @generated
6834
		 */
6835
		public static final EAttribute OPAQUE_MENU_SEPARATOR__OPAQUE_ITEM = eINSTANCE.getOpaqueMenuSeparator_OpaqueItem();
6836
6837
		/**
6838
		 * The meta object literal for the '{@link org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuImpl <em>Opaque Menu</em>}' class.
6839
		 * <!-- begin-user-doc -->
6840
		 * <!-- end-user-doc -->
6841
		 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuImpl
6842
		 * @see org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl#getOpaqueMenu()
6843
		 * @generated
6844
		 */
6845
		public static final EClass OPAQUE_MENU = eINSTANCE.getOpaqueMenu();
6846
6847
		/**
6068
		 * The meta object literal for the '{@link org.eclipse.e4.ui.model.application.ui.menu.ItemType <em>Item Type</em>}' enum.
6848
		 * The meta object literal for the '{@link org.eclipse.e4.ui.model.application.ui.menu.ItemType <em>Item Type</em>}' enum.
6069
		 * <!-- begin-user-doc -->
6849
		 * <!-- begin-user-doc -->
6070
		 * <!-- end-user-doc -->
6850
		 * <!-- end-user-doc -->
(-)src/org/eclipse/e4/ui/model/application/ui/menu/impl/OpaqueMenuImpl.java (+46 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *      IBM Corporation - initial API and implementation
10
 */
11
package org.eclipse.e4.ui.model.application.ui.menu.impl;
12
13
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenu;
14
15
import org.eclipse.emf.ecore.EClass;
16
17
/**
18
 * <!-- begin-user-doc -->
19
 * An implementation of the model object '<em><b>Opaque Menu</b></em>'.
20
 * <!-- end-user-doc -->
21
 * <p>
22
 * </p>
23
 *
24
 * @generated
25
 */
26
public class OpaqueMenuImpl extends MenuImpl implements MOpaqueMenu {
27
	/**
28
	 * <!-- begin-user-doc -->
29
	 * <!-- end-user-doc -->
30
	 * @generated
31
	 */
32
	protected OpaqueMenuImpl() {
33
		super();
34
	}
35
36
	/**
37
	 * <!-- begin-user-doc -->
38
	 * <!-- end-user-doc -->
39
	 * @generated
40
	 */
41
	@Override
42
	protected EClass eStaticClass() {
43
		return MenuPackageImpl.Literals.OPAQUE_MENU;
44
	}
45
46
} //OpaqueMenuImpl
(-)src/org/eclipse/e4/ui/model/application/ui/menu/impl/OpaqueMenuItemImpl.java (+169 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *      IBM Corporation - initial API and implementation
10
 */
11
package org.eclipse.e4.ui.model.application.ui.menu.impl;
12
13
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem;
14
15
import org.eclipse.emf.common.notify.Notification;
16
17
import org.eclipse.emf.ecore.EClass;
18
19
import org.eclipse.emf.ecore.impl.ENotificationImpl;
20
21
/**
22
 * <!-- begin-user-doc -->
23
 * An implementation of the model object '<em><b>Opaque Menu Item</b></em>'.
24
 * <!-- end-user-doc -->
25
 * <p>
26
 * The following features are implemented:
27
 * <ul>
28
 *   <li>{@link org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuItemImpl#getOpaqueItem <em>Opaque Item</em>}</li>
29
 * </ul>
30
 * </p>
31
 *
32
 * @generated
33
 */
34
public class OpaqueMenuItemImpl extends MenuItemImpl implements MOpaqueMenuItem {
35
	/**
36
	 * The default value of the '{@link #getOpaqueItem() <em>Opaque Item</em>}' attribute.
37
	 * <!-- begin-user-doc -->
38
	 * <!-- end-user-doc -->
39
	 * @see #getOpaqueItem()
40
	 * @generated
41
	 * @ordered
42
	 */
43
	protected static final Object OPAQUE_ITEM_EDEFAULT = null;
44
45
	/**
46
	 * The cached value of the '{@link #getOpaqueItem() <em>Opaque Item</em>}' attribute.
47
	 * <!-- begin-user-doc -->
48
	 * <!-- end-user-doc -->
49
	 * @see #getOpaqueItem()
50
	 * @generated
51
	 * @ordered
52
	 */
53
	protected Object opaqueItem = OPAQUE_ITEM_EDEFAULT;
54
55
	/**
56
	 * <!-- begin-user-doc -->
57
	 * <!-- end-user-doc -->
58
	 * @generated
59
	 */
60
	protected OpaqueMenuItemImpl() {
61
		super();
62
	}
63
64
	/**
65
	 * <!-- begin-user-doc -->
66
	 * <!-- end-user-doc -->
67
	 * @generated
68
	 */
69
	@Override
70
	protected EClass eStaticClass() {
71
		return MenuPackageImpl.Literals.OPAQUE_MENU_ITEM;
72
	}
73
74
	/**
75
	 * <!-- begin-user-doc -->
76
	 * <!-- end-user-doc -->
77
	 * @generated
78
	 */
79
	public Object getOpaqueItem() {
80
		return opaqueItem;
81
	}
82
83
	/**
84
	 * <!-- begin-user-doc -->
85
	 * <!-- end-user-doc -->
86
	 * @generated
87
	 */
88
	public void setOpaqueItem(Object newOpaqueItem) {
89
		Object oldOpaqueItem = opaqueItem;
90
		opaqueItem = newOpaqueItem;
91
		if (eNotificationRequired())
92
			eNotify(new ENotificationImpl(this, Notification.SET, MenuPackageImpl.OPAQUE_MENU_ITEM__OPAQUE_ITEM, oldOpaqueItem, opaqueItem));
93
	}
94
95
	/**
96
	 * <!-- begin-user-doc -->
97
	 * <!-- end-user-doc -->
98
	 * @generated
99
	 */
100
	@Override
101
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
102
		switch (featureID) {
103
			case MenuPackageImpl.OPAQUE_MENU_ITEM__OPAQUE_ITEM:
104
				return getOpaqueItem();
105
		}
106
		return super.eGet(featureID, resolve, coreType);
107
	}
108
109
	/**
110
	 * <!-- begin-user-doc -->
111
	 * <!-- end-user-doc -->
112
	 * @generated
113
	 */
114
	@Override
115
	public void eSet(int featureID, Object newValue) {
116
		switch (featureID) {
117
			case MenuPackageImpl.OPAQUE_MENU_ITEM__OPAQUE_ITEM:
118
				setOpaqueItem(newValue);
119
				return;
120
		}
121
		super.eSet(featureID, newValue);
122
	}
123
124
	/**
125
	 * <!-- begin-user-doc -->
126
	 * <!-- end-user-doc -->
127
	 * @generated
128
	 */
129
	@Override
130
	public void eUnset(int featureID) {
131
		switch (featureID) {
132
			case MenuPackageImpl.OPAQUE_MENU_ITEM__OPAQUE_ITEM:
133
				setOpaqueItem(OPAQUE_ITEM_EDEFAULT);
134
				return;
135
		}
136
		super.eUnset(featureID);
137
	}
138
139
	/**
140
	 * <!-- begin-user-doc -->
141
	 * <!-- end-user-doc -->
142
	 * @generated
143
	 */
144
	@Override
145
	public boolean eIsSet(int featureID) {
146
		switch (featureID) {
147
			case MenuPackageImpl.OPAQUE_MENU_ITEM__OPAQUE_ITEM:
148
				return OPAQUE_ITEM_EDEFAULT == null ? opaqueItem != null : !OPAQUE_ITEM_EDEFAULT.equals(opaqueItem);
149
		}
150
		return super.eIsSet(featureID);
151
	}
152
153
	/**
154
	 * <!-- begin-user-doc -->
155
	 * <!-- end-user-doc -->
156
	 * @generated
157
	 */
158
	@Override
159
	public String toString() {
160
		if (eIsProxy()) return super.toString();
161
162
		StringBuffer result = new StringBuffer(super.toString());
163
		result.append(" (opaqueItem: "); //$NON-NLS-1$
164
		result.append(opaqueItem);
165
		result.append(')');
166
		return result.toString();
167
	}
168
169
} //OpaqueMenuItemImpl
(-)src/org/eclipse/e4/ui/model/application/ui/menu/impl/OpaqueMenuSeparatorImpl.java (+166 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *      IBM Corporation - initial API and implementation
10
 */
11
package org.eclipse.e4.ui.model.application.ui.menu.impl;
12
13
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator;
14
15
import org.eclipse.emf.common.notify.Notification;
16
import org.eclipse.emf.ecore.EClass;
17
import org.eclipse.emf.ecore.impl.ENotificationImpl;
18
19
/**
20
 * <!-- begin-user-doc -->
21
 * An implementation of the model object '<em><b>Opaque Menu Separator</b></em>'.
22
 * <!-- end-user-doc -->
23
 * <p>
24
 * The following features are implemented:
25
 * <ul>
26
 *   <li>{@link org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuSeparatorImpl#getOpaqueItem <em>Opaque Item</em>}</li>
27
 * </ul>
28
 * </p>
29
 *
30
 * @generated
31
 */
32
public class OpaqueMenuSeparatorImpl extends MenuSeparatorImpl implements MOpaqueMenuSeparator {
33
	/**
34
	 * The default value of the '{@link #getOpaqueItem() <em>Opaque Item</em>}' attribute.
35
	 * <!-- begin-user-doc -->
36
	 * <!-- end-user-doc -->
37
	 * @see #getOpaqueItem()
38
	 * @generated
39
	 * @ordered
40
	 */
41
	protected static final Object OPAQUE_ITEM_EDEFAULT = null;
42
	/**
43
	 * The cached value of the '{@link #getOpaqueItem() <em>Opaque Item</em>}' attribute.
44
	 * <!-- begin-user-doc -->
45
	 * <!-- end-user-doc -->
46
	 * @see #getOpaqueItem()
47
	 * @generated
48
	 * @ordered
49
	 */
50
	protected Object opaqueItem = OPAQUE_ITEM_EDEFAULT;
51
52
	/**
53
	 * <!-- begin-user-doc -->
54
	 * <!-- end-user-doc -->
55
	 * @generated
56
	 */
57
	protected OpaqueMenuSeparatorImpl() {
58
		super();
59
	}
60
61
	/**
62
	 * <!-- begin-user-doc -->
63
	 * <!-- end-user-doc -->
64
	 * @generated
65
	 */
66
	@Override
67
	protected EClass eStaticClass() {
68
		return MenuPackageImpl.Literals.OPAQUE_MENU_SEPARATOR;
69
	}
70
71
	/**
72
	 * <!-- begin-user-doc -->
73
	 * <!-- end-user-doc -->
74
	 * @generated
75
	 */
76
	public Object getOpaqueItem() {
77
		return opaqueItem;
78
	}
79
80
	/**
81
	 * <!-- begin-user-doc -->
82
	 * <!-- end-user-doc -->
83
	 * @generated
84
	 */
85
	public void setOpaqueItem(Object newOpaqueItem) {
86
		Object oldOpaqueItem = opaqueItem;
87
		opaqueItem = newOpaqueItem;
88
		if (eNotificationRequired())
89
			eNotify(new ENotificationImpl(this, Notification.SET, MenuPackageImpl.OPAQUE_MENU_SEPARATOR__OPAQUE_ITEM, oldOpaqueItem, opaqueItem));
90
	}
91
92
	/**
93
	 * <!-- begin-user-doc -->
94
	 * <!-- end-user-doc -->
95
	 * @generated
96
	 */
97
	@Override
98
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
99
		switch (featureID) {
100
			case MenuPackageImpl.OPAQUE_MENU_SEPARATOR__OPAQUE_ITEM:
101
				return getOpaqueItem();
102
		}
103
		return super.eGet(featureID, resolve, coreType);
104
	}
105
106
	/**
107
	 * <!-- begin-user-doc -->
108
	 * <!-- end-user-doc -->
109
	 * @generated
110
	 */
111
	@Override
112
	public void eSet(int featureID, Object newValue) {
113
		switch (featureID) {
114
			case MenuPackageImpl.OPAQUE_MENU_SEPARATOR__OPAQUE_ITEM:
115
				setOpaqueItem(newValue);
116
				return;
117
		}
118
		super.eSet(featureID, newValue);
119
	}
120
121
	/**
122
	 * <!-- begin-user-doc -->
123
	 * <!-- end-user-doc -->
124
	 * @generated
125
	 */
126
	@Override
127
	public void eUnset(int featureID) {
128
		switch (featureID) {
129
			case MenuPackageImpl.OPAQUE_MENU_SEPARATOR__OPAQUE_ITEM:
130
				setOpaqueItem(OPAQUE_ITEM_EDEFAULT);
131
				return;
132
		}
133
		super.eUnset(featureID);
134
	}
135
136
	/**
137
	 * <!-- begin-user-doc -->
138
	 * <!-- end-user-doc -->
139
	 * @generated
140
	 */
141
	@Override
142
	public boolean eIsSet(int featureID) {
143
		switch (featureID) {
144
			case MenuPackageImpl.OPAQUE_MENU_SEPARATOR__OPAQUE_ITEM:
145
				return OPAQUE_ITEM_EDEFAULT == null ? opaqueItem != null : !OPAQUE_ITEM_EDEFAULT.equals(opaqueItem);
146
		}
147
		return super.eIsSet(featureID);
148
	}
149
150
	/**
151
	 * <!-- begin-user-doc -->
152
	 * <!-- end-user-doc -->
153
	 * @generated
154
	 */
155
	@Override
156
	public String toString() {
157
		if (eIsProxy()) return super.toString();
158
159
		StringBuffer result = new StringBuffer(super.toString());
160
		result.append(" (opaqueItem: "); //$NON-NLS-1$
161
		result.append(opaqueItem);
162
		result.append(')');
163
		return result.toString();
164
	}
165
166
} //OpaqueMenuSeparatorImpl
(-)src/org/eclipse/e4/ui/model/application/ui/menu/util/MenuAdapterFactory.java (+54 lines)
Lines 206-211 Link Here
206
				return createRenderedMenuItemAdapter();
206
				return createRenderedMenuItemAdapter();
207
			}
207
			}
208
			@Override
208
			@Override
209
			public Adapter caseOpaqueMenuItem(MOpaqueMenuItem object) {
210
				return createOpaqueMenuItemAdapter();
211
			}
212
			@Override
213
			public Adapter caseOpaqueMenuSeparator(MOpaqueMenuSeparator object) {
214
				return createOpaqueMenuSeparatorAdapter();
215
			}
216
			@Override
217
			public Adapter caseOpaqueMenu(MOpaqueMenu object) {
218
				return createOpaqueMenuAdapter();
219
			}
220
			@Override
209
			public Adapter caseApplicationElement(MApplicationElement object) {
221
			public Adapter caseApplicationElement(MApplicationElement object) {
210
				return createApplicationElementAdapter();
222
				return createApplicationElementAdapter();
211
			}
223
			}
Lines 604-609 Link Here
604
	}
616
	}
605
617
606
	/**
618
	/**
619
	 * Creates a new adapter for an object of class '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem <em>Opaque Menu Item</em>}'.
620
	 * <!-- begin-user-doc -->
621
	 * This default implementation returns null so that we can easily ignore cases;
622
	 * it's useful to ignore a case when inheritance will catch all the cases anyway.
623
	 * <!-- end-user-doc -->
624
	 * @return the new adapter.
625
	 * @see org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem
626
	 * @generated
627
	 */
628
	public Adapter createOpaqueMenuItemAdapter() {
629
		return null;
630
	}
631
632
	/**
633
	 * Creates a new adapter for an object of class '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator <em>Opaque Menu Separator</em>}'.
634
	 * <!-- begin-user-doc -->
635
	 * This default implementation returns null so that we can easily ignore cases;
636
	 * it's useful to ignore a case when inheritance will catch all the cases anyway.
637
	 * <!-- end-user-doc -->
638
	 * @return the new adapter.
639
	 * @see org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator
640
	 * @generated
641
	 */
642
	public Adapter createOpaqueMenuSeparatorAdapter() {
643
		return null;
644
	}
645
646
	/**
647
	 * Creates a new adapter for an object of class '{@link org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenu <em>Opaque Menu</em>}'.
648
	 * <!-- begin-user-doc -->
649
	 * This default implementation returns null so that we can easily ignore cases;
650
	 * it's useful to ignore a case when inheritance will catch all the cases anyway.
651
	 * <!-- end-user-doc -->
652
	 * @return the new adapter.
653
	 * @see org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenu
654
	 * @generated
655
	 */
656
	public Adapter createOpaqueMenuAdapter() {
657
		return null;
658
	}
659
660
	/**
607
	 * Creates a new adapter for an object of class '{@link org.eclipse.e4.ui.model.application.MApplicationElement <em>Element</em>}'.
661
	 * Creates a new adapter for an object of class '{@link org.eclipse.e4.ui.model.application.MApplicationElement <em>Element</em>}'.
608
	 * <!-- begin-user-doc -->
662
	 * <!-- begin-user-doc -->
609
	 * This default implementation returns null so that we can easily ignore cases;
663
	 * This default implementation returns null so that we can easily ignore cases;
(-)src/org/eclipse/e4/ui/model/application/ui/menu/util/MenuSwitch.java (+80 lines)
Lines 376-381 Link Here
376
				if (result == null) result = defaultCase(theEObject);
376
				if (result == null) result = defaultCase(theEObject);
377
				return result;
377
				return result;
378
			}
378
			}
379
			case MenuPackageImpl.OPAQUE_MENU_ITEM: {
380
				MOpaqueMenuItem opaqueMenuItem = (MOpaqueMenuItem)theEObject;
381
				T1 result = caseOpaqueMenuItem(opaqueMenuItem);
382
				if (result == null) result = caseMenuItem(opaqueMenuItem);
383
				if (result == null) result = caseItem(opaqueMenuItem);
384
				if (result == null) result = caseMenuElement(opaqueMenuItem);
385
				if (result == null) result = caseUIElement(opaqueMenuItem);
386
				if (result == null) result = caseUILabel(opaqueMenuItem);
387
				if (result == null) result = caseApplicationElement(opaqueMenuItem);
388
				if (result == null) result = defaultCase(theEObject);
389
				return result;
390
			}
391
			case MenuPackageImpl.OPAQUE_MENU_SEPARATOR: {
392
				MOpaqueMenuSeparator opaqueMenuSeparator = (MOpaqueMenuSeparator)theEObject;
393
				T1 result = caseOpaqueMenuSeparator(opaqueMenuSeparator);
394
				if (result == null) result = caseMenuSeparator(opaqueMenuSeparator);
395
				if (result == null) result = caseMenuElement(opaqueMenuSeparator);
396
				if (result == null) result = caseUIElement(opaqueMenuSeparator);
397
				if (result == null) result = caseUILabel(opaqueMenuSeparator);
398
				if (result == null) result = caseApplicationElement(opaqueMenuSeparator);
399
				if (result == null) result = defaultCase(theEObject);
400
				return result;
401
			}
402
			case MenuPackageImpl.OPAQUE_MENU: {
403
				MOpaqueMenu opaqueMenu = (MOpaqueMenu)theEObject;
404
				T1 result = caseOpaqueMenu(opaqueMenu);
405
				if (result == null) result = caseMenu(opaqueMenu);
406
				if (result == null) result = caseMenuElement(opaqueMenu);
407
				if (result == null) result = caseElementContainer(opaqueMenu);
408
				if (result == null) result = caseUIElement(opaqueMenu);
409
				if (result == null) result = caseUILabel(opaqueMenu);
410
				if (result == null) result = caseApplicationElement(opaqueMenu);
411
				if (result == null) result = defaultCase(theEObject);
412
				return result;
413
			}
379
			default: return defaultCase(theEObject);
414
			default: return defaultCase(theEObject);
380
		}
415
		}
381
	}
416
	}
Lines 756-761 Link Here
756
	}
791
	}
757
792
758
	/**
793
	/**
794
	 * Returns the result of interpreting the object as an instance of '<em>Opaque Menu Item</em>'.
795
	 * <!-- begin-user-doc -->
796
	 * This implementation returns null;
797
	 * returning a non-null result will terminate the switch.
798
	 * <!-- end-user-doc -->
799
	 * @param object the target of the switch.
800
	 * @return the result of interpreting the object as an instance of '<em>Opaque Menu Item</em>'.
801
	 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
802
	 * @generated
803
	 */
804
	public T1 caseOpaqueMenuItem(MOpaqueMenuItem object) {
805
		return null;
806
	}
807
808
	/**
809
	 * Returns the result of interpreting the object as an instance of '<em>Opaque Menu Separator</em>'.
810
	 * <!-- begin-user-doc -->
811
	 * This implementation returns null;
812
	 * returning a non-null result will terminate the switch.
813
	 * <!-- end-user-doc -->
814
	 * @param object the target of the switch.
815
	 * @return the result of interpreting the object as an instance of '<em>Opaque Menu Separator</em>'.
816
	 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
817
	 * @generated
818
	 */
819
	public T1 caseOpaqueMenuSeparator(MOpaqueMenuSeparator object) {
820
		return null;
821
	}
822
823
	/**
824
	 * Returns the result of interpreting the object as an instance of '<em>Opaque Menu</em>'.
825
	 * <!-- begin-user-doc -->
826
	 * This implementation returns null;
827
	 * returning a non-null result will terminate the switch.
828
	 * <!-- end-user-doc -->
829
	 * @param object the target of the switch.
830
	 * @return the result of interpreting the object as an instance of '<em>Opaque Menu</em>'.
831
	 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
832
	 * @generated
833
	 */
834
	public T1 caseOpaqueMenu(MOpaqueMenu object) {
835
		return null;
836
	}
837
838
	/**
759
	 * Returns the result of interpreting the object as an instance of '<em>Element</em>'.
839
	 * Returns the result of interpreting the object as an instance of '<em>Element</em>'.
760
	 * <!-- begin-user-doc -->
840
	 * <!-- begin-user-doc -->
761
	 * This implementation returns null;
841
	 * This implementation returns null;
(-)UIAllTests.launch (-1 / +1 lines)
Lines 27-33 Link Here
27
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
27
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
28
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
28
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
29
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
29
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
30
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
30
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
31
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.e4.ui.tests.UIAllTests"/>
31
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.e4.ui.tests.UIAllTests"/>
32
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/>
32
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/>
33
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.e4.ui.tests"/>
33
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.e4.ui.tests"/>
(-)src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java (-14 / +146 lines)
Lines 33-43 Link Here
33
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
33
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
34
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
34
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
35
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
35
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
36
import org.eclipse.e4.ui.workbench.renderers.swt.MenuRenderer;
36
import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer;
37
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
37
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
38
import org.eclipse.jface.action.IContributionItem;
39
import org.eclipse.jface.action.MenuManager;
38
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.widgets.Event;
41
import org.eclipse.swt.widgets.Event;
42
import org.eclipse.swt.widgets.Menu;
40
import org.eclipse.swt.widgets.MenuItem;
43
import org.eclipse.swt.widgets.MenuItem;
44
import org.eclipse.swt.widgets.Widget;
41
45
42
public class MMenuItemTest extends TestCase {
46
public class MMenuItemTest extends TestCase {
43
	protected IEclipseContext appContext;
47
	protected IEclipseContext appContext;
Lines 78-83 Link Here
78
		wb = new E4Workbench(window, appContext);
82
		wb = new E4Workbench(window, appContext);
79
		wb.createAndRunUI(window);
83
		wb.createAndRunUI(window);
80
84
85
		((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true);
86
81
		Object widget = menuItem.getWidget();
87
		Object widget = menuItem.getWidget();
82
		assertNotNull(widget);
88
		assertNotNull(widget);
83
		assertTrue(widget instanceof MenuItem);
89
		assertTrue(widget instanceof MenuItem);
Lines 153-158 Link Here
153
		wb = new E4Workbench(window, appContext);
159
		wb = new E4Workbench(window, appContext);
154
		wb.createAndRunUI(window);
160
		wb.createAndRunUI(window);
155
161
162
		((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true);
163
156
		Object widget1 = menuItem1.getWidget();
164
		Object widget1 = menuItem1.getWidget();
157
		assertNotNull(widget1);
165
		assertNotNull(widget1);
158
		assertTrue(widget1 instanceof MenuItem);
166
		assertTrue(widget1 instanceof MenuItem);
Lines 208-213 Link Here
208
		wb = new E4Workbench(window, appContext);
216
		wb = new E4Workbench(window, appContext);
209
		wb.createAndRunUI(window);
217
		wb.createAndRunUI(window);
210
218
219
		((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true);
220
211
		Object widget1 = menuItem.getWidget();
221
		Object widget1 = menuItem.getWidget();
212
		assertNotNull(widget1);
222
		assertNotNull(widget1);
213
		assertTrue(widget1 instanceof MenuItem);
223
		assertTrue(widget1 instanceof MenuItem);
Lines 224-230 Link Here
224
		MCommand command = CommandsFactoryImpl.eINSTANCE.createCommand();
234
		MCommand command = CommandsFactoryImpl.eINSTANCE.createCommand();
225
235
226
		command.setElementId("commandId");
236
		command.setElementId("commandId");
227
		command.setCommandName("CommandForTest");
228
237
229
		menuItem.setCommand(command);
238
		menuItem.setCommand(command);
230
		menuItem.setType(ItemType.CHECK);
239
		menuItem.setType(ItemType.CHECK);
Lines 236-248 Link Here
236
		MApplication application = ApplicationFactoryImpl.eINSTANCE
245
		MApplication application = ApplicationFactoryImpl.eINSTANCE
237
				.createApplication();
246
				.createApplication();
238
		application.getChildren().add(window);
247
		application.getChildren().add(window);
239
		application.getCommands().add(command);
240
		application.setContext(appContext);
248
		application.setContext(appContext);
241
		appContext.set(MApplication.class.getName(), application);
249
		appContext.set(MApplication.class.getName(), application);
242
250
243
		wb = new E4Workbench(window, appContext);
251
		wb = new E4Workbench(window, appContext);
244
		wb.createAndRunUI(window);
252
		wb.createAndRunUI(window);
245
253
254
		MenuManager barManager = (MenuManager) ((Menu) menu.getWidget())
255
				.getData();
256
		barManager.updateAll(true);
257
246
		Object widget1 = menuItem.getWidget();
258
		Object widget1 = menuItem.getWidget();
247
		assertNotNull(widget1);
259
		assertNotNull(widget1);
248
		assertTrue(widget1 instanceof MenuItem);
260
		assertTrue(widget1 instanceof MenuItem);
Lines 251-257 Link Here
251
		assertTrue(menuItemWidget.getSelection());
263
		assertTrue(menuItemWidget.getSelection());
252
	}
264
	}
253
265
254
	public void XXXtestSubMenuCreation() throws Exception {
266
	public void testSubMenuCreation() throws Exception {
255
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
267
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
256
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
268
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
257
		menuBar.setElementId("org.eclipse.ui.main.menu");
269
		menuBar.setElementId("org.eclipse.ui.main.menu");
Lines 285-293 Link Here
285
		wb = new E4Workbench(window, appContext);
297
		wb = new E4Workbench(window, appContext);
286
		wb.createAndRunUI(window);
298
		wb.createAndRunUI(window);
287
299
300
		MenuManagerRenderer renderer = getRenderer(appContext, menuBar);
301
		MenuManager manager = renderer.getManager(menuBar);
302
		assertNotNull("failed to create menu bar manager", manager);
303
304
		assertEquals(1, manager.getSize());
305
306
		MenuManager fileManager = (MenuManager) manager.getItems()[0];
307
		MenuManager fileR = renderer.getManager(fileMenu);
308
		assertEquals(fileManager, fileR);
309
310
		assertEquals(3, fileManager.getSize());
288
	}
311
	}
289
312
290
	public void XXXtestTbrItem() throws Exception {
313
	public void testTbrItem() throws Exception {
291
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
314
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
292
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
315
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
293
		menuBar.setElementId("org.eclipse.ui.main.menu");
316
		menuBar.setElementId("org.eclipse.ui.main.menu");
Lines 322-332 Link Here
322
		wb = new E4Workbench(window, appContext);
345
		wb = new E4Workbench(window, appContext);
323
		wb.createAndRunUI(window);
346
		wb.createAndRunUI(window);
324
347
325
		// MenuRenderer renderer = getRenderer(appContext, menuBar);
348
		MenuManagerRenderer renderer = getRenderer(appContext, menuBar);
349
		MenuManager manager = renderer.getManager(menuBar);
350
		assertNotNull("failed to create menu bar manager", manager);
351
352
		assertEquals(1, manager.getSize());
353
354
		MenuManager fileManager = (MenuManager) manager.getItems()[0];
355
		MenuManager fileR = renderer.getManager(fileMenu);
356
		assertEquals(fileManager, fileR);
326
357
358
		assertEquals(2, fileManager.getSize());
327
	}
359
	}
328
360
329
	public void XXXtestInvisibleItem() throws Exception {
361
	public void testInvisibleItem() throws Exception {
330
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
362
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
331
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
363
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
332
		menuBar.setElementId("org.eclipse.ui.main.menu");
364
		menuBar.setElementId("org.eclipse.ui.main.menu");
Lines 361-371 Link Here
361
		wb = new E4Workbench(window, appContext);
393
		wb = new E4Workbench(window, appContext);
362
		wb.createAndRunUI(window);
394
		wb.createAndRunUI(window);
363
395
364
		// MenuRenderer renderer = getRenderer(appContext, menuBar);
396
		MenuManagerRenderer renderer = getRenderer(appContext, menuBar);
397
		MenuManager manager = renderer.getManager(menuBar);
398
		assertNotNull("failed to create menu bar manager", manager);
399
400
		assertEquals(1, manager.getSize());
401
402
		MenuManager fileManager = (MenuManager) manager.getItems()[0];
403
		MenuManager fileR = renderer.getManager(fileMenu);
404
		assertEquals(fileManager, fileR);
365
405
406
		assertEquals(3, fileManager.getSize());
407
408
		assertEquals(false, fileManager.getItems()[2].isVisible());
366
	}
409
	}
367
410
368
	public void XXXtestMenuContribution() throws Exception {
411
	public void testMenuContribution() throws Exception {
369
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
412
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
370
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
413
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
371
		menuBar.setElementId("org.eclipse.ui.main.menu");
414
		menuBar.setElementId("org.eclipse.ui.main.menu");
Lines 400-408 Link Here
400
		wb = new E4Workbench(window, appContext);
443
		wb = new E4Workbench(window, appContext);
401
		wb.createAndRunUI(window);
444
		wb.createAndRunUI(window);
402
445
446
		MenuManagerRenderer renderer = getRenderer(appContext, menuBar);
447
448
		MenuManager fileManager = renderer.getManager(fileMenu);
449
		assertNotNull("No file menu?", fileManager);
450
451
		assertEquals(4, fileManager.getSize());
452
453
		assertEquals("mmc.item1", fileManager.getItems()[3].getId());
403
	}
454
	}
404
455
405
	public void XXXtestWithVisible() throws Exception {
456
	public void testWithVisible() throws Exception {
406
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
457
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
407
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
458
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
408
		menuBar.setElementId("org.eclipse.ui.main.menu");
459
		menuBar.setElementId("org.eclipse.ui.main.menu");
Lines 437-445 Link Here
437
		wb = new E4Workbench(window, appContext);
488
		wb = new E4Workbench(window, appContext);
438
		wb.createAndRunUI(window);
489
		wb.createAndRunUI(window);
439
490
491
		MenuManagerRenderer renderer = getRenderer(appContext, menuBar);
492
493
		MenuManager fileManager = renderer.getManager(fileMenu);
494
		assertNotNull("No file menu?", fileManager);
495
496
		assertEquals(4, fileManager.getSize());
497
498
		IContributionItem mmcItem = fileManager.getItems()[3];
499
		assertEquals("mmc.item1", mmcItem.getId());
500
		assertEquals("before the first show, we have no context to evaluate",
501
				true, mmcItem.isVisible());
502
503
		MenuManager manager = renderer.getManager(menuBar);
504
		manager.updateAll(true);
505
		Menu fileWidget = fileManager.getMenu();
506
		assertNotNull(fileWidget);
507
508
		Event show = new Event();
509
		show.widget = fileWidget;
510
		show.type = SWT.Show;
511
512
		Event hide = new Event();
513
		hide.widget = fileWidget;
514
		hide.type = SWT.Hide;
515
516
		fileWidget.notifyListeners(SWT.Show, show);
517
518
		assertEquals("after the first show, it should not be visible", false,
519
				mmcItem.isVisible());
520
521
		fileWidget.notifyListeners(SWT.Hide, hide);
522
523
		appContext.set("mmc1", Boolean.TRUE);
524
525
		assertEquals("Change should not show up until next show", false,
526
				mmcItem.isVisible());
527
528
		fileWidget.notifyListeners(SWT.Show, show);
529
530
		assertEquals(true, mmcItem.isVisible());
531
532
		fileWidget.notifyListeners(SWT.Hide, hide);
533
534
		appContext.remove("mmc1");
535
536
		fileWidget.notifyListeners(SWT.Show, show);
537
538
		assertEquals(false, mmcItem.isVisible());
539
540
		fileWidget.notifyListeners(SWT.Hide, hide);
440
	}
541
	}
441
542
442
	public void XXXtestMenuBarVisibility() throws Exception {
543
	public void testMenuBarVisibility() throws Exception {
443
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
544
		MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
444
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
545
		MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
445
		menuBar.setElementId("org.eclipse.ui.main.menu");
546
		menuBar.setElementId("org.eclipse.ui.main.menu");
Lines 474-479 Link Here
474
		wb = new E4Workbench(window, appContext);
575
		wb = new E4Workbench(window, appContext);
475
		wb.createAndRunUI(window);
576
		wb.createAndRunUI(window);
476
577
578
		MenuManagerRenderer renderer = getRenderer(appContext, menuBar);
579
		MenuManager manager = renderer.getManager(menuBar);
580
		manager.updateAll(true);
581
582
		assertEquals(2, manager.getSize());
583
584
		MenuManager vanishManager = (MenuManager) manager.getItems()[1];
585
		assertEquals("vanish", vanishManager.getId());
586
587
		assertFalse(vanishManager.isVisible());
588
		assertNull(vanishManager.getMenu());
589
590
		appContext.set("mmc1", Boolean.TRUE);
591
592
		assertTrue(vanishManager.isVisible());
593
		assertNotNull(vanishManager.getMenu());
594
595
		appContext.remove("mmc1");
596
597
		assertFalse(vanishManager.isVisible());
598
		Menu vanishMenu = vanishManager.getMenu();
599
		if (vanishMenu != null) {
600
			assertTrue(vanishMenu.isDisposed());
601
		}
602
603
		appContext.set("mmc1", Boolean.TRUE);
604
605
		assertTrue(vanishManager.isVisible());
606
		assertNotNull(vanishManager.getMenu());
607
		assertFalse(vanishManager.getMenu().isDisposed());
477
	}
608
	}
478
609
479
	private MMenuContribution createContribution(boolean withVisibleWhen) {
610
	private MMenuContribution createContribution(boolean withVisibleWhen) {
Lines 533-543 Link Here
533
		application.getMenuContributions().add(mmc);
664
		application.getMenuContributions().add(mmc);
534
	}
665
	}
535
666
536
	MenuRenderer getRenderer(IEclipseContext context, MUIElement element) {
667
	private MenuManagerRenderer getRenderer(IEclipseContext context,
668
			MUIElement element) {
537
		IRendererFactory rendererFactory = context.get(IRendererFactory.class);
669
		IRendererFactory rendererFactory = context.get(IRendererFactory.class);
538
		AbstractPartRenderer renderer = rendererFactory.getRenderer(element,
670
		AbstractPartRenderer renderer = rendererFactory.getRenderer(element,
539
				null);
671
				null);
540
		assertEquals(MenuRenderer.class, renderer.getClass());
672
		assertEquals(MenuManagerRenderer.class, renderer.getClass());
541
		return (MenuRenderer) renderer;
673
		return (MenuManagerRenderer) renderer;
542
	}
674
	}
543
}
675
}
(-)src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java (+3 lines)
Lines 29-34 Link Here
29
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
29
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
30
import org.eclipse.e4.ui.services.IServiceConstants;
30
import org.eclipse.e4.ui.services.IServiceConstants;
31
import org.eclipse.e4.ui.widgets.CTabFolder;
31
import org.eclipse.e4.ui.widgets.CTabFolder;
32
import org.eclipse.jface.action.MenuManager;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.graphics.Rectangle;
34
import org.eclipse.swt.graphics.Rectangle;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Composite;
Lines 226-231 Link Here
226
227
227
		wb = new E4Workbench(application, appContext);
228
		wb = new E4Workbench(application, appContext);
228
		wb.createAndRunUI(window);
229
		wb.createAndRunUI(window);
230
		((MenuManager) ((Widget) window.getMainMenu().getWidget()).getData())
231
				.updateAll(true);
229
232
230
		Widget topWidget = (Widget) window.getWidget();
233
		Widget topWidget = (Widget) window.getWidget();
231
		assertNotNull(topWidget);
234
		assertNotNull(topWidget);
(-)src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java (-1 / +1 lines)
Lines 176-182 Link Here
176
		return isVisible((MCoreExpression) contribution.getVisibleWhen(), eContext);
176
		return isVisible((MCoreExpression) contribution.getVisibleWhen(), eContext);
177
	}
177
	}
178
178
179
	static boolean isVisible(MCoreExpression exp, ExpressionContext eContext) {
179
	public static boolean isVisible(MCoreExpression exp, ExpressionContext eContext) {
180
		Expression ref = null;
180
		Expression ref = null;
181
		if (exp.getCoreExpression() instanceof Expression) {
181
		if (exp.getCoreExpression() instanceof Expression) {
182
			ref = (Expression) exp.getCoreExpression();
182
			ref = (Expression) exp.getCoreExpression();
(-)src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java (-4 / +11 lines)
Lines 85-90 Link Here
85
	 */
85
	 */
86
	public void createAndRunUI(MApplicationElement uiRoot) {
86
	public void createAndRunUI(MApplicationElement uiRoot) {
87
		// Has someone already created one ?
87
		// Has someone already created one ?
88
		instantiateRenderer();
89
90
		if (renderer != null) {
91
			renderer.run(uiRoot, appContext);
92
		}
93
	}
94
95
	/**
96
	 * 
97
	 */
98
	public void instantiateRenderer() {
88
		renderer = (IPresentationEngine) appContext.get(IPresentationEngine.class.getName());
99
		renderer = (IPresentationEngine) appContext.get(IPresentationEngine.class.getName());
89
		if (renderer == null) {
100
		if (renderer == null) {
90
			String presentationURI = (String) appContext.get(PRESENTATION_URI_ARG);
101
			String presentationURI = (String) appContext.get(PRESENTATION_URI_ARG);
Lines 99-108 Link Here
99
				logger.error("Failed to create the presentation engine for URI: " + presentationURI); //$NON-NLS-1$
110
				logger.error("Failed to create the presentation engine for URI: " + presentationURI); //$NON-NLS-1$
100
			}
111
			}
101
		}
112
		}
102
103
		if (renderer != null) {
104
			renderer.run(uiRoot, appContext);
105
		}
106
	}
113
	}
107
114
108
	private void init(MApplication appElement) {
115
	private void init(MApplication appElement) {
(-)src/org/eclipse/e4/ui/workbench/UIEvents.java (+5 lines)
Lines 276-281 Link Here
276
		public static final String MNEMONICS = "mnemonics"; //$NON-NLS-1$
276
		public static final String MNEMONICS = "mnemonics"; //$NON-NLS-1$
277
	}
277
	}
278
278
279
	public static interface OpaqueMenuItem {
280
		public static final String TOPIC = UITopicBase + "/menu/OpaqueMenuItem"; //$NON-NLS-1$
281
		public static final String OPAQUEITEM = "opaqueItem"; //$NON-NLS-1$
282
	}
283
279
	public static interface RenderedMenu {
284
	public static interface RenderedMenu {
280
		public static final String TOPIC = UITopicBase + "/menu/RenderedMenu"; //$NON-NLS-1$
285
		public static final String TOPIC = UITopicBase + "/menu/RenderedMenu"; //$NON-NLS-1$
281
		public static final String CONTRIBUTIONMANAGER = "contributionManager"; //$NON-NLS-1$
286
		public static final String CONTRIBUTIONMANAGER = "contributionManager"; //$NON-NLS-1$
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java (-90 / +290 lines)
Lines 20-33 Link Here
20
import javax.annotation.PreDestroy;
20
import javax.annotation.PreDestroy;
21
import javax.inject.Inject;
21
import javax.inject.Inject;
22
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
22
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
23
import org.eclipse.e4.core.contexts.IContextFunction;
23
import org.eclipse.e4.core.contexts.IEclipseContext;
24
import org.eclipse.e4.core.contexts.IEclipseContext;
24
import org.eclipse.e4.core.contexts.RunAndTrack;
25
import org.eclipse.e4.core.contexts.RunAndTrack;
25
import org.eclipse.e4.core.services.events.IEventBroker;
26
import org.eclipse.e4.core.services.events.IEventBroker;
26
import org.eclipse.e4.core.services.log.Logger;
27
import org.eclipse.e4.core.services.log.Logger;
27
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
28
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;
29
import org.eclipse.e4.ui.model.application.MApplication;
30
import org.eclipse.e4.ui.model.application.ui.MContext;
30
import org.eclipse.e4.ui.model.application.ui.MCoreExpression;
31
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
31
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
32
import org.eclipse.e4.ui.model.application.ui.MUIElement;
32
import org.eclipse.e4.ui.model.application.ui.MUIElement;
33
import org.eclipse.e4.ui.model.application.ui.MUILabel;
33
import org.eclipse.e4.ui.model.application.ui.MUILabel;
Lines 39-45 Link Here
39
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
39
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
40
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
40
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
41
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
41
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
42
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenu;
43
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem;
44
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuSeparator;
42
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
45
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
46
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenuItem;
47
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
43
import org.eclipse.e4.ui.workbench.IResourceUtilities;
48
import org.eclipse.e4.ui.workbench.IResourceUtilities;
44
import org.eclipse.e4.ui.workbench.UIEvents;
49
import org.eclipse.e4.ui.workbench.UIEvents;
45
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
50
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
Lines 48-64 Link Here
48
import org.eclipse.emf.ecore.EObject;
53
import org.eclipse.emf.ecore.EObject;
49
import org.eclipse.emf.ecore.util.EcoreUtil;
54
import org.eclipse.emf.ecore.util.EcoreUtil;
50
import org.eclipse.jface.action.AbstractGroupMarker;
55
import org.eclipse.jface.action.AbstractGroupMarker;
56
import org.eclipse.jface.action.ContributionItem;
51
import org.eclipse.jface.action.GroupMarker;
57
import org.eclipse.jface.action.GroupMarker;
52
import org.eclipse.jface.action.IContributionItem;
58
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;
59
import org.eclipse.jface.action.MenuManager;
56
import org.eclipse.jface.action.Separator;
60
import org.eclipse.jface.action.Separator;
57
import org.eclipse.jface.resource.ImageDescriptor;
61
import org.eclipse.jface.resource.ImageDescriptor;
62
import org.eclipse.swt.SWT;
58
import org.eclipse.swt.events.DisposeEvent;
63
import org.eclipse.swt.events.DisposeEvent;
59
import org.eclipse.swt.events.DisposeListener;
64
import org.eclipse.swt.events.DisposeListener;
60
import org.eclipse.swt.widgets.Control;
65
import org.eclipse.swt.widgets.Control;
61
import org.eclipse.swt.widgets.Decorations;
66
import org.eclipse.swt.widgets.Decorations;
67
import org.eclipse.swt.widgets.Display;
62
import org.eclipse.swt.widgets.Menu;
68
import org.eclipse.swt.widgets.Menu;
63
import org.osgi.service.event.Event;
69
import org.osgi.service.event.Event;
64
import org.osgi.service.event.EventHandler;
70
import org.osgi.service.event.EventHandler;
Lines 72-78 Link Here
72
	private Map<MMenu, MenuManager> modelToManager = new HashMap<MMenu, MenuManager>();
78
	private Map<MMenu, MenuManager> modelToManager = new HashMap<MMenu, MenuManager>();
73
	private Map<MenuManager, MMenu> managerToModel = new HashMap<MenuManager, MMenu>();
79
	private Map<MenuManager, MMenu> managerToModel = new HashMap<MenuManager, MMenu>();
74
80
75
	private Map<MMenuItem, IContributionItem> modelToContribution = new HashMap<MMenuItem, IContributionItem>();
81
	private Map<MMenuElement, IContributionItem> modelToContribution = new HashMap<MMenuElement, IContributionItem>();
82
	private Map<IContributionItem, MMenuElement> contributionToModel = new HashMap<IContributionItem, MMenuElement>();
76
83
77
	private Map<MMenuElement, ContributionRecord> modelContributionToRecord = new HashMap<MMenuElement, ContributionRecord>();
84
	private Map<MMenuElement, ContributionRecord> modelContributionToRecord = new HashMap<MMenuElement, ContributionRecord>();
78
85
Lines 126-133 Link Here
126
							modelProcessSwitch(parent, itemModel);
133
							modelProcessSwitch(parent, itemModel);
127
						}
134
						}
128
					} else {
135
					} else {
129
						IContributionItem ici = modelToContribution
136
						IContributionItem ici = getContribution(itemModel);
130
								.remove(itemModel);
137
						clearModelToContribution(itemModel, ici);
131
						if (ici != null && parent != null) {
138
						if (ici != null && parent != null) {
132
							parent.remove(ici);
139
							parent.remove(ici);
133
						}
140
						}
Lines 145-157 Link Here
145
						return;
152
						return;
146
					}
153
					}
147
					manager.setVisible(menuModel.isVisible());
154
					manager.setVisible(menuModel.isVisible());
155
					if (manager.getParent() != null) {
156
						manager.getParent().markDirty();
157
					}
148
				} else if (element instanceof MMenuElement) {
158
				} else if (element instanceof MMenuElement) {
149
					MMenuElement itemModel = (MMenuElement) element;
159
					MMenuElement itemModel = (MMenuElement) element;
150
					IContributionItem ici = getContribution(itemModel);
160
					Object obj = getContribution(itemModel);
151
					if (ici == null) {
161
					if (!(obj instanceof ContributionItem)) {
152
						return;
162
						return;
153
					}
163
					}
154
					ici.setVisible(itemModel.isVisible());
164
					ContributionItem item = (ContributionItem) obj;
165
					item.setVisible(itemModel.isVisible());
166
					if (item.getParent() != null) {
167
						item.getParent().markDirty();
168
					}
155
				}
169
				}
156
			}
170
			}
157
		}
171
		}
Lines 165-171 Link Here
165
179
166
			MMenuItem itemModel = (MMenuItem) event
180
			MMenuItem itemModel = (MMenuItem) event
167
					.getProperty(UIEvents.EventTags.ELEMENT);
181
					.getProperty(UIEvents.EventTags.ELEMENT);
168
			IContributionItem ici = modelToContribution.get(itemModel);
182
			IContributionItem ici = getContribution(itemModel);
169
			if (ici != null) {
183
			if (ici != null) {
170
				ici.update();
184
				ici.update();
171
			}
185
			}
Lines 180-229 Link Here
180
194
181
			MMenuItem itemModel = (MMenuItem) event
195
			MMenuItem itemModel = (MMenuItem) event
182
					.getProperty(UIEvents.EventTags.ELEMENT);
196
					.getProperty(UIEvents.EventTags.ELEMENT);
183
			IContributionItem ici = modelToContribution.get(itemModel);
197
			IContributionItem ici = getContribution(itemModel);
184
			if (ici != null) {
198
			if (ici != null) {
185
				ici.update();
199
				ici.update();
186
			}
200
			}
187
		}
201
		}
188
	};
202
	};
189
203
190
	private IMenuListener visibilityCalculationListener = new IMenuListener() {
204
	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
205
228
	@PostConstruct
206
	@PostConstruct
229
	public void init() {
207
	public void init() {
Lines 237-242 Link Here
237
		eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC),
215
		eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC),
238
				toBeRenderedUpdater);
216
				toBeRenderedUpdater);
239
217
218
		context.set(MenuManagerRenderer.class, this);
219
		Display display = context.get(Display.class);
220
		rendererFilter = ContextInjectionFactory.make(
221
				MenuManagerRendererFilter.class, context);
222
		display.addFilter(SWT.Show, rendererFilter);
223
		display.addFilter(SWT.Hide, rendererFilter);
224
		display.addFilter(SWT.Dispose, rendererFilter);
225
		context.set(MenuManagerRendererFilter.class, rendererFilter);
226
240
	}
227
	}
241
228
242
	@PreDestroy
229
	@PreDestroy
Lines 245-250 Link Here
245
		eventBroker.unsubscribe(selectionUpdater);
232
		eventBroker.unsubscribe(selectionUpdater);
246
		eventBroker.unsubscribe(enabledUpdater);
233
		eventBroker.unsubscribe(enabledUpdater);
247
		eventBroker.unsubscribe(toBeRenderedUpdater);
234
		eventBroker.unsubscribe(toBeRenderedUpdater);
235
236
		context.remove(MenuManagerRendererFilter.class);
237
		Display display = context.get(Display.class);
238
		if (display != null && !display.isDisposed() && rendererFilter != null) {
239
			display.removeFilter(SWT.Show, rendererFilter);
240
			display.removeFilter(SWT.Hide, rendererFilter);
241
			display.removeFilter(SWT.Dispose, rendererFilter);
242
		}
243
		if (rendererFilter != null) {
244
			ContextInjectionFactory.uninject(rendererFilter, context);
245
			rendererFilter = null;
246
		}
247
		context.remove(MenuManagerRenderer.class);
248
	}
248
	}
249
249
250
	/*
250
	/*
Lines 261-310 Link Here
261
261
262
		final MMenu menuModel = (MMenu) element;
262
		final MMenu menuModel = (MMenu) element;
263
		Menu newMenu = null;
263
		Menu newMenu = null;
264
		MenuManager menuManager = null;
264
		boolean menuBar = false;
265
		boolean menuBar = false;
265
266
266
		if (parent instanceof Decorations) {
267
		if (parent instanceof Decorations) {
267
			MUIElement container = (MUIElement) ((EObject) element)
268
			MUIElement container = (MUIElement) ((EObject) element)
268
					.eContainer();
269
					.eContainer();
269
			if (container instanceof MWindow) {
270
			if (container instanceof MWindow) {
270
				MenuManager menuBarManager = getManager(menuModel);
271
				menuManager = getManager(menuModel);
271
				if (menuBarManager == null) {
272
				if (menuManager == null) {
272
					menuBarManager = new MenuManager(NO_LABEL,
273
					menuManager = new MenuManager(NO_LABEL,
273
							menuModel.getElementId());
274
							menuModel.getElementId());
274
					linkModelToManager(menuModel, menuBarManager);
275
					linkModelToManager(menuModel, menuManager);
275
				}
276
				}
276
				newMenu = menuBarManager.createMenuBar((Decorations) parent);
277
				newMenu = menuManager.createMenuBar((Decorations) parent);
277
				((Decorations) parent).setMenuBar(newMenu);
278
				((Decorations) parent).setMenuBar(newMenu);
278
				newMenu.setData(menuBarManager);
279
				newMenu.setData(menuManager);
279
				menuBar = true;
280
				menuBar = true;
280
			} else {
281
			} else {
281
				MenuManager popupManager = getManager(menuModel);
282
				menuManager = getManager(menuModel);
282
				if (popupManager == null) {
283
				if (menuManager == null) {
283
					popupManager = new MenuManager(NO_LABEL,
284
					menuManager = new MenuManager(NO_LABEL,
284
							menuModel.getElementId());
285
							menuModel.getElementId());
285
					linkModelToManager(menuModel, popupManager);
286
					linkModelToManager(menuModel, menuManager);
286
				}
287
				}
287
				newMenu = popupManager.createContextMenu((Control) parent);
288
				newMenu = menuManager.createContextMenu((Control) parent);
288
				((Control) parent).setMenu(newMenu);
289
				// we can't be sure this is the correct parent.
289
				newMenu.setData(popupManager);
290
				// ((Control) parent).setMenu(newMenu);
291
				newMenu.setData(menuManager);
290
			}
292
			}
291
		} else if (parent instanceof Menu) {
293
		} else if (parent instanceof Menu) {
292
			// Object data = ((Menu) parent).getData();
294
			// Object data = ((Menu) parent).getData();
293
			logger.debug(new Exception(), "Trying to render a sub menu " //$NON-NLS-1$
295
			logger.debug(new Exception(), "Trying to render a sub menu " //$NON-NLS-1$
294
					+ menuModel + "\n\t" + parent); //$NON-NLS-1$
296
					+ menuModel + "\n\t" + parent); //$NON-NLS-1$
297
			return null;
295
298
296
		} else if (parent instanceof Control) {
299
		} else if (parent instanceof Control) {
297
			MenuManager popupManager = getManager(menuModel);
300
			menuManager = getManager(menuModel);
298
			if (popupManager == null) {
301
			if (menuManager == null) {
299
				popupManager = new MenuManager(NO_LABEL,
302
				menuManager = new MenuManager(NO_LABEL,
300
						menuModel.getElementId());
303
						menuModel.getElementId());
301
				linkModelToManager(menuModel, popupManager);
304
				linkModelToManager(menuModel, menuManager);
302
			}
305
			}
303
			newMenu = popupManager.createContextMenu((Control) parent);
306
			newMenu = menuManager.createContextMenu((Control) parent);
304
			((Control) parent).setMenu(newMenu);
307
			// we can't be sure this is the correct parent.
305
			newMenu.setData(popupManager);
308
			// ((Control) parent).setMenu(newMenu);
309
			newMenu.setData(menuManager);
310
		}
311
		if (!menuManager.getRemoveAllWhenShown()) {
312
			processContributions(menuModel, menuBar);
306
		}
313
		}
307
		processContributions(menuModel, menuBar);
308
		if (newMenu != null) {
314
		if (newMenu != null) {
309
			newMenu.addDisposeListener(new DisposeListener() {
315
			newMenu.addDisposeListener(new DisposeListener() {
310
				public void widgetDisposed(DisposeEvent e) {
316
				public void widgetDisposed(DisposeEvent e) {
Lines 318-324 Link Here
318
	/**
324
	/**
319
	 * @param menuModel
325
	 * @param menuModel
320
	 */
326
	 */
321
	protected void cleanUp(MMenu menuModel) {
327
	public void cleanUp(MMenu menuModel) {
322
		Collection<ContributionRecord> vals = modelContributionToRecord
328
		Collection<ContributionRecord> vals = modelContributionToRecord
323
				.values();
329
				.values();
324
		for (ContributionRecord record : vals
330
		for (ContributionRecord record : vals
Lines 336-343 Link Here
336
							copyManager.dispose();
342
							copyManager.dispose();
337
						}
343
						}
338
					} else {
344
					} else {
339
						IContributionItem ici = modelToContribution
345
						IContributionItem ici = getContribution(copy);
340
								.remove(copy);
346
						clearModelToContribution(copy, ici);
341
						if (ici != null) {
347
						if (ici != null) {
342
							record.manager.remove(ici);
348
							record.manager.remove(ici);
343
						}
349
						}
Lines 352-358 Link Here
352
	 * @param menuModel
358
	 * @param menuModel
353
	 * @param menuBar
359
	 * @param menuBar
354
	 */
360
	 */
355
	private void processContributions(MMenu menuModel, boolean menuBar) {
361
	public void processContributions(MMenu menuModel, boolean menuBar) {
356
		final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>();
362
		final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>();
357
		ContributionsAnalyzer.XXXgatherMenuContributions(menuModel,
363
		ContributionsAnalyzer.XXXgatherMenuContributions(menuModel,
358
				application.getMenuContributions(), menuModel.getElementId(),
364
				application.getMenuContributions(), menuModel.getElementId(),
Lines 500-506 Link Here
500
			boolean isVisible = ContributionsAnalyzer.isVisible(
506
			boolean isVisible = ContributionsAnalyzer.isVisible(
501
					menuContribution, exprContext);
507
					menuContribution, exprContext);
502
			for (MMenuElement item : generatedElements) {
508
			for (MMenuElement item : generatedElements) {
503
				item.setVisible(isVisible);
509
				if (isVisible && item.getVisibleWhen() != null) {
510
					MenuManagerRenderer.updateVisibility(manager, item,
511
							exprContext);
512
				} else {
513
					item.setVisible(isVisible);
514
				}
504
			}
515
			}
505
			manager.markDirty();
516
			manager.markDirty();
506
		}
517
		}
Lines 564-576 Link Here
564
	 * @param menuModel
575
	 * @param menuModel
565
	 */
576
	 */
566
	private void processMenu(MenuManager parentManager, MMenu menuModel) {
577
	private void processMenu(MenuManager parentManager, MMenu menuModel) {
567
		String menuText = getText(menuModel);
578
		MenuManager menuManager = getManager(menuModel);
568
		ImageDescriptor desc = getImageDescriptor(menuModel);
579
		if (menuManager == null) {
569
		MenuManager menuManager = new MenuManager(menuText, desc,
580
			String menuText = getText(menuModel);
570
				menuModel.getElementId());
581
			ImageDescriptor desc = getImageDescriptor(menuModel);
571
		linkModelToManager(menuModel, menuManager);
582
			menuManager = new MenuManager(menuText, desc,
572
		menuManager.setVisible(menuModel.isVisible());
583
					menuModel.getElementId());
573
		parentManager.add(menuManager);
584
			linkModelToManager(menuModel, menuManager);
585
			menuManager.setVisible(menuModel.isVisible());
586
			parentManager.add(menuManager);
587
		}
574
		processContributions(menuModel, false);
588
		processContributions(menuModel, false);
575
		List<MMenuElement> parts = menuModel.getChildren();
589
		List<MMenuElement> parts = menuModel.getChildren();
576
		if (parts != null) {
590
		if (parts != null) {
Lines 591-597 Link Here
591
		if (!childME.isToBeRendered()) {
605
		if (!childME.isToBeRendered()) {
592
			return;
606
			return;
593
		}
607
		}
594
		if (childME instanceof MHandledMenuItem) {
608
		if (childME instanceof MRenderedMenuItem) {
609
			MRenderedMenuItem itemModel = (MRenderedMenuItem) childME;
610
			processRenderedItem(menuManager, itemModel);
611
		} else if (childME instanceof MHandledMenuItem) {
595
			MHandledMenuItem itemModel = (MHandledMenuItem) childME;
612
			MHandledMenuItem itemModel = (MHandledMenuItem) childME;
596
			processHandledItem(menuManager, itemModel);
613
			processHandledItem(menuManager, itemModel);
597
		} else if (childME instanceof MDirectMenuItem) {
614
		} else if (childME instanceof MDirectMenuItem) {
Lines 600-605 Link Here
600
		} else if (childME instanceof MMenuSeparator) {
617
		} else if (childME instanceof MMenuSeparator) {
601
			MMenuSeparator sep = (MMenuSeparator) childME;
618
			MMenuSeparator sep = (MMenuSeparator) childME;
602
			processSeparator(menuManager, sep);
619
			processSeparator(menuManager, sep);
620
		} else if (childME instanceof MOpaqueMenu) {
621
			// I'm not sure what to do here
622
			// so I'll just take it out of the running
603
		} else if (childME instanceof MMenu) {
623
		} else if (childME instanceof MMenu) {
604
			MMenu itemModel = (MMenu) childME;
624
			MMenu itemModel = (MMenu) childME;
605
			processMenu(menuManager, itemModel);
625
			processMenu(menuManager, itemModel);
Lines 607-612 Link Here
607
	}
627
	}
608
628
609
	/**
629
	/**
630
	 * @param parentManager
631
	 * @param itemModel
632
	 */
633
	void processRenderedItem(MenuManager parentManager,
634
			MRenderedMenuItem itemModel) {
635
		IContributionItem ici = getContribution(itemModel);
636
		if (ici != null) {
637
			return;
638
		}
639
		Object obj = itemModel.getContributionItem();
640
		if (obj instanceof IContextFunction) {
641
			final IEclipseContext lclContext = getContext(itemModel);
642
			ici = (IContributionItem) ((IContextFunction) obj)
643
					.compute(lclContext);
644
			itemModel.setContributionItem(ici);
645
		} else if (obj instanceof IContributionItem) {
646
			ici = (IContributionItem) obj;
647
		}
648
		ici.setVisible(itemModel.isVisible());
649
		parentManager.add(ici);
650
		linkModelToContribution(itemModel, ici);
651
	}
652
653
	/**
610
	 * @param menuManager
654
	 * @param menuManager
611
	 * @param itemModel
655
	 * @param itemModel
612
	 */
656
	 */
Lines 628-644 Link Here
628
	 * @param parentManager
672
	 * @param parentManager
629
	 * @param itemModel
673
	 * @param itemModel
630
	 * @param id
674
	 * @param id
631
	 *            TODO
632
	 */
675
	 */
633
	void processDirectItem(MenuManager parentManager,
676
	void processDirectItem(MenuManager parentManager,
634
			MDirectMenuItem itemModel, String id) {
677
			MDirectMenuItem itemModel, String id) {
678
		IContributionItem ici = getContribution(itemModel);
679
		if (ici != null) {
680
			return;
681
		}
635
		final IEclipseContext lclContext = getContext(itemModel);
682
		final IEclipseContext lclContext = getContext(itemModel);
636
		DirectContributionItem ci = ContextInjectionFactory.make(
683
		DirectContributionItem ci = ContextInjectionFactory.make(
637
				DirectContributionItem.class, lclContext);
684
				DirectContributionItem.class, lclContext);
638
		ci.setModel(itemModel);
685
		ci.setModel(itemModel);
639
		ci.setVisible(itemModel.isVisible());
686
		ci.setVisible(itemModel.isVisible());
640
		parentManager.add(ci);
687
		parentManager.add(ci);
641
		modelToContribution.put(itemModel, ci);
688
		linkModelToContribution(itemModel, ci);
642
	}
689
	}
643
690
644
	/**
691
	/**
Lines 647-659 Link Here
647
	 */
694
	 */
648
	void processHandledItem(MenuManager parentManager,
695
	void processHandledItem(MenuManager parentManager,
649
			MHandledMenuItem itemModel) {
696
			MHandledMenuItem itemModel) {
697
		IContributionItem ici = getContribution(itemModel);
698
		if (ici != null) {
699
			return;
700
		}
650
		final IEclipseContext lclContext = getContext(itemModel);
701
		final IEclipseContext lclContext = getContext(itemModel);
651
		HandledContributionItem ci = ContextInjectionFactory.make(
702
		HandledContributionItem ci = ContextInjectionFactory.make(
652
				HandledContributionItem.class, lclContext);
703
				HandledContributionItem.class, lclContext);
653
		ci.setModel(itemModel);
704
		ci.setModel(itemModel);
654
		ci.setVisible(itemModel.isVisible());
705
		ci.setVisible(itemModel.isVisible());
655
		parentManager.add(ci);
706
		parentManager.add(ci);
656
		modelToContribution.put(itemModel, ci);
707
		linkModelToContribution(itemModel, ci);
657
	}
708
	}
658
709
659
	private String getText(MMenu menuModel) {
710
	private String getText(MMenu menuModel) {
Lines 686-703 Link Here
686
	public void linkModelToManager(MMenu model, MenuManager manager) {
737
	public void linkModelToManager(MMenu model, MenuManager manager) {
687
		modelToManager.put(model, manager);
738
		modelToManager.put(model, manager);
688
		managerToModel.put(manager, model);
739
		managerToModel.put(manager, model);
689
		manager.addMenuListener(visibilityCalculationListener);
690
	}
740
	}
691
741
692
	public void clearModelToManager(MMenu model, MenuManager manager) {
742
	public void clearModelToManager(MMenu model, MenuManager manager) {
693
		modelToManager.remove(model);
743
		modelToManager.remove(model);
694
		managerToModel.remove(manager);
744
		managerToModel.remove(manager);
695
		if (manager != null) {
696
			manager.removeMenuListener(visibilityCalculationListener);
697
		}
698
	}
745
	}
699
746
700
	public IContributionItem getContribution(MMenuElement model) {
747
	public IContributionItem getContribution(MMenuElement model) {
701
		return modelToContribution.get(model);
748
		return modelToContribution.get(model);
702
	}
749
	}
750
751
	public MMenuElement getMenuElement(IContributionItem item) {
752
		return contributionToModel.get(item);
753
	}
754
755
	public void linkModelToContribution(MMenuElement model,
756
			IContributionItem item) {
757
		modelToContribution.put(model, item);
758
		contributionToModel.put(item, model);
759
	}
760
761
	public void clearModelToContribution(MMenuElement model,
762
			IContributionItem item) {
763
		modelToContribution.remove(model);
764
		contributionToModel.remove(item);
765
	}
766
767
	public ContributionRecord getContributionRecord(MMenuElement element) {
768
		return modelContributionToRecord.get(element);
769
	}
770
771
	/**
772
	 * @param menuManager
773
	 * @param menuModel
774
	 */
775
	public void reconcileManagerToModel(MenuManager menuManager, MMenu menuModel) {
776
		List<MMenuElement> modelChildren = menuModel.getChildren();
777
778
		HashSet<MOpaqueMenuItem> oldModelItems = new HashSet<MOpaqueMenuItem>();
779
		HashSet<MOpaqueMenu> oldMenus = new HashSet<MOpaqueMenu>();
780
		HashSet<MOpaqueMenuSeparator> oldSeps = new HashSet<MOpaqueMenuSeparator>();
781
		for (MMenuElement itemModel : modelChildren) {
782
			if (itemModel instanceof MOpaqueMenuSeparator) {
783
				oldSeps.add((MOpaqueMenuSeparator) itemModel);
784
			} else if (itemModel instanceof MOpaqueMenuItem) {
785
				oldModelItems.add((MOpaqueMenuItem) itemModel);
786
			} else if (itemModel instanceof MOpaqueMenu) {
787
				oldMenus.add((MOpaqueMenu) itemModel);
788
			}
789
		}
790
791
		IContributionItem[] items = menuManager.getItems();
792
		for (int src = 0, dest = 0; src < items.length; src++, dest++) {
793
			IContributionItem item = items[src];
794
			if (item instanceof MenuManager) {
795
				MenuManager childManager = (MenuManager) item;
796
				MMenu childModel = getMenuModel(childManager);
797
				if (childModel == null) {
798
					MMenu legacyModel = MenuFactoryImpl.eINSTANCE
799
							.createOpaqueMenu();
800
					legacyModel.setElementId(childManager.getId());
801
					legacyModel.setVisible(childManager.isVisible());
802
					linkModelToManager(legacyModel, childManager);
803
					modelChildren.add(dest, legacyModel);
804
				} else {
805
					if (childModel instanceof MOpaqueMenu) {
806
						oldMenus.remove(childModel);
807
					}
808
					if (modelChildren.size() > dest) {
809
						if (modelChildren.get(dest) != childModel) {
810
							modelChildren.remove(childModel);
811
							modelChildren.add(dest, childModel);
812
						}
813
					} else {
814
						modelChildren.add(childModel);
815
					}
816
				}
817
			} else if (item.isSeparator() || item.isGroupMarker()) {
818
				MMenuElement menuElement = getMenuElement(item);
819
				if (menuElement == null) {
820
					MOpaqueMenuSeparator legacySep = MenuFactoryImpl.eINSTANCE
821
							.createOpaqueMenuSeparator();
822
					legacySep.setElementId(item.getId());
823
					legacySep.setVisible(item.isVisible());
824
					legacySep.setOpaqueItem(item);
825
					linkModelToContribution(legacySep, item);
826
					modelChildren.add(dest, legacySep);
827
				} else if (menuElement instanceof MOpaqueMenuSeparator) {
828
					MOpaqueMenuSeparator legacySep = (MOpaqueMenuSeparator) menuElement;
829
					oldSeps.remove(legacySep);
830
					if (modelChildren.size() > dest) {
831
						if (modelChildren.get(dest) != legacySep) {
832
							modelChildren.remove(legacySep);
833
							modelChildren.add(dest, legacySep);
834
						}
835
					} else {
836
						modelChildren.add(legacySep);
837
					}
838
				}
839
			} else {
840
				MMenuElement menuElement = getMenuElement(item);
841
				if (menuElement == null) {
842
					MOpaqueMenuItem legacyItem = MenuFactoryImpl.eINSTANCE
843
							.createOpaqueMenuItem();
844
					legacyItem.setElementId(item.getId());
845
					legacyItem.setVisible(item.isVisible());
846
					legacyItem.setOpaqueItem(item);
847
					linkModelToContribution(legacyItem, item);
848
					modelChildren.add(dest, legacyItem);
849
				} else if (menuElement instanceof MOpaqueMenuItem) {
850
					MOpaqueMenuItem legacyItem = (MOpaqueMenuItem) menuElement;
851
					oldModelItems.remove(legacyItem);
852
					if (modelChildren.size() > dest) {
853
						if (modelChildren.get(dest) != legacyItem) {
854
							modelChildren.remove(legacyItem);
855
							modelChildren.add(dest, legacyItem);
856
						}
857
					} else {
858
						modelChildren.add(legacyItem);
859
					}
860
				}
861
			}
862
		}
863
		if (!oldModelItems.isEmpty()) {
864
			modelChildren.removeAll(oldModelItems);
865
			for (MOpaqueMenuItem model : oldModelItems) {
866
				clearModelToContribution(model,
867
						(IContributionItem) model.getOpaqueItem());
868
			}
869
		}
870
		if (!oldMenus.isEmpty()) {
871
			modelChildren.removeAll(oldMenus);
872
			for (MOpaqueMenu oldMenu : oldMenus) {
873
				MenuManager oldManager = getManager(oldMenu);
874
				clearModelToManager(oldMenu, oldManager);
875
			}
876
		}
877
		if (!oldSeps.isEmpty()) {
878
			modelChildren.removeAll(oldSeps);
879
			for (MOpaqueMenuSeparator model : oldSeps) {
880
				clearModelToContribution(model,
881
						(IContributionItem) model.getOpaqueItem());
882
			}
883
		}
884
	}
885
886
	/**
887
	 * @param menuManager
888
	 * @param element
889
	 * @param evalContext
890
	 */
891
	public static void updateVisibility(MenuManager menuManager,
892
			MMenuElement element, ExpressionContext evalContext) {
893
		if (!(element.getVisibleWhen() instanceof MCoreExpression)) {
894
			return;
895
		}
896
		boolean val = ContributionsAnalyzer.isVisible(
897
				(MCoreExpression) element.getVisibleWhen(), evalContext);
898
		if (val != element.isVisible()) {
899
			element.setVisible(val);
900
			menuManager.markDirty();
901
		}
902
	}
703
}
903
}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java (+386 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.workbench.renderers.swt;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
15
import java.util.HashMap;
16
import java.util.HashSet;
17
import javax.inject.Inject;
18
import org.eclipse.core.commands.ParameterizedCommand;
19
import org.eclipse.core.runtime.ISafeRunnable;
20
import org.eclipse.core.runtime.SafeRunner;
21
import org.eclipse.e4.core.commands.EHandlerService;
22
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
23
import org.eclipse.e4.core.contexts.EclipseContextFactory;
24
import org.eclipse.e4.core.contexts.IEclipseContext;
25
import org.eclipse.e4.core.di.annotations.CanExecute;
26
import org.eclipse.e4.core.services.log.Logger;
27
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
28
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
29
import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator;
30
import org.eclipse.e4.ui.model.application.ui.MContext;
31
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
32
import org.eclipse.e4.ui.model.application.ui.MUIElement;
33
import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem;
34
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
35
import org.eclipse.e4.ui.model.application.ui.menu.MItem;
36
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
37
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
38
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
39
import org.eclipse.e4.ui.workbench.modeling.EModelService;
40
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
41
import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.ContributionRecord;
42
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
43
import org.eclipse.jface.action.MenuManager;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.widgets.Event;
46
import org.eclipse.swt.widgets.Listener;
47
import org.eclipse.swt.widgets.Menu;
48
import org.eclipse.swt.widgets.Widget;
49
50
public class MenuManagerRendererFilter implements Listener {
51
	public static final String NUL_MENU_ITEM = "(None Applicable)"; //$NON-NLS-1$
52
53
	private static final String TMP_ORIGINAL_CONTEXT = "MenuServiceFilter.original.context"; //$NON-NLS-1$
54
55
	private static void trace(String msg, Widget menu, MMenu menuModel) {
56
		WorkbenchSWTActivator.trace(Policy.MENUS, msg + ": " + menu + ": " //$NON-NLS-1$ //$NON-NLS-2$
57
				+ menuModel, null);
58
	}
59
60
	private static Method aboutToShow;
61
62
	private static Method aboutToHide;
63
64
	public static Method getAboutToShow() {
65
		if (aboutToShow == null) {
66
			try {
67
				aboutToShow = MenuManager.class
68
						.getDeclaredMethod("handleAboutToShow"); //$NON-NLS-1$
69
				aboutToShow.setAccessible(true);
70
			} catch (SecurityException e) {
71
				// TODO Auto-generated catch block
72
				e.printStackTrace();
73
			} catch (NoSuchMethodException e) {
74
				// TODO Auto-generated catch block
75
				e.printStackTrace();
76
			}
77
		}
78
		return aboutToShow;
79
	}
80
81
	public static Method getAboutToHide() {
82
		if (aboutToHide == null) {
83
			try {
84
				aboutToHide = MenuManager.class
85
						.getDeclaredMethod("handleAboutToHide"); //$NON-NLS-1$
86
				aboutToHide.setAccessible(true);
87
			} catch (SecurityException e) {
88
				// TODO Auto-generated catch block
89
				e.printStackTrace();
90
			} catch (NoSuchMethodException e) {
91
				// TODO Auto-generated catch block
92
				e.printStackTrace();
93
			}
94
		}
95
		return aboutToHide;
96
	}
97
98
	@Inject
99
	private Logger logger;
100
101
	@Inject
102
	private EModelService modelService;
103
104
	@Inject
105
	private IRendererFactory rendererFactory;
106
107
	@Inject
108
	private MenuManagerRenderer renderer;
109
110
	@Inject
111
	private EHandlerService handlerService;
112
113
	private HashMap<Menu, Runnable> pendingCleanup = new HashMap<Menu, Runnable>();
114
115
	private class SafeWrapper implements ISafeRunnable {
116
		Event event;
117
118
		public void handleException(Throwable e) {
119
			if (e instanceof Error) {
120
				// errors are deadly, we shouldn't ignore these
121
				throw (Error) e;
122
			}
123
			// log exceptions otherwise
124
			if (logger != null) {
125
				logger.error(e);
126
			}
127
		}
128
129
		public void run() throws Exception {
130
			safeHandleEvent(event);
131
		}
132
	}
133
134
	private SafeWrapper safeWrapper = new SafeWrapper();
135
136
	public void handleEvent(final Event event) {
137
		// wrap the handling in a SafeRunner so that exceptions do not prevent
138
		// the menu from being shown
139
		safeWrapper.event = event;
140
		SafeRunner.run(safeWrapper);
141
	}
142
143
	private void safeHandleEvent(Event event) {
144
		if (!(event.widget instanceof Menu)) {
145
			return;
146
		}
147
		final Menu menu = (Menu) event.widget;
148
		if ((menu.getStyle() & SWT.BAR) != 0) {
149
			// don't process the menu bar, it's not fair :-)
150
			return;
151
		}
152
		if (event.type == SWT.Dispose) {
153
			trace("handleMenu.Dispose", menu, null); //$NON-NLS-1$
154
			cleanUp(menu, null, null);
155
			return;
156
		}
157
158
		// fill in all of the pieces
159
		MMenu menuModel = null;
160
		MenuManager menuManager = null;
161
		Object obj = menu.getData(AbstractPartRenderer.OWNING_ME);
162
		if (obj == null && menu.getParentItem() != null) {
163
			obj = menu.getParentItem().getData(AbstractPartRenderer.OWNING_ME);
164
			if (obj == null) {
165
				// hack because MenuManager doesn't do a setData()
166
				Object tmp = menu.getParentItem().getData();
167
				if (tmp instanceof MenuManager) {
168
					MenuManager tmpManager = (MenuManager) tmp;
169
					if (menu == tmpManager.getMenu()) {
170
						// Eureka! We found a match, by golly!
171
						menuManager = tmpManager;
172
						obj = renderer.getMenuModel(tmpManager);
173
					}
174
				}
175
			}
176
		}
177
		if (obj instanceof MMenu) {
178
			menuModel = (MMenu) obj;
179
		}
180
		if (menuManager == null && menuModel != null) {
181
			menuManager = renderer.getManager(menuModel);
182
		}
183
184
		switch (event.type) {
185
		case SWT.Show:
186
			handleShow(event, menu, menuModel, menuManager);
187
			break;
188
		case SWT.Hide:
189
			handleHide(event, menu, menuModel, menuManager);
190
			break;
191
		}
192
193
	}
194
195
	private void handleShow(final Event event, final Menu menu,
196
			MMenu menuModel, MenuManager menuManager) {
197
		if (menuModel != null && menuManager != null) {
198
			cleanUp(menu, menuModel, menuManager);
199
		}
200
		if (menuModel instanceof MPopupMenu) {
201
			showPopup(event, menu, (MPopupMenu) menuModel, menuManager);
202
		}
203
		if (menuModel != null) {
204
			showMenu(event, menu, menuModel, menuManager);
205
		} else {
206
			trace("Incorrect menu model to work with " + menuManager, menu, menuModel); //$NON-NLS-1$
207
		}
208
	}
209
210
	private void handleHide(final Event event, final Menu menu,
211
			MMenu menuModel, MenuManager menuManager) {
212
		if (menuModel instanceof MPopupMenu) {
213
			hidePopup(event, menu, (MPopupMenu) menuModel, menuManager);
214
		}
215
	}
216
217
	public void showMenu(final Event event, final Menu menu,
218
			final MMenu menuModel, MenuManager menuManager) {
219
		AbstractPartRenderer obj = rendererFactory.getRenderer(menuModel,
220
				menu.getParent());
221
		if (!(obj instanceof MenuManagerRenderer)) {
222
			trace("Not the correct renderer: " + obj, menu, menuModel); //$NON-NLS-1$
223
			return;
224
		}
225
		MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
226
		if (menuModel.getWidget() == null) {
227
			renderer.bindWidget(menuModel, menuManager.getMenu());
228
		}
229
230
		Method handleAboutToShow = getAboutToShow();
231
		try {
232
			handleAboutToShow.invoke(menuManager);
233
		} catch (IllegalArgumentException e) {
234
			// TODO Auto-generated catch block
235
			e.printStackTrace();
236
		} catch (IllegalAccessException e) {
237
			// TODO Auto-generated catch block
238
			e.printStackTrace();
239
		} catch (InvocationTargetException e) {
240
			// TODO Auto-generated catch block
241
			e.printStackTrace();
242
		}
243
244
		if (!menuManager.getRemoveAllWhenShown()) {
245
			renderer.reconcileManagerToModel(menuManager, menuModel);
246
			// this will make sure all model elements are represented in the
247
			// menu itself.
248
			// double cast because we're bad people
249
			renderer.processContents((MElementContainer<MUIElement>) ((Object) menuModel));
250
		}
251
252
		final IEclipseContext evalContext;
253
		if (menuModel instanceof MContext) {
254
			evalContext = ((MContext) menuModel).getContext();
255
		} else {
256
			evalContext = modelService.getContainingContext(menuModel);
257
		}
258
		updateElementVisibility(menuModel, renderer, menuManager, evalContext,
259
				true);
260
261
		// last thing to do, kill the event and update the menu manager
262
		event.type = SWT.None;
263
		event.doit = false;
264
		menuManager.update(false);
265
	}
266
267
	/**
268
	 * @param menuModel
269
	 * @param renderer
270
	 * @param menuManager
271
	 * @param evalContext
272
	 */
273
	private void updateElementVisibility(final MMenu menuModel,
274
			MenuManagerRenderer renderer, MenuManager menuManager,
275
			final IEclipseContext evalContext, boolean recurse) {
276
		final ExpressionContext exprContext = new ExpressionContext(evalContext);
277
		HashSet<ContributionRecord> records = new HashSet<ContributionRecord>();
278
		for (MMenuElement element : menuModel.getChildren()) {
279
			ContributionRecord record = renderer.getContributionRecord(element);
280
			if (record != null) {
281
				if (records.add(record)) {
282
					record.updateVisibility(evalContext);
283
				}
284
			} else {
285
				MenuManagerRenderer.updateVisibility(menuManager, element,
286
						exprContext);
287
			}
288
			if (recurse && element.isVisible() && element instanceof MMenu) {
289
				MMenu childMenu = (MMenu) element;
290
				MenuManager childManager = renderer.getManager(childMenu);
291
				if (childManager != null) {
292
					updateElementVisibility(childMenu, renderer, childManager,
293
							evalContext, false);
294
				}
295
			}
296
297
			if (element instanceof MHandledMenuItem) {
298
				ParameterizedCommand cmd = ((MHandledMenuItem) element)
299
						.getWbCommand();
300
				if (cmd != null) {
301
					((MHandledMenuItem) element).setEnabled(handlerService
302
							.canExecute(cmd));
303
				}
304
			} else if (element instanceof MDirectMenuItem) {
305
				MDirectMenuItem contrib = (MDirectMenuItem) element;
306
				if (contrib.getObject() != null) {
307
					IEclipseContext staticContext = EclipseContextFactory
308
							.create();
309
					staticContext.set(MItem.class, contrib);
310
					Object rc = ContextInjectionFactory.invoke(
311
							contrib.getObject(), CanExecute.class, evalContext,
312
							staticContext, Boolean.TRUE);
313
					if (rc instanceof Boolean) {
314
						contrib.setEnabled((Boolean) rc);
315
					}
316
				}
317
			}
318
		}
319
	}
320
321
	public void hidePopup(Event event, Menu menu, MPopupMenu menuModel,
322
			MenuManager menuManager) {
323
		final IEclipseContext popupContext = menuModel.getContext();
324
		final IEclipseContext originalChild = (IEclipseContext) popupContext
325
				.get(TMP_ORIGINAL_CONTEXT);
326
		popupContext.remove(TMP_ORIGINAL_CONTEXT);
327
		if (!menu.isDisposed()) {
328
			menu.getDisplay().asyncExec(new Runnable() {
329
				public void run() {
330
					if (originalChild == null) {
331
						popupContext.deactivate();
332
					} else {
333
						originalChild.activate();
334
					}
335
				}
336
			});
337
		}
338
	}
339
340
	public void showPopup(final Event event, final Menu menu,
341
			final MPopupMenu menuModel, MenuManager menuManager) {
342
		// System.err.println("showPopup: " + menuModel + "\n\t" + menu);
343
		// we need some context foolery here
344
		final IEclipseContext popupContext = menuModel.getContext();
345
		final IEclipseContext parentContext = popupContext.getParent();
346
		final IEclipseContext originalChild = parentContext.getActiveChild();
347
		popupContext.activate();
348
		popupContext.set(TMP_ORIGINAL_CONTEXT, originalChild);
349
	}
350
351
	void setEnabled(MHandledMenuItem item) {
352
		if (!item.isToBeRendered() || !item.isVisible()
353
				|| item.getWidget() == null) {
354
			return;
355
		}
356
		ParameterizedCommand cmd = item.getWbCommand();
357
		if (cmd == null) {
358
			return;
359
		}
360
		final IEclipseContext lclContext = modelService
361
				.getContainingContext(item);
362
		EHandlerService service = lclContext.get(EHandlerService.class);
363
		item.setEnabled(service.canExecute(cmd));
364
	}
365
366
	public void cleanUp(final Menu menu, MMenu menuModel,
367
			MenuManager menuManager) {
368
		trace("cleanUp", menu, null); //$NON-NLS-1$
369
		if (pendingCleanup.isEmpty()) {
370
			return;
371
		}
372
		Runnable cleanUp = pendingCleanup.remove(menu);
373
		if (cleanUp != null) {
374
			trace("cleanUp.run()", menu, null); //$NON-NLS-1$
375
			cleanUp.run();
376
		}
377
	}
378
379
	public void dispose() {
380
		Menu[] keys = pendingCleanup.keySet().toArray(
381
				new Menu[pendingCleanup.size()]);
382
		for (Menu menu : keys) {
383
			cleanUp(menu, null, null);
384
		}
385
	}
386
}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerServiceFilter.java (+182 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.workbench.renderers.swt;
12
13
import java.lang.reflect.Method;
14
import javax.inject.Inject;
15
import org.eclipse.core.runtime.ISafeRunnable;
16
import org.eclipse.core.runtime.SafeRunner;
17
import org.eclipse.e4.core.contexts.IEclipseContext;
18
import org.eclipse.e4.core.services.log.Logger;
19
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
20
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
21
import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator;
22
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
23
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
24
import org.eclipse.e4.ui.workbench.modeling.EModelService;
25
import org.eclipse.jface.action.MenuManager;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.swt.widgets.Listener;
29
import org.eclipse.swt.widgets.Menu;
30
import org.eclipse.swt.widgets.Widget;
31
32
public class MenuManagerServiceFilter implements Listener {
33
	public static final String NUL_MENU_ITEM = "(None Applicable)"; //$NON-NLS-1$
34
35
	private static final String TMP_ORIGINAL_CONTEXT = "MenuServiceFilter.original.context"; //$NON-NLS-1$
36
37
	private static void trace(String msg, Widget menu, MMenu menuModel) {
38
		WorkbenchSWTActivator.trace(Policy.MENUS, msg + ": " + menu + ": " //$NON-NLS-1$ //$NON-NLS-2$
39
				+ menuModel, null);
40
	}
41
42
	private static Method aboutToShow;
43
44
	public static Method getAboutToShow() {
45
		if (aboutToShow == null) {
46
			try {
47
				aboutToShow = MenuManager.class
48
						.getDeclaredMethod("handleAboutToShow"); //$NON-NLS-1$
49
				aboutToShow.setAccessible(true);
50
			} catch (SecurityException e) {
51
				// TODO Auto-generated catch block
52
				e.printStackTrace();
53
			} catch (NoSuchMethodException e) {
54
				// TODO Auto-generated catch block
55
				e.printStackTrace();
56
			}
57
		}
58
		return aboutToShow;
59
	}
60
61
	@Inject
62
	private Logger logger;
63
64
	@Inject
65
	EModelService modelService;
66
67
	public void handleEvent(final Event event) {
68
		// wrap the handling in a SafeRunner so that exceptions do not prevent
69
		// the menu from being shown
70
		SafeRunner.run(new ISafeRunnable() {
71
			public void handleException(Throwable e) {
72
				if (e instanceof Error) {
73
					// errors are deadly, we shouldn't ignore these
74
					throw (Error) e;
75
				} else {
76
					// log exceptions otherwise
77
					if (logger != null) {
78
						logger.error(e);
79
					}
80
				}
81
			}
82
83
			public void run() throws Exception {
84
				safeHandleEvent(event);
85
			}
86
		});
87
	}
88
89
	private void safeHandleEvent(Event event) {
90
		if (!(event.widget instanceof Menu)) {
91
			return;
92
		}
93
		final Menu menu = (Menu) event.widget;
94
		if (event.type == SWT.Dispose) {
95
			trace("handleMenu.Dispose", menu, null); //$NON-NLS-1$
96
			cleanUp(menu);
97
		}
98
		Object obj = menu.getData(AbstractPartRenderer.OWNING_ME);
99
		if (obj == null && menu.getParentItem() != null) {
100
			obj = menu.getParentItem().getData(AbstractPartRenderer.OWNING_ME);
101
		}
102
		if (obj instanceof MPopupMenu) {
103
			handleContextMenu(event, menu, (MPopupMenu) obj);
104
		} else if (obj instanceof MMenu) {
105
			handleMenu(event, menu, (MMenu) obj);
106
		}
107
	}
108
109
	private void handleMenu(final Event event, final Menu menu,
110
			final MMenu menuModel) {
111
		if ((menu.getStyle() & SWT.BAR) != 0) {
112
			// don't process the menu bar, it's not fair :-)
113
			return;
114
		}
115
		switch (event.type) {
116
		case SWT.Show:
117
			cleanUp(menu);
118
			showMenu(event, menu, menuModel);
119
			break;
120
		case SWT.Hide:
121
			// TODO we'll clean up on show
122
			break;
123
		}
124
	}
125
126
	public void showMenu(final Event event, final Menu menu,
127
			final MMenu menuModel) {
128
		// System.err.println("showMenu: " + menuModel + "\n\t" + menu);
129
	}
130
131
	private void handleContextMenu(final Event event, final Menu menu,
132
			final MPopupMenu menuModel) {
133
		switch (event.type) {
134
		case SWT.Show:
135
			cleanUp(menu);
136
			showPopup(event, menu, menuModel);
137
			break;
138
		case SWT.Hide:
139
			hidePopup(event, menu, menuModel);
140
			break;
141
		}
142
	}
143
144
	public void hidePopup(Event event, Menu menu, MPopupMenu menuModel) {
145
		// System.err.println("hidePopup: " + menuModel + "\n\t" + menu);
146
		final IEclipseContext popupContext = menuModel.getContext();
147
		final IEclipseContext originalChild = (IEclipseContext) popupContext
148
				.get(TMP_ORIGINAL_CONTEXT);
149
		popupContext.remove(TMP_ORIGINAL_CONTEXT);
150
		if (!menu.isDisposed()) {
151
			menu.getDisplay().asyncExec(new Runnable() {
152
				public void run() {
153
					if (originalChild == null) {
154
						popupContext.deactivate();
155
					} else {
156
						originalChild.activate();
157
					}
158
				}
159
			});
160
		}
161
	}
162
163
	public void showPopup(final Event event, final Menu menu,
164
			final MPopupMenu menuModel) {
165
		// System.err.println("showPopup: " + menuModel + "\n\t" + menu);
166
		// we need some context foolery here
167
		final IEclipseContext popupContext = menuModel.getContext();
168
		final IEclipseContext parentContext = popupContext.getParent();
169
		final IEclipseContext originalChild = parentContext.getActiveChild();
170
		popupContext.activate();
171
		popupContext.set(TMP_ORIGINAL_CONTEXT, originalChild);
172
173
	}
174
175
	public void cleanUp(final Menu menu) {
176
		// System.err.println("cleanUp: " + menu);
177
	}
178
179
	public void dispose() {
180
		// System.err.println("dispose");
181
	}
182
}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java (-2 / +1 lines)
Lines 25-31 Link Here
25
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
25
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
26
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
26
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
27
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
27
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
28
import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter;
29
import org.eclipse.emf.ecore.EObject;
28
import org.eclipse.emf.ecore.EObject;
30
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.events.DisposeEvent;
30
import org.eclipse.swt.events.DisposeEvent;
Lines 102-108 Link Here
102
				}
101
				}
103
				Menu menu = mi.getMenu();
102
				Menu menu = mi.getMenu();
104
				MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
103
				MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
105
				menuItem.setText(MenuServiceFilter.NUL_MENU_ITEM);
104
				menuItem.setText(MenuManagerRendererFilter.NUL_MENU_ITEM);
106
				menuItem.setEnabled(false);
105
				menuItem.setEnabled(false);
107
			}
106
			}
108
		}
107
		}
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/SeparatorRenderer.java (-16 / +2 lines)
Lines 12-22 Link Here
12
12
13
import java.util.List;
13
import java.util.List;
14
import org.eclipse.e4.ui.model.application.ui.MUIElement;
14
import org.eclipse.e4.ui.model.application.ui.MUIElement;
15
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
16
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator;
15
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator;
17
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Menu;
19
import org.eclipse.swt.widgets.MenuItem;
20
import org.eclipse.swt.widgets.ToolBar;
17
import org.eclipse.swt.widgets.ToolBar;
21
import org.eclipse.swt.widgets.ToolItem;
18
import org.eclipse.swt.widgets.ToolItem;
22
import org.eclipse.swt.widgets.Widget;
19
import org.eclipse.swt.widgets.Widget;
Lines 41-61 Link Here
41
			return null;
38
			return null;
42
		}
39
		}
43
		if (nextVisibleChild.isVisible()
40
		if (nextVisibleChild.isVisible()
44
				&& (nextVisibleChild instanceof MMenuSeparator || nextVisibleChild instanceof MToolBarSeparator)) {
41
				&& (nextVisibleChild instanceof MToolBarSeparator)) {
45
			return null;
42
			return null;
46
		}
43
		}
47
		if (element instanceof MMenuSeparator) {
44
		if (element instanceof MToolBarSeparator) {
48
			Menu menu = null;
49
			Object widget = element.getParent().getWidget();
50
			if (widget instanceof Menu) {
51
				menu = (Menu) widget;
52
			} else if (widget instanceof MenuItem) {
53
				menu = ((MenuItem) widget).getMenu();
54
			}
55
			if (menu != null) {
56
				newSep = new MenuItem(menu, SWT.SEPARATOR, addIndex);
57
			}
58
		} else if (element instanceof MToolBarSeparator) {
59
			ToolBar tb = parent instanceof ToolBar ? (ToolBar) parent
45
			ToolBar tb = parent instanceof ToolBar ? (ToolBar) parent
60
					: (ToolBar) element.getParent().getWidget();
46
					: (ToolBar) element.getParent().getWidget();
61
			newSep = new ToolItem(tb, SWT.SEPARATOR, addIndex);
47
			newSep = new ToolItem(tb, SWT.SEPARATOR, addIndex);
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/WorkbenchRendererFactory.java (-34 / +2 lines)
Lines 14-25 Link Here
14
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
14
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
15
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
15
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
16
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
16
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
17
import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
17
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
20
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
18
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
21
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu;
22
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenuItem;
23
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar;
19
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar;
24
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
20
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
25
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator;
21
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator;
Lines 30-37 Link Here
30
public class WorkbenchRendererFactory implements IRendererFactory {
26
public class WorkbenchRendererFactory implements IRendererFactory {
31
27
32
	private AreaRenderer areaRenderer;
28
	private AreaRenderer areaRenderer;
33
	private MenuRenderer menuRenderer;
29
	private MenuManagerRenderer menuRenderer;
34
	private HandledMenuItemRenderer handledMenuItemRenderer;
35
	private ToolBarRenderer toolbarRenderer;
30
	private ToolBarRenderer toolbarRenderer;
36
	private ToolItemRenderer toolItemRenderer;
31
	private ToolItemRenderer toolItemRenderer;
37
	private SeparatorRenderer separatorRenderer;
32
	private SeparatorRenderer separatorRenderer;
Lines 46-54 Link Here
46
	private WBWRenderer wbwRenderer;
41
	private WBWRenderer wbwRenderer;
47
42
48
	private IEclipseContext context;
43
	private IEclipseContext context;
49
	private DirectMenuItemRenderer directMenuItemRenderer;
50
	private RenderedMenuRenderer renderedMenuRenderer;
51
	private RenderedMenuItemRenderer renderedMenuItemRenderer;
52
	private RenderedToolBarRenderer renderedToolbarRenderer;
44
	private RenderedToolBarRenderer renderedToolbarRenderer;
53
45
54
	public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
46
	public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
Lines 64-96 Link Here
64
				initRenderer(contributedPartRenderer);
56
				initRenderer(contributedPartRenderer);
65
			}
57
			}
66
			return contributedPartRenderer;
58
			return contributedPartRenderer;
67
		} else if (uiElement instanceof MHandledMenuItem) {
68
			if (handledMenuItemRenderer == null) {
69
				handledMenuItemRenderer = new HandledMenuItemRenderer();
70
				initRenderer(handledMenuItemRenderer);
71
			}
72
			return handledMenuItemRenderer;
73
		} else if (uiElement instanceof MDirectMenuItem) {
74
			if (directMenuItemRenderer == null) {
75
				directMenuItemRenderer = new DirectMenuItemRenderer();
76
				initRenderer(directMenuItemRenderer);
77
			}
78
			return directMenuItemRenderer;
79
		} else if (uiElement instanceof MRenderedMenu) {
80
			if (renderedMenuRenderer == null) {
81
				renderedMenuRenderer = new RenderedMenuRenderer();
82
				initRenderer(renderedMenuRenderer);
83
			}
84
			return renderedMenuRenderer;
85
		} else if (uiElement instanceof MRenderedMenuItem) {
86
			if (renderedMenuItemRenderer == null) {
87
				renderedMenuItemRenderer = new RenderedMenuItemRenderer();
88
				initRenderer(renderedMenuItemRenderer);
89
			}
90
			return renderedMenuItemRenderer;
91
		} else if (uiElement instanceof MMenu) {
59
		} else if (uiElement instanceof MMenu) {
92
			if (menuRenderer == null) {
60
			if (menuRenderer == null) {
93
				menuRenderer = new MenuRenderer();
61
				menuRenderer = new MenuManagerRenderer();
94
				initRenderer(menuRenderer);
62
				initRenderer(menuRenderer);
95
			}
63
			}
96
			return menuRenderer;
64
			return menuRenderer;
(-)src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java (-24 / +13 lines)
Lines 51-56 Link Here
51
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
51
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
52
import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
52
import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
53
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
53
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
54
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
54
import org.eclipse.e4.ui.services.IStylingEngine;
55
import org.eclipse.e4.ui.services.IStylingEngine;
55
import org.eclipse.e4.ui.workbench.IPresentationEngine;
56
import org.eclipse.e4.ui.workbench.IPresentationEngine;
56
import org.eclipse.e4.ui.workbench.IResourceUtilities;
57
import org.eclipse.e4.ui.workbench.IResourceUtilities;
Lines 58-64 Link Here
58
import org.eclipse.e4.ui.workbench.UIEvents;
59
import org.eclipse.e4.ui.workbench.UIEvents;
59
import org.eclipse.e4.ui.workbench.modeling.EModelService;
60
import org.eclipse.e4.ui.workbench.modeling.EModelService;
60
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
61
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
61
import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter;
62
import org.eclipse.emf.ecore.impl.EObjectImpl;
62
import org.eclipse.emf.ecore.impl.EObjectImpl;
63
import org.eclipse.equinox.app.IApplication;
63
import org.eclipse.equinox.app.IApplication;
64
import org.eclipse.equinox.app.IApplicationContext;
64
import org.eclipse.equinox.app.IApplicationContext;
Lines 90-97 Link Here
90
90
91
	IRendererFactory curFactory = null;
91
	IRendererFactory curFactory = null;
92
92
93
	MenuServiceFilter menuServiceFilter;
94
95
	org.eclipse.swt.widgets.Listener keyListener;
93
	org.eclipse.swt.widgets.Listener keyListener;
96
94
97
	// Life Cycle handlers
95
	// Life Cycle handlers
Lines 108-115 Link Here
108
						.eContainer();
106
						.eContainer();
109
			}
107
			}
110
108
109
			boolean menuChild = parent instanceof MMenu;
110
111
			// If the parent isn't displayed who cares?
111
			// If the parent isn't displayed who cares?
112
			if (parent == null || parent.getWidget() == null)
112
			if (parent == null || parent.getWidget() == null || menuChild)
113
				return;
113
				return;
114
114
115
			if (changedElement.isToBeRendered()) {
115
			if (changedElement.isToBeRendered()) {
Lines 207-215 Link Here
207
			MElementContainer<MUIElement> changedElement = (MElementContainer<MUIElement>) changedObj;
207
			MElementContainer<MUIElement> changedElement = (MElementContainer<MUIElement>) changedObj;
208
			boolean isApplication = changedObj instanceof MApplication;
208
			boolean isApplication = changedObj instanceof MApplication;
209
209
210
			boolean menuChild = changedObj instanceof MMenu;
210
			// If the parent isn't in the UI then who cares?
211
			// If the parent isn't in the UI then who cares?
211
			AbstractPartRenderer renderer = getRendererFor(changedElement);
212
			AbstractPartRenderer renderer = getRendererFor(changedElement);
212
			if (!isApplication && renderer == null)
213
			if ((!isApplication && renderer == null) || menuChild)
213
				return;
214
				return;
214
215
215
			String eventType = (String) event
216
			String eventType = (String) event
Lines 685-691 Link Here
685
686
686
	public Object run(final MApplicationElement uiRoot,
687
	public Object run(final MApplicationElement uiRoot,
687
			final IEclipseContext runContext) {
688
			final IEclipseContext runContext) {
688
		final Display display = Display.getDefault();
689
		final Display display;
690
		if (runContext.get(Display.class) != null) {
691
			display = runContext.get(Display.class);
692
		} else {
693
			display = Display.getDefault();
694
			runContext.set(Display.class, display);
695
		}
689
		Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
696
		Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
690
697
691
			public void run() {
698
			public void run() {
Lines 703-715 Link Here
703
				display.addFilter(SWT.KeyDown, keyListener);
710
				display.addFilter(SWT.KeyDown, keyListener);
704
				display.addFilter(SWT.Traverse, keyListener);
711
				display.addFilter(SWT.Traverse, keyListener);
705
712
706
				menuServiceFilter = ContextInjectionFactory.make(
707
						MenuServiceFilter.class, runContext);
708
				display.addFilter(SWT.Show, menuServiceFilter);
709
				display.addFilter(SWT.Hide, menuServiceFilter);
710
				display.addFilter(SWT.Dispose, menuServiceFilter);
711
				runContext.set(MenuServiceFilter.class, menuServiceFilter);
712
713
				// Show the initial UI
713
				// Show the initial UI
714
714
715
				// Create a 'limbo' shell (used to host controls that shouldn't
715
				// Create a 'limbo' shell (used to host controls that shouldn't
Lines 842-858 Link Here
842
	 * why this is needed we should make this safe for multiple calls
842
	 * why this is needed we should make this safe for multiple calls
843
	 */
843
	 */
844
	private void cleanUp() {
844
	private void cleanUp() {
845
		if (menuServiceFilter != null) {
846
			Display display = Display.getDefault();
847
			if (!display.isDisposed()) {
848
				display.removeFilter(SWT.Show, menuServiceFilter);
849
				display.removeFilter(SWT.Hide, menuServiceFilter);
850
				display.removeFilter(SWT.Dispose, menuServiceFilter);
851
				menuServiceFilter.dispose();
852
				menuServiceFilter = null;
853
				appContext.remove(MenuServiceFilter.class);
854
			}
855
		}
856
		if (keyListener != null) {
845
		if (keyListener != null) {
857
			Display display = Display.getDefault();
846
			Display display = Display.getDefault();
858
			if (!display.isDisposed()) {
847
			if (!display.isDisposed()) {
(-)src/org/eclipse/e4/ui/workbench/swt/modeling/MenuManagerServiceFilter.java (-193 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.workbench.swt.modeling;
12
13
import java.lang.reflect.Method;
14
import java.util.HashMap;
15
import javax.inject.Inject;
16
import org.eclipse.core.runtime.ISafeRunnable;
17
import org.eclipse.core.runtime.SafeRunner;
18
import org.eclipse.e4.core.contexts.IEclipseContext;
19
import org.eclipse.e4.core.services.log.Logger;
20
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
21
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
22
import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator;
23
import org.eclipse.e4.ui.model.application.MApplication;
24
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
25
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
26
import org.eclipse.e4.ui.workbench.IPresentationEngine;
27
import org.eclipse.e4.ui.workbench.modeling.EModelService;
28
import org.eclipse.jface.action.MenuManager;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.widgets.Event;
31
import org.eclipse.swt.widgets.Listener;
32
import org.eclipse.swt.widgets.Menu;
33
import org.eclipse.swt.widgets.Widget;
34
35
public class MenuManagerServiceFilter implements Listener {
36
	public static final String NUL_MENU_ITEM = "(None Applicable)"; //$NON-NLS-1$
37
38
	private static final String TMP_ORIGINAL_CONTEXT = "MenuServiceFilter.original.context";
39
40
	private static void trace(String msg, Widget menu, MMenu menuModel) {
41
		WorkbenchSWTActivator.trace(Policy.MENUS, msg + ": " + menu + ": "
42
				+ menuModel, null);
43
	}
44
45
	private static Method aboutToShow;
46
47
	public static Method getAboutToShow() {
48
		if (aboutToShow == null) {
49
			try {
50
				aboutToShow = MenuManager.class
51
						.getDeclaredMethod("handleAboutToShow");
52
				aboutToShow.setAccessible(true);
53
			} catch (SecurityException e) {
54
				// TODO Auto-generated catch block
55
				e.printStackTrace();
56
			} catch (NoSuchMethodException e) {
57
				// TODO Auto-generated catch block
58
				e.printStackTrace();
59
			}
60
		}
61
		return aboutToShow;
62
	}
63
64
	@Inject
65
	private MApplication application;
66
67
	@Inject
68
	private IPresentationEngine renderer;
69
70
	@Inject
71
	private Logger logger;
72
73
	@Inject
74
	EModelService modelService;
75
76
	private HashMap<Menu, Runnable> pendingCleanup = new HashMap<Menu, Runnable>();
77
78
	public void handleEvent(final Event event) {
79
		// wrap the handling in a SafeRunner so that exceptions do not prevent
80
		// the menu from being shown
81
		SafeRunner.run(new ISafeRunnable() {
82
			public void handleException(Throwable e) {
83
				if (e instanceof Error) {
84
					// errors are deadly, we shouldn't ignore these
85
					throw (Error) e;
86
				} else {
87
					// log exceptions otherwise
88
					if (logger != null) {
89
						logger.error(e);
90
					}
91
				}
92
			}
93
94
			public void run() throws Exception {
95
				safeHandleEvent(event);
96
			}
97
		});
98
	}
99
100
	private void safeHandleEvent(Event event) {
101
		if (!(event.widget instanceof Menu)) {
102
			return;
103
		}
104
		final Menu menu = (Menu) event.widget;
105
		if (event.type == SWT.Dispose) {
106
			trace("handleMenu.Dispose", menu, null);
107
			cleanUp(menu);
108
		}
109
		Object obj = menu.getData(AbstractPartRenderer.OWNING_ME);
110
		if (obj == null && menu.getParentItem() != null) {
111
			obj = menu.getParentItem().getData(AbstractPartRenderer.OWNING_ME);
112
		}
113
		if (obj instanceof MPopupMenu) {
114
			handleContextMenu(event, menu, (MPopupMenu) obj);
115
		} else if (obj instanceof MMenu) {
116
			handleMenu(event, menu, (MMenu) obj);
117
		}
118
	}
119
120
	private void handleMenu(final Event event, final Menu menu,
121
			final MMenu menuModel) {
122
		if ((menu.getStyle() & SWT.BAR) != 0) {
123
			// don't process the menu bar, it's not fair :-)
124
			return;
125
		}
126
		switch (event.type) {
127
		case SWT.Show:
128
			cleanUp(menu);
129
			showMenu(event, menu, menuModel);
130
			break;
131
		case SWT.Hide:
132
			// TODO we'll clean up on show
133
			break;
134
		}
135
	}
136
137
	public void showMenu(final Event event, final Menu menu,
138
			final MMenu menuModel) {
139
		// System.err.println("showMenu: " + menuModel + "\n\t" + menu);
140
	}
141
142
	private void handleContextMenu(final Event event, final Menu menu,
143
			final MPopupMenu menuModel) {
144
		switch (event.type) {
145
		case SWT.Show:
146
			cleanUp(menu);
147
			showPopup(event, menu, menuModel);
148
			break;
149
		case SWT.Hide:
150
			hidePopup(event, menu, menuModel);
151
			break;
152
		}
153
	}
154
155
	public void hidePopup(Event event, Menu menu, MPopupMenu menuModel) {
156
		// System.err.println("hidePopup: " + menuModel + "\n\t" + menu);
157
		final IEclipseContext popupContext = menuModel.getContext();
158
		final IEclipseContext originalChild = (IEclipseContext) popupContext
159
				.get(TMP_ORIGINAL_CONTEXT);
160
		popupContext.remove(TMP_ORIGINAL_CONTEXT);
161
		if (!menu.isDisposed()) {
162
			menu.getDisplay().asyncExec(new Runnable() {
163
				public void run() {
164
					if (originalChild == null) {
165
						popupContext.deactivate();
166
					} else {
167
						originalChild.activate();
168
					}
169
				}
170
			});
171
		}
172
	}
173
174
	public void showPopup(final Event event, final Menu menu,
175
			final MPopupMenu menuModel) {
176
		// System.err.println("showPopup: " + menuModel + "\n\t" + menu);
177
		// we need some context foolery here
178
		final IEclipseContext popupContext = menuModel.getContext();
179
		final IEclipseContext parentContext = popupContext.getParent();
180
		final IEclipseContext originalChild = parentContext.getActiveChild();
181
		popupContext.activate();
182
		popupContext.set(TMP_ORIGINAL_CONTEXT, originalChild);
183
184
	}
185
186
	public void cleanUp(final Menu menu) {
187
		// System.err.println("cleanUp: " + menu);
188
	}
189
190
	public void dispose() {
191
		// System.err.println("dispose");
192
	}
193
}
(-)src/org/eclipse/e4/ui/workbench/swt/modeling/MenuService.java (-20 / +42 lines)
Lines 13-25 Link Here
13
import javax.inject.Inject;
13
import javax.inject.Inject;
14
import org.eclipse.e4.core.contexts.IEclipseContext;
14
import org.eclipse.e4.core.contexts.IEclipseContext;
15
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
15
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
16
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
17
import org.eclipse.e4.ui.model.application.ui.MUIElement;
16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
17
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
19
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
18
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
20
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
20
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.swt.widgets.Listener;
23
import org.eclipse.swt.widgets.Menu;
23
import org.eclipse.swt.widgets.Menu;
24
24
25
public class MenuService implements EMenuService {
25
public class MenuService implements EMenuService {
Lines 34-40 Link Here
34
		for (MMenu mmenu : myPart.getMenus()) {
34
		for (MMenu mmenu : myPart.getMenus()) {
35
			if (menuId.equals(mmenu.getElementId())
35
			if (menuId.equals(mmenu.getElementId())
36
					&& mmenu instanceof MPopupMenu) {
36
					&& mmenu instanceof MPopupMenu) {
37
				if (registerMenu(parentControl, (MPopupMenu) mmenu)) {
37
				Menu menu = registerMenu(parentControl, (MPopupMenu) mmenu,
38
						myPart);
39
				if (menu != null) {
40
					parentControl.setMenu(menu);
38
					return (MPopupMenu) mmenu;
41
					return (MPopupMenu) mmenu;
39
				} else {
42
				} else {
40
					return null;
43
					return null;
Lines 44-68 Link Here
44
		return null;
47
		return null;
45
	}
48
	}
46
49
47
	private boolean registerMenu(final Control parentControl,
50
	public static Menu registerMenu(final Control parentControl,
48
			final MPopupMenu mmenu) {
51
			final MPopupMenu mmenu, final MPart part) {
49
		if (mmenu.getWidget() != null) {
52
		if (mmenu.getWidget() != null) {
50
			return false;
53
			return (Menu) mmenu.getWidget();
51
		}
54
		}
52
		Menu menu = new Menu(parentControl);
55
		// we need to delegate to the renderer so that it "processes" the
53
		parentControl.setMenu(menu);
56
		// MenuManager correctly
54
		mmenu.setWidget(menu);
57
		IRendererFactory rendererFactory = part.getContext().get(
55
		menu.setData(AbstractPartRenderer.OWNING_ME, mmenu);
58
				IRendererFactory.class);
56
		IEclipseContext popupContext = myPart.getContext().createChild(
59
		AbstractPartRenderer renderer = rendererFactory.getRenderer(mmenu,
60
				parentControl);
61
		IEclipseContext popupContext = part.getContext().createChild(
57
				"popup:" + mmenu.getElementId());
62
				"popup:" + mmenu.getElementId());
58
		mmenu.setContext(popupContext);
63
		mmenu.setContext(popupContext);
59
		menu.addListener(SWT.Dispose, new Listener() {
64
		Object widget = renderer.createWidget(mmenu, parentControl);
60
			public void handleEvent(Event event) {
65
		if (!(widget instanceof Menu)) {
61
				mmenu.getContext().dispose();
66
			return null;
62
				mmenu.setContext(null);
67
		}
63
				mmenu.setWidget(null);
68
		renderer.bindWidget(mmenu, widget);
64
			}
69
		renderer.hookControllerLogic(mmenu);
65
		});
70
66
		return true;
71
		// Process its internal structure through the renderer that created
72
		// it
73
		Object castObject = mmenu;
74
		renderer.processContents((MElementContainer<MUIElement>) castObject);
75
76
		// Allow a final chance to set up
77
		renderer.postProcess(mmenu);
78
79
		// Now that we have a widget let the parent (if any) know
80
		if (mmenu.getParent() instanceof MUIElement) {
81
			MElementContainer<MUIElement> parentElement = mmenu.getParent();
82
			AbstractPartRenderer parentRenderer = rendererFactory.getRenderer(
83
					parentElement, null);
84
			if (parentRenderer != null)
85
				parentRenderer.childRendered(parentElement, mmenu);
86
		}
87
88
		return (Menu) widget;
67
	}
89
	}
68
}
90
}
(-)src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java (-369 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.workbench.swt.modeling;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.List;
18
import javax.inject.Inject;
19
import org.eclipse.core.commands.ParameterizedCommand;
20
import org.eclipse.core.runtime.ISafeRunnable;
21
import org.eclipse.core.runtime.SafeRunner;
22
import org.eclipse.e4.core.commands.EHandlerService;
23
import org.eclipse.e4.core.contexts.IEclipseContext;
24
import org.eclipse.e4.core.services.log.Logger;
25
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
26
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
27
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
28
import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator;
29
import org.eclipse.e4.ui.model.application.MApplication;
30
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
31
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
32
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
33
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
34
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
35
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu;
36
import org.eclipse.e4.ui.workbench.IPresentationEngine;
37
import org.eclipse.e4.ui.workbench.modeling.EModelService;
38
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
39
import org.eclipse.jface.action.MenuManager;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.widgets.Event;
42
import org.eclipse.swt.widgets.Listener;
43
import org.eclipse.swt.widgets.Menu;
44
import org.eclipse.swt.widgets.MenuItem;
45
import org.eclipse.swt.widgets.Widget;
46
47
public class MenuServiceFilter implements Listener {
48
	public static final String NUL_MENU_ITEM = "(None Applicable)"; //$NON-NLS-1$
49
50
	private static final String TMP_ORIGINAL_CONTEXT = "MenuServiceFilter.original.context";
51
52
	private static void trace(String msg, Widget menu, MMenu menuModel) {
53
		WorkbenchSWTActivator.trace(Policy.MENUS, msg + ": " + menu + ": "
54
				+ menuModel, null);
55
	}
56
57
	private static Method aboutToShow;
58
59
	public static Method getAboutToShow() {
60
		if (aboutToShow == null) {
61
			try {
62
				aboutToShow = MenuManager.class
63
						.getDeclaredMethod("handleAboutToShow");
64
				aboutToShow.setAccessible(true);
65
			} catch (SecurityException e) {
66
				// TODO Auto-generated catch block
67
				e.printStackTrace();
68
			} catch (NoSuchMethodException e) {
69
				// TODO Auto-generated catch block
70
				e.printStackTrace();
71
			}
72
		}
73
		return aboutToShow;
74
	}
75
76
	@Inject
77
	private MApplication application;
78
79
	@Inject
80
	private IPresentationEngine renderer;
81
82
	@Inject
83
	private Logger logger;
84
85
	@Inject
86
	EModelService modelService;
87
88
	private HashMap<Menu, Runnable> pendingCleanup = new HashMap<Menu, Runnable>();
89
90
	public void handleEvent(final Event event) {
91
		// wrap the handling in a SafeRunner so that exceptions do not prevent
92
		// the menu from being shown
93
		SafeRunner.run(new ISafeRunnable() {
94
			public void handleException(Throwable e) {
95
				if (e instanceof Error) {
96
					// errors are deadly, we shouldn't ignore these
97
					throw (Error) e;
98
				} else {
99
					// log exceptions otherwise
100
					if (logger != null) {
101
						logger.error(e);
102
					}
103
				}
104
			}
105
106
			public void run() throws Exception {
107
				safeHandleEvent(event);
108
			}
109
		});
110
	}
111
112
	private void safeHandleEvent(Event event) {
113
		if (!(event.widget instanceof Menu)) {
114
			return;
115
		}
116
		final Menu menu = (Menu) event.widget;
117
		if (event.type == SWT.Dispose) {
118
			trace("handleMenu.Dispose", menu, null);
119
			cleanUp(menu);
120
		}
121
		Object obj = menu.getData(AbstractPartRenderer.OWNING_ME);
122
		if (obj == null && menu.getParentItem() != null) {
123
			obj = menu.getParentItem().getData(AbstractPartRenderer.OWNING_ME);
124
		}
125
		if (obj instanceof MRenderedMenu) {
126
			handlerRenderedMenu(event, menu, (MRenderedMenu) obj);
127
		} else if (obj instanceof MPopupMenu) {
128
			handleContextMenu(event, menu, (MPopupMenu) obj);
129
		} else if (obj instanceof MMenu) {
130
			handleMenu(event, menu, (MMenu) obj);
131
		}
132
	}
133
134
	private void handleMenu(final Event event, final Menu menu,
135
			final MMenu menuModel) {
136
		if ((menu.getStyle() & SWT.BAR) != 0) {
137
			// don't process the menu bar, it's not fair :-)
138
			return;
139
		}
140
		switch (event.type) {
141
		case SWT.Show:
142
			trace("handleMenu.Show", menu, menuModel);
143
			cleanUp(menu);
144
			showMenu(event, menu, menuModel);
145
			break;
146
		case SWT.Hide:
147
			trace("handleMenu.Hide", menu, menuModel);
148
			// TODO we'll clean up on show
149
			break;
150
		}
151
	}
152
153
	public void showMenu(final Event event, final Menu menu,
154
			final MMenu menuModel) {
155
		final IEclipseContext parentContext = modelService
156
				.getContainingContext(menuModel);
157
158
		final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>();
159
		final ArrayList<MMenuElement> menuContributionsToRemove = new ArrayList<MMenuElement>();
160
		ExpressionContext eContext = new ExpressionContext(parentContext);
161
		ContributionsAnalyzer.gatherMenuContributions(menuModel,
162
				application.getMenuContributions(), menuModel.getElementId(),
163
				toContribute, eContext, false);
164
		if (menu.getItemCount() == 1) {
165
			MenuItem item = menu.getItem(0);
166
			if (NUL_MENU_ITEM.equals(item.getText())) {
167
				item.dispose();
168
			}
169
		}
170
		ContributionsAnalyzer.addMenuContributions(menuModel, toContribute,
171
				menuContributionsToRemove);
172
173
		// create a cleanup routine for the Hide or next Show
174
		pendingCleanup.put(menu, new Runnable() {
175
			public void run() {
176
				if (!menu.isDisposed()) {
177
					unrender(menuContributionsToRemove);
178
				}
179
				removeMenuContributions(menuModel, menuContributionsToRemove);
180
			}
181
		});
182
		render(menu, menuModel);
183
		if (menu.getItemCount() == 0) {
184
			MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
185
			menuItem.setText(NUL_MENU_ITEM);
186
			menuItem.setEnabled(false);
187
		}
188
	}
189
190
	private void handleContextMenu(final Event event, final Menu menu,
191
			final MPopupMenu menuModel) {
192
		switch (event.type) {
193
		case SWT.Show:
194
			trace("handleContextMenu.Show", menu, menuModel);
195
			cleanUp(menu);
196
			showPopup(event, menu, menuModel);
197
			break;
198
		case SWT.Hide:
199
			trace("handleContextMenu.Hide", menu, menuModel);
200
			hidePopup(event, menu, menuModel);
201
			break;
202
		}
203
	}
204
205
	public void hidePopup(Event event, Menu menu, MPopupMenu menuModel) {
206
		final IEclipseContext popupContext = menuModel.getContext();
207
		final IEclipseContext originalChild = (IEclipseContext) popupContext
208
				.get(TMP_ORIGINAL_CONTEXT);
209
		popupContext.remove(TMP_ORIGINAL_CONTEXT);
210
		if (!menu.isDisposed()) {
211
			menu.getDisplay().asyncExec(new Runnable() {
212
				public void run() {
213
					if (originalChild == null) {
214
						popupContext.deactivate();
215
					} else {
216
						originalChild.activate();
217
					}
218
				}
219
			});
220
		}
221
	}
222
223
	public void showPopup(final Event event, final Menu menu,
224
			final MPopupMenu menuModel) {
225
		// System.err.println("showPopup: " + menuModel + "\n\t" + menu);
226
		// we need some context foolery here
227
		final IEclipseContext popupContext = menuModel.getContext();
228
		final IEclipseContext parentContext = popupContext.getParent();
229
		final IEclipseContext originalChild = parentContext.getActiveChild();
230
		popupContext.activate();
231
		popupContext.set(TMP_ORIGINAL_CONTEXT, originalChild);
232
233
		final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>();
234
		final ArrayList<MMenuElement> menuContributionsToRemove = new ArrayList<MMenuElement>();
235
		ExpressionContext eContext = new ExpressionContext(popupContext);
236
		ContributionsAnalyzer.gatherMenuContributions(menuModel,
237
				application.getMenuContributions(), menuModel.getElementId(),
238
				toContribute, eContext, true);
239
240
		for (String tag : menuModel.getTags()) {
241
			if (tag.startsWith("popup:") && tag.length() > 6) {
242
				ContributionsAnalyzer.gatherMenuContributions(menuModel,
243
						application.getMenuContributions(), tag.substring(6),
244
						toContribute, eContext, false);
245
			}
246
		}
247
		ContributionsAnalyzer.addMenuContributions(menuModel, toContribute,
248
				menuContributionsToRemove);
249
250
		// create a cleanup routine for the Hide or next Show
251
		pendingCleanup.put(menu, new Runnable() {
252
			public void run() {
253
				if (!menu.isDisposed()) {
254
					unrender(menuContributionsToRemove);
255
				}
256
				removeMenuContributions(menuModel, menuContributionsToRemove);
257
			}
258
		});
259
		render(menu, menuModel);
260
	}
261
262
	private void render(final Menu menu, final MMenu menuModel) {
263
		trace("render", menu, menuModel);
264
		for (MMenuElement element : menuModel.getChildren()) {
265
			renderer.createGui(element, menu, null);
266
			if (element instanceof MHandledMenuItem) {
267
				setEnabled((MHandledMenuItem) element);
268
			}
269
		}
270
	}
271
272
	private void setEnabled(MHandledMenuItem item) {
273
		if (!item.isToBeRendered() || !item.isVisible()
274
				|| item.getWidget() == null) {
275
			return;
276
		}
277
		ParameterizedCommand cmd = item.getWbCommand();
278
		if (cmd == null) {
279
			return;
280
		}
281
		final IEclipseContext lclContext = modelService
282
				.getContainingContext(item);
283
		EHandlerService service = lclContext.get(EHandlerService.class);
284
		item.setEnabled(service.canExecute(cmd));
285
	}
286
287
	private void unrender(final List<MMenuElement> menuModel) {
288
		trace("unrender", null, null);
289
		for (MMenuElement element : menuModel) {
290
			renderer.removeGui(element);
291
		}
292
	}
293
294
	private void removeMenuContributions(final MMenu menuModel,
295
			final ArrayList<MMenuElement> menuContributionsToRemove) {
296
		for (MMenuElement item : menuContributionsToRemove) {
297
			trace("removeMenuContributions " + item,
298
					(Widget) menuModel.getWidget(), menuModel);
299
			menuModel.getChildren().remove(item);
300
		}
301
	}
302
303
	private void handlerRenderedMenu(final Event event, final Menu menu,
304
			final MRenderedMenu menuModel) {
305
		// Do nothing here for the moment, except process any cleanups
306
		switch (event.type) {
307
		case SWT.Show:
308
			trace("handlerRenderedMenu.Show", menu, menuModel);
309
			cleanUp(menu);
310
			showRenderedMenu(event, menu, menuModel);
311
			break;
312
		case SWT.Hide:
313
			trace("handlerRenderedMenu.Hide", menu, menuModel);
314
			// TODO don't care
315
			break;
316
		}
317
	}
318
319
	public void showRenderedMenu(final Event event, final Menu menu,
320
			final MRenderedMenu menuModel) {
321
		if (!(menuModel.getContributionManager() instanceof MenuManager)) {
322
			return;
323
		}
324
325
		MenuManager manager = (MenuManager) menuModel.getContributionManager();
326
		Method handleAboutToShow = getAboutToShow();
327
		try {
328
			handleAboutToShow.invoke(manager);
329
		} catch (IllegalArgumentException e) {
330
			// TODO Auto-generated catch block
331
			e.printStackTrace();
332
		} catch (IllegalAccessException e) {
333
			// TODO Auto-generated catch block
334
			e.printStackTrace();
335
		} catch (InvocationTargetException e) {
336
			// TODO Auto-generated catch block
337
			e.printStackTrace();
338
		}
339
340
		if (menuModel.getChildren().size() == 1
341
				&& menuModel.getChildren().get(0) instanceof MPopupMenu) {
342
			showPopup(event, menu, (MPopupMenu) menuModel.getChildren().get(0));
343
		} else {
344
			showMenu(event, menu, menuModel);
345
		}
346
		event.type = SWT.None;
347
		event.doit = false;
348
	}
349
350
	public void cleanUp(final Menu menu) {
351
		trace("cleanUp", menu, null);
352
		if (pendingCleanup.isEmpty()) {
353
			return;
354
		}
355
		Runnable cleanUp = pendingCleanup.remove(menu);
356
		if (cleanUp != null) {
357
			trace("cleanUp.run()", menu, null);
358
			cleanUp.run();
359
		}
360
	}
361
362
	public void dispose() {
363
		Menu[] keys = pendingCleanup.keySet().toArray(
364
				new Menu[pendingCleanup.size()]);
365
		for (Menu menu : keys) {
366
			cleanUp(menu);
367
		}
368
	}
369
}
(-)Eclipse UI/org/eclipse/ui/internal/EditorMenuManager.java (+8 lines)
Lines 188-194 Link Here
188
			mc.getChildren().add(separator);
188
			mc.getChildren().add(separator);
189
		} else if (!(item instanceof SubContributionItem) && !(item instanceof SubMenuManager)) {
189
		} else if (!(item instanceof SubContributionItem) && !(item instanceof SubMenuManager)) {
190
			MRenderedMenuItem menuItem = MenuFactoryImpl.eINSTANCE.createRenderedMenuItem();
190
			MRenderedMenuItem menuItem = MenuFactoryImpl.eINSTANCE.createRenderedMenuItem();
191
			menuItem.setElementId(item.getId());
191
			menuItem.setContributionItem(item);
192
			menuItem.setContributionItem(item);
193
			// IRendererFactory factory =
194
			// application.getContext().get(IRendererFactory.class);
195
			// AbstractPartRenderer renderer = factory.getRenderer(mc, null);
196
			// if (renderer instanceof MenuManagerRenderer) {
197
			// ((MenuManagerRenderer)
198
			// renderer).linkModelToContribution(menuItem, item);
199
			// }
192
			mc.getChildren().add(menuItem);
200
			mc.getChildren().add(menuItem);
193
		}
201
		}
194
	}
202
	}
(-)Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java (-100 / +34 lines)
Lines 24-43 Link Here
24
import org.eclipse.core.runtime.IRegistryChangeEvent;
24
import org.eclipse.core.runtime.IRegistryChangeEvent;
25
import org.eclipse.core.runtime.IRegistryChangeListener;
25
import org.eclipse.core.runtime.IRegistryChangeListener;
26
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.e4.core.contexts.IEclipseContext;
28
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
27
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
29
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
28
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
30
import org.eclipse.e4.ui.model.application.MApplication;
29
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
30
import org.eclipse.e4.ui.model.application.ui.MUIElement;
31
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
31
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
32
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
32
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
33
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
34
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
35
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
33
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
36
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu;
37
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
34
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
38
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
35
import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer;
36
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
37
import org.eclipse.e4.ui.workbench.swt.modeling.MenuService;
39
import org.eclipse.jface.action.ContributionManager;
38
import org.eclipse.jface.action.ContributionManager;
40
import org.eclipse.jface.action.GroupMarker;
41
import org.eclipse.jface.action.IContributionItem;
39
import org.eclipse.jface.action.IContributionItem;
42
import org.eclipse.jface.action.IMenuListener2;
40
import org.eclipse.jface.action.IMenuListener2;
43
import org.eclipse.jface.action.IMenuManager;
41
import org.eclipse.jface.action.IMenuManager;
Lines 51-57 Link Here
51
import org.eclipse.swt.widgets.Display;
49
import org.eclipse.swt.widgets.Display;
52
import org.eclipse.ui.IEditorPart;
50
import org.eclipse.ui.IEditorPart;
53
import org.eclipse.ui.IWorkbench;
51
import org.eclipse.ui.IWorkbench;
54
import org.eclipse.ui.IWorkbenchActionConstants;
55
import org.eclipse.ui.IWorkbenchPart;
52
import org.eclipse.ui.IWorkbenchPart;
56
import org.eclipse.ui.IWorkbenchPartSite;
53
import org.eclipse.ui.IWorkbenchPartSite;
57
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
54
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
Lines 93-100 Link Here
93
	
90
	
94
	private ArrayList actionContributionCache = new ArrayList();
91
	private ArrayList actionContributionCache = new ArrayList();
95
	private ArrayList managerContributionCache = new ArrayList();
92
	private ArrayList managerContributionCache = new ArrayList();
96
	private ArrayList<MRenderedMenu> renderedMenuCache = new ArrayList<MRenderedMenu>();
97
	private ArrayList<MRenderedMenu> lastRenderedMenuCache = new ArrayList<MRenderedMenu>();
98
	private boolean cleanupNeeded = false;
93
	private boolean cleanupNeeded = false;
99
94
100
	private MPart modelPart;
95
	private MPart modelPart;
Lines 159-193 Link Here
159
		}
154
		}
160
		menuModel = null;
155
		menuModel = null;
161
		for (MMenu item : modelPart.getMenus()) {
156
		for (MMenu item : modelPart.getMenus()) {
162
			if (id.equals(item.getElementId()) && item instanceof MRenderedMenu
157
			if (id.equals(item.getElementId()) && item instanceof MPopupMenu
163
					&& item.getTags().contains("popup")) { //$NON-NLS-1$
158
					&& item.getTags().contains("popup")) { //$NON-NLS-1$
164
				menuModel = (MRenderedMenu) item;
159
				menuModel = (MPopupMenu) item;
165
				break;
160
				break;
166
			}
161
			}
167
		}
162
		}
168
		if (menuModel == null) {
163
		if (menuModel == null) {
169
			menuModel = MenuFactoryImpl.eINSTANCE.createRenderedMenu();
164
			menuModel = MenuFactoryImpl.eINSTANCE.createPopupMenu();
170
			menuModel.setElementId(id);
165
			menuModel.setElementId(id);
171
			menuModel.getTags().add(ContributionsAnalyzer.MC_POPUP);
166
			menuModel.getTags().add(ContributionsAnalyzer.MC_POPUP);
172
			modelPart.getMenus().add(menuModel);
167
			modelPart.getMenus().add(menuModel);
173
			MPopupMenu popup = MenuFactoryImpl.eINSTANCE.createPopupMenu();
174
			popup.setElementId(id);
175
			popup.getTags().add(ContributionsAnalyzer.MC_POPUP);
176
			menuModel.getChildren().add(popup);
177
		}
168
		}
178
		menuModel.setContributionManager(menu);
169
		IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
170
		AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
171
		if (obj instanceof MenuManagerRenderer) {
172
			((MenuManagerRenderer) obj).linkModelToManager(menuModel, menu);
173
		}
179
		registerE4Support();
174
		registerE4Support();
180
	}
175
	}
181
176
182
	private void registerE4Support() {
177
	private void registerE4Support() {
183
		if (menuModel.getWidget() == null && menu.getMenu() != null) {
178
		if (menuModel.getWidget() == null && menu.getMenu() != null) {
184
			menuModel.setWidget(menu.getMenu());
179
			MenuService.registerMenu(menu.getMenu().getParent(), menuModel, modelPart);
185
			menu.getMenu().setData(AbstractPartRenderer.OWNING_ME, menuModel);
186
			MPopupMenu popup = (MPopupMenu) menuModel.getChildren().get(0);
187
			IEclipseContext popupContext = modelPart.getContext().createChild(
188
					"popup:" + popup.getElementId()); //$NON-NLS-1$
189
			popup.setContext(popupContext);
190
191
		}
180
		}
192
	}
181
	}
193
	// getMenuId() added by Dan Rubel (dan_rubel@instantiations.com)
182
	// getMenuId() added by Dan Rubel (dan_rubel@instantiations.com)
Lines 227-233 Link Here
227
    public final void addMenuId(final String menuId) {
216
    public final void addMenuId(final String menuId) {
228
		bitSet &= ~STATIC_ACTION_READ;
217
		bitSet &= ~STATIC_ACTION_READ;
229
		if (menuModel != null) {
218
		if (menuModel != null) {
230
			List<String> tags = menuModel.getChildren().get(0).getTags();
219
			List<String> tags = menuModel.getTags();
231
			String tag = "popup:" + menuId; //$NON-NLS-1$
220
			String tag = "popup:" + menuId; //$NON-NLS-1$
232
			if (!tags.contains(tag)) {
221
			if (!tags.contains(tag)) {
233
				tags.add(tag);
222
				tags.add(tag);
Lines 388-490 Link Here
388
			}
377
			}
389
		}
378
		}
390
    	
379
    	
380
		addMenuContributions(mgr);
381
391
    	readStaticActions();
382
    	readStaticActions();
392
        // test for additions removed to comply with menu contributions
383
        // test for additions removed to comply with menu contributions
393
        if (menuWrapper != null) {
384
        if (menuWrapper != null) {
394
            mgr = menuWrapper;
385
            mgr = menuWrapper;
395
            menuWrapper.removeAll();
386
            menuWrapper.removeAll();
396
        }
387
        }
397
		addMenuContributions(mgr);
398
        if ((bitSet & INCLUDE_EDITOR_INPUT) != 0) {
388
        if ((bitSet & INCLUDE_EDITOR_INPUT) != 0) {
399
            addEditorActions(mgr);
389
            addEditorActions(mgr);
400
        }
390
        }
401
        addObjectActions(mgr);
391
        addObjectActions(mgr);
402
        addStaticActions(mgr);
392
        addStaticActions(mgr);
403
        cleanUpContributionCache();
404
    }
393
    }
405
    
394
    
406
395
407
	/**
396
	/**
397
	 * well, this goes to the renderer.
398
	 * 
408
	 * @param mgr
399
	 * @param mgr
409
	 */
400
	 */
410
	private void addMenuContributions(IMenuManager mgr) {
401
	private void addMenuContributions(IMenuManager mgr) {
411
		MPopupMenu popup = (MPopupMenu) menuModel.getChildren().get(0);
402
		IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
412
		final IEclipseContext popupContext = popup.getContext();
403
		AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
413
		final IEclipseContext parentContext = popupContext.getParent();
404
		if (obj instanceof MenuManagerRenderer) {
414
		// final IEclipseContext originalChild = (IEclipseContext) parentContext
405
			MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
415
		// .getLocal(IContextConstants.ACTIVE_CHILD);
406
			renderer.reconcileManagerToModel(menu, menuModel);
416
		// parentContext.set(IContextConstants.ACTIVE_CHILD, popupContext);
407
			renderer.processContributions(menuModel, false);
417
		// popupContext.set(TMP_ORIGINAL_CONTEXT, originalChild);
408
			// double cast because we're bad people
418
		MApplication application = parentContext.get(MApplication.class);
409
			renderer.processContents((MElementContainer<MUIElement>) ((Object) menuModel));
419
420
		final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>();
421
		// final ArrayList<MMenuElement> menuContributionsToRemove = new
422
		// ArrayList<MMenuElement>();
423
		ExpressionContext eContext = new ExpressionContext(popupContext);
424
		ContributionsAnalyzer.gatherMenuContributions(popup, application.getMenuContributions(),
425
				popup.getElementId(), toContribute, eContext, true);
426
427
		for (String tag : popup.getTags()) {
428
			if (tag.startsWith("popup:") && tag.length() > 6) { //$NON-NLS-1$
429
				ContributionsAnalyzer.gatherMenuContributions(popup,
430
						application.getMenuContributions(), tag.substring(6), toContribute,
431
						eContext, false);
432
			}
433
		}
434
		for (MMenuContribution contribution : toContribute) {
435
			String positionInParent = contribution.getPositionInParent();
436
			String id = null;
437
			String modifier = null;
438
			if (positionInParent != null && positionInParent.length() > 0) {
439
				String[] array = positionInParent.split("="); //$NON-NLS-1$
440
				modifier = array[0];
441
				id = array[1];
442
			}
443
			if (id == null) {
444
				continue;
445
			}
446
			IContributionItem item = mgr.find(id);
447
			if (item == null) {
448
				if (IWorkbenchActionConstants.MB_ADDITIONS.equals(id)) {
449
					mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
450
				} else {
451
					continue;
452
				}
453
			}
454
			for (MMenuElement element : contribution.getChildren()) {
455
				if (element instanceof MMenu) {
456
					MMenu menu = (MMenu) element;
457
					if (mgr.find(menu.getElementId()) != null) {
458
						continue;
459
					}
460
					MenuManager submenu = new MenuManager(menu.getLabel(), menu.getElementId());
461
					if (modifier.equals("before")) { //$NON-NLS-1$
462
						mgr.insertBefore(id, submenu);
463
					} else {
464
						mgr.insertAfter(id, submenu);
465
					}
466
					MRenderedMenu renderedMenu = MenuFactoryImpl.eINSTANCE.createRenderedMenu();
467
					renderedMenu.setElementId(menu.getElementId());
468
					renderedMenu.getTags().add(ContributionsAnalyzer.MC_POPUP);
469
					renderedMenu.setContributionManager(submenu);
470
					popup.getChildren().add(renderedMenu);
471
					renderedMenuCache.add(renderedMenu);
472
				}
473
			}
474
		}
410
		}
475
	}
411
	}
476
412
477
	private MRenderedMenu menuModel;
413
	private MPopupMenu menuModel;
478
    
414
    
479
    /**
415
    /**
480
	 * Notifies the listener that the menu is about to be hidden.
416
	 * Notifies the listener that the menu is about to be hidden.
481
	 */
417
	 */
482
    public final void menuAboutToHide(final IMenuManager mgr) {
418
    public final void menuAboutToHide(final IMenuManager mgr) {
483
    	gatherContributions(mgr);
419
    	gatherContributions(mgr);
484
		if (!renderedMenuCache.isEmpty()) {
485
			lastRenderedMenuCache = renderedMenuCache;
486
			renderedMenuCache = new ArrayList<MRenderedMenu>();
487
		}
488
		cleanupNeeded = true;
420
		cleanupNeeded = true;
489
    	// Remove this menu as a visible menu.
421
    	// Remove this menu as a visible menu.
490
    	final IWorkbenchPartSite site = part.getSite();
422
    	final IWorkbenchPartSite site = part.getSite();
Lines 539-549 Link Here
539
			}
471
			}
540
		}
472
		}
541
473
542
		for (MRenderedMenu rmenu : lastRenderedMenuCache) {
474
		IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
543
			MPopupMenu popup = (MPopupMenu) menuModel.getChildren().get(0);
475
		AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
544
			popup.getChildren().remove(rmenu);
476
		if (obj instanceof MenuManagerRenderer) {
477
			MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
478
			renderer.cleanUp(menuModel);
545
		}
479
		}
546
		lastRenderedMenuCache.clear();
480
547
		managerContributionCache.clear();
481
		managerContributionCache.clear();
548
482
549
	}
483
	}
(-)Eclipse UI/org/eclipse/ui/internal/Workbench.java (+2 lines)
Lines 533-538 Link Here
533
					IEclipseContext workbenchContext = e4Workbench.getContext();
533
					IEclipseContext workbenchContext = e4Workbench.getContext();
534
					workbenchContext.set(Display.class, display);
534
					workbenchContext.set(Display.class, display);
535
535
536
					e4Workbench.instantiateRenderer();
537
536
					// create the workbench instance
538
					// create the workbench instance
537
					Workbench workbench = new Workbench(display, advisor, e4Workbench
539
					Workbench workbench = new Workbench(display, advisor, e4Workbench
538
							.getApplication(), e4Workbench.getContext());
540
							.getApplication(), e4Workbench.getContext());
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java (+1 lines)
Lines 659-664 Link Here
659
			} else {
659
			} else {
660
				MRenderedMenuItem menuItem = MenuFactoryImpl.eINSTANCE.createRenderedMenuItem();
660
				MRenderedMenuItem menuItem = MenuFactoryImpl.eINSTANCE.createRenderedMenuItem();
661
				menuItem.setContributionItem(item);
661
				menuItem.setContributionItem(item);
662
				menuItem.setElementId(item.getId());
662
				menu.getChildren().add(menuItem);
663
				menu.getChildren().add(menuItem);
663
			}
664
			}
664
		}
665
		}
(-)Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java (-6 / +15 lines)
Lines 12-25 Link Here
12
package org.eclipse.ui.internal.e4.compatibility;
12
package org.eclipse.ui.internal.e4.compatibility;
13
13
14
import javax.inject.Inject;
14
import javax.inject.Inject;
15
import org.eclipse.e4.core.contexts.IEclipseContext;
15
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
16
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
17
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
17
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
19
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
18
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu;
19
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar;
20
import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar;
20
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
21
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
21
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
22
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
23
import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer;
22
import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer;
24
import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer;
25
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
23
import org.eclipse.jface.action.MenuManager;
26
import org.eclipse.jface.action.MenuManager;
24
import org.eclipse.jface.action.ToolBarManager;
27
import org.eclipse.jface.action.ToolBarManager;
25
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Composite;
Lines 75-90 Link Here
75
		// dispose the tb, it will be re-created when the tab is shown
78
		// dispose the tb, it will be re-created when the tab is shown
76
		tb.dispose();
79
		tb.dispose();
77
80
81
		IEclipseContext context = getModel().getContext();
82
		IRendererFactory rendererFactory = context.get(IRendererFactory.class);
83
78
		MenuManager mm = (MenuManager) actionBars.getMenuManager();
84
		MenuManager mm = (MenuManager) actionBars.getMenuManager();
79
		MRenderedMenu menu = null;
85
		MMenu menu = null;
80
		for (MMenu me : part.getMenus()) {
86
		for (MMenu me : part.getMenus()) {
81
			if (me.getTags().contains(StackRenderer.TAG_VIEW_MENU) && (me instanceof MRenderedMenu)) {
87
			if (me.getTags().contains(StackRenderer.TAG_VIEW_MENU)) {
82
				menu = (MRenderedMenu) me;
88
				menu = me;
83
				break;
89
				break;
84
			}
90
			}
85
		}
91
		}
86
		if (menu == null) {
92
		if (menu == null) {
87
			menu = MenuFactoryImpl.eINSTANCE.createRenderedMenu();
93
			menu = MenuFactoryImpl.eINSTANCE.createMenu();
88
			menu.setElementId(part.getElementId());
94
			menu.setElementId(part.getElementId());
89
95
90
			menu.getTags().add(StackRenderer.TAG_VIEW_MENU);
96
			menu.getTags().add(StackRenderer.TAG_VIEW_MENU);
Lines 92-98 Link Here
92
			part.getMenus().add(menu);
98
			part.getMenus().add(menu);
93
99
94
		}
100
		}
95
		menu.setContributionManager(mm);
101
		AbstractPartRenderer apr = rendererFactory.getRenderer(menu, parent);
102
		if (apr instanceof MenuManagerRenderer) {
103
			((MenuManagerRenderer) apr).linkModelToManager(menu, mm);
104
		}
96
105
97
		// Construct the toolbar (if necessary)
106
		// Construct the toolbar (if necessary)
98
		MToolBar toolbar = part.getToolbar();
107
		MToolBar toolbar = part.getToolbar();
(-)Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java (-53 / +41 lines)
Lines 26-36 Link Here
26
import org.eclipse.core.runtime.IConfigurationElement;
26
import org.eclipse.core.runtime.IConfigurationElement;
27
import org.eclipse.core.runtime.InvalidRegistryObjectException;
27
import org.eclipse.core.runtime.InvalidRegistryObjectException;
28
import org.eclipse.e4.core.commands.ECommandService;
28
import org.eclipse.e4.core.commands.ECommandService;
29
import org.eclipse.e4.core.contexts.ContextFunction;
30
import org.eclipse.e4.core.contexts.IContextFunction;
29
import org.eclipse.e4.core.contexts.IEclipseContext;
31
import org.eclipse.e4.core.contexts.IEclipseContext;
30
import org.eclipse.e4.core.di.annotations.CanExecute;
32
import org.eclipse.e4.core.di.annotations.CanExecute;
31
import org.eclipse.e4.core.di.annotations.Execute;
33
import org.eclipse.e4.core.di.annotations.Execute;
32
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
34
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
33
import org.eclipse.e4.ui.internal.workbench.ExtensionPointProxy;
34
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
35
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
35
import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator;
36
import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator;
36
import org.eclipse.e4.ui.model.application.MApplication;
37
import org.eclipse.e4.ui.model.application.MApplication;
Lines 60-74 Link Here
60
import org.eclipse.ui.IActionDelegate;
61
import org.eclipse.ui.IActionDelegate;
61
import org.eclipse.ui.ISelectionService;
62
import org.eclipse.ui.ISelectionService;
62
import org.eclipse.ui.IWorkbenchCommandConstants;
63
import org.eclipse.ui.IWorkbenchCommandConstants;
64
import org.eclipse.ui.IWorkbenchWindow;
63
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate;
65
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate;
64
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2;
66
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2;
65
import org.eclipse.ui.PlatformUI;
67
import org.eclipse.ui.PlatformUI;
66
import org.eclipse.ui.commands.ICommandImageService;
68
import org.eclipse.ui.commands.ICommandImageService;
67
import org.eclipse.ui.commands.ICommandService;
69
import org.eclipse.ui.commands.ICommandService;
68
import org.eclipse.ui.internal.OpenPreferencesAction;
70
import org.eclipse.ui.internal.OpenPreferencesAction;
71
import org.eclipse.ui.internal.WWinPluginPulldown;
69
import org.eclipse.ui.internal.WorkbenchWindow;
72
import org.eclipse.ui.internal.WorkbenchWindow;
70
import org.eclipse.ui.internal.handlers.ActionDelegateHandlerProxy;
73
import org.eclipse.ui.internal.handlers.ActionDelegateHandlerProxy;
71
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
74
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
75
import org.eclipse.ui.internal.services.ServiceLocator;
72
import org.eclipse.ui.internal.util.Util;
76
import org.eclipse.ui.internal.util.Util;
73
import org.eclipse.ui.menus.CommandContributionItem;
77
import org.eclipse.ui.menus.CommandContributionItem;
74
import org.eclipse.ui.menus.CommandContributionItemParameter;
78
import org.eclipse.ui.menus.CommandContributionItemParameter;
Lines 348-360 Link Here
348
				.getIconUrl(menuAddition, IWorkbenchRegistryConstants.ATT_ICON));
352
				.getIconUrl(menuAddition, IWorkbenchRegistryConstants.ATT_ICON));
349
		element.setLabel(Util.safeString(text));
353
		element.setLabel(Util.safeString(text));
350
354
351
		for (IConfigurationElement child : menuAddition.getChildren()) {
355
		for (final IConfigurationElement child : menuAddition.getChildren()) {
352
			if (child.getName().equals(IWorkbenchRegistryConstants.TAG_DYNAMIC)) {
356
			if (child.getName().equals(IWorkbenchRegistryConstants.TAG_DYNAMIC)) {
353
				ExtensionPointProxy proxy = new ExtensionPointProxy(child,
357
				ContextFunction generator = new ContextFunction() {
354
						IWorkbenchRegistryConstants.TAG_CLASS, new ExtensionContribution());
358
					@Override
359
					public Object compute(IEclipseContext context) {
360
						ServiceLocator sl = new ServiceLocator();
361
						sl.setContext(context);
362
						DynamicMenuContributionItem item = new DynamicMenuContributionItem(
363
								getId(child), sl, child);
364
						return item;
365
					}
366
				};
367
355
				MRenderedMenuItem menuItem = MenuFactoryImpl.eINSTANCE.createRenderedMenuItem();
368
				MRenderedMenuItem menuItem = MenuFactoryImpl.eINSTANCE.createRenderedMenuItem();
356
				menuItem.setElementId(getId(child));
369
				menuItem.setElementId(getId(child));
357
				menuItem.setContributionItem(proxy);
370
				menuItem.setContributionItem(generator);
371
				// IRendererFactory factory =
372
				// application.getContext().get(IRendererFactory.class);
373
				// AbstractPartRenderer renderer = factory.getRenderer(element,
374
				// null);
375
				// if (renderer instanceof MenuManagerRenderer) {
376
				// ((MenuManagerRenderer)
377
				// renderer).linkModelToContribution(menuItem, item);
378
				// }
358
				element.getChildren().add(menuItem);
379
				element.getChildren().add(menuItem);
359
			}
380
			}
360
		}
381
		}
Lines 395-452 Link Here
395
		String pulldown = element.getAttribute("pulldown"); //$NON-NLS-1$
416
		String pulldown = element.getAttribute("pulldown"); //$NON-NLS-1$
396
		if (IWorkbenchRegistryConstants.STYLE_PULLDOWN.equals(style)
417
		if (IWorkbenchRegistryConstants.STYLE_PULLDOWN.equals(style)
397
				|| (pulldown != null && pulldown.equals("true"))) { //$NON-NLS-1$
418
				|| (pulldown != null && pulldown.equals("true"))) { //$NON-NLS-1$
398
			MRenderedMenu menu = MenuFactoryImpl.eINSTANCE.createRenderedMenu();
419
			MRenderedMenuItem item = MenuFactoryImpl.eINSTANCE.createRenderedMenuItem();
399
			menu.setElementId(id);
420
			item.setLabel(text);
400
			menu.setLabel(text);
401
			if (iconUri != null) {
421
			if (iconUri != null) {
402
				menu.setIconURI(iconUri);
422
				item.setIconURI(iconUri);
403
			}
423
			}
404
			ECommandService cs = app.getContext().get(ECommandService.class);
424
			IContextFunction generator = new ContextFunction() {
405
			final ParameterizedCommand parmCmd = cs.createCommand(cmdId, null);
425
				@Override
406
			menu.setContributionManager(new IMenuCreator() {
426
				public Object compute(IEclipseContext context) {
407
				private ActionDelegateHandlerProxy handlerProxy;
427
					IWorkbenchWindow window = context.get(IWorkbenchWindow.class);
408
428
					if (window == null) {
409
				private ActionDelegateHandlerProxy getProxy() {
410
					if (handlerProxy == null) {
411
						handlerProxy = new ActionDelegateHandlerProxy(element,
412
								IWorkbenchRegistryConstants.ATT_CLASS, id, parmCmd, PlatformUI
413
										.getWorkbench().getActiveWorkbenchWindow(), null, null,
414
								null);
415
					}
416
					return handlerProxy;
417
				}
418
419
				private IWorkbenchWindowPulldownDelegate getDelegate() {
420
					getProxy();
421
					if (handlerProxy == null) {
422
						return null;
429
						return null;
423
					}
430
					}
424
					if (handlerProxy.getDelegate() == null) {
431
					WWinPluginPulldown action = new WWinPluginPulldown(element, window, cmdId,
425
						handlerProxy.loadDelegate();
432
							IAction.AS_DROP_DOWN_MENU);
426
					}
433
					return new ActionContributionItem(action);
427
					return (IWorkbenchWindowPulldownDelegate) handlerProxy.getDelegate();
434
				}
428
				}
435
			};
429
436
			item.setContributionItem(generator);
430
				public Menu getMenu(Menu parent) {
437
			return item;
431
					IWorkbenchWindowPulldownDelegate2 delegate = (IWorkbenchWindowPulldownDelegate2) getDelegate();
432
					if (delegate == null) {
433
						return null;
434
					}
435
					return delegate.getMenu(parent);
436
				}
437
438
				public Menu getMenu(Control parent) {
439
					return getDelegate() == null ? null : getDelegate().getMenu(parent);
440
				}
441
442
				public void dispose() {
443
					if (handlerProxy != null) {
444
						handlerProxy.dispose();
445
						handlerProxy = null;
446
					}
447
				}
448
			});
449
			return menu;
450
		}
438
		}
451
439
452
		ItemType type = ItemType.PUSH;
440
		ItemType type = ItemType.PUSH;

Return to bug 325392