Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/parser/AssociationEndLabelParser.java')
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/parser/AssociationEndLabelParser.java50
1 files changed, 35 insertions, 15 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/parser/AssociationEndLabelParser.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/parser/AssociationEndLabelParser.java
index 3714a8a30c5..67aee13d461 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/parser/AssociationEndLabelParser.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/parser/AssociationEndLabelParser.java
@@ -7,20 +7,23 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
* CEA LIST - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.parser;
-import java.util.Collections;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Map;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants;
import org.eclipse.papyrus.uml.tools.utils.ValueSpecificationUtil;
+import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.InstanceValue;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.ValueSpecification;
@@ -39,8 +42,9 @@ public class AssociationEndLabelParser extends PropertyLabelParser {
*/
@Override
public String getPrintString(IAdaptable element, int flags) {
+ Collection<String> maskValues = getMaskValues(element);
- if(flags == 0) {
+ if(maskValues.isEmpty()) {
return MaskedLabel;
}
@@ -52,7 +56,7 @@ public class AssociationEndLabelParser extends PropertyLabelParser {
Property property = (Property)eObject;
// manage visibility
- if((flags & ILabelPreferenceConstants.DISP_VISIBILITY) == ILabelPreferenceConstants.DISP_VISIBILITY) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_VISIBILITY)) {
String visibility;
switch(property.getVisibility().getValue()) {
case VisibilityKind.PACKAGE:
@@ -75,24 +79,24 @@ public class AssociationEndLabelParser extends PropertyLabelParser {
}
// manage derived modifier
- if(((flags & ILabelPreferenceConstants.DISP_DERIVE) == ILabelPreferenceConstants.DISP_DERIVE) && (property.isDerived())) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_DERIVE) && property.isDerived()) {
result = String.format(DERIVED_FORMAT, result);
}
// manage name
- if(((flags & ILabelPreferenceConstants.DISP_NAME) == ILabelPreferenceConstants.DISP_NAME) && (property.isSetName())) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_NAME) && property.isSetName()) {
String name = property.getName();
// If property is owned by Association (non navigable) only show the name when explicitly asked.
- if(((flags & ILabelPreferenceConstants.DISP_NON_NAVIGABLE_ROLE) == ILabelPreferenceConstants.DISP_NON_NAVIGABLE_ROLE) || !((property.getOwningAssociation() != null) && (property.getOwningAssociation().getOwnedEnds().contains(property)))) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_NON_NAVIGABLE_ROLE) || !((property.getOwningAssociation() != null) && (property.getOwningAssociation().getOwnedEnds().contains(property)))) {
result = String.format(NAME_FORMAT, result, name);
}
}
// manage type
- if(((flags & ILabelPreferenceConstants.DISP_TYPE) == ILabelPreferenceConstants.DISP_TYPE)) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_TYPE)) {
String type = "<Undefined>";
if(property.getType() != null) {
type = property.getType().getName();
@@ -100,19 +104,19 @@ public class AssociationEndLabelParser extends PropertyLabelParser {
// If type is undefined only show "<Undefined>" when explicitly asked.
- if(((flags & ILabelPreferenceConstants.DISP_UNDEFINED_TYPE) == ILabelPreferenceConstants.DISP_UNDEFINED_TYPE) || (!"<Undefined>".equals(type))) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_UNDEFINED_TYPE) || (!"<Undefined>".equals(type))) {
result = String.format(TYPE_FORMAT, result, type);
}
}
// manage multiplicity
- if(((flags & ILabelPreferenceConstants.DISP_MULTIPLICITY) == ILabelPreferenceConstants.DISP_MULTIPLICITY)) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_MULTIPLICITY)) {
// If multiplicity is [1] (SysML default), only show when explicitly asked.
String lower = (property.getLowerValue() != null) ? ValueSpecificationUtil.getSpecificationValue(property.getLowerValue()) : "1";
String upper = (property.getLowerValue() != null) ? ValueSpecificationUtil.getSpecificationValue(property.getUpperValue()) : "1";
- if(((flags & ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY) == ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY) || !("1".equals(lower) && "1".equals(upper))) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY) || !("1".equals(lower) && "1".equals(upper))) {
if(lower.equals(upper)) {
result = String.format(MULTIPLICITY_FORMAT_ALT, result, lower, upper);
@@ -123,7 +127,7 @@ public class AssociationEndLabelParser extends PropertyLabelParser {
}
// manage default value
- if(((flags & ILabelPreferenceConstants.DISP_DEFAULTVALUE) == ILabelPreferenceConstants.DISP_DEFAULTVALUE) && ((property.getDefaultValue() != null))) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_DEFAULT_VALUE) && property.getDefaultValue() != null) {
ValueSpecification valueSpecification = property.getDefaultValue();
if((valueSpecification instanceof InstanceValue && property.getType().equals(valueSpecification.getType())) || !(valueSpecification instanceof InstanceValue)) {
result = String.format(DEFAULT_VALUE_FORMAT, result, ValueSpecificationUtil.getSpecificationValue(valueSpecification));
@@ -131,7 +135,7 @@ public class AssociationEndLabelParser extends PropertyLabelParser {
}
// manage modifier
- if((flags & ILabelPreferenceConstants.DISP_MODIFIERS) == ILabelPreferenceConstants.DISP_MODIFIERS) {
+ if(maskValues.contains(ILabelPreferenceConstants.DISP_MODIFIERS)) {
StringBuffer sb = new StringBuffer();
if(property.isReadOnly()) {
sb.append(sb.length() == 0 ? "readOnly" : ", readOnly");
@@ -163,7 +167,23 @@ public class AssociationEndLabelParser extends PropertyLabelParser {
* {@inheritDoc}
*/
@Override
- public Map<Integer, String> getMasks() {
- return Collections.emptyMap();
+ public Map<String, String> getMasks() {
+ return super.getMasks();
+ }
+
+ @Override
+ public Collection<String> getDefaultValue(IAdaptable element) {
+ View view = (View)element.getAdapter(View.class);
+ if(view == null) {
+ return super.getDefaultValue(element);
+ }
+
+ if(view.getType() != null && view.getType().contains("multiplicity")) {
+ return Arrays.asList(ILabelPreferenceConstants.DISP_MULTIPLICITY, ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY);
+ } else if(view.getType() != null && view.getType().contains("role")) {
+ return Arrays.asList(ILabelPreferenceConstants.DISP_NAME, ILabelPreferenceConstants.DISP_VISIBILITY, ILabelPreferenceConstants.DISP_DERIVE);
+ }
+
+ return super.getDefaultValue(element);
}
}

Back to the top