Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schindl2010-06-23 15:28:53 +0000
committerThomas Schindl2010-06-23 15:28:53 +0000
commit721d46817f9b79a2cc204496ea3aa023d3076db5 (patch)
tree03dbc793f658a90f87c12f92feb8843697cbbd19
parent23a4e3cd82f15fc51bf6d853cdea2c942a3f08f6 (diff)
downloadorg.eclipse.e4.tools-721d46817f9b79a2cc204496ea3aa023d3076db5.tar.gz
org.eclipse.e4.tools-721d46817f9b79a2cc204496ea3aa023d3076db5.tar.xz
org.eclipse.e4.tools-721d46817f9b79a2cc204496ea3aa023d3076db5.zip
Bug 304584 - [Tooling] Implement Workbench-Model-Tooling
* adding support for ToolBar and MenuContribution
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/ToolBarContribution.gifbin0 -> 129 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java3
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties2
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java8
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ApplicationEditor.java20
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolBarContributionEditor.java350
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VToolBarContributionsEditor.java258
7 files changed, 640 insertions, 1 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/ToolBarContribution.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/ToolBarContribution.gif
new file mode 100644
index 00000000..59155918
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/ToolBarContribution.gif
Binary files differ
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 183288dc..f6bafe95 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
@@ -24,6 +24,8 @@ public class Messages {
public static String ApplicationEditor_Commands;
public static String ApplicationEditor_Windows;
public static String ApplicationEditor_Addons;
+ public static String ApplicationEditor_MenuContributions;
+ public static String ApplicationEditor_ToolBarContributions;
public static String BindingTableEditor_Label;
public static String BindingTableEditor_Description;
@@ -349,6 +351,7 @@ public class Messages {
public static String FeatureSelectionDialog_DialogMessage;
+
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 58fa4972..47c911aa 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
@@ -19,6 +19,8 @@ ApplicationEditor_BindingTables=BindingTables
ApplicationEditor_Commands=Commands
ApplicationEditor_Windows=Windows
ApplicationEditor_Addons=Addons
+ApplicationEditor_MenuContributions=Menu Contributions
+ApplicationEditor_ToolBarContributions=Toolbar Contributions
BindingTableEditor_Label=BindingTable
BindingTableEditor_Description=BindingTable bla bla bla
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 d72d2805..633769c6 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
@@ -10,6 +10,10 @@
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VToolBarContributionsEditor;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.component.ToolBarContributionEditor;
+
import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VWindowSharedElementsEditor;
import org.eclipse.e4.tools.emf.ui.common.IEditorFeature.FeatureClass;
@@ -143,6 +147,7 @@ public class ModelEditor {
public static final String VIRTUAL_TRIMMED_WINDOW_TRIMS = ModelEditor.class.getName() + ".VIRTUAL_TRIMMED_WINDOW_TRIMS"; //$NON-NLS-1$
public static final String VIRTUAL_ADDONS = ModelEditor.class.getName() + ".VIRTUAL_ADDONS"; //$NON-NLS-1$
public static final String VIRTUAL_MENU_CONTRIBUTIONS = ModelEditor.class.getName() + ".VIRTUAL_MENU_CONTRIBUTIONS"; //$NON-NLS-1$
+ public static final String VIRTUAL_TOOLBAR_CONTRIBUTIONS = ModelEditor.class.getName() + ".VIRTUAL_TOOLBAR_CONTRIBUTIONS"; //$NON-NLS-1$
public static final String VIRTUAL_WINDOW_SHARED_ELEMENTS = ModelEditor.class.getName() + ".VIRTUAL_WINDOW_SHARED_ELEMENTS"; //$NON-NLS-1$
@@ -421,6 +426,7 @@ public class ModelEditor {
registerVirtualEditor(VIRTUAL_TRIMMED_WINDOW_TRIMS, new VWindowTrimEditor(modelProvider.getEditingDomain(), this));
registerVirtualEditor(VIRTUAL_ADDONS, new VApplicationAddons(modelProvider.getEditingDomain(), this));
registerVirtualEditor(VIRTUAL_MENU_CONTRIBUTIONS, new VMenuContributionsEditor(modelProvider.getEditingDomain(), this));
+ registerVirtualEditor(VIRTUAL_TOOLBAR_CONTRIBUTIONS, new VToolBarContributionsEditor(modelProvider.getEditingDomain(), this));
registerVirtualEditor(VIRTUAL_WINDOW_SHARED_ELEMENTS, new VWindowSharedElementsEditor(modelProvider.getEditingDomain(), this));
}
@@ -474,6 +480,8 @@ public class ModelEditor {
registerEditor(MenuPackageImpl.Literals.HANDLED_MENU_ITEM, new HandledMenuItemEditor(modelProvider.getEditingDomain(), project, modelProvider));
registerEditor(MenuPackageImpl.Literals.DIRECT_MENU_ITEM, new DirectMenuItemEditor(modelProvider.getEditingDomain(), this, project));
registerEditor(MenuPackageImpl.Literals.MENU_CONTRIBUTION, new MenuContributionEditor(modelProvider.getEditingDomain(),project, this));
+ registerEditor(MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTION, new ToolBarContributionEditor(modelProvider.getEditingDomain(),project, this));
+
registerEditor(BasicPackageImpl.Literals.PART, new PartEditor(modelProvider.getEditingDomain(), project));
registerEditor(BasicPackageImpl.Literals.WINDOW, new WindowEditor(modelProvider.getEditingDomain(), project));
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 08c1ea03..4d0fb5cd 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
@@ -10,6 +10,8 @@
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
+import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl;
+
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.databinding.observable.list.IObservableList;
@@ -50,7 +52,9 @@ public class ApplicationEditor extends AbstractComponentEditor {
private IListProperty PART_DESCRIPTOR_CONTAINER__DESCRIPTORS = EMFProperties.list(BasicPackageImpl.Literals.PART_DESCRIPTOR_CONTAINER__DESCRIPTORS);
private IListProperty ELEMENT_CONTAINER__CHILDREN = EMFProperties.list(UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN);
private IListProperty APPLICATION__ADDONS = EMFProperties.list(ApplicationPackageImpl.Literals.APPLICATION__ADDONS);
-
+ private IListProperty MENU_CONTRIBUTIONS = EMFProperties.list(MenuPackageImpl.Literals.MENU_CONTRIBUTIONS__MENU_CONTRIBUTIONS);
+ private IListProperty TOOLBAR_CONTRIBUTIONS = EMFProperties.list(MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTIONS__TOOL_BAR_CONTRIBUTIONS);
+
public ApplicationEditor(EditingDomain editingDomain) {
super(editingDomain);
}
@@ -168,6 +172,20 @@ public class ApplicationEditor extends AbstractComponentEditor {
}
});
+
+ list.add(new VirtualEntry<Object>( ModelEditor.VIRTUAL_MENU_CONTRIBUTIONS, MENU_CONTRIBUTIONS, element, Messages.ApplicationEditor_MenuContributions ) {
+ @Override
+ protected boolean accepted(Object o) {
+ return true;
+ }
+ });
+
+ list.add(new VirtualEntry<Object>( ModelEditor.VIRTUAL_TOOLBAR_CONTRIBUTIONS, TOOLBAR_CONTRIBUTIONS, element, Messages.ApplicationEditor_ToolBarContributions ) {
+ @Override
+ protected boolean accepted(Object o) {
+ return true;
+ }
+ });
return list;
}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolBarContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolBarContributionEditor.java
new file mode 100644
index 00000000..977a26ca
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolBarContributionEditor.java
@@ -0,0 +1,350 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement;
+
+import org.eclipse.core.databinding.property.list.IListProperty;
+import org.eclipse.emf.databinding.EMFProperties;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.tools.emf.ui.internal.common.ModelEditor;
+
+import java.util.List;
+import org.eclipse.e4.tools.emf.ui.internal.Messages;
+import org.eclipse.e4.tools.emf.ui.internal.ObservableColumnLabelProvider;
+import org.eclipse.e4.tools.emf.ui.internal.common.ComponentLabelProvider;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.MenuIconDialogEditor;
+import org.eclipse.e4.ui.model.application.commands.MHandler;
+import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
+import org.eclipse.e4.ui.model.application.ui.MElementContainer;
+import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
+import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.databinding.IEMFListProperty;
+import org.eclipse.emf.databinding.edit.EMFEditProperties;
+import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
+import org.eclipse.emf.ecore.EClass;
+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.databinding.swt.IWidgetValueProperty;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
+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.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.swt.SWT;
+
+import org.eclipse.core.databinding.observable.value.WritableValue;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.emf.databinding.EMFDataBindingContext;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor;
+
+public class ToolBarContributionEditor extends AbstractComponentEditor {
+ private Composite composite;
+ private Image image;
+ private EMFDataBindingContext context;
+ private ModelEditor editor;
+ private IProject project;
+
+ private IListProperty ELEMENT_CONTAINER__CHILDREN = EMFProperties.list(UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN);
+
+ private static class Struct {
+ private final String label;
+ private final EClass eClass;
+ private final boolean separator;
+
+ public Struct(String label, EClass eClass, boolean separator) {
+ this.label = label;
+ this.eClass = eClass;
+ this.separator = separator;
+ }
+ }
+
+ public ToolBarContributionEditor(EditingDomain editingDomain, IProject project, ModelEditor editor) {
+ super(editingDomain);
+ this.editor = editor;
+ this.project = project;
+ }
+
+ @Override
+ public Image getImage(Object element, Display display) {
+ if( image == null ) {
+ try {
+ image = loadSharedImage(display, new URL("platform:/plugin/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/ToolBarContribution.gif")); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ return image;
+ }
+
+ @Override
+ public String getLabel(Object element) {
+ return "ToolBar Contribution";
+ }
+
+ @Override
+ public String getDetailLabel(Object element) {
+ return null;
+ }
+
+ @Override
+ public String getDescription(Object element) {
+ return "ToolBar Contribution Bla Bla Bla Bla";
+ }
+
+ @Override
+ public Composite getEditor(Composite parent, Object object) {
+ if( composite == null ) {
+ context = new EMFDataBindingContext();
+ composite = createForm(parent,context, getMaster());
+ }
+ getMaster().setValue(object);
+ return composite;
+ }
+
+ private Composite createForm(Composite parent, EMFDataBindingContext context2, WritableValue master) {
+ parent = new Composite(parent, SWT.NONE);
+ parent.setLayout(new GridLayout(3, false));
+
+ IWidgetValueProperty textProp = WidgetProperties.text(SWT.Modify);
+
+ // ------------------------------------------------------------
+ {
+ Label l = new Label(parent, SWT.NONE);
+ l.setText(Messages.MenuContributionEditor_Id);
+
+ Text t = new Text(parent, SWT.BORDER);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ t.setLayoutData(gd);
+ 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.MenuContributionEditor_ParentId);
+
+ Text t = new Text(parent, SWT.BORDER);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ t.setLayoutData(gd);
+ context.bindValue(textProp.observeDelayed(200, t), EMFEditProperties.value(getEditingDomain(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTION__PARENT_ID).observeDetail(getMaster()));
+ }
+
+ // ------------------------------------------------------------
+ {
+ Label l = new Label(parent, SWT.NONE);
+ l.setText(Messages.MenuContributionEditor_Position);
+
+ Text t = new Text(parent, SWT.BORDER);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ t.setLayoutData(gd);
+ context.bindValue(textProp.observeDelayed(200, t), EMFEditProperties.value(getEditingDomain(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTION__POSITION_IN_PARENT).observeDetail(getMaster()));
+ }
+
+
+ // ------------------------------------------------------------
+ {
+ Label l = new Label(parent, SWT.NONE);
+ l.setText(Messages.ToolBarEditor_ToolbarItems);
+ l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+
+ final TableViewer 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.getTable().setHeaderVisible(true);
+
+ {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.getColumn().setText(Messages.ToolBarEditor_ToolbarItemsType);
+ column.getColumn().setWidth(300);
+ column.setLabelProvider(new ComponentLabelProvider(editor));
+ }
+
+ {
+ IEMFEditValueProperty prop = EMFEditProperties.value(getEditingDomain(), MenuPackageImpl.Literals.ITEM__TYPE);
+
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.getColumn().setText(Messages.ToolBarEditor_ToolbarItemsItemType);
+ column.getColumn().setWidth(100);
+ column.setLabelProvider(new ObservableColumnLabelProvider<MHandler>(prop.observeDetail(cp.getKnownElements())));
+ }
+
+ IEMFListProperty prop = EMFEditProperties.list(getEditingDomain(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN);
+ viewer.setInput(prop.observeDetail(master));
+
+ Composite buttonComp = new Composite(parent, SWT.NONE);
+ buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false));
+ GridLayout gl = new GridLayout(2, false);
+ 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.ToolBarEditor_Up);
+ b.setImage(getImage(b.getDisplay(), ARROW_UP));
+ b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
+ 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();
+ MElementContainer<?> container = (MElementContainer<?>) getMaster().getValue();
+ int idx = container.getChildren().indexOf(obj) - 1;
+ if (idx >= 0) {
+ Command cmd = MoveCommand.create(getEditingDomain(), getMaster().getValue(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, 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.ToolBarEditor_Down);
+ b.setImage(getImage(b.getDisplay(), ARROW_DOWN));
+ b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
+ 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();
+ MElementContainer<?> container = (MElementContainer<?>) getMaster().getValue();
+ int idx = container.getChildren().indexOf(obj) + 1;
+ if (idx < container.getChildren().size()) {
+ Command cmd = MoveCommand.create(getEditingDomain(), getMaster().getValue(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, obj, idx);
+
+ if (cmd.canExecute()) {
+ getEditingDomain().getCommandStack().execute(cmd);
+ viewer.setSelection(new StructuredSelection(obj));
+ }
+ }
+
+ }
+ }
+ }
+ });
+
+ 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) {
+ Struct struct = (Struct) element;
+ return struct.label;
+ }
+ });
+
+ Struct defaultStruct = new Struct(Messages.ToolBarEditor_HandledToolItem, MenuPackageImpl.Literals.HANDLED_TOOL_ITEM, false);
+ childrenDropDown.setInput(new Struct[] { defaultStruct, new Struct(Messages.ToolBarEditor_DirectToolItem, MenuPackageImpl.Literals.DIRECT_TOOL_ITEM, false), new Struct(Messages.ToolBarEditor_ToolControl, MenuPackageImpl.Literals.TOOL_CONTROL, false), new Struct(Messages.ToolBarEditor_Separator, MenuPackageImpl.Literals.TOOL_BAR_SEPARATOR, true) });
+ childrenDropDown.setSelection(new StructuredSelection(defaultStruct));
+
+ b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+ b.setImage(getImage(b.getDisplay(), TABLE_ADD_IMAGE));
+ b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
+ b.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (!childrenDropDown.getSelection().isEmpty()) {
+ Struct struct = (Struct) ((IStructuredSelection) childrenDropDown.getSelection()).getFirstElement();
+ EClass eClass = struct.eClass;
+ MToolBarElement eObject = (MToolBarElement) EcoreUtil.create(eClass);
+
+ Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, eObject);
+
+ if (cmd.canExecute()) {
+ getEditingDomain().getCommandStack().execute(cmd);
+ if (!struct.separator) {
+ editor.setSelection(eObject);
+ }
+ }
+ }
+ }
+ });
+
+ b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+ b.setText(Messages.ToolBarEditor_Remove);
+ b.setImage(getImage(b.getDisplay(), TABLE_DELETE_IMAGE));
+ b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
+ b.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (!viewer.getSelection().isEmpty()) {
+ List<?> keybinding = ((IStructuredSelection) viewer.getSelection()).toList();
+ Command cmd = RemoveCommand.create(getEditingDomain(), getMaster().getValue(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, keybinding);
+ if (cmd.canExecute()) {
+ getEditingDomain().getCommandStack().execute(cmd);
+ }
+ }
+ }
+ });
+ }
+
+ ControlFactory.createTagsWidget(parent, this);
+
+ return parent;
+ }
+
+ @Override
+ public IObservableList getChildList(Object element) {
+ return ELEMENT_CONTAINER__CHILDREN.observe(element);
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VToolBarContributionsEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VToolBarContributionsEditor.java
new file mode 100644
index 00000000..6ec69138
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VToolBarContributionsEditor.java
@@ -0,0 +1,258 @@
+/*******************************************************************************
+ * 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 org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution;
+
+import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContributions;
+
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
+
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuContributions;
+
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
+
+import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl;
+
+import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
+
+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.ObservableColumnLabelProvider;
+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.commands.MHandler;
+import org.eclipse.e4.ui.model.application.descriptor.basic.MBasicFactory;
+import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
+import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptorContainer;
+import org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl;
+import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.databinding.EMFDataBindingContext;
+import org.eclipse.emf.databinding.edit.EMFEditProperties;
+import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
+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.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+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 VToolBarContributionsEditor extends AbstractComponentEditor {
+ private Composite composite;
+ private EMFDataBindingContext context;
+ private ModelEditor editor;
+ private TableViewer viewer;
+
+ public VToolBarContributionsEditor(EditingDomain editingDomain, ModelEditor editor) {
+ super(editingDomain);
+ this.editor = editor;
+ }
+
+ @Override
+ public Image getImage(Object element, Display display) {
+ return null;
+ }
+
+ @Override
+ public String getLabel(Object element) {
+ return "ToolBar Contributions";
+ }
+
+ @Override
+ public String getDetailLabel(Object element) {
+ return null;
+ }
+
+ @Override
+ public String getDescription(Object element) {
+ return "ToolBar Contributions Bla Bla Bla Bla Bla";
+ }
+
+ @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);
+ parent.setLayout(new GridLayout(3, false));
+
+ {
+ Label l = new Label(parent, SWT.NONE);
+ l.setText("ToolBar Contributions");
+ 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.getTable().setHeaderVisible(true);
+
+ {
+ IEMFEditValueProperty prop = EMFEditProperties.value(getEditingDomain(), ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID);
+
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.getColumn().setText("Id");
+ column.getColumn().setWidth(200);
+ column.setLabelProvider(new ObservableColumnLabelProvider<MHandler>(prop.observeDetail(cp.getKnownElements())));
+ }
+
+ {
+ IEMFEditValueProperty prop = EMFEditProperties.value(getEditingDomain(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTION__PARENT_ID);
+
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.getColumn().setText("ParentId");
+ column.getColumn().setWidth(200);
+ column.setLabelProvider(new ObservableColumnLabelProvider<MHandler>(prop.observeDetail(cp.getKnownElements())));
+ }
+
+ {
+ IEMFEditValueProperty prop = EMFEditProperties.value(getEditingDomain(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTION__POSITION_IN_PARENT);
+
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.getColumn().setText("Position");
+ column.getColumn().setWidth(200);
+ column.setLabelProvider(new ObservableColumnLabelProvider<MHandler>(prop.observeDetail(cp.getKnownElements())));
+ }
+
+ Composite buttonComp = new Composite(parent, SWT.NONE);
+ buttonComp.setLayoutData(new GridData(GridData.FILL,GridData.END,false,false));
+ GridLayout 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("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();
+ MToolBarContributions container = (MToolBarContributions) getMaster().getValue();
+ int idx = container.getToolBarContributions().indexOf(obj) - 1;
+ if( idx >= 0 ) {
+ Command cmd = MoveCommand.create(getEditingDomain(), getMaster().getValue(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTIONS__TOOL_BAR_CONTRIBUTIONS, obj, idx);
+
+ if( cmd.canExecute() ) {
+ getEditingDomain().getCommandStack().execute(cmd);
+ viewer.setSelection(new StructuredSelection(obj));
+ }
+ }
+
+ }
+ }
+ }
+ });
+
+ b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+ b.setText("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();
+ MToolBarContributions container = (MToolBarContributions) getMaster().getValue();
+ int idx = container.getToolBarContributions().indexOf(obj) + 1;
+ if( idx < container.getToolBarContributions().size() ) {
+ Command cmd = MoveCommand.create(getEditingDomain(), getMaster().getValue(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTIONS__TOOL_BAR_CONTRIBUTIONS, obj, idx);
+
+ if( cmd.canExecute() ) {
+ getEditingDomain().getCommandStack().execute(cmd);
+ viewer.setSelection(new StructuredSelection(obj));
+ }
+ }
+
+ }
+ }
+ }
+ });
+
+ b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+ b.setText("Add ...");
+ 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) {
+ MToolBarContribution command = MMenuFactory.INSTANCE.createToolBarContribution();
+ Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTIONS__TOOL_BAR_CONTRIBUTIONS, command);
+
+ if( cmd.canExecute() ) {
+ getEditingDomain().getCommandStack().execute(cmd);
+ editor.setSelection(command);
+ }
+ }
+ });
+
+ b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
+ b.setText("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() ) {
+ List<?> commands = ((IStructuredSelection)viewer.getSelection()).toList();
+ Command cmd = RemoveCommand.create(getEditingDomain(), getMaster().getValue(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTIONS__TOOL_BAR_CONTRIBUTIONS, commands);
+ if( cmd.canExecute() ) {
+ getEditingDomain().getCommandStack().execute(cmd);
+ }
+ }
+ }
+ });
+ }
+
+ return parent;
+ }
+
+ @Override
+ public IObservableList getChildList(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}

Back to the top