Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-01-30 11:44:16 -0500
committercletavernie2012-01-30 11:44:16 -0500
commitb7c441f5b9da67a2e3042efcddf835e3e0983fb2 (patch)
tree56171517b252afa1225e1daf196cb8f9e365f753 /plugins/customization
parent985a219a13e0f4494a090ae07a70da072e69072e (diff)
downloadorg.eclipse.papyrus-b7c441f5b9da67a2e3042efcddf835e3e0983fb2.tar.gz
org.eclipse.papyrus-b7c441f5b9da67a2e3042efcddf835e3e0983fb2.tar.xz
org.eclipse.papyrus-b7c441f5b9da67a2e3042efcddf835e3e0983fb2.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
Diffstat (limited to 'plugins/customization')
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/META-INF/MANIFEST.MF3
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml3
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/generators/ProfileGenerator.java49
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ILayoutGenerator.java11
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ProfileWithDatatypes.java262
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/StandardLayoutGenerator.java136
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/CreateContextWizard.java57
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/GeneratorPage.java21
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/transforms/profile2datacontext.qvto65
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties/Model/custom.querySet4
10 files changed, 464 insertions, 147 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/META-INF/MANIFEST.MF b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/META-INF/MANIFEST.MF
index b10703628c3..f674044f8bf 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/META-INF/MANIFEST.MF
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/META-INF/MANIFEST.MF
@@ -26,7 +26,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.6.1",
org.eclipse.core.databinding.property;bundle-version="1.3.0",
org.eclipse.papyrus.customization.properties.model.xwt;bundle-version="0.9.0",
org.eclipse.papyrus.infra.tools;bundle-version="0.9.0",
- org.eclipse.papyrus.infra.constraints;bundle-version="0.9.0"
+ org.eclipse.papyrus.infra.constraints;bundle-version="0.9.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.9.0"
Bundle-Vendor: %Bundle-Vendor
Bundle-Version: 0.9.0.qualifier
Bundle-ManifestVersion: 2
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml
index 3fc210e5138..4bfda9f5c9c 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml
@@ -35,6 +35,9 @@
<generator
generator="org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator">
</generator>
+ <generator
+ generator="org.eclipse.papyrus.customization.properties.generation.layout.ProfileWithDatatypes">
+ </generator>
</extension>
</plugin>
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 76cfae4e0ee..ff54c23e494 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,12 +19,12 @@ import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EPackage;
import org.eclipse.m2m.qvt.oml.BasicModelExtent;
import org.eclipse.m2m.qvt.oml.ModelExtent;
import org.eclipse.papyrus.customization.properties.generation.Activator;
import org.eclipse.papyrus.customization.properties.generation.messages.Messages;
import org.eclipse.papyrus.customization.properties.generation.wizard.widget.FileChooser;
+import org.eclipse.papyrus.views.properties.contexts.Context;
import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
import org.eclipse.papyrus.views.properties.contexts.Property;
import org.eclipse.papyrus.views.properties.root.PropertiesRoot;
@@ -34,13 +34,12 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PrimitiveType;
import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.UMLPackage;
/**
* An IGenerator for building Contexts from a UML Profile
@@ -87,16 +86,20 @@ public class ProfileGenerator extends AbstractQVTGenerator {
try {
URI profileURI = URI.createPlatformResourceURI(sourceFileChooser.getFilePath(), true);
umlProfile = (Profile)loadEMFModel(profileURI);
- ModelExtent inPackage = new BasicModelExtent(Collections.singletonList(umlProfile));
+ ModelExtent inProfile = new BasicModelExtent(Collections.singletonList(umlProfile));
- EPackage umlPackage = UMLPackage.eINSTANCE;
- ModelExtent inUml = new BasicModelExtent(Collections.singletonList(umlPackage));
+ URI umlURI = URI.createURI("ppe:/context/org.eclipse.papyrus.uml.properties/Model/UML/UML.ctx", true);
+ Context umlContext = (Context)loadEMFModel(umlURI);
+ if(umlContext == null) {
+ Activator.log.warn("Cannot find the UML Property View configuration");
+ }
+ ModelExtent inUml = new BasicModelExtent(Collections.singletonList(umlContext));
PropertiesRoot root = ConfigurationManager.instance.getPropertiesRoot();
ModelExtent inRoot = new BasicModelExtent(Collections.singletonList(root));
LinkedList<ModelExtent> result = new LinkedList<ModelExtent>();
- result.add(inPackage);
+ result.add(inProfile);
result.add(getOutContextExtent());
result.add(inUml);
result.add(inRoot);
@@ -115,27 +118,27 @@ public class ProfileGenerator extends AbstractQVTGenerator {
}
/**
- * Retrieve the Stereotype corresponding to the given path, in the given Package
+ * Retrieve the Classifier corresponding to the given path, in the given Package
*
* @param path
- * The list of package and subpackages names, and the stereotype name, i.e.
- * the list of segments in the stereotype's qualified name
+ * 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
* The root Package in which the stereotype should be retrieved
* @return
- * The corresponding Stereotype, or null if it couldn't be retrieved
+ * The corresponding Classifier, or null if it couldn't be retrieved
*/
- protected Stereotype findStereotype(List<String> path, Package profilePackage) {
+ protected Classifier findClassifier(List<String> path, Package profilePackage) {
NamedElement element = profilePackage.getOwnedMember(path.get(0));
path.remove(0);
if(path.size() == 0) {
- if(element instanceof Stereotype) {
- return (Stereotype)element;
+ if(element instanceof Classifier) {
+ return (Classifier)element;
}
} else {
if(element instanceof Package) {
- return findStereotype(path, (Package)element);
+ return findClassifier(path, (Package)element);
}
}
return null;
@@ -164,14 +167,15 @@ public class ProfileGenerator extends AbstractQVTGenerator {
* @param property
* @return
*/
- protected org.eclipse.uml2.uml.Property getAttribute(Property property) {
+ 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
- Stereotype stereotype = findStereotype(path, umlProfile);
- if(stereotype == null)
+ Classifier classifier = findClassifier(path, umlProfile);
+ if(classifier == null) {
return null;
+ }
- org.eclipse.uml2.uml.Property attribute = stereotype.getOwnedAttribute(property.getName(), null);
+ org.eclipse.uml2.uml.Property attribute = classifier.getAttribute(property.getName(), null);
return attribute;
}
@@ -202,9 +206,8 @@ public class ProfileGenerator extends AbstractQVTGenerator {
Set<String> validDataTypes = new HashSet<String>(Arrays.asList(new String[]{ "Integer", "Boolean", "Float", "Double" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- if(attribute.getType() instanceof DataType) {
- if(validDataTypes.contains(((DataType)attribute.getType()).getName()))
- return true;
+ if(attribute.getType() instanceof PrimitiveType) {
+ return validDataTypes.contains(((PrimitiveType)attribute.getType()).getName());
}
if(attribute.getType() instanceof Enumeration) {
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ILayoutGenerator.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ILayoutGenerator.java
index 6a1a7f2ab94..930dae9353a 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ILayoutGenerator.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ILayoutGenerator.java
@@ -13,6 +13,7 @@ package org.eclipse.papyrus.customization.properties.generation.layout;
import java.util.List;
+import org.eclipse.papyrus.customization.properties.generation.generators.IGenerator;
import org.eclipse.papyrus.views.properties.contexts.Section;
import org.eclipse.papyrus.views.properties.contexts.View;
import org.eclipse.papyrus.views.properties.ui.PropertyEditor;
@@ -43,4 +44,14 @@ public interface ILayoutGenerator {
* @return the name of the Layout generator
*/
public String getName();
+
+ /**
+ * Sets the generator used to generate the Property view configuration
+ *
+ * @param generator
+ */
+ //TODO : This method has been added for a specific case (Profile layout).
+ //It should be removed when we have a better way to retrieve the source
+ //profile
+ public void setGenerator(IGenerator generator);
}
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
new file mode 100644
index 00000000000..6dee47e268d
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/ProfileWithDatatypes.java
@@ -0,0 +1,262 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.customization.properties.generation.layout;
+
+import java.util.List;
+
+import org.eclipse.papyrus.customization.properties.generation.Activator;
+import org.eclipse.papyrus.customization.properties.generation.generators.IGenerator;
+import org.eclipse.papyrus.customization.properties.generation.generators.ProfileGenerator;
+import org.eclipse.papyrus.views.properties.contexts.Context;
+import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
+import org.eclipse.papyrus.views.properties.contexts.DataContextPackage;
+import org.eclipse.papyrus.views.properties.contexts.DataContextRoot;
+import org.eclipse.papyrus.views.properties.contexts.Property;
+import org.eclipse.papyrus.views.properties.contexts.View;
+import org.eclipse.papyrus.views.properties.environment.CompositeWidgetType;
+import org.eclipse.papyrus.views.properties.environment.Environment;
+import org.eclipse.papyrus.views.properties.environment.LayoutType;
+import org.eclipse.papyrus.views.properties.environment.PropertyEditorType;
+import org.eclipse.papyrus.views.properties.environment.Type;
+import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager;
+import org.eclipse.papyrus.views.properties.ui.CompositeWidget;
+import org.eclipse.papyrus.views.properties.ui.Layout;
+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.UMLPackage;
+
+
+public class ProfileWithDatatypes extends StandardLayoutGenerator {
+
+ protected IGenerator generator;
+
+ @Override
+ protected void sortEditors(List<PropertyEditor> editors) {
+ for(PropertyEditor editor : editors) {
+ Category category = new TypeCategory(editor.getProperty());
+ getByCategory(category).add(editor);
+
+ if(editor.getWidgetType() == null) {
+ Activator.log.warn(String.format("Editor for property %s doesn't have a WidgetType", editor.getProperty().getName())); //$NON-NLS-1$
+ continue;
+ }
+
+ namespaces.add(editor.getWidgetType().getNamespace());
+ }
+ }
+
+ @Override
+ protected CompositeWidget layoutCategorizedEditors(Category category, List<PropertyEditor> editors) {
+ if(((TypeCategory)category).isDatatype) {
+ CompositeWidgetType compositeType = ConfigurationManager.instance.getDefaultCompositeType();
+
+ CompositeWidget container = UiFactory.eINSTANCE.createCompositeWidget();
+ container.setWidgetType(compositeType);
+
+ Layout layout = createLayout(category.getNumColumns());
+ container.setLayout(layout);
+
+ for(PropertyEditor editor : editors) {
+ CompositeWidget group = createDataTypeGroup(editor.getProperty());
+
+ PropertyEditor viewEditor = UiFactory.eINSTANCE.createPropertyEditor();
+ viewEditor.setWidgetType(getViewEditor());
+ viewEditor.setProperty(editor.getProperty());
+
+ ValueAttribute view = UiFactory.eINSTANCE.createValueAttribute();
+ view.setName("view");
+ view.setValue(getViewName(editor.getProperty()));
+ viewEditor.getAttributes().add(view);
+
+ group.getWidgets().add(viewEditor);
+ container.getWidgets().add(group);
+ }
+
+ return container;
+ }
+
+ return super.layoutCategorizedEditors(category, editors);
+ }
+
+ protected String getViewName(Property property) {
+ 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();
+ }
+
+ protected Context findContext(Property property) {
+ DataContextElement element = property.getContextElement();
+ if(element instanceof DataContextRoot) {
+ //TODO : Add a container reference to Context
+ return (Context)element.eContainer();
+ }
+
+ return findContext(element);
+ }
+
+ protected Context findContext(DataContextElement element) {
+ DataContextPackage dataContextPackage = element.getPackage();
+ if(dataContextPackage instanceof DataContextRoot) {
+ return (Context)dataContextPackage.eContainer();
+ }
+ return findContext(dataContextPackage);
+ }
+
+ protected String getQualifiedName(View view) {
+ return view.getContext().getName() + ":" + view.getName();
+ }
+
+ protected CompositeWidget createDataTypeGroup(Property property) {
+ CompositeWidgetType groupType = getGroupComposite();
+ CompositeWidget group = UiFactory.eINSTANCE.createCompositeWidget();
+ group.setWidgetType(groupType);
+
+ ValueAttribute text = UiFactory.eINSTANCE.createValueAttribute();
+ text.setName("text");
+ text.setValue(PropertiesUtil.getLabel(property));
+
+ group.getAttributes().add(text);
+
+ Layout layout = createLayout(1);
+ group.setLayout(layout);
+
+ return group;
+ }
+
+ protected Layout createLayout(Integer columns) {
+ LayoutType propertiesLayoutType = ConfigurationManager.instance.getDefaultLayoutType();
+
+ Layout layout = UiFactory.eINSTANCE.createLayout();
+ ValueAttribute numColumns = UiFactory.eINSTANCE.createValueAttribute();
+ numColumns.setName("numColumns"); //$NON-NLS-1$
+ numColumns.setValue(columns.toString());
+
+ layout.getAttributes().add(numColumns);
+ layout.setLayoutType(propertiesLayoutType);
+
+ return layout;
+ }
+
+ protected CompositeWidgetType getGroupComposite() {
+ for(Environment environment : ConfigurationManager.instance.getPropertiesRoot().getEnvironments()) {
+ for(CompositeWidgetType widgetType : environment.getCompositeWidgetTypes()) {
+ if(widgetType.getNamespace() == null && widgetType.getWidgetClass().equals("Group")) {
+ return widgetType;
+ }
+ }
+ }
+
+ Activator.log.warn("Cannot find the Group composite type");
+ return ConfigurationManager.instance.getDefaultCompositeType();
+ }
+
+ protected PropertyEditorType getViewEditor() {
+ for(Environment environment : ConfigurationManager.instance.getPropertiesRoot().getEnvironments()) {
+ for(PropertyEditorType widgetType : environment.getPropertyEditorTypes()) {
+ if(widgetType.getNamespace() != null && "ppe".equals(widgetType.getNamespace().getName()) && widgetType.getWidgetClass().equals("ViewEditor")) {
+ return widgetType;
+ }
+ }
+ }
+
+ Activator.log.warn("Cannot find the Group composite type");
+ return ConfigurationManager.instance.getDefaultEditorType(Type.STRING, false);
+ }
+
+ @Override
+ public void setGenerator(IGenerator generator) {
+ this.generator = generator;
+ }
+
+ protected class TypeCategory extends Category {
+
+ protected boolean isDatatype;
+
+ public TypeCategory(Property property) {
+ super(property);
+ org.eclipse.uml2.uml.Property attribute = resolveProperty(property);
+ if(attribute != null) {
+ isDatatype = attribute.getType().eClass() == UMLPackage.eINSTANCE.getDataType();
+ }
+ }
+
+ protected org.eclipse.uml2.uml.Property resolveProperty(Property property) {
+ //TODO : We should not have to rely on the IGenerator to retrieve the property...
+ if(generator instanceof ProfileGenerator) {
+ ProfileGenerator profileGenerator = (ProfileGenerator)generator;
+ return profileGenerator.getAttribute(property);
+ }
+
+ return null;
+ }
+
+ @Override
+ public Integer getNumColumns() {
+ if(isDatatype) {
+ return 1;
+ }
+ return super.getNumColumns();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + (isDatatype ? 1231 : 1237);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj) {
+ return true;
+ }
+ if(!super.equals(obj)) {
+ return false;
+ }
+ if(!(obj instanceof TypeCategory)) {
+ return false;
+ }
+ TypeCategory other = (TypeCategory)obj;
+ if(!getOuterType().equals(other.getOuterType())) {
+ return false;
+ }
+ if(isDatatype != other.isDatatype) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public Integer getTypeIndex() {
+ if(isDatatype) {
+ return orderedTypes.length + 1;
+ }
+ return super.getTypeIndex();
+ }
+
+ private ProfileWithDatatypes getOuterType() {
+ return ProfileWithDatatypes.this;
+ }
+ }
+
+ @Override
+ public String getName() {
+ return "UML Profile with DataTypes";
+ }
+}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/StandardLayoutGenerator.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/StandardLayoutGenerator.java
index 1c657282f16..48f6a4786a5 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/StandardLayoutGenerator.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/StandardLayoutGenerator.java
@@ -23,6 +23,7 @@ import java.util.TreeMap;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.papyrus.customization.properties.generation.Activator;
+import org.eclipse.papyrus.customization.properties.generation.generators.IGenerator;
import org.eclipse.papyrus.customization.properties.generation.messages.Messages;
import org.eclipse.papyrus.views.properties.contexts.ContextsFactory;
import org.eclipse.papyrus.views.properties.contexts.Property;
@@ -51,37 +52,87 @@ import org.eclipse.papyrus.views.properties.util.PropertiesUtil;
*/
public class StandardLayoutGenerator implements ILayoutGenerator {
- private TreeMap<Category, List<PropertyEditor>> editorsByCategory = new TreeMap<Category, List<PropertyEditor>>();
+ protected final TreeMap<Category, List<PropertyEditor>> editorsByCategory = new TreeMap<Category, List<PropertyEditor>>();
- public List<Section> layoutElements(List<PropertyEditor> editors, View parent) {
+ protected final Set<Namespace> namespaces = new HashSet<Namespace>();
+
+ public synchronized List<Section> layoutElements(List<PropertyEditor> editors, View parent) {
editorsByCategory.clear();
+ namespaces.clear();
+
+ namespaces.addAll(ConfigurationManager.instance.getBaseNamespaces());
+
+ sortEditors(editors);
+
+ Section section = createSection(parent);
+
+ for(Map.Entry<Category, List<PropertyEditor>> mapping : editorsByCategory.entrySet()) {
+ Category category = mapping.getKey();
+ List<PropertyEditor> categorizedEditors = mapping.getValue();
+
+ CompositeWidget container = layoutCategorizedEditors(category, categorizedEditors);
+
+ section.getWidget().getWidgets().add(container);
+ }
+
+ return Collections.singletonList(section);
+ }
- Set<Namespace> namespaces = new HashSet<Namespace>(ConfigurationManager.instance.getBaseNamespaces());
+ protected CompositeWidget layoutCategorizedEditors(Category category, List<PropertyEditor> editors) {
+ CompositeWidgetType compositeType = ConfigurationManager.instance.getDefaultCompositeType();
+ LayoutType propertiesLayoutType = ConfigurationManager.instance.getDefaultLayoutType();
+ CompositeWidget container = UiFactory.eINSTANCE.createCompositeWidget();
+ container.setWidgetType(compositeType);
+ Layout layout = UiFactory.eINSTANCE.createLayout();
+ container.setLayout(layout);
+ ValueAttribute numColumns = UiFactory.eINSTANCE.createValueAttribute();
+ numColumns.setName("numColumns"); //$NON-NLS-1$
+ numColumns.setValue(category.getNumColumns().toString());
+ layout.getAttributes().add(numColumns);
+ layout.setLayoutType(propertiesLayoutType);
+ container.getWidgets().addAll(editors);
+
+ return container;
+ }
+
+ protected void sortEditors(List<PropertyEditor> editors) {
for(PropertyEditor editor : editors) {
Category category = new Category(editor.getProperty());
getByCategory(category).add(editor);
+
if(editor.getWidgetType() == null) {
Activator.log.warn(String.format("Editor for property %s doesn't have a WidgetType", editor.getProperty().getName())); //$NON-NLS-1$
- } else {
- namespaces.add(editor.getWidgetType().getNamespace());
+ continue;
}
+
+ namespaces.add(editor.getWidgetType().getNamespace());
}
+ }
- ConfigurationManager configManager = ConfigurationManager.instance;
+ protected Section createSection(View parent) {
+ CompositeWidget sectionRoot = createSectionRoot();
Section section = ContextsFactory.eINSTANCE.createSection();
section.setName(parent.getName());
- section.setSectionFile("ui/" + section.getName().replaceAll(" ", "") + ".xwt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ section.setSectionFile(String.format("ui/%s.xwt", section.getName().replaceAll(" ", ""))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
URI compositeURI = URI.createURI(section.getSectionFile());
compositeURI = compositeURI.resolve(parent.eResource().getURI());
Resource resource = parent.eResource().getResourceSet().createResource(compositeURI);
- CompositeWidgetType compositeType = configManager.getDefaultCompositeType();
+ section.setWidget(sectionRoot);
+
+ resource.getContents().add(sectionRoot);
+
+ return section;
+ }
+
+ protected CompositeWidget createSectionRoot() {
+ CompositeWidgetType compositeType = ConfigurationManager.instance.getDefaultCompositeType();
namespaces.add(compositeType.getNamespace());
- LayoutType propertiesLayoutType = configManager.getDefaultLayoutType();
+ LayoutType propertiesLayoutType = ConfigurationManager.instance.getDefaultLayoutType();
namespaces.add(propertiesLayoutType.getNamespace());
CompositeWidget sectionRoot = UiFactory.eINSTANCE.createCompositeWidget();
@@ -91,31 +142,10 @@ public class StandardLayoutGenerator implements ILayoutGenerator {
sectionRoot.setLayout(layout);
sectionRoot.getAttributes().addAll(createNamespaces(namespaces));
- section.setWidget(sectionRoot);
-
- resource.getContents().add(sectionRoot);
-
- for(Map.Entry<Category, List<PropertyEditor>> mapping : editorsByCategory.entrySet()) {
- Category category = mapping.getKey();
- List<PropertyEditor> categorizedEditors = mapping.getValue();
-
- CompositeWidget container = UiFactory.eINSTANCE.createCompositeWidget();
- container.setWidgetType(compositeType);
- layout = UiFactory.eINSTANCE.createLayout();
- container.setLayout(layout);
- ValueAttribute numColumns = UiFactory.eINSTANCE.createValueAttribute();
- numColumns.setName("numColumns"); //$NON-NLS-1$
- numColumns.setValue(category.getNumColumns().toString());
- layout.getAttributes().add(numColumns);
- layout.setLayoutType(propertiesLayoutType);
- container.getWidgets().addAll(categorizedEditors);
- sectionRoot.getWidgets().add(container);
- }
-
- return Collections.singletonList(section);
+ return sectionRoot;
}
- private List<ValueAttribute> createNamespaces(Collection<Namespace> namespaces) {
+ protected List<ValueAttribute> createNamespaces(Collection<Namespace> namespaces) {
List<ValueAttribute> xmlNamespaces = new LinkedList<ValueAttribute>();
for(Namespace namespace : namespaces) {
if(namespace == null) {
@@ -130,14 +160,14 @@ public class StandardLayoutGenerator implements ILayoutGenerator {
return xmlNamespaces;
}
- private List<PropertyEditor> getByCategory(Category category) {
+ protected List<PropertyEditor> getByCategory(Category category) {
if(!editorsByCategory.containsKey(category)) {
editorsByCategory.put(category, new LinkedList<PropertyEditor>());
}
return editorsByCategory.get(category);
}
- private class Category implements Comparable<Category> {
+ protected class Category implements Comparable<Category> {
public Type editorType;
@@ -166,20 +196,36 @@ public class StandardLayoutGenerator implements ILayoutGenerator {
@Override
public int hashCode() {
- return editorType.hashCode() * multiplicity;
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + ((editorType == null) ? 0 : editorType.hashCode());
+ result = prime * result + multiplicity;
+ return result;
}
@Override
- public boolean equals(Object o) {
- if(o == null) {
+ public boolean equals(Object obj) {
+ if(this == obj) {
+ return true;
+ }
+ if(obj == null) {
return false;
}
- if(!(o instanceof Category)) {
+ if(!(obj instanceof Category)) {
return false;
}
-
- Category category = (Category)o;
- return category.editorType == editorType && category.multiplicity == multiplicity;
+ Category other = (Category)obj;
+ if(!getOuterType().equals(other.getOuterType())) {
+ return false;
+ }
+ if(editorType != other.editorType) {
+ return false;
+ }
+ if(multiplicity != other.multiplicity) {
+ return false;
+ }
+ return true;
}
public int compareTo(Category category) {
@@ -210,6 +256,10 @@ public class StandardLayoutGenerator implements ILayoutGenerator {
public String toString() {
return (multiplicity == 1 ? "Single" : "Multiple") + editorType.toString(); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ private StandardLayoutGenerator getOuterType() {
+ return StandardLayoutGenerator.this;
+ }
}
/**
@@ -220,4 +270,8 @@ public class StandardLayoutGenerator implements ILayoutGenerator {
public String getName() {
return Messages.StandardLayoutGenerator_name;
}
+
+ public void setGenerator(IGenerator generator) {
+ //Ignored
+ }
}
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 65bd1ba114c..e623f837761 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
@@ -21,8 +21,6 @@ import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
@@ -94,30 +92,30 @@ public class CreateContextWizard extends Wizard implements INewWizard {
@Override
public boolean performFinish() {
- if(generator == null || context == null) {
+ if(generator == null || context == null || layoutGenerator == null) {
return false;
}
ConfigurationManager configManager = ConfigurationManager.instance;
Tab defaultTab = ContextsFactory.eINSTANCE.createTab();
- defaultTab.setCategory("default"); //$NON-NLS-1$
- defaultTab.setId("default"); //$NON-NLS-1$
- defaultTab.setLabel("Default"); //$NON-NLS-1$
+ 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$
- }
+ // 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 = layoutGenerators.get(0); //TODO : Use the layoutGenerator combo
+ layoutGenerator.setGenerator(generator);
for(View view : context.getViews()) {
if(view.getConstraints().size() == 0) {
@@ -186,35 +184,6 @@ public class CreateContextWizard extends Wizard implements INewWizard {
} catch (InterruptedException ex) {
Activator.log.error(ex);
}
- // Job job = new Job(Messages.CreateContextWizard_propertyViewGenerationJobName + context.getName()) {
- //
- // @Override
- // protected IStatus run(IProgressMonitor monitor) {
- // monitor.beginTask(getName(), numberOfSections);
- //
- // try {
- // context.eResource().save(Collections.EMPTY_MAP);
- //
- // monitor.worked(1);
- // for(Tab tab : context.getTabs()) {
- // for(Section section : tab.getSections()) {
- // if(monitor.isCanceled()) {
- // return Status.CANCEL_STATUS;
- // }
- // section.getWidget().eResource().save(Collections.EMPTY_MAP);
- // monitor.worked(1);
- // }
- // }
- // } catch (IOException ex) {
- // Activator.log.error(ex);
- // return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CreateContextWizard_propertyViewGenerationError + context.getName(), ex);
- // }
- // return Status.OK_STATUS;
- // }
- // };
- // job.setPriority(Job.INTERACTIVE);
- // job.setUser(true);
- // job.schedule();
return true;
}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/GeneratorPage.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/GeneratorPage.java
index 583e3c67788..ae09e47f834 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/GeneratorPage.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/wizard/GeneratorPage.java
@@ -12,6 +12,7 @@
package org.eclipse.papyrus.customization.properties.generation.wizard;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.papyrus.customization.properties.generation.generators.IGenerator;
import org.eclipse.papyrus.customization.properties.generation.layout.ILayoutGenerator;
import org.eclipse.papyrus.customization.properties.generation.messages.Messages;
@@ -42,6 +43,8 @@ public class GeneratorPage extends AbstractCreateContextPage implements Listener
private FileChooser targetFileChooser;
+ private CCombo layoutCombo;
+
/**
* Constructor.
*/
@@ -93,14 +96,14 @@ public class GeneratorPage extends AbstractCreateContextPage implements Listener
data.widthHint = 100;
layoutGeneratorLabel.setLayoutData(data);
- CCombo layoutGeneratorCombo = new CCombo(root, SWT.BORDER);
- layoutGeneratorCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- layoutGeneratorCombo.setEditable(false);
- layoutGeneratorCombo.setBackground(new Color(layoutGeneratorCombo.getDisplay(), 255, 255, 255));
+ layoutCombo = new CCombo(root, SWT.BORDER);
+ layoutCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ layoutCombo.setEditable(false);
+ layoutCombo.setBackground(new Color(layoutCombo.getDisplay(), 255, 255, 255));
for(ILayoutGenerator layoutGenerator : CreateContextWizard.layoutGenerators) {
- layoutGeneratorCombo.add(layoutGenerator.getName());
+ layoutCombo.add(layoutGenerator.getName());
}
- layoutGeneratorCombo.select(0);
+ layoutCombo.select(0);
Label targetLabel = new Label(root, SWT.NONE);
targetLabel.setText(Messages.GeneratorPage_target);
@@ -123,4 +126,10 @@ public class GeneratorPage extends AbstractCreateContextPage implements Listener
super.getContainer().updateButtons();
}
+ @Override
+ public IWizardPage getNextPage() {
+ int selection = layoutCombo.getSelectionIndex();
+ getWizard().layoutGenerator = CreateContextWizard.layoutGenerators.get(selection);
+ return super.getNextPage();
+ }
}
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 4404fc41dbe..3e174222e00 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
@@ -14,51 +14,40 @@ mapping Profile::toContext() : c:Context, root:DataContextRoot{
object c : Context {
name := self.name;
dataContexts := root;
- views := self.packagedElement->map toDataContextElement().viewSingle->union(
- self.packagedElement->map toDataContextElement().viewMultiple
- );
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.oclIsKindOf(Stereotype))->map toDataContextElement().element
+ 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.views.properties.uml.modelelement.StereotypeModelElementFactory');
+ ->any(e | e.factoryClass = 'org.eclipse.papyrus.uml.properties.modelelement.StereotypeModelElementFactory');
};
}
-mapping Element::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View disjuncts
- Stereotype::toDataContextElement{
+query Element::isView() : Boolean {
+ return self.oclIsTypeOf(Stereotype) or self.oclIsTypeOf(DataType);
}
-mapping PackageableElement::toDataContextPackage() : DataContextPackage disjuncts
- Package::toDataContextPackage, Profile::toDataContextPackage{
-
-}
+abstract mapping Element::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View;
-abstract mapping PackageableElement::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View{
- element.name := self.name;
+abstract mapping PackageableElement::toDataContextPackage() : DataContextPackage {
+ name := self.name;
}
mapping Package::toDataContextPackage() : DataContextPackage inherits PackageableElement::toDataContextPackage{
- name := self.name;
- elements := self.packagedElement->select(e | e.oclIsKindOf(Stereotype))->map toDataContextElement().element->union(
+ elements := self.packagedElement->map toDataContextElement().element->union(
self.packagedElement->select(e | e.oclIsKindOf(Package))->map toDataContextPackage()
);
}
-mapping Profile::toDataContextPackage() : DataContextPackage inherits Package::toDataContextPackage{
-
-}
+abstract mapping Classifier::toDCElement() : element : DataContextElement, viewSingle : View, viewMultiple : View {
+ element.name := self.name;
-mapping Stereotype::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View inherits PackageableElement::toDataContextElement{
- element.properties := self.attribute->select(e | e.isAttribute(self))->map toProperty();
- element.supertypes := self.generalization.target->map toDataContextElement().element->union(
- self.ownedAttribute->select(e | not e.isAttribute(self)).getDataContextElement()->asSet()
- );
-
viewSingle.name := 'Single '+self.name;
viewSingle.automaticContext := true;
viewSingle.datacontexts := element;
@@ -74,6 +63,22 @@ mapping Stereotype::toDataContextElement() : element : DataContextElement, viewS
viewMultiple.context := self.getContext();
}
+mapping Stereotype::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View inherits Classifier::toDCElement{
+ element.properties := self.attribute->select(e | e.isAttribute(self))->map toProperty();
+ element.supertypes := self.generalization.target->map toDataContextElement().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 {
+ self.oclIsTypeOf(DataType) -- Exclude primitive types from generation
+}{
+ element.properties := self.attribute->map toProperty();
+ element.supertypes := self.generalization.target->map toDataContextElement().element->union(
+ self.ownedAttribute->getDataContextElement()->asSet()
+ );
+}
+
query Package::getRootPackage() : Package {
var package : Package;
if self.nestingPackage.oclIsUndefined() then
@@ -84,18 +89,18 @@ query Package::getRootPackage() : Package {
return package;
}
-query Stereotype::getRootProfile() : Profile {
+query Classifier::getRootProfile() : Profile {
return self.package.getRootPackage().oclAsType(Profile);
}
-query Stereotype::getContext() : PropertyContext::Context {
+query Classifier::getContext() : PropertyContext::Context {
return self.getRootProfile().map toContext().c;
}
-mapping Stereotype::toConstraint(view : View) : SimpleConstraint{
+mapping Classifier::toConstraint(view : View) : SimpleConstraint{
name := "is" + view.name.replace(' ', '');
display := view;
- constraintType := pRoot.objectsOfType(PropertiesRoot).environments.constraintTypes->any(e | e.constraintClass = 'org.eclipse.papyrus.views.properties.uml.constraints.HasStereotypeConstraint');
+ constraintType := pRoot.objectsOfType(PropertiesRoot).environments.constraintTypes->any(e | e.constraintClass = 'org.eclipse.papyrus.uml.properties.constraints.HasStereotypeConstraint');
var stereotypeName := object ValueProperty {
name := 'stereotypeName';
value := self.qualifiedName;
@@ -119,6 +124,7 @@ mapping UML::Property::toProperty() : PropertyContext::Property {
}
query UML::Type::toType() : PropertyEnvironment::Type {
+ -- Unknown cases are handled as Strings
var type : PropertyEnvironment::Type := PropertyEnvironment::Type::String;
switch {
case (self.oclIsKindOf(Class)) type := PropertyEnvironment::Type::Reference;
@@ -128,7 +134,6 @@ query UML::Type::toType() : PropertyEnvironment::Type {
case (self.name = "Integer") type := PropertyEnvironment::Type::Integer;
case (self.name = "Boolean") type := PropertyEnvironment::Type::Boolean;
};
-
};
return type;
-} \ No newline at end of file
+}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties/Model/custom.querySet b/plugins/customization/org.eclipse.papyrus.customization.properties/Model/custom.querySet
index 0f70e58f9fb..910d951ec36 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties/Model/custom.querySet
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties/Model/custom.querySet
@@ -7,7 +7,7 @@
<returnType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<scope href="http://www.eclipse.org/papyrus/properties/ui/0.9#//CompositeWidget"/>
</queries>
- <queries xsi:type="query:OCLModelQuery" name="isUmlInstanceOf" description="" lowerBound="1" query="self.constraintType.constraintClass = 'org.eclipse.papyrus.views.properties.uml.constraints.UmlInstanceOfConstraint'">
+ <queries xsi:type="query:OCLModelQuery" name="isUmlInstanceOf" description="" lowerBound="1" query="self.constraintType.constraintClass = 'org.eclipse.papyrus.uml.properties.constraints.UmlInstanceOfConstraint'">
<returnType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<scope href="http://www.eclipse.org/papyrus/constraints/0.9#//ConstraintDescriptor"/>
</queries>
@@ -19,7 +19,7 @@
<returnType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<scope href="http://www.eclipse.org/papyrus/constraints/0.9#//ConstraintDescriptor"/>
</queries>
- <queries xsi:type="query:OCLModelQuery" name="isStereotype" description="" lowerBound="1" query="self.constraintType.constraintClass = 'org.eclipse.papyrus.views.properties.uml.constraints.HasStereotypeConstraint'">
+ <queries xsi:type="query:OCLModelQuery" name="isStereotype" description="" lowerBound="1" query="self.constraintType.constraintClass = 'org.eclipse.papyrus.uml.properties.constraints.HasStereotypeConstraint'">
<returnType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<scope href="http://www.eclipse.org/papyrus/constraints/0.9#//ConstraintDescriptor"/>
</queries>

Back to the top