Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/ConstraintParameterEditHelperAdvice.java50
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml6
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/FeatureNameInitializerHelperAdvice.java61
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java98
4 files changed, 81 insertions, 134 deletions
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/ConstraintParameterEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/ConstraintParameterEditHelperAdvice.java
index 7c59b3caa1c..1916681d448 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/ConstraintParameterEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/ConstraintParameterEditHelperAdvice.java
@@ -30,8 +30,8 @@ import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.util.UMLUtil;
-/** Specific advice for Property creation owned by a {@link ConstraintBlock}
- * ConstraintParameter are defined in ConstraintProperty but really owned by ConstraintBlock
+/**
+ * Specific advice for Property creation owned by a {@link ConstraintBlock} ConstraintParameter are defined in ConstraintProperty but really owned by ConstraintBlock
*/
public class ConstraintParameterEditHelperAdvice extends AbstractEditHelperAdvice {
@@ -41,7 +41,7 @@ public class ConstraintParameterEditHelperAdvice extends AbstractEditHelperAdvic
@Override
public ICommand getBeforeEditCommand(IEditCommandRequest request) {
if (request instanceof ConfigureRequest) {
- EObject elementToConfigure = ((ConfigureRequest)request).getElementToConfigure();
+ EObject elementToConfigure = ((ConfigureRequest) request).getElementToConfigure();
if (elementToConfigure != null && elementToConfigure instanceof Property) {
EObject container = elementToConfigure.eContainer();
if (container != null && container instanceof Property) {
@@ -49,8 +49,8 @@ public class ConstraintParameterEditHelperAdvice extends AbstractEditHelperAdvic
if (UMLUtil.getStereotypeApplication(constraintProperty, ConstraintProperty.class) != null) {
Type type = constraintProperty.getType();
if (type != null && type instanceof Class && UMLUtil.getStereotypeApplication(type, ConstraintBlock.class) != null) {
- ((Class)type).getOwnedAttributes().add((Property)elementToConfigure);
- ((Property)elementToConfigure).setAggregation(AggregationKind.COMPOSITE_LITERAL);
+ ((Class) type).getOwnedAttributes().add((Property) elementToConfigure);
+ ((Property) elementToConfigure).setAggregation(AggregationKind.COMPOSITE_LITERAL);
}
}
}
@@ -58,24 +58,36 @@ public class ConstraintParameterEditHelperAdvice extends AbstractEditHelperAdvic
}
return super.getBeforeEditCommand(request);
}
-
- /** Complete creation process by applying the expected stereotype */
+
@Override
protected ICommand getBeforeConfigureCommand(final ConfigureRequest request) {
+ // check this advice has to propose something. If element is not a constraint parameter, do not change the name
+ EObject p = request.getElementToConfigure();
+ if (p instanceof Property) {
+ // check this is a constraint parameter, not another kind of property
+ EObject container = ((Property) p).eContainer();
+ if (container != null && container instanceof Property) {
+ Property constraintProperty = (Property) container;
+ if (UMLUtil.getStereotypeApplication(constraintProperty, ConstraintProperty.class) != null) {
+ Type type = constraintProperty.getType();
+ if (type != null && type instanceof Class && UMLUtil.getStereotypeApplication(type, ConstraintBlock.class) != null) {
+ return new ConfigureElementCommand(request) {
- return new ConfigureElementCommand(request) {
-
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- NamedElement element = (NamedElement)request.getElementToConfigure();
- if(element != null) {
- // Set default name
- // Initialize the element name based on the created IElementType
- String initializedName = NamedElementHelper.getDefaultNameWithIncrementFromBase(PARAMETER, element.eContainer().eContents());
- element.setName(initializedName);
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ NamedElement element = (NamedElement) request.getElementToConfigure();
+ if (element != null) {
+ // Set default name
+ // Initialize the element name based on the created IElementType
+ String initializedName = NamedElementHelper.getDefaultNameWithIncrementFromBase(PARAMETER, element.eContainer().eContents());
+ element.setName(initializedName);
+ }
+ return CommandResult.newOKCommandResult(element);
+ }
+ };
+ }
}
- return CommandResult.newOKCommandResult(element);
}
- };
+ }
+ return null;
}
-
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml b/plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml
index cf2b73b299c..eddb2e4315b 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml
@@ -2038,12 +2038,6 @@
inheritance="all" typeId="org.eclipse.papyrus.uml.ExecutionSpecification">
</adviceBinding>
- <!-- Helper advice for Feature name initialization -->
- <adviceBinding id="org.eclipse.papyrus.uml.advice.FeatureNameInitializer"
- class="org.eclipse.papyrus.uml.service.types.helper.advice.FeatureNameInitializerHelperAdvice"
- inheritance="all" typeId="org.eclipse.papyrus.uml.Feature">
- </adviceBinding>
-
<!-- Helper advice for Lifeline -->
<adviceBinding id="org.eclipse.papyrus.uml.advice.Lifeline"
class="org.eclipse.papyrus.uml.service.types.helper.advice.LifelineHelperAdvice"
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/FeatureNameInitializerHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/FeatureNameInitializerHelperAdvice.java
deleted file mode 100644
index 29759668708..00000000000
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/FeatureNameInitializerHelperAdvice.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.service.types.helper.advice;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
-import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
-import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper;
-import org.eclipse.uml2.uml.Feature;
-
-/**
- * <pre>
- * This is an advice helper used to initialize {@link Feature}.
- *
- * In particular the name of such elements is initialized in order
- * to have a unique name for a specific type of element per {@link Namespace}.
- *
- * Feature name is lower case by default.
- *
- * </pre>
- */
-public class FeatureNameInitializerHelperAdvice extends AbstractEditHelperAdvice {
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected ICommand getBeforeConfigureCommand(final ConfigureRequest request) {
- return new ConfigureElementCommand(request) {
-
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
-
- Feature element = (Feature)request.getElementToConfigure();
-
- // Initialize the element name based on the created IElementType
- String initializedName = NamedElementHelper.getDefaultNameWithIncrementFromBase(element.eClass().getName().toLowerCase(), element.eContainer().eContents());
- element.setName(initializedName);
-
- return CommandResult.newOKCommandResult(element);
- }
- };
- }
-
-}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java
index 8cb239e92b2..eafad62be20 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java
@@ -51,22 +51,22 @@ public class NamedElementUtil {
private final static String PACKAGE_STRING = "~";
private static final UMLSwitch<Boolean> IS_AUTONAMED = getIsAutoNamedSwitch();
-
+
/**
* A helper method to calculate the max depth of an element
*
* @param the
- * named element
+ * named element
* @return the maximum depth found in qualified name
*/
public static int getQualifiedNameMaxDepth(NamedElement namedElement) {
int d = 0;
String s = namedElement.getQualifiedName();
- if(s == null) {
+ if (s == null) {
return 0;
}
int n = 0;
- while((n = s.indexOf(QUALIFIED_NAME_SEPARATOR, n)) != -1) {
+ while ((n = s.indexOf(QUALIFIED_NAME_SEPARATOR, n)) != -1) {
n += 2;
d++;
}
@@ -81,7 +81,7 @@ public class NamedElementUtil {
* @return
*/
public static String getDefaultNameWithIncrement(EObject newElement) {
- if(newElement.eContainer() != null) {
+ if (newElement.eContainer() != null) {
return getDefaultNameWithIncrement(newElement, newElement.eContainer().eContents());
}
return null;
@@ -101,11 +101,11 @@ public class NamedElementUtil {
public static String getDefaultCopyNameWithIncrement(NamedElement namedElement, Collection<?> contents) {
// A NamedElement with empty string for a name is logically unnamed, so any copy of it should also be unnamed
String rootName = Strings.emptyToNull(namedElement.getName());
- if(rootName != null) {
- for(Object o : contents) {
- if(o instanceof EObject) {
- String name = EMFCoreUtil.getName((EObject)o);
- if(rootName.equals(name)) {
+ if (rootName != null) {
+ for (Object o : contents) {
+ if (o instanceof EObject) {
+ String name = EMFCoreUtil.getName((EObject) o);
+ if (rootName.equals(name)) {
String newName = NLS.bind(COPY_OF + "_{0}_", rootName);
return NamedElementUtil.getDefaultNameWithIncrementFromBase(newName, contents);
}
@@ -116,7 +116,7 @@ public class NamedElementUtil {
}
public static String getDefaultNameWithIncrement(String prefix, EObject newElement, Collection<?> contents) {
- if(prefix == null) {
+ if (prefix == null) {
prefix = "";
}
return getDefaultNameWithIncrementFromBase(prefix + newElement.eClass().getName(), contents, newElement, "");
@@ -128,7 +128,7 @@ public class NamedElementUtil {
public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents, EObject elementToRename, String separator) {
return (elementToRename != null) ? //
- getDefaultNameSwitch(base, contents, separator).doSwitch(elementToRename).orNull() : //
+ getDefaultNameSwitch(base, contents, separator).doSwitch(elementToRename).orNull(): //
computeDefaultNameWithIncrementFromBase(base, contents, elementToRename, separator);
}
@@ -139,15 +139,15 @@ public class NamedElementUtil {
public Optional<String> defaultCase(EObject object) {
return Optional.fromNullable(computeDefaultNameWithIncrementFromBase(base, contents, object, separator));
}
-
+
@Override
public Optional<String> casePseudostate(Pseudostate object) {
String base = object.getKind().getLiteral();
base = base.substring(0, 1).toUpperCase() + base.substring(1);
-
+
return Optional.fromNullable(computeDefaultNameWithIncrementFromBase(base, contents, object, separator));
}
-
+
@Override
public Optional<String> caseRelationship(Relationship object) {
return Optional.absent();
@@ -157,21 +157,21 @@ public class NamedElementUtil {
public Optional<String> caseAssociation(Association object) {
return Optional.absent();
}
-
+
public Optional<String> caseAssociationClass(AssociationClass object) {
return defaultCase(object);
}
-
+
@Override
public Optional<String> caseActivityEdge(ActivityEdge object) {
return Optional.absent();
}
-
+
@Override
public Optional<String> caseTransition(Transition object) {
return Optional.absent();
}
-
+
@Override
public Optional<String> caseGeneralOrdering(GeneralOrdering object) {
return Optional.absent();
@@ -186,7 +186,7 @@ public class NamedElementUtil {
public Boolean defaultCase(EObject object) {
return Boolean.TRUE;
}
-
+
@Override
public Boolean caseRelationship(Relationship object) {
return Boolean.FALSE;
@@ -196,21 +196,21 @@ public class NamedElementUtil {
public Boolean caseAssociation(Association object) {
return Boolean.FALSE;
}
-
+
public Boolean caseAssociationClass(AssociationClass object) {
return Boolean.TRUE;
}
-
+
@Override
public Boolean caseActivityEdge(ActivityEdge object) {
return Boolean.FALSE;
}
-
+
@Override
public Boolean caseTransition(Transition object) {
return Boolean.FALSE;
}
-
+
@Override
public Boolean caseGeneralOrdering(GeneralOrdering object) {
return Boolean.FALSE;
@@ -221,41 +221,43 @@ public class NamedElementUtil {
public static boolean isAutoNamed(EObject element) {
return IS_AUTONAMED.doSwitch(element);
}
-
+
static String computeDefaultNameWithIncrementFromBase(String base, Collection<?> contents, EObject elementToRename, String separator) {
- if(elementToRename != null) {
+ if (elementToRename != null) {
// Is this even an element that we should auto-name?
- if(!isAutoNamed(elementToRename)) {
+ if (!isAutoNamed(elementToRename)) {
return null;
}
-
+
// Do not change the name if it's already present in the contents collection and already has a name
- if(contents.contains(elementToRename)) {
- if(elementToRename instanceof ENamedElement) {
- ENamedElement eNamedElement = (ENamedElement)elementToRename;
- if(eNamedElement.getName() != null) {
+ if (contents.contains(elementToRename)) {
+ if (elementToRename instanceof ENamedElement) {
+ ENamedElement eNamedElement = (ENamedElement) elementToRename;
+ if (eNamedElement.getName() != null) {
return eNamedElement.getName();
}
}
// UML specific
- if(elementToRename instanceof NamedElement) {
- NamedElement namedElement = (NamedElement)elementToRename;
- if(namedElement.getName() != null) {
+ if (elementToRename instanceof NamedElement) {
+ NamedElement namedElement = (NamedElement) elementToRename;
+ if (namedElement.getName() != null) {
return namedElement.getName();
}
}
}
}
- if("property".equalsIgnoreCase(base)) {
- base = "Attribute";
- }
int nextNumber = 1;
-
- for(Object o : contents) {
- if(o instanceof EObject && o != elementToRename) {
- String name = EMFCoreUtil.getName((EObject)o);
- if(name != null && name.startsWith(base)) {
+
+ // specific value for properties. default name is attribute
+ if ("property".equalsIgnoreCase(base)) {
+ base = "attribute";
+ }
+
+ for (Object o : contents) {
+ if (o instanceof EObject && o != elementToRename) {
+ String name = EMFCoreUtil.getName((EObject) o);
+ if (name != null && name.startsWith(base)) {
String end = name.substring(base.length());
int nextNumberTmp = 1;
@@ -264,7 +266,7 @@ public class NamedElementUtil {
} catch (NumberFormatException ex) {
}
- if(nextNumberTmp > nextNumber) {
+ if (nextNumberTmp > nextNumber) {
nextNumber = nextNumberTmp;
}
}
@@ -288,7 +290,7 @@ public class NamedElementUtil {
public static String getVisibilityAsSign(NamedElement element) {
String vKindValue = "";
- switch(element.getVisibility().getValue()) {
+ switch (element.getVisibility().getValue()) {
case org.eclipse.uml2.uml.VisibilityKind.PUBLIC:
vKindValue = PUBLIC_STRING;
break;
@@ -309,7 +311,7 @@ public class NamedElementUtil {
* Returns the name of an element, given its qualified name
*
* @param qualifiedName
- * the qualified name of the element
+ * the qualified name of the element
* @return the name of the element. It shall never be <code>null</code>.
*/
public static String getNameFromQualifiedName(String qualifiedName) {
@@ -320,7 +322,7 @@ public class NamedElementUtil {
/**
*
* @param childQualifiedName
- * the qualifiedName of an element
+ * the qualifiedName of an element
* @return
* the qualified name of its parent
*/
@@ -332,7 +334,7 @@ public class NamedElementUtil {
public static String getName(NamedElement element) {
- if(element.getName() != null) {
+ if (element.getName() != null) {
return element.getName();
} else {
return (NamedElementUtil.getDefaultNameWithIncrement(element));

Back to the top