Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-01-31 09:38:44 -0500
committercletavernie2012-01-31 09:38:44 -0500
commit53e0af0d9bb89e0f3b1fa1904e72735dbab45808 (patch)
tree1dd7815b4a97a719a9a0ab144ea948b5b59d3acd
parent3165174ea0033fe16a1a80ed0748712cbd5b30f6 (diff)
downloadorg.eclipse.papyrus-53e0af0d9bb89e0f3b1fa1904e72735dbab45808.tar.gz
org.eclipse.papyrus-53e0af0d9bb89e0f3b1fa1904e72735dbab45808.tar.xz
org.eclipse.papyrus-53e0af0d9bb89e0f3b1fa1904e72735dbab45808.zip
364586: [Property View - UML] There should be a better support for editing UML Datatype instances
https://bugs.eclipse.org/bugs/show_bug.cgi?id=364586
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/AbstractQVTGenerator.java31
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/EditContextGenerator.java2
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/IGenerator.java4
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/ProfileGenerator.java30
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ProfileWithDatatypes.java14
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/CreateContextWizard.java179
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/SelectFieldsPage.java30
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/transforms/profile2datacontext.qvto135
8 files changed, 254 insertions, 171 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/AbstractQVTGenerator.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/AbstractQVTGenerator.java
index 1327d6a4765..e6ffe34c71d 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/AbstractQVTGenerator.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/AbstractQVTGenerator.java
@@ -12,7 +12,9 @@
package org.eclipse.papyrus.customization.properties.generation.generators;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -29,6 +31,7 @@ import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
import org.eclipse.m2m.qvt.oml.ModelExtent;
import org.eclipse.m2m.qvt.oml.TransformationExecutor;
+import org.eclipse.m2m.qvt.oml.util.WriterLog;
import org.eclipse.papyrus.customization.properties.generation.Activator;
import org.eclipse.papyrus.views.properties.contexts.Context;
import org.eclipse.swt.widgets.Event;
@@ -44,9 +47,9 @@ import org.eclipse.swt.widgets.Listener;
public abstract class AbstractQVTGenerator implements IGenerator, Listener {
/**
- * The Context created by the transformation.
+ * The Contexts created by the transformation.
*/
- protected Context generatedContext;
+ protected List<Context> generatedContexts;
/**
* The output ModelExtent
@@ -55,7 +58,7 @@ public abstract class AbstractQVTGenerator implements IGenerator, Listener {
private Set<Listener> listeners = new HashSet<Listener>();
- public Context generate(URI targetURI) {
+ public List<Context> generate(URI targetURI) {
URI transformationURI = getTransformationURI();
@@ -63,14 +66,14 @@ public abstract class AbstractQVTGenerator implements IGenerator, Listener {
Diagnostic diagnostic = executor.loadTransformation();
if(diagnostic.getSeverity() != Diagnostic.OK) {
Activator.log.warn("Cannot load the transformation : " + transformationURI);
- return generatedContext = null;
+ return generatedContexts = null;
}
List<ModelExtent> extents = getModelExtents();
ExecutionContextImpl context = new ExecutionContextImpl();
context.setConfigProperty("keepModeling", true); //$NON-NLS-1$
- //context.setLog(new WriterLog(new OutputStreamWriter(System.out)));
+ context.setLog(new WriterLog(new OutputStreamWriter(System.out)));
ExecutionDiagnostic result = executor.execute(context, extents.toArray(new ModelExtent[0]));
@@ -85,12 +88,12 @@ public abstract class AbstractQVTGenerator implements IGenerator, Listener {
Resource contextResource = resourceSet.createResource(targetURI);
contextResource.getContents().addAll(outObjects);
- return generatedContext = getContext(outObjects);
+ return generatedContexts = getContexts(outObjects);
} else {
IStatus status = BasicDiagnostic.toIStatus(result);
Activator.log.warn(String.format("%s : %s", status.getPlugin(), status.getMessage()));
}
- return generatedContext = null;
+ return generatedContexts = null;
}
/**
@@ -159,11 +162,15 @@ public abstract class AbstractQVTGenerator implements IGenerator, Listener {
* @return
* The main generated context
*/
- protected Context getContext(List<EObject> outObjects) {
- Object objectResult = outObjects.get(0);
- if(!(objectResult instanceof Context)) {
- return null;
+ protected List<Context> getContexts(List<EObject> outObjects) {
+ List<Context> result = new LinkedList<Context>();
+
+ for(Object objectResult : outObjects) {
+ if(objectResult instanceof Context) {
+ result.add((Context)objectResult);
+ }
}
- return (Context)objectResult;
+
+ return result;
}
}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/EditContextGenerator.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/EditContextGenerator.java
index 7fb4b0b6b34..20110320915 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/EditContextGenerator.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/EditContextGenerator.java
@@ -32,7 +32,7 @@ import org.eclipse.swt.widgets.Listener;
*/
public class EditContextGenerator implements IGenerator {
- public Context generate(URI targetURI) {
+ public List<Context> generate(URI targetURI) {
// TODO Auto-generated method stub
return null;
}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/IGenerator.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/IGenerator.java
index 45d854ba61c..97261d3bad5 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/IGenerator.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/IGenerator.java
@@ -11,6 +11,8 @@
*****************************************************************************/
package org.eclipse.papyrus.customization.properties.generation.generators;
+import java.util.List;
+
import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.views.properties.contexts.Context;
import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
@@ -37,7 +39,7 @@ public interface IGenerator {
* @param targetURI
* @return The generated Context
*/
- public Context generate(URI targetURI);
+ public List<Context> generate(URI targetURI);
/**
* Creates the controls for this Generator. The generator is responsible
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/ProfileGenerator.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/ProfileGenerator.java
index ff54c23e494..5bc604718fa 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/ProfileGenerator.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/ProfileGenerator.java
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.m2m.qvt.oml.BasicModelExtent;
import org.eclipse.m2m.qvt.oml.ModelExtent;
import org.eclipse.papyrus.customization.properties.generation.Activator;
@@ -124,13 +125,13 @@ public class ProfileGenerator extends AbstractQVTGenerator {
* The list of package and subpackages names, and the classifier name, i.e.
* the list of segments in the classifier qualified name
* e.g. : SysML::Blocks::Block : ["SysML", "Blocks", "Block"]
- * @param profilePackage
+ * @param rootPackage
* The root Package in which the stereotype should be retrieved
* @return
* The corresponding Classifier, or null if it couldn't be retrieved
*/
- protected Classifier findClassifier(List<String> path, Package profilePackage) {
- NamedElement element = profilePackage.getOwnedMember(path.get(0));
+ protected Classifier findClassifier(List<String> path, Package rootPackage) {
+ NamedElement element = rootPackage.getOwnedMember(path.get(0));
path.remove(0);
if(path.size() == 0) {
if(element instanceof Classifier) {
@@ -169,8 +170,13 @@ public class ProfileGenerator extends AbstractQVTGenerator {
*/
public org.eclipse.uml2.uml.Property getAttribute(Property property) {
List<String> path = getPath(property);
- path.remove(0); //The first path element corresponds to this.umlProfile
- Classifier classifier = findClassifier(path, umlProfile);
+
+ Package propertyRootPackage = findPackage(path.remove(0));
+ if(propertyRootPackage == null) {
+ return null;
+ }
+
+ Classifier classifier = findClassifier(path, propertyRootPackage);
if(classifier == null) {
return null;
}
@@ -179,6 +185,20 @@ public class ProfileGenerator extends AbstractQVTGenerator {
return attribute;
}
+ public Package findPackage(String name) {
+ for(Resource resource : umlProfile.eResource().getResourceSet().getResources()) {
+ for(Object rootElement : resource.getContents()) {
+ if(rootElement instanceof Package) {
+ Package rootPackage = (Package)rootElement;
+ if(name.equals(rootPackage.getName())) {
+ return rootPackage;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
public boolean isSelectedSingle(Property property) {
org.eclipse.uml2.uml.Property attribute = getAttribute(property);
if(attribute == null) {
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ProfileWithDatatypes.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ProfileWithDatatypes.java
index 6dee47e268d..eae51078835 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ProfileWithDatatypes.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ProfileWithDatatypes.java
@@ -34,6 +34,7 @@ import org.eclipse.papyrus.views.properties.ui.PropertyEditor;
import org.eclipse.papyrus.views.properties.ui.UiFactory;
import org.eclipse.papyrus.views.properties.ui.ValueAttribute;
import org.eclipse.papyrus.views.properties.util.PropertiesUtil;
+import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.UMLPackage;
@@ -93,9 +94,18 @@ public class ProfileWithDatatypes extends StandardLayoutGenerator {
if(!(generator instanceof ProfileGenerator)) {
return "";
}
- Context context = findContext(property);
+
org.eclipse.uml2.uml.Property attribute = ((ProfileGenerator)generator).getAttribute(property);
- return context.getName() + ":Single " + attribute.getType().getName();
+
+ Package nearestPackage = attribute.getType().getNearestPackage();
+ Package rootPackage = nearestPackage;
+ while(rootPackage.getNestingPackage() != null) {
+ rootPackage = rootPackage.getNestingPackage();
+ }
+
+ //TODO : We're assuming the rootPackage has the same name as the context...
+ //This layout generator is really only compatible with ProfileGenerator
+ return rootPackage.getName() + ":Single " + attribute.getType().getName();
}
protected Context findContext(Property property) {
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/CreateContextWizard.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/CreateContextWizard.java
index e623f837761..a892b2db7c0 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/CreateContextWizard.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/CreateContextWizard.java
@@ -53,13 +53,13 @@ import org.eclipse.ui.IWorkbench;
*/
public class CreateContextWizard extends Wizard implements INewWizard {
- CreateContextMainPage mainPage;
+ protected CreateContextMainPage mainPage;
- GeneratorPage generatorPage;
+ protected GeneratorPage generatorPage;
//protected LayoutPage layout;
- SelectFieldsPage selectFieldsPage;
+ protected SelectFieldsPage selectFieldsPage;
/**
* All available context generators
@@ -72,9 +72,9 @@ public class CreateContextWizard extends Wizard implements INewWizard {
protected static List<ILayoutGenerator> layoutGenerators = new LinkedList<ILayoutGenerator>();
/**
- * The generated context
+ * The generated contexts
*/
- protected Context context;
+ protected List<Context> contexts;
/**
* The IGenerator used to generate the context
@@ -92,97 +92,101 @@ public class CreateContextWizard extends Wizard implements INewWizard {
@Override
public boolean performFinish() {
- if(generator == null || context == null || layoutGenerator == null) {
+ if(generator == null || contexts == null || contexts.isEmpty() || layoutGenerator == null) {
return false;
}
ConfigurationManager configManager = ConfigurationManager.instance;
- Tab defaultTab = ContextsFactory.eINSTANCE.createTab();
- defaultTab.setId(context.getName().toLowerCase());
- defaultTab.setLabel(context.getName());
- defaultTab.setPriority(100);
- context.getTabs().add(defaultTab);
-
- FieldSelection fieldSelection = selectFieldsPage.getFieldSelection();
-
- // URI contextURI = context.eResource().getURI();
- // Resource selectionResource = context.eResource().getResourceSet().createResource(URI.createURI(context.getName() + "FieldSelection.xmi").resolve(contextURI)); //$NON-NLS-1$
- // selectionResource.getContents().add(fieldSelection);
- // try {
- // selectionResource.save(null);
- // } catch (IOException ex) {
- // Activator.log.error("Couldn't persist the field selection model", ex); //$NON-NLS-1$
- // }
-
- layoutGenerator.setGenerator(generator);
-
- for(View view : context.getViews()) {
- if(view.getConstraints().size() == 0) {
- continue;
- }
+ for(Context context : contexts) {
+ Tab defaultTab = ContextsFactory.eINSTANCE.createTab();
+ defaultTab.setId(context.getName().toLowerCase());
+ defaultTab.setLabel(context.getName());
+ defaultTab.setPriority(100);
+ context.getTabs().add(defaultTab);
+
+ FieldSelection fieldSelection = selectFieldsPage.getFieldSelection();
+
+ // URI contextURI = context.eResource().getURI();
+ // Resource selectionResource = context.eResource().getResourceSet().createResource(URI.createURI(context.getName() + "FieldSelection.xmi").resolve(contextURI)); //$NON-NLS-1$
+ // selectionResource.getContents().add(fieldSelection);
+ // try {
+ // selectionResource.save(null);
+ // } catch (IOException ex) {
+ // Activator.log.error("Couldn't persist the field selection model", ex); //$NON-NLS-1$
+ // }
+
+ layoutGenerator.setGenerator(generator);
+
+ for(View view : context.getViews()) {
+ if(view.getConstraints().size() == 0) {
+ continue;
+ }
- List<PropertyEditor> editors = new LinkedList<PropertyEditor>();
-
- for(DataContextElement element : getAllContextElements(view.getDatacontexts())) {
- for(Property property : element.getProperties()) {
- if(isSelected(fieldSelection, property, view.getElementMultiplicity() != 1)) {
- PropertyEditor editor = UiFactory.eINSTANCE.createPropertyEditor();
- editor.setProperty(property);
- editor.setWidgetType(configManager.getDefaultEditorType(property));
- editors.add(editor);
- ValueAttribute input = UiFactory.eINSTANCE.createValueAttribute();
- input.setName("input"); //$NON-NLS-1$
- input.setValue("{Binding}"); //$NON-NLS-1$
- editor.getAttributes().add(input);
+ List<PropertyEditor> editors = new LinkedList<PropertyEditor>();
+
+ for(DataContextElement element : getAllContextElements(view.getDatacontexts())) {
+ for(Property property : element.getProperties()) {
+ if(isSelected(fieldSelection, property, view.getElementMultiplicity() != 1)) {
+ PropertyEditor editor = UiFactory.eINSTANCE.createPropertyEditor();
+ editor.setProperty(property);
+ editor.setWidgetType(configManager.getDefaultEditorType(property));
+ editors.add(editor);
+ ValueAttribute input = UiFactory.eINSTANCE.createValueAttribute();
+ input.setName("input"); //$NON-NLS-1$
+ input.setValue("{Binding}"); //$NON-NLS-1$
+ editor.getAttributes().add(input);
+ }
}
}
- }
- List<Section> generatedSections = layoutGenerator.layoutElements(editors, view);
- defaultTab.getSections().addAll(generatedSections);
- view.getSections().addAll(generatedSections);
- context.getViews().add(view);
- }
-
- int i = 1;
- for(Tab tab : context.getTabs()) {
- i += tab.getSections().size();
- }
- final int numberOfSections = i;
- try {
- setNeedsProgressMonitor(true);
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- monitor.beginTask(Messages.CreateContextWizard_propertyViewGenerationJobName + context.getName(), numberOfSections + 1);
- monitor.worked(1);
-
- try {
- context.eResource().save(Collections.EMPTY_MAP);
+ List<Section> generatedSections = layoutGenerator.layoutElements(editors, view);
+ defaultTab.getSections().addAll(generatedSections);
+ view.getSections().addAll(generatedSections);
+ context.getViews().add(view);
+ }
+ int i = 1;
+ for(Tab tab : context.getTabs()) {
+ i += tab.getSections().size();
+ }
+ final int numberOfSections = i;
+ try {
+ setNeedsProgressMonitor(true);
+ final Context currentContext = context;
+ getContainer().run(true, true, new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ monitor.beginTask(Messages.CreateContextWizard_propertyViewGenerationJobName + currentContext.getName(), numberOfSections + 1);
monitor.worked(1);
- for(Tab tab : context.getTabs()) {
- for(Section section : tab.getSections()) {
- if(monitor.isCanceled()) {
- return;
+
+ try {
+ currentContext.eResource().save(Collections.EMPTY_MAP);
+
+ monitor.worked(1);
+ for(Tab tab : currentContext.getTabs()) {
+ for(Section section : tab.getSections()) {
+ if(monitor.isCanceled()) {
+ return;
+ }
+ section.getWidget().eResource().save(Collections.EMPTY_MAP);
+ monitor.worked(1);
}
- section.getWidget().eResource().save(Collections.EMPTY_MAP);
- monitor.worked(1);
}
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ return;
}
- } catch (IOException ex) {
- Activator.log.error(ex);
- return;
+ monitor.done();
}
- monitor.done();
- }
- });
- } catch (InvocationTargetException ex) {
- Activator.log.error(ex);
- } catch (InterruptedException ex) {
- Activator.log.error(ex);
+ });
+ } catch (InvocationTargetException ex) {
+ Activator.log.error(ex);
+ } catch (InterruptedException ex) {
+ Activator.log.error(ex);
+ }
+
}
return true;
@@ -206,7 +210,7 @@ public class CreateContextWizard extends Wizard implements INewWizard {
return false;
}
- PropertyDefinition getPropertyDefinition(FieldSelection fieldSelection, Property property) {
+ protected PropertyDefinition getPropertyDefinition(FieldSelection fieldSelection, Property property) {
List<String> propertyPath = getPropertyPath(property.getContextElement());
if(propertyPath.isEmpty()) {
return null;
@@ -218,6 +222,7 @@ public class CreateContextWizard extends Wizard implements INewWizard {
currentElement = contextRoot;
}
}
+
propertyPath.remove(0);
if(currentElement == null) {
return null;
@@ -238,7 +243,7 @@ public class CreateContextWizard extends Wizard implements INewWizard {
return null;
}
- ContextElement findByName(ContextElement source, String name) {
+ protected ContextElement findByName(ContextElement source, String name) {
for(ContextElement element : source.getElements()) {
if(element.getName().equals(name)) {
return element;
@@ -247,7 +252,7 @@ public class CreateContextWizard extends Wizard implements INewWizard {
return null;
}
- List<String> getPropertyPath(DataContextElement element) {
+ protected List<String> getPropertyPath(DataContextElement element) {
List<String> result;
if(element.getPackage() == null) {
result = new LinkedList<String>();
@@ -287,13 +292,15 @@ public class CreateContextWizard extends Wizard implements INewWizard {
}
- void setGenerator(IGenerator generator) {
+ protected void setGenerator(IGenerator generator) {
this.generator = generator;
generatorPage.setGenerator(generator);
}
- void setContext(Context context) {
- this.context = context;
+ protected void setContexts(List<Context> contexts) {
+ if(!contexts.isEmpty()) {
+ this.contexts = contexts;
+ }
}
/**
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/SelectFieldsPage.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/SelectFieldsPage.java
index e2c7b3957f7..dd211d42082 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/SelectFieldsPage.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/SelectFieldsPage.java
@@ -11,6 +11,8 @@
*****************************************************************************/
package org.eclipse.papyrus.customization.properties.generation.wizard;
+import java.util.List;
+
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.databinding.EMFProperties;
@@ -50,7 +52,7 @@ public class SelectFieldsPage extends AbstractCreateContextPage {
private URI targetURI;
- private Context context;
+ private List<Context> contexts;
private Composite root;
@@ -81,17 +83,17 @@ public class SelectFieldsPage extends AbstractCreateContextPage {
* @param context
* The partially generated context
*/
- public void setContext(Context context) {
- if(context == null) {
+ public void setContexts(List<Context> contexts) {
+ if(contexts == null || contexts.isEmpty()) {
Activator.log.warn("Generated context is null"); //$NON-NLS-1$
return;
}
- this.context = context;
+ this.contexts = contexts;
fieldSelection = createNewFieldSelection();
- getWizard().setContext(context);
+ getWizard().setContexts(contexts);
Label label = new Label(root, SWT.NONE);
label.setText(Messages.SelectFieldsPage_availableFields);
@@ -119,8 +121,10 @@ public class SelectFieldsPage extends AbstractCreateContextPage {
selectionMultiple.setText(Messages.SelectFieldsPage_displayMultiple);
descriptionLabel.setText(Messages.SelectFieldsPage_description);
- for(DataContextRoot dataContextRoot : context.getDataContexts()) {
- displayFields(dataContextRoot);
+ for(Context context : contexts) {
+ for(DataContextRoot dataContextRoot : context.getDataContexts()) {
+ displayFields(dataContextRoot);
+ }
}
fields.setSize(fields.computeSize(SWT.DEFAULT, SWT.DEFAULT));
@@ -133,9 +137,11 @@ public class SelectFieldsPage extends AbstractCreateContextPage {
private FieldSelection createNewFieldSelection() {
FieldSelection selection = FieldSelectionFactory.eINSTANCE.createFieldSelection();
- for(DataContextRoot dataContextRoot : context.getDataContexts()) {
- ContextElement definition = createContextPackage(dataContextRoot);
- selection.getContextElements().add(definition);
+ for(Context context : contexts) {
+ for(DataContextRoot dataContextRoot : context.getDataContexts()) {
+ ContextElement definition = createContextPackage(dataContextRoot);
+ selection.getContextElements().add(definition);
+ }
}
return selection;
@@ -256,8 +262,8 @@ public class SelectFieldsPage extends AbstractCreateContextPage {
public void setVisible(boolean visible) {
super.setPageComplete(true);
super.setVisible(visible);
- if(context == null && visible) {
- setContext(getWizard().generator.generate(targetURI));
+ if(contexts == null && visible) {
+ setContexts(getWizard().generator.generate(targetURI));
}
}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/transforms/profile2datacontext.qvto b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/transforms/profile2datacontext.qvto
index 3e174222e00..8bf467e21b2 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/transforms/profile2datacontext.qvto
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/transforms/profile2datacontext.qvto
@@ -10,93 +10,114 @@ main() {
profile.rootObjects()[Profile]->map toContext();
}
-mapping Profile::toContext() : c:Context, root:DataContextRoot{
- object c : Context {
- name := self.name;
- dataContexts := root;
- dependencies := uml.rootObjects()[Context];
- };
-
- self.packagedElement->select(e | e.isView())->map toDataContextElement();
-
- object root : DataContextRoot{
- name := self.name;
- label := self.name;
- elements := self.packagedElement->select(e | e.isView())->map toDataContextElement().element
- ->union(self.packagedElement->select(e | e.oclIsKindOf(Package))->map toDataContextPackage());
- modelElementFactory := pRoot.rootObjects()[PropertiesRoot].environments.modelElementFactories
- ->any(e | e.factoryClass = 'org.eclipse.papyrus.uml.properties.modelelement.StereotypeModelElementFactory');
- };
+----- Context -----
+
+mapping Package::toContext() : Context{
+ name := self.name;
+ dataContexts := self.map toDCRoot();
+ dependencies := uml.rootObjects()[Context];
+ self.getClassifiers()->map toDCElement();
}
-query Element::isView() : Boolean {
- return self.oclIsTypeOf(Stereotype) or self.oclIsTypeOf(DataType);
+query Package::getRootPackage() : Package {
+ var package : Package;
+ if self.nestingPackage.oclIsUndefined() then
+ package := self
+ else
+ package := self.nestingPackage.getRootPackage()
+ endif;
+ return package;
}
-abstract mapping Element::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View;
+query Classifier::getRootPackage() : Package {
+ return self.package.getRootPackage();
+}
-abstract mapping PackageableElement::toDataContextPackage() : DataContextPackage {
- name := self.name;
+query Package::getClassifiers() : Collection(Classifier) {
+ return self.packagedElement->select(e | e.isView()).oclAsType(Classifier);
}
-mapping Package::toDataContextPackage() : DataContextPackage inherits PackageableElement::toDataContextPackage{
- elements := self.packagedElement->map toDataContextElement().element->union(
- self.packagedElement->select(e | e.oclIsKindOf(Package))->map toDataContextPackage()
+-------------------
+
+----- DataContextPackage & DataContextRoot -------
+
+mapping Package::toDCPackage() : DataContextPackage disjuncts
+ Package::toDataContextPackage, Package::toDCRoot;
+
+abstract mapping Package::toAbstractDCPackage() : DataContextPackage {
+ name := self.name;
+ elements := self.getClassifiers().map toDCElement().element->union(
+ self.packagedElement->select(e | e.oclIsKindOf(Package)).oclAsType(Package)->map toDataContextPackage()
);
}
-abstract mapping Classifier::toDCElement() : element : DataContextElement, viewSingle : View, viewMultiple : View {
+mapping Package::toDataContextPackage() : DataContextPackage inherits Package::toAbstractDCPackage when {
+ not self.nestingPackage.oclIsUndefined()
+}{
+ if not self.nestingPackage.oclIsUndefined() then
+ package := self.nestingPackage.map toDataContextPackage()
+ endif;
+}
+
+mapping Package::toDCRoot() : DataContextRoot disjuncts Model::toDataContextRoot, Profile::toDatacontextRoot when {
+ self.nestingPackage.oclIsUndefined();
+};
+
+mapping Model::toDataContextRoot() : DataContextRoot inherits Package::toAbstractDCPackage {
+ modelElementFactory := findFactory('org.eclipse.papyrus.uml.properties.modelelement.UMLModelElementFactory');
+}
+
+mapping Profile::toDatacontextRoot() : DataContextRoot inherits Package::toAbstractDCPackage{
+ modelElementFactory := findFactory('org.eclipse.papyrus.uml.properties.modelelement.StereotypeModelElementFactory');
+}
+
+query findFactory(className : String) : ModelElementFactoryDescriptor {
+ return pRoot.rootObjects()[PropertiesRoot].environments.modelElementFactories
+ ->any(e | e.factoryClass = className);
+}
+
+--------------------------------------------------
+
+----- DataContextElement & View -------
+
+mapping Classifier::toDCElement() : element : DataContextElement, viewSingle : View, viewMultiple : View
+ disjuncts Stereotype::toDataContextElement, DataType::toDataContextElement;
+
+abstract mapping Classifier::toAbstractDCElement() : element : DataContextElement, viewSingle : View, viewMultiple : View{
element.name := self.name;
+ element.package := self.package.map toDCPackage();
viewSingle.name := 'Single '+self.name;
viewSingle.automaticContext := true;
viewSingle.datacontexts := element;
viewSingle.elementMultiplicity := 1;
viewSingle.constraints := self.map toConstraint(viewSingle);
- viewSingle.context := self.getContext();
+ viewSingle.context := self.getRootPackage().map toContext();
viewMultiple.name := 'Multiple '+self.name;
viewMultiple.automaticContext := true;
viewMultiple.datacontexts := element;
viewMultiple.elementMultiplicity := -1;
viewMultiple.constraints := self.map toConstraint(viewMultiple);
- viewMultiple.context := self.getContext();
+ viewMultiple.context := self.getRootPackage().map toContext();
}
-mapping Stereotype::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View inherits Classifier::toDCElement{
+mapping Stereotype::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View inherits Classifier::toAbstractDCElement{
element.properties := self.attribute->select(e | e.isAttribute(self))->map toProperty();
- element.supertypes := self.generalization.target->map toDataContextElement().element->union(
+ element.supertypes := self.generalization.target->select(e | e.isView()).oclAsType(Classifier)->map toDCElement().element->union(
self.ownedAttribute->select(e | not e.isAttribute(self)).getDataContextElement()->asSet()
);
}
-mapping DataType::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View inherits Classifier::toDCElement when {
+mapping DataType::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View inherits Classifier::toAbstractDCElement when {
self.oclIsTypeOf(DataType) -- Exclude primitive types from generation
}{
element.properties := self.attribute->map toProperty();
- element.supertypes := self.generalization.target->map toDataContextElement().element->union(
+ element.supertypes := self.generalization.target->select(e | e.isView()).oclAsType(Classifier)->map toDCElement().element->union(
self.ownedAttribute->getDataContextElement()->asSet()
);
}
-query Package::getRootPackage() : Package {
- var package : Package;
- if self.nestingPackage.oclIsUndefined() then
- package := self
- else
- package := self.nestingPackage.getRootPackage()
- endif;
- return package;
-}
-
-query Classifier::getRootProfile() : Profile {
- return self.package.getRootPackage().oclAsType(Profile);
-}
-
-query Classifier::getContext() : PropertyContext::Context {
- return self.getRootProfile().map toContext().c;
-}
-
mapping Classifier::toConstraint(view : View) : SimpleConstraint{
name := "is" + view.name.replace(' ', '');
display := view;
@@ -108,6 +129,10 @@ mapping Classifier::toConstraint(view : View) : SimpleConstraint{
properties := stereotypeName;
}
+query Element::isView() : Boolean {
+ return self.oclIsTypeOf(Stereotype) or self.oclIsTypeOf(DataType);
+}
+
query Property::getDataContextElement() : DataContextElement {
var extension := self.association.memberEnd->any(e | not self.association.ownedEnd->includes(e));
var metaclassName := extension.type.name;
@@ -118,12 +143,18 @@ query UML::Property::isAttribute(stereo : Stereotype) : Boolean{
return not self.name.startsWith('base_');
}
+---------------------------------------
+
mapping UML::Property::toProperty() : PropertyContext::Property {
name := self.name;
- type := self.type.toType();
+ type := self.type.getType();
+
+ if self.type.isView() then
+ self.type.oclAsType(Classifier).map toDCElement()
+ endif;
}
-query UML::Type::toType() : PropertyEnvironment::Type {
+query UML::Type::getType() : PropertyEnvironment::Type {
-- Unknown cases are handled as Strings
var type : PropertyEnvironment::Type := PropertyEnvironment::Type::String;
switch {

Back to the top