Bug 332362 - [ModelTooling] Update model to use multiple root contexts
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 58f47fc..1c41e70 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
@@ -13,6 +13,7 @@
 import org.eclipse.osgi.util.NLS;
 
 public class Messages extends NLS {
+
 	public static String ModelTooling_Common_Up;
 	public static String ModelTooling_Common_Down;
 	public static String ModelTooling_Common_AddEllipsis;
@@ -45,7 +46,7 @@
 	public static String ApplicationEditor_MenuContributions;
 	public static String ApplicationEditor_ToolBarContributions;
 	public static String ApplicationEditor_TrimContributions;
-	public static String ApplicationEditor_RootContext;
+	public static String ApplicationEditor_RootContexts;
 	public static String ApplicationEditor_BindingContexts;
 	public static String ApplicationEditor_Categories;
 
@@ -509,6 +510,11 @@
 
 	public static String CommandToStringConverter_None;
 
+	public static String VRootBindingContexts_AddContext;
+	public static String VRootBindingContexts_TreeLabel;
+	public static String VRootBindingContexts_TreeLabelDescription;
+	public static String VRootBindingContexts_Contexts;
+
 	static {
 		NLS.initializeMessages(Messages.class.getName(), Messages.class);
 	}
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 0ce2646..26e7868 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
@@ -41,7 +41,7 @@
 ApplicationEditor_MenuContributions=Menu Contributions
 ApplicationEditor_ToolBarContributions=Toolbar Contributions
 ApplicationEditor_TrimContributions=Trim Contributions
-ApplicationEditor_RootContext=Root Context
+ApplicationEditor_RootContexts=Binding Contexts
 ApplicationEditor_BindingContexts=Binding Contexts
 ApplicationEditor_Categories=Command Categories
 
@@ -502,4 +502,9 @@
 ExpressionIdDialog_DialogTitle=Find Expression Id
 ExpressionIdDialog_DialogMessage=Find the expression id defined through the 'org.eclipse.core.expressions.definitions' extension point
 ExpressionIdDialog_Id=Id
-CommandToStringConverter_None=<None>
\ No newline at end of file
+CommandToStringConverter_None=<None>
+
+VRootBindingContexts_AddContext=Add Binding Context
+VRootBindingContexts_TreeLabel=Binding Context
+VRootBindingContexts_TreeLabelDescription=Binding Context Bla Bla Bla
+VRootBindingContexts_Contexts=Binding Contexts
\ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
index 91103d1..efe9305 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
@@ -104,6 +104,7 @@
 import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VModelFragmentsEditor;
 import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VModelImportsEditor;
 import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VPartDescriptor;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VRootBindingContexts;
 import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VToolBarContributionsEditor;
 import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VTrimContributionsEditor;
 import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VWindowControlEditor;
@@ -194,6 +195,7 @@
 	public static final String VIRTUAL_CATEGORIES = ModelEditor.class.getName() + ".VIRTUAL_CATEGORIES"; //$NON-NLS-1$
 	public static final String VIRTUAL_PARAMETERS = ModelEditor.class.getName() + ".VIRTUAL_PARAMETERS"; //$NON-NLS-1$
 	public static final String VIRTUAL_MENUELEMENTS = ModelEditor.class.getName() + ".VIRTUAL_MENUELEMENTS"; //$NON-NLS-1$
+	public static final String VIRTUAL_ROOT_CONTEXTS = ModelEditor.class.getName() + ".VIRTUAL_ROOT_CONTEXTS"; //$NON-NLS-1$
 
 	private Map<EClass, AbstractComponentEditor> editorMap = new HashMap<EClass, AbstractComponentEditor>();
 	private Map<String, AbstractComponentEditor> virtualEditors = new HashMap<String, AbstractComponentEditor>();
@@ -582,6 +584,7 @@
 		registerVirtualEditor(VIRTUAL_CATEGORIES, new VApplicationCategoriesEditor(modelProvider.getEditingDomain(), this));
 		registerVirtualEditor(VIRTUAL_PARAMETERS, new VItemParametersEditor(modelProvider.getEditingDomain(), this));
 		registerVirtualEditor(VIRTUAL_MENUELEMENTS, new VMenuElementsEditor(modelProvider.getEditingDomain(), this));
+		registerVirtualEditor(VIRTUAL_ROOT_CONTEXTS, new VRootBindingContexts(modelProvider.getEditingDomain(), this));
 	}
 
 	private void registerVirtualEditor(String id, AbstractComponentEditor editor) {
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ApplicationEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ApplicationEditor.java
index c6067d2..5b4730b 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ApplicationEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ApplicationEditor.java
@@ -14,39 +14,28 @@
 import java.net.URL;
 import org.eclipse.core.databinding.observable.list.IObservableList;
 import org.eclipse.core.databinding.observable.list.WritableList;
-import org.eclipse.core.databinding.observable.value.IValueChangeListener;
-import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
 import org.eclipse.core.databinding.property.list.IListProperty;
-import org.eclipse.core.databinding.property.value.IValueProperty;
 import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor;
 import org.eclipse.e4.tools.emf.ui.internal.Messages;
 import org.eclipse.e4.tools.emf.ui.internal.common.ModelEditor;
 import org.eclipse.e4.tools.emf.ui.internal.common.VirtualEntry;
-import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.commands.MBindingContext;
-import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
 import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl;
 import org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl;
 import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
 import org.eclipse.e4.ui.model.application.ui.MUIElement;
 import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
 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.databinding.EMFProperties;
 import org.eclipse.emf.databinding.FeaturePath;
 import org.eclipse.emf.databinding.edit.EMFEditProperties;
-import org.eclipse.emf.edit.command.SetCommand;
 import org.eclipse.emf.edit.domain.EditingDomain;
 import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
 import org.eclipse.jface.databinding.swt.WidgetProperties;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
@@ -58,7 +47,7 @@
 	private Image image;
 	private Image tbrImage;
 	private EMFDataBindingContext context;
-	private Button createRemoveRootContext;
+	// private Button createRemoveRootContext;
 
 	private IListProperty HANDLER_CONTAINER__HANDLERS = EMFProperties.list(CommandsPackageImpl.Literals.HANDLER_CONTAINER__HANDLERS);
 	private IListProperty BINDING_CONTAINER__BINDINGS = EMFProperties.list(CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__BINDING_TABLES);
@@ -71,7 +60,7 @@
 	private IListProperty TRIM_CONTRIBUTIONS = EMFProperties.list(MenuPackageImpl.Literals.TRIM_CONTRIBUTIONS__TRIM_CONTRIBUTIONS);
 	private IListProperty APPLICATION__CATEGORIES = EMFProperties.list(ApplicationPackageImpl.Literals.APPLICATION__CATEGORIES);
 
-	private IValueProperty BINDING_TABLE_CONTAINER__ROOT_CONTEXT = EMFProperties.value(CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__ROOT_CONTEXT);
+	private IListProperty BINDING_TABLE_CONTAINER__ROOT_CONTEXT = EMFProperties.list(CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__ROOT_CONTEXT);
 
 	public ApplicationEditor(EditingDomain editingDomain, ModelEditor editor) {
 		super(editingDomain, editor);
@@ -123,10 +112,6 @@
 		}
 		getMaster().setValue(object);
 
-		if (createRemoveRootContext != null) {
-			createRemoveRootContext.setSelection(((MApplication) object).getRootContext() != null);
-		}
-
 		return composite;
 	}
 
@@ -154,26 +139,6 @@
 			context.bindValue(textProp.observeDelayed(200, t), EMFEditProperties.value(getEditingDomain(), ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID).observeDetail(getMaster()));
 		}
 
-		{
-			Label l = new Label(parent, SWT.NONE);
-			l.setText(Messages.ApplicationEditor_RootContext);
-			l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
-
-			createRemoveRootContext = new Button(parent, SWT.CHECK);
-			createRemoveRootContext.addSelectionListener(new SelectionAdapter() {
-				@Override
-				public void widgetSelected(SelectionEvent e) {
-					MApplication app = (MApplication) getMaster().getValue();
-					if (app.getRootContext() == null) {
-						addContext();
-					} else {
-						removeContext();
-					}
-				}
-			});
-			createRemoveRootContext.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));
-		}
-
 		ControlFactory.createCheckBox(parent, Messages.ModelTooling_UIElement_ToBeRendered, getMaster(), context, WidgetProperties.selection(), EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__TO_BE_RENDERED));
 		ControlFactory.createCheckBox(parent, Messages.ModelTooling_UIElement_Visible, getMaster(), context, WidgetProperties.selection(), EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__VISIBLE));
 
@@ -183,21 +148,6 @@
 		return parent;
 	}
 
-	void removeContext() {
-		Command cmd = SetCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__ROOT_CONTEXT, null);
-		if (cmd.canExecute()) {
-			getEditingDomain().getCommandStack().execute(cmd);
-		}
-	}
-
-	void addContext() {
-		MBindingContext context = MCommandsFactory.INSTANCE.createBindingContext();
-		Command cmd = SetCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__ROOT_CONTEXT, context);
-		if (cmd.canExecute()) {
-			getEditingDomain().getCommandStack().execute(cmd);
-		}
-	}
-
 	@Override
 	public IObservableList getChildList(final Object element) {
 		final WritableList list = new WritableList();
@@ -210,6 +160,24 @@
 
 		});
 
+		list.add(new VirtualEntry<Object>(ModelEditor.VIRTUAL_ROOT_CONTEXTS, BINDING_TABLE_CONTAINER__ROOT_CONTEXT, element, Messages.ApplicationEditor_RootContexts) {
+
+			@Override
+			protected boolean accepted(Object o) {
+				return true;
+			}
+
+		});
+
+		list.add(new VirtualEntry<Object>(ModelEditor.VIRTUAL_BINDING_TABLE, BINDING_CONTAINER__BINDINGS, element, Messages.ApplicationEditor_BindingTables) {
+
+			@Override
+			protected boolean accepted(Object o) {
+				return true;
+			}
+
+		});
+
 		list.add(new VirtualEntry<Object>(ModelEditor.VIRTUAL_HANDLER, HANDLER_CONTAINER__HANDLERS, element, Messages.ApplicationEditor_Handlers) {
 
 			@Override
@@ -228,15 +196,6 @@
 
 		});
 
-		list.add(new VirtualEntry<Object>(ModelEditor.VIRTUAL_BINDING_TABLE, BINDING_CONTAINER__BINDINGS, element, Messages.ApplicationEditor_BindingTables) {
-
-			@Override
-			protected boolean accepted(Object o) {
-				return true;
-			}
-
-		});
-
 		list.add(new VirtualEntry<Object>(ModelEditor.VIRTUAL_COMMAND, APPLICATION__COMMANDS, element, Messages.ApplicationEditor_Commands) {
 
 			@Override
@@ -284,30 +243,31 @@
 				return true;
 			}
 		});
+		//
+		// MApplication application = (MApplication) element;
+		// if (application.getRootContext() != null) {
+		// list.add(0, application.getRootContext());
+		// }
 
-		MApplication application = (MApplication) element;
-		if (application.getRootContext() != null) {
-			list.add(0, application.getRootContext());
-		}
-
-		BINDING_TABLE_CONTAINER__ROOT_CONTEXT.observe(element).addValueChangeListener(new IValueChangeListener() {
-
-			public void handleValueChange(ValueChangeEvent event) {
-				if (event.diff.getOldValue() != null) {
-					list.remove(event.diff.getOldValue());
-					if (getMaster().getValue() == element) {
-						createRemoveRootContext.setSelection(false);
-					}
-				}
-
-				if (event.diff.getNewValue() != null) {
-					list.add(0, event.diff.getNewValue());
-					if (getMaster().getValue() == element) {
-						createRemoveRootContext.setSelection(true);
-					}
-				}
-			}
-		});
+		// BINDING_TABLE_CONTAINER__ROOT_CONTEXT.observe(element).addValueChangeListener(new
+		// IValueChangeListener() {
+		//
+		// public void handleValueChange(ValueChangeEvent event) {
+		// if (event.diff.getOldValue() != null) {
+		// list.remove(event.diff.getOldValue());
+		// if (getMaster().getValue() == element) {
+		// createRemoveRootContext.setSelection(false);
+		// }
+		// }
+		//
+		// if (event.diff.getNewValue() != null) {
+		// list.add(0, event.diff.getNewValue());
+		// if (getMaster().getValue() == element) {
+		// createRemoveRootContext.setSelection(true);
+		// }
+		// }
+		// }
+		// });
 
 		return list;
 	}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VRootBindingContexts.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VRootBindingContexts.java
new file mode 100644
index 0000000..3bc2433
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VRootBindingContexts.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Copyright (c) 2010 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.component.virtual;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.value.WritableValue;
+import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor;
+import org.eclipse.e4.tools.emf.ui.internal.Messages;
+import org.eclipse.e4.tools.emf.ui.internal.common.ComponentLabelProvider;
+import org.eclipse.e4.tools.emf.ui.internal.common.ModelEditor;
+import org.eclipse.e4.tools.emf.ui.internal.common.VirtualEntry;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.commands.MBindingContext;
+import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
+import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.databinding.EMFDataBindingContext;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.command.MoveCommand;
+import org.eclipse.emf.edit.command.RemoveCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+
+public class VRootBindingContexts extends AbstractComponentEditor {
+	private Composite composite;
+	private TableViewer viewer;
+	private EMFDataBindingContext context;
+
+	private List<Action> actions = new ArrayList<Action>();
+
+	public VRootBindingContexts(EditingDomain editingDomain, ModelEditor editor) {
+		super(editingDomain, editor);
+		actions.add(new Action(Messages.VRootBindingContexts_AddContext) {
+			@Override
+			public void run() {
+				handleAddContext();
+			}
+		});
+	}
+
+	@Override
+	public Image getImage(Object element, Display display) {
+		return null;
+	}
+
+	@Override
+	public String getLabel(Object element) {
+		return Messages.VRootBindingContexts_TreeLabel;
+	}
+
+	@Override
+	public String getDetailLabel(Object element) {
+		return null;
+	}
+
+	@Override
+	public String getDescription(Object element) {
+		return Messages.VRootBindingContexts_TreeLabelDescription;
+	}
+
+	@Override
+	public Composite getEditor(Composite parent, Object object) {
+		if (composite == null) {
+			context = new EMFDataBindingContext();
+			composite = createForm(parent, context, getMaster());
+		}
+		VirtualEntry<?> o = (VirtualEntry<?>) object;
+		viewer.setInput(o.getList());
+		getMaster().setValue(o.getOriginalParent());
+		return composite;
+	}
+
+	private Composite createForm(Composite parent, EMFDataBindingContext context, WritableValue master) {
+		parent = new Composite(parent, SWT.NONE);
+		GridLayout gl = new GridLayout(3, false);
+		gl.horizontalSpacing = 10;
+		parent.setLayout(gl);
+
+		{
+			Label l = new Label(parent, SWT.NONE);
+			l.setText(Messages.VRootBindingContexts_Contexts);
+			l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+
+			viewer = new TableViewer(parent);
+			ObservableListContentProvider cp = new ObservableListContentProvider();
+			viewer.setContentProvider(cp);
+			GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+			gd.heightHint = 300;
+			viewer.getControl().setLayoutData(gd);
+			viewer.setLabelProvider(new ComponentLabelProvider(getEditor()));
+
+			Composite buttonComp = new Composite(parent, SWT.NONE);
+			buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false));
+			gl = new GridLayout();
+			gl.marginLeft = 0;
+			gl.marginRight = 0;
+			gl.marginWidth = 0;
+			gl.marginHeight = 0;
+			buttonComp.setLayout(gl);
+
+			Button b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+			b.setText(Messages.ModelTooling_Common_Up);
+			b.setImage(getImage(b.getDisplay(), ARROW_UP));
+			b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+			b.addSelectionListener(new SelectionAdapter() {
+				@Override
+				public void widgetSelected(SelectionEvent e) {
+					if (!viewer.getSelection().isEmpty()) {
+						IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
+						if (s.size() == 1) {
+							Object obj = s.getFirstElement();
+							MApplication container = (MApplication) getMaster().getValue();
+							int idx = container.getAddons().indexOf(obj) - 1;
+							if (idx >= 0) {
+								Command cmd = MoveCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__ROOT_CONTEXT, obj, idx);
+
+								if (cmd.canExecute()) {
+									getEditingDomain().getCommandStack().execute(cmd);
+									viewer.setSelection(new StructuredSelection(obj));
+								}
+							}
+
+						}
+					}
+				}
+			});
+
+			b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+			b.setText(Messages.ModelTooling_Common_Down);
+			b.setImage(getImage(b.getDisplay(), ARROW_DOWN));
+			b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+			b.addSelectionListener(new SelectionAdapter() {
+				@Override
+				public void widgetSelected(SelectionEvent e) {
+					if (!viewer.getSelection().isEmpty()) {
+						IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
+						if (s.size() == 1) {
+							Object obj = s.getFirstElement();
+							MApplication container = (MApplication) getMaster().getValue();
+							int idx = container.getAddons().indexOf(obj) + 1;
+							if (idx < container.getAddons().size()) {
+								Command cmd = MoveCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__ROOT_CONTEXT, obj, idx);
+
+								if (cmd.canExecute()) {
+									getEditingDomain().getCommandStack().execute(cmd);
+									viewer.setSelection(new StructuredSelection(obj));
+								}
+							}
+
+						}
+					}
+				}
+			});
+
+			b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+			b.setText(Messages.ModelTooling_Common_AddEllipsis);
+			b.setImage(getImage(b.getDisplay(), TABLE_ADD_IMAGE));
+			b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+			b.addSelectionListener(new SelectionAdapter() {
+				@Override
+				public void widgetSelected(SelectionEvent e) {
+					handleAddContext();
+				}
+			});
+
+			b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+			b.setText(Messages.ModelTooling_Common_Remove);
+			b.setImage(getImage(b.getDisplay(), TABLE_DELETE_IMAGE));
+			b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+			b.addSelectionListener(new SelectionAdapter() {
+				@Override
+				public void widgetSelected(SelectionEvent e) {
+					if (!viewer.getSelection().isEmpty()) {
+						handleRemoveContexts(((IStructuredSelection) viewer.getSelection()).toList());
+					}
+				}
+			});
+		}
+
+		return parent;
+	}
+
+	private void handleAddContext() {
+		MBindingContext context = MCommandsFactory.INSTANCE.createBindingContext();
+		setElementId(context);
+
+		Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__ROOT_CONTEXT, context);
+
+		if (cmd.canExecute()) {
+			getEditingDomain().getCommandStack().execute(cmd);
+		}
+	}
+
+	private void handleRemoveContexts(List<?> contexts) {
+		Command cmd = RemoveCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__ROOT_CONTEXT, contexts);
+		if (cmd.canExecute()) {
+			getEditingDomain().getCommandStack().execute(cmd);
+		}
+	}
+
+	@Override
+	public IObservableList getChildList(Object element) {
+		return null;
+	}
+
+	@Override
+	public List<Action> getActions(Object element) {
+		ArrayList<Action> l = new ArrayList<Action>(super.getActions(element));
+		l.addAll(actions);
+		return l;
+	}
+}