diff options
author | Sopot Cela | 2013-10-17 13:09:54 +0000 |
---|---|---|
committer | Sopot Cela | 2013-10-17 13:09:54 +0000 |
commit | 287ca8759967fa0cdb25b04ee8fa538f19dc9a58 (patch) | |
tree | 56ec5cdd91bb2bb04bc2983bbd9b9cff4431086f | |
parent | 119b69048b106ce7853ff05223b9ad054efeb50a (diff) | |
download | org.eclipse.e4.tools-287ca8759967fa0cdb25b04ee8fa538f19dc9a58.tar.gz org.eclipse.e4.tools-287ca8759967fa0cdb25b04ee8fa538f19dc9a58.tar.xz org.eclipse.e4.tools-287ca8759967fa0cdb25b04ee8fa538f19dc9a58.zip |
Bug 412377 - add "Add child" item in right click menu at "Model
Fragement" (adding new features)
-rw-r--r-- | bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java index 0ec25be9..a9118515 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java @@ -11,7 +11,10 @@ package org.eclipse.e4.tools.emf.ui.internal.common.component; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; +import javax.annotation.PostConstruct; import javax.inject.Inject; import org.eclipse.core.databinding.observable.list.IObservableList; import org.eclipse.core.databinding.property.list.IListProperty; @@ -40,6 +43,7 @@ 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.swt.IWidgetValueProperty; import org.eclipse.jface.databinding.swt.WidgetProperties; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; @@ -69,6 +73,8 @@ public class StringModelFragment extends AbstractComponentEditor { private IListProperty MODEL_FRAGMENT__ELEMENTS = EMFProperties.list(FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS); + private List<Action> actions = new ArrayList<Action>(); + @Inject IEclipseContext eclipseContext; @@ -77,6 +83,22 @@ public class StringModelFragment extends AbstractComponentEditor { super(); } + @PostConstruct + public void init() { + List<FeatureClass> list = new ArrayList<FeatureClass>(); + Util.addClasses(ApplicationPackageImpl.eINSTANCE, list); + list.addAll(getEditor().getFeatureClasses(FragmentPackageImpl.Literals.MODEL_FRAGMENT, FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS)); + for (final FeatureClass featureClass : list) { + actions.add(new Action(featureClass.label) { + + @Override + public void run() { + handleAdd(featureClass.eClass, false); + } + }); + } + } + @Override public Image getImage(Object element, Display display) { return createImage(ResourceProvider.IMG_StringModelFragment); @@ -340,4 +362,29 @@ public class StringModelFragment extends AbstractComponentEditor { return MODEL_FRAGMENT__ELEMENTS.observe(element); } + protected void handleAdd(EClass eClass, boolean separator) { + EObject eObject = EcoreUtil.create(eClass); + setElementId(eObject); + Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS, eObject); + + if (cmd.canExecute()) { + getEditingDomain().getCommandStack().execute(cmd); + getEditor().setSelection(eObject); + } + } + + @Override + public List<Action> getActions(Object element) { + ArrayList<Action> l = new ArrayList<Action>(super.getActions(element)); + l.addAll(actions); + Collections.sort(l, new Comparator<Action>() { + @Override + public int compare(Action o1, Action o2) { + + return o1.getText().compareTo(o2.getText()); + } + }); + return l; + } + } |