Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian de Alwis2012-02-14 22:30:21 +0000
committerBrian de Alwis2012-02-14 22:30:21 +0000
commit156228f92340e73b2ab1ad917273bfb67d295f7a (patch)
tree69487fca0cde817d973e789c8757aa6abe9cf660
parent64aa94ad28cd2ad5a2621aba11f73ed5cf087343 (diff)
downloadorg.eclipse.e4.tools-156228f92340e73b2ab1ad917273bfb67d295f7a.tar.gz
org.eclipse.e4.tools-156228f92340e73b2ab1ad917273bfb67d295f7a.tar.xz
org.eclipse.e4.tools-156228f92340e73b2ab1ad917273bfb67d295f7a.zip
Bug 371549 - [Model Editor] Parts can define both menus and popup-menus
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java1
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties1
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VMenuEditor.java49
3 files changed, 38 insertions, 13 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
index 3b0e0830..d8e672f6 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
@@ -413,6 +413,7 @@ public class Messages {
public String VMenuEditor_TreeLabelDescription;
public String VMenuEditor_Menus;
public String VMenuEditor_AddMenuContribution;
+ public String VMenuEditor_AddPopupMenuContribution;
public String VModelFragmentsEditor_TreeLabel;
public String VModelFragmentsEditor_TreeLabelDescription;
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
index 27b4e90d..52deb0ac 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
@@ -412,6 +412,7 @@ VMenuEditor_TreeLabel=Menus
VMenuEditor_TreeLabelDescription=Menus Bla Bla Bla Bla Bla
VMenuEditor_Menus=Menus
VMenuEditor_AddMenuContribution=Menu
+VMenuEditor_AddPopupMenuContribution=Popup Menu
VModelFragmentsEditor_TreeLabel=Fragments
VModelFragmentsEditor_TreeLabelDescription=Fragments Bla Bla Bla Bla Bla
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VMenuEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VMenuEditor.java
index 7204aabb..7fc2f058 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VMenuEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VMenuEditor.java
@@ -21,18 +21,22 @@ import org.eclipse.e4.tools.emf.ui.internal.common.ComponentLabelProvider;
import org.eclipse.e4.tools.emf.ui.internal.common.VirtualEntry;
import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl;
import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicPackageImpl;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
+import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.databinding.EMFDataBindingContext;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.command.MoveCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
@@ -52,8 +56,8 @@ public class VMenuEditor extends AbstractComponentEditor {
private Composite composite;
private EMFDataBindingContext context;
private TableViewer viewer;
- private EStructuralFeature feature;
private List<Action> actions = new ArrayList<Action>();
+ private EStructuralFeature feature;
protected VMenuEditor(EStructuralFeature feature) {
super();
@@ -65,7 +69,13 @@ public class VMenuEditor extends AbstractComponentEditor {
actions.add(new Action(Messages.VMenuEditor_AddMenuContribution, createImageDescriptor(ResourceProvider.IMG_Menu)) {
@Override
public void run() {
- handleAdd();
+ handleAdd(MenuPackageImpl.Literals.MENU);
+ }
+ });
+ actions.add(new Action(Messages.VMenuEditor_AddPopupMenuContribution, createImageDescriptor(ResourceProvider.IMG_Menu)) {
+ @Override
+ public void run() {
+ handleAdd(MenuPackageImpl.Literals.POPUP_MENU);
}
});
}
@@ -124,7 +134,7 @@ public class VMenuEditor extends AbstractComponentEditor {
Composite buttonComp = new Composite(parent, SWT.NONE);
buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false));
- GridLayout gl = new GridLayout();
+ GridLayout gl = new GridLayout(2, false);
gl.marginLeft = 0;
gl.marginRight = 0;
gl.marginWidth = 0;
@@ -134,7 +144,7 @@ public class VMenuEditor extends AbstractComponentEditor {
Button b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
b.setText(Messages.ModelTooling_Common_Up);
b.setImage(createImage(ResourceProvider.IMG_Obj16_arrow_up));
- b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+ b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -161,7 +171,7 @@ public class VMenuEditor extends AbstractComponentEditor {
b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
b.setText(Messages.ModelTooling_Common_Down);
b.setImage(createImage(ResourceProvider.IMG_Obj16_arrow_down));
- b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+ b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -186,21 +196,34 @@ public class VMenuEditor extends AbstractComponentEditor {
}
});
+ final ComboViewer childrenDropDown = new ComboViewer(buttonComp);
+ childrenDropDown.getControl().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+ childrenDropDown.setContentProvider(new ArrayContentProvider());
+ childrenDropDown.setLabelProvider(new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ EClass eclass = (EClass) element;
+ return eclass.getName();
+ }
+ });
+ childrenDropDown.setInput(new EClass[] { MenuPackageImpl.Literals.MENU, MenuPackageImpl.Literals.POPUP_MENU });
+ childrenDropDown.setSelection(new StructuredSelection(MenuPackageImpl.Literals.MENU));
+
b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
- b.setText(Messages.ModelTooling_Common_AddEllipsis);
b.setImage(createImage(ResourceProvider.IMG_Obj16_table_add));
- b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+ b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- handleAdd();
+ EClass eClass = (EClass) ((IStructuredSelection) childrenDropDown.getSelection()).getFirstElement();
+ handleAdd(eClass);
}
});
b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
b.setText(Messages.ModelTooling_Common_Remove);
b.setImage(createImage(ResourceProvider.IMG_Obj16_table_delete));
- b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+ b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -224,8 +247,8 @@ public class VMenuEditor extends AbstractComponentEditor {
return null;
}
- protected void handleAdd() {
- MMenu handler = MMenuFactory.INSTANCE.createMenu();
+ protected void handleAdd(EClass eClass) {
+ EObject handler = EcoreUtil.create(eClass);
setElementId(handler);
Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), feature, handler);

Back to the top