Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorglefur2009-11-17 18:44:16 +0000
committerglefur2009-11-17 18:44:16 +0000
commit26cb9d71dc9ec3b74951185799294544003fe8d7 (patch)
treecc6b7f80d03e3699d3ad4fdd08a81fa16e9283c7
parent7769744575235a4665a803ac2bdf0e8d6d1b4c2f (diff)
downloadorg.eclipse.eef-26cb9d71dc9ec3b74951185799294544003fe8d7.tar.gz
org.eclipse.eef-26cb9d71dc9ec3b74951185799294544003fe8d7.tar.xz
org.eclipse.eef-26cb9d71dc9ec3b74951185799294544003fe8d7.zip
ADDED: Ability to create sub element (by wizard) for TableComposition with composition on abstract type
UPDATED: TabbedPropertiesEditionSP deprecated
-rw-r--r--plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/EReferencePropertiesEditionContext.java71
-rw-r--r--plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/StandardPropertiesEditionPolicy.java23
-rw-r--r--plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFUtils.java72
-rw-r--r--plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/TabbedPropertiesEditionSheetPage.java1
-rw-r--r--plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/sections/PropertiesEditionSection.java11
-rw-r--r--plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/wizards/PropertiesEditionWizard.java102
6 files changed, 250 insertions, 30 deletions
diff --git a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/EReferencePropertiesEditionContext.java b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/EReferencePropertiesEditionContext.java
new file mode 100644
index 000000000..247cac9b0
--- /dev/null
+++ b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/EReferencePropertiesEditionContext.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2009 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.eef.runtime.impl.policies;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent;
+import org.eclipse.emf.eef.runtime.api.policies.IPropertiesEditionContext;
+
+/**
+ * @author <a href="mailto:goulwen.lefur@obeo.fr">Goulwen Le Fur</a>
+ */
+public class EReferencePropertiesEditionContext implements
+ IPropertiesEditionContext {
+
+ /**
+ * the source EditionComponent
+ */
+ protected IPropertiesEditionComponent propertiesEditionComponent;
+
+ /**
+ * the EReference to edit
+ */
+ protected EReference eReference;
+
+ /**
+ * The ResourceSet where the EObjects are located
+ */
+ protected ResourceSet resourceSet;
+
+ /**
+ * @param propertiesEditionComponent
+ * @param eReference
+ * @param resourceSet
+ */
+ public EReferencePropertiesEditionContext(IPropertiesEditionComponent propertiesEditionComponent, EReference eReference, ResourceSet resourceSet) {
+ this.propertiesEditionComponent = propertiesEditionComponent;
+ this.eReference = eReference;
+ this.resourceSet = resourceSet;
+ }
+
+ /**
+ * @return the propertiesEditionComponent
+ */
+ public IPropertiesEditionComponent getPropertiesEditionComponent() {
+ return propertiesEditionComponent;
+ }
+
+ /**
+ * @return the eReference
+ */
+ public EReference getEReference() {
+ return eReference;
+ }
+
+ /**
+ * @return the resourceSet
+ */
+ public ResourceSet getResourceSet() {
+ return resourceSet;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/StandardPropertiesEditionPolicy.java b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/StandardPropertiesEditionPolicy.java
index 566287c8a..8843dfcff 100644
--- a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/StandardPropertiesEditionPolicy.java
+++ b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/policies/StandardPropertiesEditionPolicy.java
@@ -17,6 +17,7 @@ import org.eclipse.emf.eef.runtime.api.policies.IPropertiesEditionPolicy;
import org.eclipse.emf.eef.runtime.api.providers.IPropertiesEditionProvider;
import org.eclipse.emf.eef.runtime.impl.services.PropertiesEditionComponentService;
import org.eclipse.emf.eef.runtime.ui.wizards.EditPropertyWizard;
+import org.eclipse.emf.eef.runtime.ui.wizards.PropertiesEditionWizard;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
@@ -37,7 +38,7 @@ public class StandardPropertiesEditionPolicy implements IPropertiesEditionPolicy
IPropertiesEditionProvider provider = PropertiesEditionComponentService.getInstance().getProvider(
eObject);
if (provider != null) {
- EditPropertyWizard wizard = new EditPropertyWizard(editionContext.getEditingDomain(),
+ PropertiesEditionWizard wizard = new PropertiesEditionWizard(editionContext.getEditingDomain(),
eObject, editionContext.getEditingDomain().getResourceSet());
WizardDialog wDialog = new WizardDialog(new Shell(), wizard);
if (wDialog.open() == Window.OK)
@@ -56,15 +57,17 @@ public class StandardPropertiesEditionPolicy implements IPropertiesEditionPolicy
if (propertiesEditionContext instanceof EObjectPropertiesEditionContext) {
EObjectPropertiesEditionContext editionContext = (EObjectPropertiesEditionContext)propertiesEditionContext;
EObject eObject = editionContext.getEObject();
- IPropertiesEditionProvider provider = PropertiesEditionComponentService.getInstance()
- .getProvider(eObject);
- if (provider != null) {
- EditPropertyWizard wizard = new EditPropertyWizard(null, eObject, editionContext
- .getResourceSet());
- WizardDialog wDialog = new WizardDialog(new Shell(), wizard);
- if (wDialog.open() == Window.OK)
- return wizard.getEObject();
- }
+ PropertiesEditionWizard wizard = new PropertiesEditionWizard(null, eObject, editionContext.getResourceSet());
+ WizardDialog wDialog = new WizardDialog(new Shell(), wizard);
+ if (wDialog.open() == Window.OK)
+ return wizard.getEObject();
+ }
+ else if (propertiesEditionContext instanceof EReferencePropertiesEditionContext) {
+ EReferencePropertiesEditionContext editionContext = (EReferencePropertiesEditionContext)propertiesEditionContext;
+ PropertiesEditionWizard wizard = new PropertiesEditionWizard(null, editionContext.getEReference(), editionContext.getResourceSet());
+ WizardDialog wDialog = new WizardDialog(new Shell(), wizard);
+ if (wDialog.open() == Window.OK)
+ return wizard.getEObject();
}
return null;
}
diff --git a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFUtils.java b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFUtils.java
index d1fade4aa..83327026e 100644
--- a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFUtils.java
+++ b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFUtils.java
@@ -11,14 +11,20 @@
package org.eclipse.emf.eef.runtime.impl.utils;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.eef.runtime.EMFPropertiesRuntime;
@@ -59,7 +65,73 @@ public class EEFUtils {
choiceOfValues = eObject.eResource().getResourceSet();
return choiceOfValues;
}
+
+ public static List<EClass> instanciableTypesInHierarchy(EClassifier eClassifier) {
+ List<EClass> result = new ArrayList<EClass>();
+ if (eClassifier instanceof EClass) {
+ EClass eClass = (EClass) eClassifier;
+ if (!eClass.isAbstract())
+ result.add(eClass);
+ result.addAll(instanciableSubTypes(eClass));
+ }
+ return result;
+ }
+
+ private static List<EClass> instanciableSubTypes(EClass eClass) {
+ List<EClass> result = new ArrayList<EClass>();
+ for (EPackage ePackage : allPackages(eClass)) {
+ for (EClassifier eClassifier : ePackage.getEClassifiers()) {
+ if (eClassifier instanceof EClass) {
+ EClass eClass2 = (EClass) eClassifier;
+ if (!eClass2.equals(eClass) && eClass.isSuperTypeOf(eClass2) && !eClass2.isAbstract() && !eClass2.isInterface())
+ result.add(eClass2);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private static List<EPackage> allPackages(EClass eClass) {
+ List<EPackage> result = new ArrayList<EPackage>();
+ if (eClass.eResource() != null) {
+ EcoreUtil.resolveAll(eClass);
+ List<Resource> resourcesToProcess = null;
+ if (eClass.eResource().getResourceSet() != null)
+ resourcesToProcess = eClass.eResource().getResourceSet().getResources();
+ else {
+ resourcesToProcess = new ArrayList<Resource>();
+ resourcesToProcess.add(eClass.eResource());
+ }
+ for (Resource resource : resourcesToProcess)
+ result.addAll(allPackageOfResource(resource));
+ }
+ else {
+ EPackage rootPackage = eClass.getEPackage();
+ while (rootPackage.getESuperPackage() != null)
+ rootPackage = rootPackage.getESuperPackage();
+ result.addAll(allSubPackages(rootPackage));
+ }
+ return result;
+ }
+
+ private static List<EPackage> allSubPackages(EPackage ePackage) {
+ List<EPackage> result = new ArrayList<EPackage>();
+ for (EPackage subPackage : ePackage.getESubpackages())
+ result.addAll(allSubPackages(subPackage));
+ return result;
+ }
+ private static List<EPackage> allPackageOfResource(Resource resource) {
+ List<EPackage> result = new ArrayList<EPackage>();
+ for (Iterator iterator = resource.getAllContents(); iterator.hasNext();) {
+ EObject type = (EObject) iterator.next();
+ if (type instanceof EPackage)
+ result .add((EPackage)type);
+ }
+ return result;
+ }
+
/**
* Convert a treeIterator in Object list
* @param iter the iterator
diff --git a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/TabbedPropertiesEditionSheetPage.java b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/TabbedPropertiesEditionSheetPage.java
index bc168d94b..03ecaa385 100644
--- a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/TabbedPropertiesEditionSheetPage.java
+++ b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/TabbedPropertiesEditionSheetPage.java
@@ -27,6 +27,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
/**
* @author <a href="mailto:goulwen.lefur@obeo.fr">Goulwen Le Fur</a>
+ * @deprecated use {@link TabbedPropertySheetPage} instead now.
*/
public class TabbedPropertiesEditionSheetPage extends TabbedPropertySheetPage {
diff --git a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/sections/PropertiesEditionSection.java b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/sections/PropertiesEditionSection.java
index ea9146f61..269c7241d 100644
--- a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/sections/PropertiesEditionSection.java
+++ b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/properties/sections/PropertiesEditionSection.java
@@ -44,7 +44,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
/**
* @author <a href="mailto:goulwen.lefur@obeo.fr">Goulwen Le Fur</a>
*/
-public class PropertiesEditionSection extends AbstractPropertySection implements IFilter {
+public class PropertiesEditionSection extends AbstractPropertySection {
/**
* the property sheet page for this section.
@@ -151,15 +151,6 @@ public class PropertiesEditionSection extends AbstractPropertySection implement
/**
* {@inheritDoc}
- * @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object)
- */
- public boolean select(Object toTest) {
- EObject resolveSemanticObject = resolveSemanticObject(toTest);
- return propertiesEditionProvider.provides(resolveSemanticObject);
- }
-
- /**
- * {@inheritDoc}
*
* @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#dispose()
*/
diff --git a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/wizards/PropertiesEditionWizard.java b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/wizards/PropertiesEditionWizard.java
index 8945aa15a..31f267d30 100644
--- a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/wizards/PropertiesEditionWizard.java
+++ b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/ui/wizards/PropertiesEditionWizard.java
@@ -10,11 +10,18 @@
*******************************************************************************/
package org.eclipse.emf.eef.runtime.ui.wizards;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.eef.runtime.EMFPropertiesRuntime;
import org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent;
@@ -22,12 +29,18 @@ import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionListener;
import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.impl.providers.RegistryPropertiesEditionProvider;
import org.eclipse.emf.eef.runtime.impl.services.PropertiesContextService;
-import org.eclipse.emf.eef.runtime.impl.services.PropertiesEditionComponentService;
+import org.eclipse.emf.eef.runtime.impl.utils.EEFUtils;
import org.eclipse.emf.eef.runtime.ui.utils.MessagesTool;
import org.eclipse.emf.eef.runtime.ui.viewers.PropertiesEditionContentProvider;
import org.eclipse.emf.eef.runtime.ui.viewers.PropertiesEditionViewer;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+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.Composite;
/**
@@ -37,10 +50,14 @@ public class PropertiesEditionWizard extends Wizard {
private EditPropertyWizardPage mainPage;
+ private ElementCreationWizardPage elementCreationPage;
+
protected EditingDomain editingDomain;
protected EObject eObject;
+ protected EReference eReference;
+
protected Command command;
protected ResourceSet allResources;
@@ -63,6 +80,20 @@ public class PropertiesEditionWizard extends Wizard {
}
/**
+ * Default constructor - define the eObject to edit.
+ *
+ * @param editingDomain (optional) defines the editingDomain where to perform commands.
+ * @param eReference the reference where create the EObject.
+ * @param allResources the resourceSet where the EObject is located.
+ */
+ public PropertiesEditionWizard(EditingDomain editingDomain, EReference eReference, ResourceSet allResources) {
+ this.editingDomain = editingDomain;
+ this.eReference = eReference;
+ this.allResources = allResources;
+ this.setWindowTitle(eReference.getName());
+ }
+
+ /**
* @return the editingDomain where to perform commands.
*/
public EditingDomain getEditingDomain() {
@@ -160,8 +191,56 @@ public class PropertiesEditionWizard extends Wizard {
@Override
public void addPages() {
+ if (inReferenceMode()) {
+ elementCreationPage = new ElementCreationWizardPage();
+ addPage(elementCreationPage);
+ }
mainPage = new EditPropertyWizardPage();
addPage(mainPage);
+ super.addPages();
+ }
+
+ /**
+ * @return
+ */
+ private boolean inReferenceMode() {
+ return eReference != null && eReference.isContainment() && eObject == null;
+ }
+
+ private class ElementCreationWizardPage extends WizardPage {
+
+ private List<Button> buttons = new ArrayList<Button>();
+
+ protected ElementCreationWizardPage() {
+ super("Element creation page page"); //$NON-NLS-1$
+ this.setTitle("Element type"); //$NON-NLS-1$
+ this.setDescription("Choose the type of element to create");//$NON-NLS-1$
+ }
+
+ public void createControl(Composite parent) {
+ Composite control = new Composite(parent, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ control.setLayoutData(gd);
+ GridLayout layout = new GridLayout();
+ control.setLayout(layout);
+ List<EClass> instanciableTypesInHierarchy = EEFUtils.instanciableTypesInHierarchy(eReference.getEType());
+ for (final EClass eClass : instanciableTypesInHierarchy) {
+ Button button = new Button(control, SWT.RADIO);
+ button.setText(eClass.getName());
+ button.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ eObject = EcoreUtil.create(eClass);
+ mainPage.setInput(eObject);
+ }
+ });
+ buttons.add(button);
+ }
+ buttons.get(0).setSelection(true);
+ eObject = EcoreUtil.create(instanciableTypesInHierarchy.get(0));
+ setControl(control);
+ }
+
}
private class EditPropertyWizardPage extends WizardPage implements IPropertiesEditionListener {
@@ -170,25 +249,28 @@ public class PropertiesEditionWizard extends Wizard {
protected EditPropertyWizardPage() {
super("Main page"); //$NON-NLS-1$
- this.setTitle(eObject.eClass().getName());
- this.setDescription(MessagesTool.getString("EditPropertyWizard.description", new Object[] {eObject.eClass().getName()}));
}
public void createControl(Composite parent) {
- viewer = new PropertiesEditionViewer(parent, PropertiesEditionWizard.this.allResources, 0);
- viewer.setDynamicTabHeader(true);
- setControl(viewer.getControl());
- }
-
- public void setInput(EObject eObject) {
try {
+ Composite control = new Composite(parent, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ control.setLayoutData(gd);
+ viewer = new PropertiesEditionViewer(control, PropertiesEditionWizard.this.allResources, 0);
+ viewer.setDynamicTabHeader(true);
viewer.setContentProvider(new PropertiesEditionContentProvider(new RegistryPropertiesEditionProvider(), IPropertiesEditionComponent.BATCH_MODE));
- viewer.setInput(eObject);
viewer.addPropertiesListener(this);
+ setControl(viewer.getControl());
} catch (InstantiationException e) {
EMFPropertiesRuntime.getDefault().logError("Trying to use PropertiesEditionWizard in LIVE_MODE.", e);
}
}
+
+ public void setInput(EObject eObject) {
+ this.setTitle(eObject.eClass().getName());
+ this.setDescription(MessagesTool.getString("EditPropertyWizard.description", new Object[] {eObject.eClass().getName()}));
+ viewer.setInput(eObject);
+ }
public void firePropertiesChanged(PropertiesEditionEvent event) {
handleChange(event);

Back to the top