diff options
author | Ansgar Radermacher | 2018-03-07 14:45:53 +0000 |
---|---|---|
committer | Ansgar Radermacher | 2018-03-07 14:45:53 +0000 |
commit | 782bd293bad76e08c2efb8d56c326fa6df20f1c7 (patch) | |
tree | b45fde810dbb39ec9151351ee6ef39e403ebc1ab /plugins/uml | |
parent | 9a8c10b4eef2304f47e2904d6d95661e7299b224 (diff) | |
download | org.eclipse.papyrus-782bd293bad76e08c2efb8d56c326fa6df20f1c7.tar.gz org.eclipse.papyrus-782bd293bad76e08c2efb8d56c326fa6df20f1c7.tar.xz org.eclipse.papyrus-782bd293bad76e08c2efb8d56c326fa6df20f1c7.zip |
Bug 526156 - [ElementTypes] Generated DI element types contain semantic element types as well
- Lookup semantic element type in the element type registry (i.e. it must already be registered).
(was chiefly already done in https://git.eclipse.org/r/#/c/110360/)
The lookup is based on identifiers and assumes that either the same base identifier as for semantic element creation
is used or the same with a ".di" postfix (which is a good convention) If the semantic element is found, reference it
instead of creating a semantic element type within a DI element types file.
- Automatically add DI popstfix
Signed-off-by: Ansgar Radermacher <ansgar.radermacher@cea.fr>
Change-Id: I843c2aae892e8811ee96cf08d07a7a3af97828eb
Diffstat (limited to 'plugins/uml')
7 files changed, 104 insertions, 14 deletions
diff --git a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/META-INF/MANIFEST.MF b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/META-INF/MANIFEST.MF index e596fdfd48b..2f19c9d4c2b 100644 --- a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/META-INF/MANIFEST.MF +++ b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Require-Bundle: org.eclipse.xtend.lib;bundle-version="[2.10.0,3.0.0)", org.eclipse.papyrus.uml.service.types;bundle-version="[3.0.0,4.0.0)", com.google.inject;bundle-version="[3.0.0,4.0.0)", - org.eclipse.papyrus.uml.profile.types.generator;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.uml.profile.types.generator;bundle-version="[2.1.0,3.0.0)", org.eclipse.papyrus.uml.diagram.wizards;bundle-version="[3.0.0,4.0.0)" Export-Package: org.eclipse.papyrus.uml.profile.types.generator.ui.internal, org.eclipse.papyrus.uml.profile.types.generator.ui.internal.handlers, diff --git a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/BaseElementTypeSetBlock.java b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/BaseElementTypeSetBlock.java index 2205febf5cb..e0b2f8e1d9d 100644 --- a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/BaseElementTypeSetBlock.java +++ b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/BaseElementTypeSetBlock.java @@ -8,7 +8,8 @@ * * Contributors: * Christian W. Damus - Initial API and implementation - * + * Ansgar Radermacher - Bug 526156, add postfix, if generating DI element types + * *****************************************************************************/ package org.eclipse.papyrus.uml.profile.types.generator.ui.internal.wizards; @@ -59,7 +60,14 @@ class BaseElementTypeSetBlock { private static final String SUPPRESS_SEMANTIC_SUPERTYPES = "suppressSemanticSupertypes"; //$NON-NLS-1$ - private static final String UML_ELEMENT_TYPE_SET = "org.eclipse.papyrus.uml.service.types.UMLElementTypeSet"; //$NON-NLS-1$ + /** + * Add a .di postfix, if DI element types are created + */ + private static final String ADD_DI_POSTFIX = "addDiPostfix"; //$NON-NLS-1$ + + protected static final String UML_ELEMENT_TYPE_SET = "org.eclipse.papyrus.uml.service.types.UMLElementTypeSet"; //$NON-NLS-1$ + + protected static final String UMLDI_ELEMENT_TYPE_SET = "org.eclipse.papyrus.umldi.service.types.UMLDIElementTypeSet"; //$NON-NLS-1$ private final GeneratorWizardModel model; @@ -107,7 +115,18 @@ class BaseElementTypeSetBlock { suppressSemanticSuperElementTypes.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, false, false, 2, 1)); suppressSemanticSuperElementTypes.setText("Suppress semantic parent in diagram-specific element types"); suppressSemanticSuperElementTypes.setSelection(model.getDialogSettings().getBoolean(SUPPRESS_SEMANTIC_SUPERTYPES)); - + + final Button addDiPostfix = new Button(parent, SWT.CHECK); + addDiPostfix.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, false, false, 2, 1)); + addDiPostfix.setText("Add .di postfix to identifier in diagram-specific element types"); + if (model.getDialogSettings().get(ADD_DI_POSTFIX) != null) { + addDiPostfix.setSelection(model.getDialogSettings().getBoolean(ADD_DI_POSTFIX)); + } + else { + // set by default + addDiPostfix.setSelection(true); + } + ElementTypeSetConfiguration initialSelection = getInitialSelection(); if (initialSelection != null) { combo.setSelection(new StructuredSelection(initialSelection)); @@ -119,18 +138,30 @@ class BaseElementTypeSetBlock { public void selectionChanged(SelectionChangedEvent event) { elementTypeSetSelectionChanged((IStructuredSelection) event.getSelection()); suppressSemanticSuperElementTypes.setEnabled(!UML_ELEMENT_TYPE_SET.equals(model.getSelectedElementTypeSet())); + addDiPostfix.setEnabled(UMLDI_ELEMENT_TYPE_SET.equals(model.getSelectedElementTypeSet())); model.validatePage(); } }); setSuppressSemanticSupertypes(suppressSemanticSuperElementTypes.getSelection()); suppressSemanticSuperElementTypes.setEnabled(!UML_ELEMENT_TYPE_SET.equals(model.getSelectedElementTypeSet())); + addDiPostfix.setEnabled(UMLDI_ELEMENT_TYPE_SET.equals(model.getSelectedElementTypeSet())); + model.setAddDiPostfix(addDiPostfix.getSelection()); + suppressSemanticSuperElementTypes.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setSuppressSemanticSupertypes(suppressSemanticSuperElementTypes.getSelection()); } }); + + addDiPostfix.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + System.err.println(addDiPostfix.getSelection()); + model.setAddDiPostfix(addDiPostfix.getSelection()); + } + }); } void elementTypeSetSelectionChanged(IStructuredSelection selection) { @@ -152,6 +183,7 @@ class BaseElementTypeSetBlock { void save() { model.getDialogSettings().put(DIAGRAM, model.getSelectedElementTypeSet()); model.getDialogSettings().put(SUPPRESS_SEMANTIC_SUPERTYPES, model.isSuppressSemanticSuperElementTypes()); + model.getDialogSettings().put(ADD_DI_POSTFIX, model.isAddDiPostfix()); } private ElementTypeSetConfiguration getInitialSelection() { diff --git a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/GeneratorWizard.java b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/GeneratorWizard.java index fffcc69f60a..887e4f40865 100644 --- a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/GeneratorWizard.java +++ b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/GeneratorWizard.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015 Christian W. Damus and others. + * Copyright (c) 2015, 2018 Christian W. Damus and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,7 +8,8 @@ * * Contributors: * Christian W. Damus - Initial API and implementation - * + * Ansgar Radermacher - Bug 526156, add postfix, if generating DI element types + * *****************************************************************************/ package org.eclipse.papyrus.uml.profile.types.generator.ui.internal.wizards; @@ -117,7 +118,13 @@ public class GeneratorWizard extends Wizard { IStatus result = Status.OK_STATUS; Identifiers identifiers = new Identifiers(); - identifiers.setPrefix(model.getIdentifier()); + if (model.isAddDiPostfixActive()) { + identifiers.setPrefix(model.getIdentifier() + Identifiers.diPostfix()); + identifiers.setUseDiPostfix(true); + } + else { + identifiers.setPrefix(model.getIdentifier()); + } identifiers.setBaseElementTypesSet(model.getSelectedElementTypeSet()); identifiers.setSuppressSemanticSuperElementTypes(model.isSuppressSemanticSuperElementTypes()); diff --git a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/GeneratorWizardModel.java b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/GeneratorWizardModel.java index 87de2ad54d2..76ab27a1ee9 100644 --- a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/GeneratorWizardModel.java +++ b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator.ui/src/org/eclipse/papyrus/uml/profile/types/generator/ui/internal/wizards/GeneratorWizardModel.java @@ -8,7 +8,8 @@ * * Contributors: * Christian W. Damus - Initial API and implementation - * + * Ansgar Radermacher - Bug 526156, add postfix, if generating DI element types + * *****************************************************************************/ package org.eclipse.papyrus.uml.profile.types.generator.ui.internal.wizards; @@ -49,6 +50,8 @@ public class GeneratorWizardModel { private String fileName; private boolean suppressSemanticSuperElementTypes; + + private boolean addDiPostfix; public GeneratorWizardModel(IWizard owner, Profile profile, IDialogSettings settings) { super(); @@ -112,6 +115,30 @@ public class GeneratorWizardModel { return suppressSemanticSuperElementTypes; } + /** + * Control whether a DI postfix should be used + * @since 1.3.0 + */ + public void setAddDiPostfix(boolean addDiPostfix) { + this.addDiPostfix = addDiPostfix; + } + + /** + * Check whether a DI postfix should be used + * @since 1.3.0 + */ + public boolean isAddDiPostfix() { + return addDiPostfix; + } + + /** + * @return isAddDiPostfix configured and DI element type set is selected. + * @since 1.3.0 + */ + public boolean isAddDiPostfixActive() { + return addDiPostfix && BaseElementTypeSetBlock.UMLDI_ELEMENT_TYPE_SET.equals(getSelectedElementTypeSet()); + } + public URI getOutputModelURI() { return URI.createPlatformResourceURI(containerPath.append(fileName).toString(), true); } diff --git a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/AbstractGenerator.java b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/AbstractGenerator.java index 144c5690131..3566d4242ef 100644 --- a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/AbstractGenerator.java +++ b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/AbstractGenerator.java @@ -113,11 +113,7 @@ public abstract class AbstractGenerator<I extends EObject, O extends EObject> { for (ElementTypeConfiguration elemTypeConfig : ((ElementTypeSetConfiguration) set).getElementTypeConfigurations()) { String id = elemTypeConfig.getIdentifier(); if (id != null && id.length() > 0) { - // replace problematic characters in identifier with "_", before using it as XML-id - // in particular, the generator uses the ":", if it appends UML::MM name to the stereotype name - id = id.replaceAll(" ", "_"); - id = id.replaceAll(":", "_"); - ((XMLResource) output).setID(elemTypeConfig, id); + ((XMLResource) output).setID(elemTypeConfig, escapeID(id)); } } } @@ -137,6 +133,19 @@ public abstract class AbstractGenerator<I extends EObject, O extends EObject> { return result; } + /** + * Replace problematic characters in identifier with "_", before using it as XML-id + * in particular, the :: can be used by the generator. + * + * @param id an ID + * @return + */ + public String escapeID(String id) { + id = id.replaceAll(" ", "_"); + id = id.replaceAll(":", "_"); + return id; + } + public IStatus generate(I input, EList<? super EObject> output) { IStatus result = Status.OK_STATUS; diff --git a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/ConfigurationSetRule.xtend b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/ConfigurationSetRule.xtend index e16d472796d..967761ec9f9 100644 --- a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/ConfigurationSetRule.xtend +++ b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/ConfigurationSetRule.xtend @@ -82,6 +82,11 @@ class ConfigurationSetRule { elementTypeConfigurations.addAll(elementTypeConfigurationList.sortBy[identifier]) // set name (otherwise, the element type set remains invalid) - name = umlProfile.name + if (useDiPostfix()) { + name = umlProfile.name + " DI" + } + else { + name = umlProfile.name + } } } diff --git a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/Identifiers.xtend b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/Identifiers.xtend index f39708f66ab..da481b5b79e 100644 --- a/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/Identifiers.xtend +++ b/plugins/uml/assistants/org.eclipse.papyrus.uml.profile.types.generator/src/org/eclipse/papyrus/uml/profile/types/generator/Identifiers.xtend @@ -57,6 +57,8 @@ class Identifiers { String identifierBase + boolean useDiPostfix + /** * Constant for postfix that is appended in case of DI element types * @since 2.1 @@ -65,6 +67,14 @@ class Identifiers { ".di" } + def void setUseDiPostfix(boolean useDiPostfix) { + this.useDiPostfix = useDiPostfix + } + + def boolean useDiPostfix() { + useDiPostfix + } + def setIdentifierBase(org.eclipse.uml2.uml.Package umlPackage) { identifierBase = prefix } |