diff options
author | Thomas Schindl | 2010-06-12 21:26:14 +0000 |
---|---|---|
committer | Thomas Schindl | 2010-06-12 21:26:14 +0000 |
commit | e8ad7ba72b415581e71b1db6a7c7b06040a39264 (patch) | |
tree | 32bba1c2a0dcdc4751c8968f81e0008e4bc919e1 | |
parent | fb5ad41d88679a7a80bc0894b61b565f23b589d2 (diff) | |
download | org.eclipse.e4.tools-e8ad7ba72b415581e71b1db6a7c7b06040a39264.tar.gz org.eclipse.e4.tools-e8ad7ba72b415581e71b1db6a7c7b06040a39264.tar.xz org.eclipse.e4.tools-e8ad7ba72b415581e71b1db6a7c7b06040a39264.zip |
Bug 304584 - [Tooling] Implement Workbench-Model-Tooling
* started adding support for new fragment contributions
7 files changed, 230 insertions, 22 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/schema/org.eclipse.e4.tools.emf.ui.editors.exsd b/bundles/org.eclipse.e4.tools.emf.ui/schema/org.eclipse.e4.tools.emf.ui.editors.exsd index 352421fd..57b8c96b 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/schema/org.eclipse.e4.tools.emf.ui.editors.exsd +++ b/bundles/org.eclipse.e4.tools.emf.ui/schema/org.eclipse.e4.tools.emf.ui.editors.exsd @@ -18,8 +18,9 @@ </annotation> <complexType> <sequence> - <element ref="editor" minOccurs="1" maxOccurs="unbounded"/> - <element ref="virtualeditor" minOccurs="1" maxOccurs="unbounded"/> + <element ref="editor" minOccurs="0" maxOccurs="unbounded"/> + <element ref="virtualeditor" minOccurs="0" maxOccurs="unbounded"/> + <element ref="editorfeature" minOccurs="0" maxOccurs="unbounded"/> </sequence> <attribute name="point" type="string" use="required"> <annotation> @@ -85,6 +86,21 @@ </complexType> </element> + <element name="editorfeature"> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.eclipse.e4.tools.emf.ui.common.IEditorFeature"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + <annotation> <appinfo> <meta.section type="since"/> diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IEditorFeature.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IEditorFeature.java new file mode 100644 index 00000000..cf0411f9 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IEditorFeature.java @@ -0,0 +1,20 @@ +package org.eclipse.e4.tools.emf.ui.common; + +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.List; + +import org.eclipse.emf.ecore.EClass; + +public interface IEditorFeature { + public class FeatureClass { + public final String label; + public final EClass eClass; + + public FeatureClass(String label, EClass eClass) { + this.label = label; + this.eClass = eClass; + } + } + public List<FeatureClass> getFeatureClasses(EClass eClass, EStructuralFeature feature); +} 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 63f06f3f..10a35c0b 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 @@ -323,7 +323,7 @@ ModelFragmentsEditor_Up=Up ModelFragmentsEditor_Down=Down ModelFragmentsEditor_Add=Add ModelFragmentsEditor_Remove=Remove -ModelFragmentsEditor_Label=Label +ModelFragmentsEditor_Label=Model Fragments ModelFragmentsEditor_Description=Description StringModelFragment_Label=String Model Fragment 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 0668cc23..09e4fda2 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,12 @@ ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common; +import org.eclipse.e4.tools.emf.ui.common.IEditorFeature.FeatureClass; + +import org.eclipse.emf.ecore.EStructuralFeature; + +import org.eclipse.e4.tools.emf.ui.common.IEditorFeature; + import org.eclipse.e4.tools.emf.ui.internal.common.component.StringModelFragment; import org.eclipse.e4.tools.emf.ui.internal.common.component.ModelFragmentsEditor; @@ -147,6 +153,7 @@ public class ModelEditor { private Map<EClass, AbstractComponentEditor> editorMap = new HashMap<EClass, AbstractComponentEditor>(); private Map<String, AbstractComponentEditor> virtualEditors = new HashMap<String, AbstractComponentEditor>(); private List<FeaturePath> labelFeaturePaths = new ArrayList<FeaturePath>(); + private List<IEditorFeature> editorFeatures = new ArrayList<IEditorFeature>(); // private List<AbstractComponentEditor> editors = new // ArrayList<AbstractComponentEditor>(); @@ -167,6 +174,7 @@ public class ModelEditor { registerContributedEditors(); registerContributedVirtualEditors(); + loadEditorFeatures(); SashForm form = new SashForm(composite, SWT.HORIZONTAL); form.setBackground(form.getDisplay().getSystemColor(SWT.COLOR_WHITE)); @@ -295,6 +303,34 @@ public class ModelEditor { viewer.getControl().setMenu(mgr.createContextMenu(viewer.getControl())); } + private void loadEditorFeatures() { + IExtensionRegistry registry = RegistryFactory.getRegistry(); + IExtensionPoint extPoint = registry.getExtensionPoint("org.eclipse.e4.tools.emf.ui.editors"); //$NON-NLS-1$ + + for (IConfigurationElement el : extPoint.getConfigurationElements()) { + if (!"editorfeature".equals(el.getName())) { //$NON-NLS-1$ + continue; + } + + try { + editorFeatures.add((IEditorFeature) el.createExecutableExtension("class")); //$NON-NLS-1$ + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + public List<FeatureClass> getFeatureClasses(EClass eClass, EStructuralFeature feature) { + List<FeatureClass> list = new ArrayList<IEditorFeature.FeatureClass>(); + + for( IEditorFeature f : editorFeatures ) { + list.addAll(f.getFeatureClasses(eClass, feature)); + } + + return list; + } + @Inject @Optional public void setSelectionService(ISelectionProviderService selectionService) { diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java index 62bdbd56..6a2c7b60 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java @@ -50,6 +50,131 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; public class ControlFactory { + public static void createStringListWidget(Composite parent, final AbstractComponentEditor editor, String label, final EStructuralFeature feature) { + Label l = new Label(parent, SWT.NONE); + l.setText(label); + l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + + final Text t = new Text(parent, SWT.BORDER); + t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + t.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) { + handleAddText(editor, UiPackageImpl.Literals.CONTEXT__VARIABLES, t); + } + } + }); + + Button b = new Button(parent, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Add); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.TABLE_ADD_IMAGE)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleAddText(editor, feature, t); + } + }); + + new Label(parent, SWT.NONE); + + final TableViewer viewer = new TableViewer(parent); + viewer.setLabelProvider(new LabelProvider()); + viewer.setContentProvider(new ObservableListContentProvider()); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.heightHint = 150; + viewer.getControl().setLayoutData(gd); + + IEMFListProperty prop = EMFProperties.list(feature); + viewer.setInput(prop.observeDetail(editor.getMaster())); + + 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); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Up); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.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(); + MContext container = (MContext) editor.getMaster().getValue(); + int idx = container.getVariables().indexOf(obj) - 1; + if (idx >= 0) { + Command cmd = MoveCommand.create(editor.getEditingDomain(), editor.getMaster().getValue(), feature, obj, idx); + + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + viewer.setSelection(new StructuredSelection(obj)); + } + } + + } + } + } + }); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Down); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.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(); + MContext container = (MApplication) editor.getMaster().getValue(); + int idx = container.getVariables().indexOf(obj) + 1; + if (idx < container.getVariables().size()) { + Command cmd = MoveCommand.create(editor.getEditingDomain(), editor.getMaster().getValue(), feature, obj, idx); + + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + viewer.setSelection(new StructuredSelection(obj)); + } + } + + } + } + } + }); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Remove); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.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()) { + MContext el = (MContext) editor.getMaster().getValue(); + List<?> ids = ((IStructuredSelection) viewer.getSelection()).toList(); + Command cmd = RemoveCommand.create(editor.getEditingDomain(), el, feature, ids); + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + if (el.getVariables().size() > 0) { + viewer.setSelection(new StructuredSelection(el.getVariables().get(0))); + } + } + } + } + }); + } + + public static void createVariablesWidget(Composite parent, final AbstractComponentEditor editor) { Label l = new Label(parent, SWT.NONE); l.setText(Messages.ControlFactory_ContextVariables); 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 5540040c..95ad8e81 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 @@ -1,5 +1,7 @@ package org.eclipse.e4.tools.emf.ui.internal.common.component; +import org.eclipse.e4.tools.emf.ui.common.IEditorFeature.FeatureClass; + import org.eclipse.emf.ecore.EPackage; import java.util.ArrayList; @@ -242,15 +244,17 @@ public class StringModelFragment extends AbstractComponentEditor { childrenDropDown.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { - EClass eclass = (EClass) element; - return eclass.getName(); + FeatureClass eclass = (FeatureClass) element; + return eclass.label; } }); - List<EClass> list = new ArrayList<EClass>(); + List<FeatureClass> list = new ArrayList<FeatureClass>(); addClasses(ApplicationPackageImpl.eINSTANCE, list); + list.addAll(editor.getFeatureClasses(FragmentPackageImpl.Literals.MODEL_FRAGMENT, FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS)); childrenDropDown.setInput(list); + childrenDropDown.setSelection(new StructuredSelection(list.get(0))); b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); b.setImage(getImage(b.getDisplay(), TABLE_ADD_IMAGE)); @@ -258,7 +262,7 @@ public class StringModelFragment extends AbstractComponentEditor { b.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - EClass eClass = (EClass) ((IStructuredSelection) childrenDropDown.getSelection()).getFirstElement(); + EClass eClass = ((FeatureClass) ((IStructuredSelection) childrenDropDown.getSelection()).getFirstElement()).eClass; EObject eObject = EcoreUtil.create(eClass); Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS, eObject); @@ -291,17 +295,17 @@ public class StringModelFragment extends AbstractComponentEditor { return parent; } - - public void addClasses(EPackage ePackage, List<EClass> list) { + + public void addClasses(EPackage ePackage, List<FeatureClass> list) { for (EClassifier c : ePackage.getEClassifiers()) { if (c instanceof EClass) { EClass eclass = (EClass) c; - if ( eclass != ApplicationPackageImpl.Literals.APPLICATION && !eclass.isAbstract() && !eclass.isInterface() && eclass.getEAllSuperTypes().contains(ApplicationPackageImpl.Literals.APPLICATION_ELEMENT)) { - list.add(eclass); + if (eclass != ApplicationPackageImpl.Literals.APPLICATION && !eclass.isAbstract() && !eclass.isInterface() && eclass.getEAllSuperTypes().contains(ApplicationPackageImpl.Literals.APPLICATION_ELEMENT)) { + list.add(new FeatureClass(eclass.getName(), eclass)); } } } - + for (EPackage eSubPackage : ePackage.getESubpackages()) { addClasses(eSubPackage, list); } diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractCommandSelectionDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractCommandSelectionDialog.java index 71e57013..397cfb15 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractCommandSelectionDialog.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractCommandSelectionDialog.java @@ -10,6 +10,16 @@ ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs; +import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl; + +import org.eclipse.emf.ecore.EObject; + +import org.eclipse.emf.common.util.TreeIterator; + +import org.eclipse.emf.ecore.util.EcoreUtil; + +import org.eclipse.e4.ui.model.fragment.MModelFragments; + import java.util.ArrayList; import java.util.List; import org.eclipse.e4.tools.emf.ui.common.IModelResource; @@ -87,19 +97,16 @@ public abstract class AbstractCommandSelectionDialog extends TitleAreaDialog { } }); - if( resource.getRoot().get(0) instanceof MApplication ) { - MApplication app = (MApplication) resource.getRoot().get(0); - viewer.setInput(app.getCommands()); - } else { - MModelComponents components = (MModelComponents)resource.getRoot().get(0); - List<MCommand> commands = new ArrayList<MCommand>(); - for( MModelComponent comp : components.getComponents() ) { - commands.addAll(comp.getCommands()); + List<EObject> commands = new ArrayList<EObject>(); + TreeIterator<EObject> it = EcoreUtil.getAllContents((EObject)resource.getRoot().get(0), true); + while( it.hasNext() ) { + EObject o = it.next(); + if( o.eClass() == CommandsPackageImpl.Literals.COMMAND ) { + commands.add(o); } - viewer.setInput(commands); } + viewer.setInput(commands); - final PatternFilter filter = new PatternFilter() { @Override protected boolean isParentMatch(Viewer viewer, Object element) { |