diff options
Diffstat (limited to 'plugins/uml/tools')
20 files changed, 1618 insertions, 1551 deletions
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF index 697f7b0daec..8421fff1abb 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF @@ -3,7 +3,8 @@ Export-Package: org.eclipse.papyrus.uml.tools.utils Require-Bundle: org.eclipse.uml2.uml;bundle-version="[5.2.0,6.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)", org.eclipse.gmf.runtime.notation;bundle-version="[1.8.0,2.0.0)", - org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport + org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, + org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %pluginProvider Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CollaborationUseUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CollaborationUseUtil.java index 345a815ef08..124e850ed11 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CollaborationUseUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CollaborationUseUtil.java @@ -1,87 +1,89 @@ -/*****************************************************************************
- * Copyright (c) 2009 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.tools.utils;
-
-import java.util.Collection;
-
-import org.eclipse.uml2.uml.CollaborationUse;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.CollaborationUse</code><BR>
- */
-public class CollaborationUseUtil {
-
- public final static String UNDEFINED_TYPE_NAME = "<Undefined>";
-
- /**
- * return the full label of the CollaborationUse, given UML2 specification.
- *
- * @return the string corresponding to the label of the CollaborationUse
- */
- public static String getLabel(CollaborationUse collaborationUse) {
- StringBuffer buffer = new StringBuffer();
- // visibility
- buffer.append(" ");
- buffer.append(NamedElementUtil.getVisibilityAsSign(collaborationUse));
-
- // name
- buffer.append(" ");
- buffer.append(collaborationUse.getName());
-
- // type
- if (collaborationUse.getType() != null) {
- buffer.append(": " + collaborationUse.getType().getName());
- } else {
- buffer.append(": " + UNDEFINED_TYPE_NAME);
- }
-
- return buffer.toString();
- }
-
- /**
- * return the custom label of the CollaborationUse, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the CollaborationUse
- */
- public static String getCustomLabel(CollaborationUse collaborationUse, Collection<String> maskValues) {
- StringBuffer buffer = new StringBuffer();
- // visibility
-
- buffer.append(" ");
- if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(collaborationUse));
- }
-
- // name
- if (maskValues.contains(ICustomAppearance.DISP_NAME)) {
- buffer.append(" ");
- buffer.append(collaborationUse.getName());
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_TYPE)) {
- // type
- if (collaborationUse.getType() != null) {
- buffer.append(": " + collaborationUse.getType().getName());
- } else {
- buffer.append(": " + UNDEFINED_TYPE_NAME);
- }
- }
-
- return buffer.toString();
- }
-}
+/***************************************************************************** + * Copyright (c) 2009 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 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.tools.utils; + +import java.util.Collection; + +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.CollaborationUse; + +/** + * Utility class for <code>org.eclipse.uml2.uml.CollaborationUse</code><BR> + */ +public class CollaborationUseUtil { + + public final static String UNDEFINED_TYPE_NAME = "<Undefined>"; + + /** + * return the full label of the CollaborationUse, given UML2 specification. + * + * @return the string corresponding to the label of the CollaborationUse + */ + public static String getLabel(CollaborationUse collaborationUse) { + StringBuffer buffer = new StringBuffer(); + // visibility + buffer.append(" "); + buffer.append(NamedElementUtil.getVisibilityAsSign(collaborationUse)); + + // name + buffer.append(" "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(collaborationUse)); + + // type + if (collaborationUse.getType() != null) { + buffer.append(": " + UMLLabelInternationalization.getInstance().getLabel(collaborationUse.getType())); + } else { + buffer.append(": " + UNDEFINED_TYPE_NAME); + } + + return buffer.toString(); + } + + /** + * return the custom label of the CollaborationUse, given UML2 specification and a custom style. + * + * @param style + * the integer representing the style of the label + * + * @return the string corresponding to the label of the CollaborationUse + */ + public static String getCustomLabel(CollaborationUse collaborationUse, Collection<String> maskValues) { + StringBuffer buffer = new StringBuffer(); + // visibility + + buffer.append(" "); + if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) { + buffer.append(NamedElementUtil.getVisibilityAsSign(collaborationUse)); + } + + // name + if (maskValues.contains(ICustomAppearance.DISP_NAME)) { + buffer.append(" "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(collaborationUse)); + } + + if (maskValues.contains(ICustomAppearance.DISP_TYPE)) { + // type + if (collaborationUse.getType() != null) { + buffer.append(": " + UMLLabelInternationalization.getInstance().getLabel(collaborationUse.getType())); + } else { + buffer.append(": " + UNDEFINED_TYPE_NAME); + } + } + + return buffer.toString(); + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExtensionPointUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExtensionPointUtil.java index 9bc808106a3..a5e695f9872 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExtensionPointUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExtensionPointUtil.java @@ -1,40 +1,42 @@ -/*****************************************************************************
- * Copyright (c) 2008 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:
- * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.ExtensionPoint;
-
-/**
- * Utility class for {@link ExtensionPoint}
- */
-// @unused
-public class ExtensionPointUtil {
-
- /**
- * Returns the explanation for the extension point element
- *
- * @return the string defining explanation for the extension point element
- */
- // @unused
- public static String getExplanation(ExtensionPoint extensionPoint) {
- String explanation = "";
- final String name = ((extensionPoint.getName() != null) ? extensionPoint.getName() : "");
- int startIndexOfExplanation = name.lastIndexOf(":");
- if ((startIndexOfExplanation > 0) && (startIndexOfExplanation != name.length())) {
- explanation = name.substring(startIndexOfExplanation + 1).trim();
- }
- return explanation;
- }
-}
+/***************************************************************************** + * Copyright (c) 2008 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: + * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.tools.utils; + +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.ExtensionPoint; + +/** + * Utility class for {@link ExtensionPoint} + */ +// @unused +public class ExtensionPointUtil { + + /** + * Returns the explanation for the extension point element + * + * @return the string defining explanation for the extension point element + */ + // @unused + public static String getExplanation(ExtensionPoint extensionPoint) { + String explanation = ""; + final String name = ((extensionPoint.getName() != null) ? UMLLabelInternationalization.getInstance().getLabel(extensionPoint) : ""); + int startIndexOfExplanation = name.lastIndexOf(":"); + if ((startIndexOfExplanation > 0) && (startIndexOfExplanation != name.length())) { + explanation = name.substring(startIndexOfExplanation + 1).trim(); + } + return explanation; + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java index 505c672897f..16a8561ce1a 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java @@ -9,12 +9,14 @@ * * Contributors: * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 */ package org.eclipse.papyrus.uml.tools.utils; import java.util.Collection; import java.util.Iterator; +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; import org.eclipse.uml2.uml.Classifier; import org.eclipse.uml2.uml.InstanceSpecification; @@ -37,7 +39,11 @@ public class InstanceSpecificationUtil { // name if (maskValues.contains(ICustomAppearance.DISP_NAME)) { - buffer.append(NamedElementUtil.getName(instance)); + if(null != instance.getName()){ + buffer.append(UMLLabelInternationalization.getInstance().getLabel(instance)); + }else{ + buffer.append((NamedElementUtil.getDefaultNameWithIncrement(instance))); + } } // classifier diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/MultiplicityElementUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/MultiplicityElementUtil.java index ac868ece577..633d0ffae7d 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/MultiplicityElementUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/MultiplicityElementUtil.java @@ -9,6 +9,7 @@ * * Contributors: * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ package org.eclipse.papyrus.uml.tools.utils; @@ -215,7 +216,7 @@ public class MultiplicityElementUtil { * @return The string representing the value specification */ private static String getStringSpecificationValue(final ValueSpecification valueSpecification, final boolean isEdition) { - String boundStr = ValueSpecificationUtil.getSpecificationValue(valueSpecification); + String boundStr = ValueSpecificationUtil.getSpecificationValue(valueSpecification, true); if (isEdition && valueSpecification instanceof LiteralString) { final StringBuffer buffer = new StringBuffer(); buffer.append(QUOTE); diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OperationUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OperationUtil.java index c0492cec2ce..2927a23d0d3 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OperationUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OperationUtil.java @@ -1,236 +1,238 @@ -/*****************************************************************************
- * Copyright (c) 2009 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.tools.utils;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.papyrus.infra.tools.util.StringHelper;
-import org.eclipse.uml2.uml.Constraint;
-import org.eclipse.uml2.uml.Operation;
-import org.eclipse.uml2.uml.Parameter;
-import org.eclipse.uml2.uml.ParameterDirectionKind;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Operation</code><BR>
- */
-public class OperationUtil {
-
- /**
- * return the custom label of the operation, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the operation
- */
- public static String getCustomLabel(Operation operation, Collection<String> maskValues) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(" "); // adds " " first for correct display considerations
-
- // visibility
- if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(operation));
- }
-
- // name
- if (maskValues.contains(ICustomAppearance.DISP_NAME)) {
- buffer.append(" ");
- buffer.append(operation.getName());
- }
-
- //
- // parameters : '(' parameter-list ')'
- buffer.append("(");
- buffer.append(OperationUtil.getParametersAsString(operation, maskValues));
- buffer.append(")");
-
- // return type
- if (maskValues.contains(ICustomAppearance.DISP_RT_TYPE) || maskValues.contains(ICustomAppearance.DISP_TYPE)) {
- buffer.append(OperationUtil.getReturnTypeAsString(operation, maskValues));
- }
-
- // modifiers
- if (maskValues.contains(ICustomAppearance.DISP_MODIFIERS)) {
- String modifiers = OperationUtil.getModifiersAsString(operation);
- if (!modifiers.equals("")) {
- buffer.append("{");
- buffer.append(modifiers);
- buffer.append("}");
- }
- }
- return buffer.toString();
- }
-
- /**
- * Returns return parameter label as a string, string parametrized with a style mask.
- *
- * @param style
- * the mask that indicates which element to display
- * @return a string containing the return parameter type
- */
- private static String getReturnTypeAsString(Operation operation, Collection<String> maskValues) {
- boolean displayType = maskValues.contains(ICustomAppearance.DISP_RT_TYPE) || maskValues.contains(ICustomAppearance.DISP_TYPE);
- boolean displayMultiplicity = maskValues.contains(ICustomAppearance.DISP_RT_MULTIPLICITY) || maskValues.contains(ICustomAppearance.DISP_MULTIPLICITY);
- StringBuffer label = new StringBuffer("");
-
- // Retrieve the return parameter (assume to be unique if defined)
- Parameter returnParameter = OperationUtil.getReturnParameter(operation);
- // Create the string for the return type
- if (returnParameter == null) {
- // no-operation: label = ""
-
- } else if (!displayType && !displayMultiplicity) {
- // no-operation: label = ""
-
- } else {
- label.append(": ");
- if (displayType) {
- label.append(TypedElementUtil.getTypeAsString(returnParameter));
- }
-
- if (displayMultiplicity) {
- label.append(MultiplicityElementUtil.getMultiplicityAsString(returnParameter));
- }
- }
- return label.toString();
- }
-
- /**
- * Returns operation parameters as a string, the label is customized using a bit mask
- *
- * @return a string containing all parameters separated by commas
- */
- private static String getParametersAsString(Operation operation, Collection<String> maskValues) {
- StringBuffer paramString = new StringBuffer();
- Iterator<Parameter> paramIterator = operation.getOwnedParameters().iterator();
- boolean firstParameter = true;
- while (paramIterator.hasNext()) {
- Parameter parameter = paramIterator.next();
- // Do not include return parameters
- if (!parameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) {
-
- // get the label for this parameter
- String parameterString = ParameterUtil.getCustomLabel(parameter, extractParameterMaskValues(maskValues));
- if (!parameterString.trim().equals("")) {
- if (!firstParameter) {
- paramString.append(", ");
- }
- paramString.append(parameterString);
- firstParameter = false;
- }
- }
- }
- return paramString.toString();
- }
-
- private static Collection<String> extractParameterMaskValues(Collection<String> operationMaskValues) {
- Set<String> result = new HashSet<String>();
-
- for (String maskValue : operationMaskValues) {
- if (maskValue.startsWith(ICustomAppearance.PARAMETERS_PREFIX)) {
- String newValue = StringHelper.firstToLower(maskValue.replace(ICustomAppearance.PARAMETERS_PREFIX, ""));
- result.add(newValue);
- }
- }
-
- return result;
- }
-
- /**
- * Returns operation modifiers as string, separated with comma.
- *
- * @return a string containing the modifiers
- */
- private static String getModifiersAsString(Operation operation) {
- StringBuffer buffer = new StringBuffer();
- boolean needsComma = false;
-
- // Return parameter modifiers
- Parameter returnParameter = OperationUtil.getReturnParameter(operation);
- if (returnParameter != null) {
- // non unique parameter
- if (!returnParameter.isUnique()) {
- buffer.append("nonunique");
- needsComma = true;
- }
-
- // return parameter has ordered values
- if (returnParameter.isOrdered()) {
- if (needsComma) {
- buffer.append(", ");
- }
- buffer.append("ordered");
- needsComma = true;
- }
- }
-
- // is the operation a query ?
- if (operation.isQuery()) {
- if (needsComma) {
- buffer.append(", ");
- }
- buffer.append("query");
- needsComma = true;
- }
-
- // is the operation redefining another operation ?
- Iterator<Operation> it = operation.getRedefinedOperations().iterator();
- while (it.hasNext()) {
- Operation currentOperation = it.next();
- if (needsComma) {
- buffer.append(", ");
- }
- buffer.append("redefines ");
- buffer.append(currentOperation.getName());
- needsComma = true;
- }
-
- // has the operation a constraint ?
- Iterator<Constraint> it2 = operation.getOwnedRules().iterator();
- while (it2.hasNext()) {
- Constraint constraint = it2.next();
- if (needsComma) {
- buffer.append(", ");
- }
- if (constraint.getSpecification() != null) {
- buffer.append(constraint.getSpecification().stringValue());
- }
- needsComma = true;
- }
-
- return buffer.toString();
- }
-
- /**
- * Gives the return parameter for this operation, or <code>null</code> if none exists.
- *
- * @return the return parameter of the operation or <code>null</code>
- */
- private static Parameter getReturnParameter(Operation operation) {
- // Retrieve the return parameter (assume to be unique if defined)
- Parameter returnParameter = null;
-
- Iterator<Parameter> it = operation.getOwnedParameters().iterator();
- while ((returnParameter == null) && (it.hasNext())) {
- Parameter parameter = it.next();
- if (parameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) {
- returnParameter = parameter;
- }
- }
- return returnParameter;
- }
-}
+/***************************************************************************** + * Copyright (c) 2009 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 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.utils; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.eclipse.papyrus.infra.tools.util.StringHelper; +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.Constraint; +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.uml2.uml.ParameterDirectionKind; + +/** + * Utility class for <code>org.eclipse.uml2.uml.Operation</code><BR> + */ +public class OperationUtil { + + /** + * return the custom label of the operation, given UML2 specification and a custom style. + * + * @param style + * the integer representing the style of the label + * + * @return the string corresponding to the label of the operation + */ + public static String getCustomLabel(Operation operation, Collection<String> maskValues) { + StringBuffer buffer = new StringBuffer(); + buffer.append(" "); // adds " " first for correct display considerations + + // visibility + if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) { + buffer.append(NamedElementUtil.getVisibilityAsSign(operation)); + } + + // name + if (maskValues.contains(ICustomAppearance.DISP_NAME)) { + buffer.append(" "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(operation)); + } + + // + // parameters : '(' parameter-list ')' + buffer.append("("); + buffer.append(OperationUtil.getParametersAsString(operation, maskValues)); + buffer.append(")"); + + // return type + if (maskValues.contains(ICustomAppearance.DISP_RT_TYPE) || maskValues.contains(ICustomAppearance.DISP_TYPE)) { + buffer.append(OperationUtil.getReturnTypeAsString(operation, maskValues)); + } + + // modifiers + if (maskValues.contains(ICustomAppearance.DISP_MODIFIERS)) { + String modifiers = OperationUtil.getModifiersAsString(operation); + if (!modifiers.equals("")) { + buffer.append("{"); + buffer.append(modifiers); + buffer.append("}"); + } + } + return buffer.toString(); + } + + /** + * Returns return parameter label as a string, string parametrized with a style mask. + * + * @param style + * the mask that indicates which element to display + * @return a string containing the return parameter type + */ + private static String getReturnTypeAsString(Operation operation, Collection<String> maskValues) { + boolean displayType = maskValues.contains(ICustomAppearance.DISP_RT_TYPE) || maskValues.contains(ICustomAppearance.DISP_TYPE); + boolean displayMultiplicity = maskValues.contains(ICustomAppearance.DISP_RT_MULTIPLICITY) || maskValues.contains(ICustomAppearance.DISP_MULTIPLICITY); + StringBuffer label = new StringBuffer(""); + + // Retrieve the return parameter (assume to be unique if defined) + Parameter returnParameter = OperationUtil.getReturnParameter(operation); + // Create the string for the return type + if (returnParameter == null) { + // no-operation: label = "" + + } else if (!displayType && !displayMultiplicity) { + // no-operation: label = "" + + } else { + label.append(": "); + if (displayType) { + label.append(TypedElementUtil.getTypeAsString(returnParameter)); + } + + if (displayMultiplicity) { + label.append(MultiplicityElementUtil.getMultiplicityAsString(returnParameter)); + } + } + return label.toString(); + } + + /** + * Returns operation parameters as a string, the label is customized using a bit mask + * + * @return a string containing all parameters separated by commas + */ + private static String getParametersAsString(Operation operation, Collection<String> maskValues) { + StringBuffer paramString = new StringBuffer(); + Iterator<Parameter> paramIterator = operation.getOwnedParameters().iterator(); + boolean firstParameter = true; + while (paramIterator.hasNext()) { + Parameter parameter = paramIterator.next(); + // Do not include return parameters + if (!parameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) { + + // get the label for this parameter + String parameterString = ParameterUtil.getCustomLabel(parameter, extractParameterMaskValues(maskValues)); + if (!parameterString.trim().equals("")) { + if (!firstParameter) { + paramString.append(", "); + } + paramString.append(parameterString); + firstParameter = false; + } + } + } + return paramString.toString(); + } + + private static Collection<String> extractParameterMaskValues(Collection<String> operationMaskValues) { + Set<String> result = new HashSet<String>(); + + for (String maskValue : operationMaskValues) { + if (maskValue.startsWith(ICustomAppearance.PARAMETERS_PREFIX)) { + String newValue = StringHelper.firstToLower(maskValue.replace(ICustomAppearance.PARAMETERS_PREFIX, "")); + result.add(newValue); + } + } + + return result; + } + + /** + * Returns operation modifiers as string, separated with comma. + * + * @return a string containing the modifiers + */ + private static String getModifiersAsString(Operation operation) { + StringBuffer buffer = new StringBuffer(); + boolean needsComma = false; + + // Return parameter modifiers + Parameter returnParameter = OperationUtil.getReturnParameter(operation); + if (returnParameter != null) { + // non unique parameter + if (!returnParameter.isUnique()) { + buffer.append("nonunique"); + needsComma = true; + } + + // return parameter has ordered values + if (returnParameter.isOrdered()) { + if (needsComma) { + buffer.append(", "); + } + buffer.append("ordered"); + needsComma = true; + } + } + + // is the operation a query ? + if (operation.isQuery()) { + if (needsComma) { + buffer.append(", "); + } + buffer.append("query"); + needsComma = true; + } + + // is the operation redefining another operation ? + Iterator<Operation> it = operation.getRedefinedOperations().iterator(); + while (it.hasNext()) { + Operation currentOperation = it.next(); + if (needsComma) { + buffer.append(", "); + } + buffer.append("redefines "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(currentOperation)); + needsComma = true; + } + + // has the operation a constraint ? + Iterator<Constraint> it2 = operation.getOwnedRules().iterator(); + while (it2.hasNext()) { + Constraint constraint = it2.next(); + if (needsComma) { + buffer.append(", "); + } + if (constraint.getSpecification() != null) { + buffer.append(constraint.getSpecification().stringValue()); + } + needsComma = true; + } + + return buffer.toString(); + } + + /** + * Gives the return parameter for this operation, or <code>null</code> if none exists. + * + * @return the return parameter of the operation or <code>null</code> + */ + private static Parameter getReturnParameter(Operation operation) { + // Retrieve the return parameter (assume to be unique if defined) + Parameter returnParameter = null; + + Iterator<Parameter> it = operation.getOwnedParameters().iterator(); + while ((returnParameter == null) && (it.hasNext())) { + Parameter parameter = it.next(); + if (parameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) { + returnParameter = parameter; + } + } + return returnParameter; + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java index c779540538b..e81c1fdc86d 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java @@ -11,6 +11,7 @@ * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr * Christian W. Damus (CEA) - bug 402525 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ package org.eclipse.papyrus.uml.tools.utils; @@ -39,6 +40,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.papyrus.infra.core.services.ServiceException; import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers; +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; import org.eclipse.uml2.uml.Collaboration; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.NamedElement; @@ -606,8 +608,8 @@ public class PackageUtil { * {@inheritDoc} */ public int compare(Type o1, Type o2) { - final String o1Name = ((o1.getName() != null) ? o1.getName() : ""); //$NON-NLS-1$ - final String o2Name = ((o2.getName() != null) ? o2.getName() : ""); //$NON-NLS-1$ + final String o1Name = ((o1.getName() != null) ? UMLLabelInternationalization.getInstance().getLabel(o1) : ""); //$NON-NLS-1$ + final String o2Name = ((o2.getName() != null) ? UMLLabelInternationalization.getInstance().getLabel(o2) : ""); //$NON-NLS-1$ return o1Name.compareTo(o2Name); } } diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ParameterUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ParameterUtil.java index 7717e5bd448..7b7fcf6f954 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ParameterUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ParameterUtil.java @@ -1,214 +1,216 @@ -/*****************************************************************************
- * Copyright (c) 2009 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.tools.utils;
-
-import java.util.Collection;
-
-import org.eclipse.uml2.uml.Parameter;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Parameter</code><BR>
- */
-public class ParameterUtil {
-
- /**
- * Returns the modifier of the property, separated by a comma, as as single line if <code>multiline</code> is <code>false</code> or as a multiline
- * string if <code>multiline</code> is <code>false</code>.
- *
- * @param multiLine
- * boolean that indicates if the string should have several lines when set to <code>true</code> or only one line when set to <code>false</code>.
- *
- * @return a string giving all modifiers for the property
- */
- public static String getModifiersAsString(Parameter parameter, boolean multiLine) {
- StringBuffer buffer = new StringBuffer();
- boolean needsComma = false;
- String NL = (multiLine) ? "\n" : " ";
-
- // Return parameter modifiers
- if (parameter.isOrdered()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "ordered");
- ;
- }
- if (parameter.isUnique()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "unique");
- }
- if (parameter.isException()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "exception");
- }
- if (parameter.isStream()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "stream");
- }
-
- if (!buffer.toString().equals("")) {
- buffer.insert(0, "{");
- buffer.append("}");
- }
-
- return buffer.toString();
- }
-
- /**
- * Update the modifiers string
- *
- * @param buffer
- * the existing bufferString to append
- * @param needsComma
- * if it needs coma
- * @param NL
- * if it is multiline
- * @param message
- * the message top
- * @return true because the modifier string is no more empty
- */
- private static boolean updateModifiersString(StringBuffer buffer, boolean needsComma, String NL, String message) {
- if (needsComma) {
- buffer.append(",");
- buffer.append(NL);
- }
- buffer.append(message);
- return true;
- }
-
- /**
- * return the full label of the Parameter.
- *
- * @return the string corresponding to the label of the parameter
- */
- public static String getLabel(Parameter parameter) {
- StringBuffer buffer = new StringBuffer();
- // visibility
- buffer.append(" ");
- buffer.append(NamedElementUtil.getVisibilityAsSign(parameter));
-
- // direction
- buffer.append(" ");
- buffer.append(parameter.getDirection().getLiteral());
-
- // name
- buffer.append(" ");
- if (parameter.getName() != null) {
- buffer.append(parameter.getName());
- }
-
- // type
- if (parameter.getType() != null) {
- buffer.append(": " + parameter.getType().getName());
- } else {
- buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
- }
-
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter);
- if (!multiplicity.trim().equals("[1]")) {
- buffer.append(multiplicity);
- }
-
- // default value
- if (parameter.getDefault() != null) {
- buffer.append(" = ");
- buffer.append(parameter.getDefault());
- }
-
- // property modifiers
- buffer.append(ParameterUtil.getModifiersAsString(parameter, false));
-
- return buffer.toString();
- }
-
- /**
- * return the custom label of the property, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the property
- */
- public static String getCustomLabel(Parameter parameter, Collection<String> maskValues) {
- StringBuffer buffer = new StringBuffer();
- // visibility
- buffer.append(" ");
- if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(parameter));
- }
-
- // direction property
- if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_DIRECTION) || maskValues.contains(ICustomAppearance.DISP_DIRECTION)) {
- buffer.append(" ");
- buffer.append(parameter.getDirection().getLiteral());
- }
-
- // name
- if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_NAME) || maskValues.contains(ICustomAppearance.DISP_NAME)) {
- buffer.append(" ");
- buffer.append(parameter.getName());
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_TYPE) || maskValues.contains(ICustomAppearance.DISP_TYPE)) {
- // type
- if (parameter.getType() != null) {
- buffer.append(": " + parameter.getType().getName());
- } else {
- buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
- }
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_MULTIPLICITY) || maskValues.contains(ICustomAppearance.DISP_MULTIPLICITY)) {
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter);
- buffer.append(multiplicity);
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_DEFAULT) || maskValues.contains(ICustomAppearance.DISP_DEFAULT_VALUE)) {
- // default value
- if (parameter.getDefault() != null) {
- buffer.append(" = ");
- buffer.append(parameter.getDefault());
- }
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_MODIFIERS)) {
- boolean multiLine = (maskValues.contains(ICustomAppearance.DISP_MULTI_LINE));
- // property modifiers
- String modifiers = ParameterUtil.getModifiersAsString(parameter, multiLine);
- if (!modifiers.equals("")) {
- if (multiLine) {
- buffer.append("\n");
- }
- buffer.append(modifiers);
- }
- }
- return buffer.toString();
- }
-
- /**
- * Returns the default value as a String
- *
- * @param equalSign
- * boolean set to <code>true</code> if the label must have the <code>=</code> sign
- * before the default value
- * @return the default value as a String
- */
- private static String getDefaultAsString(Parameter parameter, boolean equalSign) {
- String defaultString = "";
- // default value
- if ((parameter.getDefault() != null) && !parameter.getDefault().equals("")) {
- if (equalSign) {
- defaultString += "= ";
- }
- defaultString += parameter.getDefault();
- }
- return "";
- }
-}
+/***************************************************************************** + * Copyright (c) 2009 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 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.utils; + +import java.util.Collection; + +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.Parameter; + +/** + * Utility class for <code>org.eclipse.uml2.uml.Parameter</code><BR> + */ +public class ParameterUtil { + + /** + * Returns the modifier of the property, separated by a comma, as as single line if <code>multiline</code> is <code>false</code> or as a multiline + * string if <code>multiline</code> is <code>false</code>. + * + * @param multiLine + * boolean that indicates if the string should have several lines when set to <code>true</code> or only one line when set to <code>false</code>. + * + * @return a string giving all modifiers for the property + */ + public static String getModifiersAsString(Parameter parameter, boolean multiLine) { + StringBuffer buffer = new StringBuffer(); + boolean needsComma = false; + String NL = (multiLine) ? "\n" : " "; + + // Return parameter modifiers + if (parameter.isOrdered()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "ordered"); + ; + } + if (parameter.isUnique()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "unique"); + } + if (parameter.isException()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "exception"); + } + if (parameter.isStream()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "stream"); + } + + if (!buffer.toString().equals("")) { + buffer.insert(0, "{"); + buffer.append("}"); + } + + return buffer.toString(); + } + + /** + * Update the modifiers string + * + * @param buffer + * the existing bufferString to append + * @param needsComma + * if it needs coma + * @param NL + * if it is multiline + * @param message + * the message top + * @return true because the modifier string is no more empty + */ + private static boolean updateModifiersString(StringBuffer buffer, boolean needsComma, String NL, String message) { + if (needsComma) { + buffer.append(","); + buffer.append(NL); + } + buffer.append(message); + return true; + } + + /** + * return the full label of the Parameter. + * + * @return the string corresponding to the label of the parameter + */ + public static String getLabel(Parameter parameter) { + StringBuffer buffer = new StringBuffer(); + // visibility + buffer.append(" "); + buffer.append(NamedElementUtil.getVisibilityAsSign(parameter)); + + // direction + buffer.append(" "); + buffer.append(parameter.getDirection().getLiteral()); + + // name + buffer.append(" "); + if (parameter.getName() != null) { + buffer.append(UMLLabelInternationalization.getInstance().getLabel(parameter)); + } + + // type + if (parameter.getType() != null) { + buffer.append(": " + UMLLabelInternationalization.getInstance().getLabel(parameter.getType())); + } else { + buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME); + } + + // multiplicity -> do not display [1] + String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter); + if (!multiplicity.trim().equals("[1]")) { + buffer.append(multiplicity); + } + + // default value + if (parameter.getDefault() != null) { + buffer.append(" = "); + buffer.append(parameter.getDefault()); + } + + // property modifiers + buffer.append(ParameterUtil.getModifiersAsString(parameter, false)); + + return buffer.toString(); + } + + /** + * return the custom label of the property, given UML2 specification and a custom style. + * + * @param style + * the integer representing the style of the label + * + * @return the string corresponding to the label of the property + */ + public static String getCustomLabel(Parameter parameter, Collection<String> maskValues) { + StringBuffer buffer = new StringBuffer(); + // visibility + buffer.append(" "); + if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) { + buffer.append(NamedElementUtil.getVisibilityAsSign(parameter)); + } + + // direction property + if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_DIRECTION) || maskValues.contains(ICustomAppearance.DISP_DIRECTION)) { + buffer.append(" "); + buffer.append(parameter.getDirection().getLiteral()); + } + + // name + if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_NAME) || maskValues.contains(ICustomAppearance.DISP_NAME)) { + buffer.append(" "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(parameter)); + } + + if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_TYPE) || maskValues.contains(ICustomAppearance.DISP_TYPE)) { + // type + if (parameter.getType() != null) { + buffer.append(": " + UMLLabelInternationalization.getInstance().getLabel(parameter.getType())); + } else { + buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME); + } + } + + if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_MULTIPLICITY) || maskValues.contains(ICustomAppearance.DISP_MULTIPLICITY)) { + // multiplicity -> do not display [1] + String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter); + buffer.append(multiplicity); + } + + if (maskValues.contains(ICustomAppearance.DISP_PARAMETER_DEFAULT) || maskValues.contains(ICustomAppearance.DISP_DEFAULT_VALUE)) { + // default value + if (parameter.getDefault() != null) { + buffer.append(" = "); + buffer.append(parameter.getDefault()); + } + } + + if (maskValues.contains(ICustomAppearance.DISP_MODIFIERS)) { + boolean multiLine = (maskValues.contains(ICustomAppearance.DISP_MULTI_LINE)); + // property modifiers + String modifiers = ParameterUtil.getModifiersAsString(parameter, multiLine); + if (!modifiers.equals("")) { + if (multiLine) { + buffer.append("\n"); + } + buffer.append(modifiers); + } + } + return buffer.toString(); + } + + /** + * Returns the default value as a String + * + * @param equalSign + * boolean set to <code>true</code> if the label must have the <code>=</code> sign + * before the default value + * @return the default value as a String + */ + private static String getDefaultAsString(Parameter parameter, boolean equalSign) { + String defaultString = ""; + // default value + if ((parameter.getDefault() != null) && !parameter.getDefault().equals("")) { + if (equalSign) { + defaultString += "= "; + } + defaultString += parameter.getDefault(); + } + return ""; + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PortUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PortUtil.java index 6d30ba4b855..7e8b21d2286 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PortUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PortUtil.java @@ -1,103 +1,105 @@ -/*****************************************************************************
- * Copyright (c) 2013 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:
- * Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Collection;
-
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Property;
-
-
-public class PortUtil extends PropertyUtil {
-
- /**
- * return the custom label of the property, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the property
- */
- public static String getCustomLabel(Property property, Collection<String> maskValues) {
- StringBuffer buffer = new StringBuffer();
- // visibility
-
- buffer.append(" ");
- if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(property));
- }
-
- // derived property
- if (maskValues.contains(ICustomAppearance.DISP_DERIVE)) {
- if (property.isDerived()) {
- buffer.append("/");
- }
- }
- // name
- if (maskValues.contains(ICustomAppearance.DISP_NAME)) {
- buffer.append(" ");
- buffer.append(property.getName());
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_TYPE)) {
- if (maskValues.contains(ICustomAppearance.DISP_CONJUGATED)) {
- if (((Port) property).isConjugated()) {
- buffer.append(": ~");
- } else {
- buffer.append(": ");
- }
- } else {
- buffer.append(": ");
- }
- // type
- if (property.getType() != null) {
- buffer.append(property.getType().getName());
- } else {
- buffer.append(TypeUtil.UNDEFINED_TYPE_NAME);
- }
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_MULTIPLICITY)) {
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(property);
- buffer.append(multiplicity);
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_DEFAULT_VALUE)) {
- // default value
- if (property.getDefaultValue() != null) {
- buffer.append(" = ");
- buffer.append(ValueSpecificationUtil.getSpecificationValue(property.getDefaultValue()));
- }
- }
-
- if (maskValues.contains(ICustomAppearance.DISP_MODIFIERS)) {
- boolean multiLine = maskValues.contains(ICustomAppearance.DISP_MULTI_LINE);
- // property modifiers
- String modifiers = PropertyUtil.getModifiersAsString(property, multiLine);
- if (!modifiers.equals("")) {
- if (multiLine) {
- buffer.append("\n");
- }
-
- if (!buffer.toString().endsWith(" ")) {
- buffer.append(" ");
- }
-
- buffer.append(modifiers);
- }
- }
- return buffer.toString();
- }
-}
+/***************************************************************************** + * Copyright (c) 2013 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: + * Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.utils; + +import java.util.Collection; + +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.Property; + + +public class PortUtil extends PropertyUtil { + + /** + * return the custom label of the property, given UML2 specification and a custom style. + * + * @param style + * the integer representing the style of the label + * + * @return the string corresponding to the label of the property + */ + public static String getCustomLabel(Property property, Collection<String> maskValues) { + StringBuffer buffer = new StringBuffer(); + // visibility + + buffer.append(" "); + if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) { + buffer.append(NamedElementUtil.getVisibilityAsSign(property)); + } + + // derived property + if (maskValues.contains(ICustomAppearance.DISP_DERIVE)) { + if (property.isDerived()) { + buffer.append("/"); + } + } + // name + if (maskValues.contains(ICustomAppearance.DISP_NAME)) { + buffer.append(" "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(property)); + } + + if (maskValues.contains(ICustomAppearance.DISP_TYPE)) { + if (maskValues.contains(ICustomAppearance.DISP_CONJUGATED)) { + if (((Port) property).isConjugated()) { + buffer.append(": ~"); + } else { + buffer.append(": "); + } + } else { + buffer.append(": "); + } + // type + if (property.getType() != null) { + buffer.append(UMLLabelInternationalization.getInstance().getLabel(property.getType())); + } else { + buffer.append(TypeUtil.UNDEFINED_TYPE_NAME); + } + } + + if (maskValues.contains(ICustomAppearance.DISP_MULTIPLICITY)) { + // multiplicity -> do not display [1] + String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(property); + buffer.append(multiplicity); + } + + if (maskValues.contains(ICustomAppearance.DISP_DEFAULT_VALUE)) { + // default value + if (property.getDefaultValue() != null) { + buffer.append(" = "); + buffer.append(ValueSpecificationUtil.getSpecificationValue(property.getDefaultValue(), true)); + } + } + + if (maskValues.contains(ICustomAppearance.DISP_MODIFIERS)) { + boolean multiLine = maskValues.contains(ICustomAppearance.DISP_MULTI_LINE); + // property modifiers + String modifiers = PropertyUtil.getModifiersAsString(property, multiLine); + if (!modifiers.equals("")) { + if (multiLine) { + buffer.append("\n"); + } + + if (!buffer.toString().endsWith(" ")) { + buffer.append(" "); + } + + buffer.append(modifiers); + } + } + return buffer.toString(); + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PropertyUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PropertyUtil.java index 23458631060..01779b93138 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PropertyUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PropertyUtil.java @@ -1,360 +1,362 @@ -/*****************************************************************************
- * Copyright (c) 2009 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.tools.utils;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Property;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Property</code><BR>
- */
-public class PropertyUtil {
-
- /**
- * Get all properties that can be subset by this {@link Property} checks the type and the
- * multiplicity.
- *
- * @param property
- * property for which the list of subsettable properties are made
- * @param noCheck
- * set this parameter to <code>true</code> if multiplicity and type check should be
- * made for the computation
- * @return all properties that can be subset
- */
- public static List<Property> getSubsettablesProperties(Property property, boolean noCheck) {
- List<Property> list = new ArrayList<Property>();
-
- // subset properties:
- Iterator<NamedElement> it = property.getClass_().getMembers().iterator();
- while (it.hasNext()) {
-
- NamedElement element = it.next();
- if (element instanceof Property) {
- boolean isValid = true;
- Property subsettableProperty = (Property) element;
-
- // check it is not itself....
- if (subsettableProperty.equals(property)) {
- isValid = false;
- }
-
- // check types conformity
- if (!noCheck) {
- if (property.getType() != null && subsettableProperty.getType() != null) {
- if (!property.getType().conformsTo(subsettableProperty.getType())) {
- isValid = false;
- }
- } else {
- isValid = false;
- }
-
- // check multiplicity (only upper bound has an OCL rule)
- if ((subsettableProperty.getUpper() != -1) && (property.getUpper() > subsettableProperty.getUpper())) {
- isValid = false;
- }
- }
-
- if (isValid) {
- list.add(subsettableProperty);
- }
- }
- }
- return list;
- }
-
- /**
- * Find a subsetted property given its name and a context to find it.
- *
- * @param name
- * the name of the property
- * @return the property found or <code>null</code> if the element was not found.
- */
- // @unused
- public static Property findSusbsettedPropertyByName(String propertyName, Property property, boolean noCheck) {
- Iterator<Property> it = PropertyUtil.getSubsettablesProperties(property, true).iterator();
- while (it.hasNext()) {
- Property tmpProperty = it.next();
- String tmpPropertyName = tmpProperty.getName();
- if (tmpPropertyName != null && propertyName.equals(tmpPropertyName.trim())) {
- return tmpProperty;
- }
- }
- return null;
- }
-
- /**
- * Get all properties that can be redefined by this {@link Property}.
- *
- * @return all properties that can be redefined
- */
- public static List<Property> getRedefinableProperties(Property property) {
- List<Property> list = new ArrayList<Property>();
-
- // redefine-able properties:
- Iterator<NamedElement> it = property.getClass_().getInheritedMembers().iterator();
- while (it.hasNext()) {
- NamedElement element = it.next();
- if (element instanceof Property) {
- list.add((Property) element);
- }
- }
-
- // adds also already redefined members. In fact, when properties are
- // redefined, they
- // disappear from the inherited members list
- Iterator<Property> it2 = property.getRedefinedProperties().iterator();
- while (it2.hasNext()) {
- Property element = it2.next();
- list.add(element);
- }
- return list;
- }
-
- /**
- * Find a redefined property given its name and a context to find it.
- *
- * @param name
- * the name of the property
- * @return the property found or <code>null</code> if the element was not found.
- */
- public static Property findRedefinedPropertyByName(String propertyName, Property property) {
- Iterator<Property> it = PropertyUtil.getRedefinableProperties(property).iterator();
- while (it.hasNext()) {
- Property tmpProperty = it.next();
- String tmpPropertyName = tmpProperty.getName();
- if (tmpPropertyName != null && propertyName.equals(tmpPropertyName.trim())) {
- return tmpProperty;
- }
- }
- return null;
- }
-
- /**
- * Get the displayed string for the derived attribute of the property.
- *
- * @param property
- * the property
- * @return If the property is derived, return "/". Otherwise return an empty String
- */
- public static String getDerived(Property property) {
- return property.isDerived() ? "/" : "";
- }
-
- /**
- * return the full label of the property, given UML2 specification.
- *
- * @return the string corresponding to the label of the property
- */
- public static String getLabel(Property property) {
- StringBuffer buffer = new StringBuffer();
- // visibility
- buffer.append(" ");
- buffer.append(getNonNullString(NamedElementUtil.getVisibilityAsSign(property)));
-
- // derived property
- buffer.append(getNonNullString(getDerived(property)));
-
- // name
- buffer.append(" ");
- buffer.append(getNonNullString(getName(property)));
-
- // type
- if (property.getType() != null) {
- buffer.append(" : " + getNonNullString(property.getType().getName()));
- } else {
- buffer.append(" : " + TypeUtil.UNDEFINED_TYPE_NAME);
- }
-
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(property);
- if (!multiplicity.trim().equals("[1]")) {
- buffer.append(getNonNullString(multiplicity));
- }
-
- // default value
- if (property.getDefaultValue() != null) {
- buffer.append(" = ");
- buffer.append(getNonNullString(ValueSpecificationUtil.getSpecificationValue(property.getDefaultValue())));
- }
-
- // property modifiers
- buffer.append(getNonNullString(PropertyUtil.getModifiersAsString(property, false)));
-
- return buffer.toString();
- }
-
- public static String getName(Property property) {
- if (property.getName() != null) {
- return property.getName();
- } else {
- return (NamedElementUtil.getDefaultNameWithIncrement(property));
- }
- }
-
- private static String getNonNullString(String source) {
- return source == null ? "" : source;
- }
-
- /**
- * return the custom label of the property, given UML2 specification and a custom style.
- *
- * @param style
- * the collection of label fragments to display
- *
- * @return the string corresponding to the label of the property
- */
- public static String getCustomLabel(Property property, Collection<String> style) {
- StringBuffer buffer = new StringBuffer();
- // visibility
-
- buffer.append(" ");
- if (style.contains(ICustomAppearance.DISP_VISIBILITY)) {
- buffer.append(getNonNullString(NamedElementUtil.getVisibilityAsSign(property)));
- }
-
- // derived property
- if (style.contains(ICustomAppearance.DISP_DERIVE)) {
- if (property.isDerived()) {
- buffer.append("/");
- }
- }
- // name
- if (style.contains(ICustomAppearance.DISP_NAME)) {
- buffer.append(" ");
- buffer.append(getNonNullString(property.getName()));
- }
-
- if (style.contains(ICustomAppearance.DISP_TYPE)) {
- // type
- if (property.getType() != null) {
- buffer.append(": " + getNonNullString(property.getType().getName()));
- } else {
- buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
- }
- }
-
- if (style.contains(ICustomAppearance.DISP_MULTIPLICITY)) {
- // multiplicity -> do not display [1]
- String multiplicity = getNonNullString(MultiplicityElementUtil.getMultiplicityAsString(property));
- buffer.append(multiplicity);
- } else if (style.contains(ICustomAppearance.DISP_MULTIPLICITY_NO_BRACKETS)) {
- String multiplicity = getNonNullString(MultiplicityElementUtil.formatMultiplicityNoBrackets(property));
- buffer.append(multiplicity);
- }
-
- if (style.contains(ICustomAppearance.DISP_DEFAULT_VALUE)) {
- // default value
- if (property.getDefaultValue() != null) {
- buffer.append(" = ");
- buffer.append(getNonNullString(ValueSpecificationUtil.getSpecificationValue(property.getDefaultValue())));
- }
- }
-
- if (style.contains(ICustomAppearance.DISP_MODIFIERS)) {
- boolean multiLine = style.contains(ICustomAppearance.DISP_MULTI_LINE);
- // property modifiers
- String modifiers = getNonNullString(PropertyUtil.getModifiersAsString(property, multiLine));
- if (!modifiers.equals("")) {
- if (multiLine) {
- buffer.append("\n");
- }
-
- if (!buffer.toString().endsWith(" ")) {
- buffer.append(" ");
- }
-
- buffer.append(modifiers);
- }
- }
- return buffer.toString();
- }
-
- /**
- * Returns the modifier of the property, separated by a comma, as as single line if <code>multiline</code> is <code>false</code> or as a multiline
- * string if <code>multiline</code> is <code>false</code>.
- *
- * @param multiLine
- * boolean that indicates if the string should have several lines when set to <code>true</code> or only one line when set to <code>false</code>.
- *
- * @return a string giving all modifiers for the property
- */
- public static String getModifiersAsString(Property property, boolean multiLine) {
- StringBuffer buffer = new StringBuffer();
- boolean needsComma = false;
- String NL = (multiLine) ? "\n" : " ";
-
- // Return property modifiers
- if (property.isReadOnly()) {
- buffer.append("readOnly");
- needsComma = true;
- }
- if (property.isDerivedUnion()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "union");
- }
- if (property.isOrdered()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "ordered");
- ;
- }
- if (property.isUnique()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "unique");
- }
-
- // is the property redefining another property ?
- for (Property current : property.getRedefinedProperties()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "redefines ");
- buffer.append(current.getName());
- }
-
- // is the property subsetting another property ?
- for (Property current : property.getSubsettedProperties()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "subsets ");
- buffer.append(current.getName());
- }
-
- if (!buffer.toString().equals("")) {
- buffer.insert(0, "{");
- buffer.append("}");
- }
-
- return buffer.toString();
- }
-
- /**
- * Update the modifiers string
- *
- * @param buffer
- * the existing bufferString to append
- * @param needsComma
- * if it needs coma
- * @param NL
- * if it is multiline
- * @param message
- * the message top
- * @return true because the modifier string is no more empty
- */
- private static boolean updateModifiersString(StringBuffer buffer, boolean needsComma, String NL, String message) {
- if (needsComma) {
- buffer.append(",");
- buffer.append(NL);
- }
- buffer.append(message);
- return true;
- }
-}
+/***************************************************************************** + * Copyright (c) 2009 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 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.tools.utils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Property; + +/** + * Utility class for <code>org.eclipse.uml2.uml.Property</code><BR> + */ +public class PropertyUtil { + + /** + * Get all properties that can be subset by this {@link Property} checks the type and the + * multiplicity. + * + * @param property + * property for which the list of subsettable properties are made + * @param noCheck + * set this parameter to <code>true</code> if multiplicity and type check should be + * made for the computation + * @return all properties that can be subset + */ + public static List<Property> getSubsettablesProperties(Property property, boolean noCheck) { + List<Property> list = new ArrayList<Property>(); + + // subset properties: + Iterator<NamedElement> it = property.getClass_().getMembers().iterator(); + while (it.hasNext()) { + + NamedElement element = it.next(); + if (element instanceof Property) { + boolean isValid = true; + Property subsettableProperty = (Property) element; + + // check it is not itself.... + if (subsettableProperty.equals(property)) { + isValid = false; + } + + // check types conformity + if (!noCheck) { + if (property.getType() != null && subsettableProperty.getType() != null) { + if (!property.getType().conformsTo(subsettableProperty.getType())) { + isValid = false; + } + } else { + isValid = false; + } + + // check multiplicity (only upper bound has an OCL rule) + if ((subsettableProperty.getUpper() != -1) && (property.getUpper() > subsettableProperty.getUpper())) { + isValid = false; + } + } + + if (isValid) { + list.add(subsettableProperty); + } + } + } + return list; + } + + /** + * Find a subsetted property given its name and a context to find it. + * + * @param name + * the name of the property + * @return the property found or <code>null</code> if the element was not found. + */ + // @unused + public static Property findSusbsettedPropertyByName(String propertyName, Property property, boolean noCheck) { + Iterator<Property> it = PropertyUtil.getSubsettablesProperties(property, true).iterator(); + while (it.hasNext()) { + Property tmpProperty = it.next(); + String tmpPropertyName = tmpProperty.getName(); + if (tmpPropertyName != null && propertyName.equals(tmpPropertyName.trim())) { + return tmpProperty; + } + } + return null; + } + + /** + * Get all properties that can be redefined by this {@link Property}. + * + * @return all properties that can be redefined + */ + public static List<Property> getRedefinableProperties(Property property) { + List<Property> list = new ArrayList<Property>(); + + // redefine-able properties: + Iterator<NamedElement> it = property.getClass_().getInheritedMembers().iterator(); + while (it.hasNext()) { + NamedElement element = it.next(); + if (element instanceof Property) { + list.add((Property) element); + } + } + + // adds also already redefined members. In fact, when properties are + // redefined, they + // disappear from the inherited members list + Iterator<Property> it2 = property.getRedefinedProperties().iterator(); + while (it2.hasNext()) { + Property element = it2.next(); + list.add(element); + } + return list; + } + + /** + * Find a redefined property given its name and a context to find it. + * + * @param name + * the name of the property + * @return the property found or <code>null</code> if the element was not found. + */ + public static Property findRedefinedPropertyByName(String propertyName, Property property) { + Iterator<Property> it = PropertyUtil.getRedefinableProperties(property).iterator(); + while (it.hasNext()) { + Property tmpProperty = it.next(); + String tmpPropertyName = tmpProperty.getName(); + if (tmpPropertyName != null && propertyName.equals(tmpPropertyName.trim())) { + return tmpProperty; + } + } + return null; + } + + /** + * Get the displayed string for the derived attribute of the property. + * + * @param property + * the property + * @return If the property is derived, return "/". Otherwise return an empty String + */ + public static String getDerived(Property property) { + return property.isDerived() ? "/" : ""; + } + + /** + * return the full label of the property, given UML2 specification. + * + * @return the string corresponding to the label of the property + */ + public static String getLabel(Property property) { + StringBuffer buffer = new StringBuffer(); + // visibility + buffer.append(" "); + buffer.append(getNonNullString(NamedElementUtil.getVisibilityAsSign(property))); + + // derived property + buffer.append(getNonNullString(getDerived(property))); + + // name + buffer.append(" "); + buffer.append(getNonNullString(getName(property))); + + // type + if (property.getType() != null) { + buffer.append(" : " + getNonNullString(UMLLabelInternationalization.getInstance().getLabel(property.getType()))); + } else { + buffer.append(" : " + TypeUtil.UNDEFINED_TYPE_NAME); + } + + // multiplicity -> do not display [1] + String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(property); + if (!multiplicity.trim().equals("[1]")) { + buffer.append(getNonNullString(multiplicity)); + } + + // default value + if (property.getDefaultValue() != null) { + buffer.append(" = "); + buffer.append(getNonNullString(ValueSpecificationUtil.getSpecificationValue(property.getDefaultValue()))); + } + + // property modifiers + buffer.append(getNonNullString(PropertyUtil.getModifiersAsString(property, false))); + + return buffer.toString(); + } + + public static String getName(Property property) { + if (property.getName() != null) { + return UMLLabelInternationalization.getInstance().getLabel(property); + } else { + return (NamedElementUtil.getDefaultNameWithIncrement(property)); + } + } + + private static String getNonNullString(String source) { + return source == null ? "" : source; + } + + /** + * return the custom label of the property, given UML2 specification and a custom style. + * + * @param style + * the collection of label fragments to display + * + * @return the string corresponding to the label of the property + */ + public static String getCustomLabel(Property property, Collection<String> style) { + StringBuffer buffer = new StringBuffer(); + // visibility + + buffer.append(" "); + if (style.contains(ICustomAppearance.DISP_VISIBILITY)) { + buffer.append(getNonNullString(NamedElementUtil.getVisibilityAsSign(property))); + } + + // derived property + if (style.contains(ICustomAppearance.DISP_DERIVE)) { + if (property.isDerived()) { + buffer.append("/"); + } + } + // name + if (style.contains(ICustomAppearance.DISP_NAME)) { + buffer.append(" "); + buffer.append(getNonNullString(UMLLabelInternationalization.getInstance().getLabel(property))); + } + + if (style.contains(ICustomAppearance.DISP_TYPE)) { + // type + if (property.getType() != null) { + buffer.append(": " + getNonNullString(UMLLabelInternationalization.getInstance().getLabel(property.getType()))); + } else { + buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME); + } + } + + if (style.contains(ICustomAppearance.DISP_MULTIPLICITY)) { + // multiplicity -> do not display [1] + String multiplicity = getNonNullString(MultiplicityElementUtil.getMultiplicityAsString(property)); + buffer.append(multiplicity); + } else if (style.contains(ICustomAppearance.DISP_MULTIPLICITY_NO_BRACKETS)) { + String multiplicity = getNonNullString(MultiplicityElementUtil.formatMultiplicityNoBrackets(property)); + buffer.append(multiplicity); + } + + if (style.contains(ICustomAppearance.DISP_DEFAULT_VALUE)) { + // default value + if (property.getDefaultValue() != null) { + buffer.append(" = "); + buffer.append(getNonNullString(ValueSpecificationUtil.getSpecificationValue(property.getDefaultValue(), true))); + } + } + + if (style.contains(ICustomAppearance.DISP_MODIFIERS)) { + boolean multiLine = style.contains(ICustomAppearance.DISP_MULTI_LINE); + // property modifiers + String modifiers = getNonNullString(PropertyUtil.getModifiersAsString(property, multiLine)); + if (!modifiers.equals("")) { + if (multiLine) { + buffer.append("\n"); + } + + if (!buffer.toString().endsWith(" ")) { + buffer.append(" "); + } + + buffer.append(modifiers); + } + } + return buffer.toString(); + } + + /** + * Returns the modifier of the property, separated by a comma, as as single line if <code>multiline</code> is <code>false</code> or as a multiline + * string if <code>multiline</code> is <code>false</code>. + * + * @param multiLine + * boolean that indicates if the string should have several lines when set to <code>true</code> or only one line when set to <code>false</code>. + * + * @return a string giving all modifiers for the property + */ + public static String getModifiersAsString(Property property, boolean multiLine) { + StringBuffer buffer = new StringBuffer(); + boolean needsComma = false; + String NL = (multiLine) ? "\n" : " "; + + // Return property modifiers + if (property.isReadOnly()) { + buffer.append("readOnly"); + needsComma = true; + } + if (property.isDerivedUnion()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "union"); + } + if (property.isOrdered()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "ordered"); + ; + } + if (property.isUnique()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "unique"); + } + + // is the property redefining another property ? + for (Property current : property.getRedefinedProperties()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "redefines "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(current)); + } + + // is the property subsetting another property ? + for (Property current : property.getSubsettedProperties()) { + needsComma = updateModifiersString(buffer, needsComma, NL, "subsets "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(current)); + } + + if (!buffer.toString().equals("")) { + buffer.insert(0, "{"); + buffer.append("}"); + } + + return buffer.toString(); + } + + /** + * Update the modifiers string + * + * @param buffer + * the existing bufferString to append + * @param needsComma + * if it needs coma + * @param NL + * if it is multiline + * @param message + * the message top + * @return true because the modifier string is no more empty + */ + private static boolean updateModifiersString(StringBuffer buffer, boolean needsComma, String NL, String message) { + if (needsComma) { + buffer.append(","); + buffer.append(NL); + } + buffer.append(message); + return true; + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/SignalUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/SignalUtil.java index 3b788ce2b5d..93569ca5f8f 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/SignalUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/SignalUtil.java @@ -1,79 +1,81 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Collection;
-
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Signal;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Signal</code><BR>
- */
-public class SignalUtil {
-
- /**
- * return the custom label of the signal, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the signal
- */
- public static String getCustomLabel(Signal signal, Collection<String> maskValues) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(" "); // adds " " first for correct display considerations
-
- // visibility
- if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(signal));
- }
-
- // name
- if (maskValues.contains(ICustomAppearance.DISP_NAME)) {
- buffer.append(" ");
- buffer.append(signal.getName());
- }
-
- //
- // parameters : '(' parameter-list ')'
- buffer.append("(");
- buffer.append(getPropertiesAsString(signal, maskValues));
- buffer.append(")");
-
- return buffer.toString();
- }
-
- /**
- * Returns signal properties as a string, the label is customized using a bit mask
- *
- * @return a string containing all properties separated by commas
- */
- private static String getPropertiesAsString(Signal signal, Collection<String> maskValues) {
- StringBuffer propertiesString = new StringBuffer();
- boolean firstProperty = true;
- for (Property property : signal.getOwnedAttributes()) {
- // get the label for this property
- String propertyString = PropertyUtil.getCustomLabel(property, maskValues);
- if (!propertyString.trim().equals("")) {
- if (!firstProperty) {
- propertiesString.append(", ");
- }
- propertiesString.append(propertyString);
- firstProperty = false;
- }
- }
- return propertiesString.toString();
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * Atos Origin - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.utils; + +import java.util.Collection; + +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Signal; + +/** + * Utility class for <code>org.eclipse.uml2.uml.Signal</code><BR> + */ +public class SignalUtil { + + /** + * return the custom label of the signal, given UML2 specification and a custom style. + * + * @param style + * the integer representing the style of the label + * + * @return the string corresponding to the label of the signal + */ + public static String getCustomLabel(Signal signal, Collection<String> maskValues) { + StringBuffer buffer = new StringBuffer(); + buffer.append(" "); // adds " " first for correct display considerations + + // visibility + if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) { + buffer.append(NamedElementUtil.getVisibilityAsSign(signal)); + } + + // name + if (maskValues.contains(ICustomAppearance.DISP_NAME)) { + buffer.append(" "); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(signal)); + } + + // + // parameters : '(' parameter-list ')' + buffer.append("("); + buffer.append(getPropertiesAsString(signal, maskValues)); + buffer.append(")"); + + return buffer.toString(); + } + + /** + * Returns signal properties as a string, the label is customized using a bit mask + * + * @return a string containing all properties separated by commas + */ + private static String getPropertiesAsString(Signal signal, Collection<String> maskValues) { + StringBuffer propertiesString = new StringBuffer(); + boolean firstProperty = true; + for (Property property : signal.getOwnedAttributes()) { + // get the label for this property + String propertyString = PropertyUtil.getCustomLabel(property, maskValues); + if (!propertyString.trim().equals("")) { + if (!firstProperty) { + propertiesString.append(", "); + } + propertiesString.append(propertyString); + firstProperty = false; + } + } + return propertiesString.toString(); + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypeUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypeUtil.java index 86714ec6772..fae53a36979 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypeUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypeUtil.java @@ -1,71 +1,73 @@ -/*****************************************************************************
- * Copyright (c) 2009 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.tools.utils;
-
-import java.util.Iterator;
-
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.Type;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Type</code><BR>
- */
-public class TypeUtil {
-
- public final static String UNDEFINED_TYPE_NAME = "<Undefined>";
-
- /**
- * Get a string that displays the name of the type, and then its namespace.
- * <p>
- * For example: "String - UMLPrimitiveType"
- *
- * @return a string that displays information about the type
- */
- public static String getInfoString(Type type) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(type.getName());
- buffer.append(" - ");
- String tmp = "";
- Iterator<Namespace> it = type.allNamespaces().iterator();
- while (it.hasNext()) {
- Namespace namespace = it.next();
- if (it.hasNext()) {
- tmp = NamedElement.SEPARATOR + namespace.getName() + tmp;
- } else {
- tmp = namespace.getName() + tmp;
- }
- }
- buffer.append(tmp);
- return buffer.toString();
- }
-
- /**
- *
- *
- * @param type
- * to check
- *
- * @return true if type is metaclass, else false
- */
- @Deprecated
- // use {@link Class#isMetaclass()} Check if a type is a metaclass.
- public static boolean isMetaclass(Type type) {
- if (type instanceof Class) {
- return ((Class) type).isMetaclass();
- }
- return false;
- }
-}
+/***************************************************************************** + * Copyright (c) 2009 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 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.utils; + +import java.util.Iterator; + +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Namespace; +import org.eclipse.uml2.uml.Type; + +/** + * Utility class for <code>org.eclipse.uml2.uml.Type</code><BR> + */ +public class TypeUtil { + + public final static String UNDEFINED_TYPE_NAME = "<Undefined>"; + + /** + * Get a string that displays the name of the type, and then its namespace. + * <p> + * For example: "String - UMLPrimitiveType" + * + * @return a string that displays information about the type + */ + public static String getInfoString(Type type) { + StringBuffer buffer = new StringBuffer(); + buffer.append(UMLLabelInternationalization.getInstance().getLabel(type)); + buffer.append(" - "); + String tmp = ""; + Iterator<Namespace> it = type.allNamespaces().iterator(); + while (it.hasNext()) { + Namespace namespace = it.next(); + if (it.hasNext()) { + tmp = NamedElement.SEPARATOR + UMLLabelInternationalization.getInstance().getLabel(namespace) + tmp; + } else { + tmp = UMLLabelInternationalization.getInstance().getLabel(namespace) + tmp; + } + } + buffer.append(tmp); + return buffer.toString(); + } + + /** + * + * + * @param type + * to check + * + * @return true if type is metaclass, else false + */ + @Deprecated + // use {@link Class#isMetaclass()} Check if a type is a metaclass. + public static boolean isMetaclass(Type type) { + if (type instanceof Class) { + return ((Class) type).isMetaclass(); + } + return false; + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypedElementUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypedElementUtil.java index cf50dfb5aca..ee227ee94a1 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypedElementUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypedElementUtil.java @@ -1,26 +1,28 @@ -/*****************************************************************************
- * Copyright (c) 2009 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.tools.utils;
-
-import org.eclipse.uml2.uml.TypedElement;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.TypedElement</code><BR>
- */
-public class TypedElementUtil {
-
- public static String getTypeAsString(TypedElement element) {
- return (element.getType() != null) ? element.getType().getName() : "<Undefined>";
- }
-}
+/***************************************************************************** + * Copyright (c) 2009 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 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.utils; + +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.TypedElement; + +/** + * Utility class for <code>org.eclipse.uml2.uml.TypedElement</code><BR> + */ +public class TypedElementUtil { + + public static String getTypeAsString(TypedElement element) { + return (element.getType() != null) ? UMLLabelInternationalization.getInstance().getLabel(element.getType()) : "<Undefined>"; + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ValueSpecificationUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ValueSpecificationUtil.java index 533941c1f97..ac4857301c8 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ValueSpecificationUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ValueSpecificationUtil.java @@ -9,6 +9,7 @@ * * Contributors: * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ @@ -16,6 +17,7 @@ package org.eclipse.papyrus.uml.tools.utils; import java.util.Collection; +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; import org.eclipse.uml2.uml.Constraint; import org.eclipse.uml2.uml.Duration; import org.eclipse.uml2.uml.Expression; @@ -49,6 +51,16 @@ public class ValueSpecificationUtil { * @param specification */ public static String getSpecificationValue(ValueSpecification specification) { + return getSpecificationValue(specification, false); + } + + /** + * Get a string representing of a ValueSpecification + * + * @param specification The Value specification. + * @param useInternationalization Boolean to determinate if the internationalization must be used for the string representation. + */ + public static String getSpecificationValue(final ValueSpecification specification, final boolean useInternationalization) { String value = ""; //$NON-NLS-1$ if (specification != null && specification.eClass() != null) { switch (specification.eClass().getClassifierID()) { @@ -75,7 +87,11 @@ public class ValueSpecificationUtil { break; case UMLPackage.INSTANCE_VALUE: if (((InstanceValue) specification).getInstance() != null) { - value = ((InstanceValue) specification).getInstance().getName(); + if(useInternationalization){ + value = UMLLabelInternationalization.getInstance().getLabel(((InstanceValue) specification).getInstance()); + }else{ + value = ((InstanceValue) specification).getInstance().getName(); + } } break; case UMLPackage.EXPRESSION: @@ -104,7 +120,11 @@ public class ValueSpecificationUtil { if (durationExpr.getExpr() != null) { value = getSpecificationValue(durationExpr.getExpr()); } else if (durationExpr.getObservations().size() > 0) { - value = durationExpr.getObservations().get(0).getName(); + if(useInternationalization){ + value = UMLLabelInternationalization.getInstance().getLabel(durationExpr.getObservations().get(0)); + }else{ + value = durationExpr.getObservations().get(0).getName(); + } } break; case UMLPackage.TIME_EXPRESSION: @@ -112,7 +132,11 @@ public class ValueSpecificationUtil { if (timeExpr.getExpr() != null) { value = getSpecificationValue(timeExpr.getExpr()); } else if (timeExpr.getObservations().size() > 0) { - value = timeExpr.getObservations().get(0).getName(); + if(useInternationalization){ + value = UMLLabelInternationalization.getInstance().getLabel(timeExpr.getObservations().get(0)); + }else{ + value = timeExpr.getObservations().get(0).getName(); + } } break; case UMLPackage.INTERVAL: @@ -148,7 +172,7 @@ public class ValueSpecificationUtil { if (specification != null) { ValueSpecification spe = specification.getSpecification(); if (spe != null) { - value = getSpecificationValue(spe); + value = getSpecificationValue(spe, true); } } return value; diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF index 272a6228f2e..33c9f50b0bb 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF @@ -24,7 +24,9 @@ Require-Bundle: org.eclipse.uml2.uml;bundle-version="[5.2.0,6.0.0)";visibility:= org.eclipse.uml2.uml.validation;bundle-version="[5.0.0,6.0.0)", org.eclipse.papyrus.infra.services.edit.ui;bundle-version="[3.0.0,4.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.core;bundle-version="[2.2.0,3.0.0)", - org.eclipse.papyrus.infra.widgets;bundle-version="[3.0.0,4.0.0)" + org.eclipse.papyrus.infra.widgets;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.uml.internationalization.edit;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: Eclipse Modeling Project Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/Activator.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/Activator.java index 26b5d8d7420..b4a52e99ec3 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/Activator.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/Activator.java @@ -11,6 +11,7 @@ * Patrick Tessier (CEA LIST) - Initial API and implementation * Christian W. Damus (CEA) - bug 425270 * Christian W. Damus - bug 469464 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * /*****************************************************************************/ package org.eclipse.papyrus.uml.tools; @@ -25,6 +26,7 @@ import org.eclipse.emf.edit.provider.ComposedAdapterFactory; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.papyrus.uml.internationalization.edit.providers.InternationalizationUMLItemProviderAdapterFactory; import org.eclipse.papyrus.uml.tools.utils.ElementUtil; import org.eclipse.papyrus.uml.tools.utils.ImageUtil; import org.eclipse.swt.graphics.Image; @@ -99,7 +101,9 @@ public class Activator extends AbstractUIPlugin { } protected ComposedAdapterFactory createAdapterFactory() { - return new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + final ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + composedAdapterFactory.insertAdapterFactory(new InternationalizationUMLItemProviderAdapterFactory()); + return composedAdapterFactory; } public AdapterFactory getItemProviderAdapterFactory() { diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/namereferences/NameReferencesHelper.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/namereferences/NameReferencesHelper.java index d965ed6e27b..4ae88854426 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/namereferences/NameReferencesHelper.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/namereferences/NameReferencesHelper.java @@ -1,231 +1,233 @@ -/*****************************************************************************
- * Copyright (c) 2013 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 (camille.letavernier@cea.fr) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.namereferences;
-
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.papyrus.infra.emf.utils.TextReferencesHelper;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * A Parser Helper to replace references to NamedElements in a text
- *
- * It relies on a parser to search references and replace them with a text value
- *
- * @author Camille Letavernier
- *
- */
-// FIXME: Reimplement listeners mechanism. The listeners are not correctly added/removed (Especially when the referenced element is moved)
-// FIXME: URI changes are not properly detected (ControlMode)
-public class NameReferencesHelper extends TextReferencesHelper {
-
- private ChangeDispatcher listener = new ChangeDispatcher();
-
- public NameReferencesHelper() {
- super();
- // Empty
- }
-
- /**
- *
- * @param baseResource
- * The resource against which the link uris will be resolved
- */
- public NameReferencesHelper(Resource baseResource) {
- super(baseResource);
- }
-
- @Override
- protected String decorate(String text) {
- return "<u>" + text + "</u>";
- }
-
- @Override
- public String replaceReferences(String text) {
- listener.clearElementListeners(); // Remove all previous listeners before adding new ones
- dispatch = false;
- String result = super.replaceReferences(text);
- dispatch = true;
- return result;
- }
-
- /**
- * Returns the String replacement for the given element
- */
- @Override
- protected String getReplacement(EObject elementToReplace, String cachedValue) {
- if (elementToReplace == null) {
- return UNKNOWN_ELEMENT;
- }
-
- if (elementToReplace.eIsProxy()) {
- return PROXY_ELEMENT;
- }
-
- if (elementToReplace instanceof NamedElement) {
- NamedElement target = (NamedElement) elementToReplace;
-
- if (installListeners()) {
-
- if (!target.eAdapters().contains(listener)) {
- // Listen on value changes (NamedElement#name)
- listener.listenOnElement(target);
- }
-
- if (!target.eResource().eAdapters().contains(listener)) {
- // Listen on resource changes (Deletion)
- listener.listenOnElement(target.eResource());
- }
-
- if (target.eContainer() != null && !target.eContainer().eAdapters().contains(listener)) {
- // Listen on the contents of the parent element (Deletion)
- listener.listenOnElement(target.eContainer());
- }
- }
-
- if (target.getName() == null) {
- return "UNNAMED";
- } else {
- return target.getName();
- }
- }
-
- if (cachedValue == null) {
- return UNKNOWN_ELEMENT;
- }
-
- return cachedValue + " (Missing)";
- }
-
- private boolean dispatch = true;
-
- private boolean installListeners() {
- return !this.listener.listeners.isEmpty();
- }
-
- public void addListener(Adapter listener) {
- this.listener.addListener(listener);
- }
-
- public void removeListener(Adapter listener) {
- this.listener.removeListener(listener);
- }
-
- public void dispose() {
- this.listener.dispose();
- this.resourceSet = null;
- this.baseResource = null;
- }
-
- private class ChangeDispatcher extends AdapterImpl {
-
- private final Set<Adapter> listeners = new HashSet<Adapter>();
-
- private final Set<Notifier> listenOnElements = new HashSet<Notifier>();
-
- @Override
- public void notifyChanged(Notification msg) {
- // A change occurred on one of the referenced elements
- try {
- if (dispatch && isValidNotification(msg)) {
- for (Adapter listener : listeners) {
- try {
- listener.notifyChanged(msg);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- // The current implementation is not strict. This will lead to useless refreshes
- // (e.g. each time the contents of the parent change, or when the name of the parent changes)
- // The NameReferencesHelper should probably handle its own listeners, and call a
- // refresh/listener method when updated, to be more precise
- boolean isValidNotification(Notification msg) {
- if (!listenOnElements.contains(msg.getNotifier())) {
- Object notifierObject = msg.getNotifier();
- if (notifierObject instanceof Notifier) {
- ((Notifier) notifierObject).eAdapters().remove(this);
- }
- return false;
- }
-
- // Name of a NamedElement
- if (msg.getFeature() == UMLPackage.eINSTANCE.getNamedElement_Name()) {
- return true;
- }
-
- // Resource contents
- if (msg.getNotifier() instanceof Resource) {
- return true;
- }
-
- // Parent contents
- Object feature = msg.getFeature();
- if (feature instanceof EReference) {
- if (((EReference) feature).isContainment()) {
- return true;
- }
- }
-
- return false;
- }
-
- public void addListener(Adapter listener) {
- listeners.add(listener);
- }
-
- public void removeListener(Adapter listener) {
- listeners.remove(listener);
- }
-
- private void listenOnElement(Notifier element) {
- if (element.eAdapters().contains(this)) {
- return;
- }
-
- listenOnElements.add(element);
- element.eAdapters().add(this);
- }
-
- private void clearElementListeners() {
- List<Notifier> notifiers = new LinkedList<Notifier>(listenOnElements);
- for (Notifier notifier : notifiers) {
- notifier.eAdapters().remove(this);
- }
- listenOnElements.clear();
- }
-
- public void dispose() {
- listeners.clear();
- clearElementListeners();
- }
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2013 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 (camille.letavernier@cea.fr) - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.namereferences; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.papyrus.infra.emf.utils.TextReferencesHelper; +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * A Parser Helper to replace references to NamedElements in a text + * + * It relies on a parser to search references and replace them with a text value + * + * @author Camille Letavernier + * + */ +// FIXME: Reimplement listeners mechanism. The listeners are not correctly added/removed (Especially when the referenced element is moved) +// FIXME: URI changes are not properly detected (ControlMode) +public class NameReferencesHelper extends TextReferencesHelper { + + private ChangeDispatcher listener = new ChangeDispatcher(); + + public NameReferencesHelper() { + super(); + // Empty + } + + /** + * + * @param baseResource + * The resource against which the link uris will be resolved + */ + public NameReferencesHelper(Resource baseResource) { + super(baseResource); + } + + @Override + protected String decorate(String text) { + return "<u>" + text + "</u>"; + } + + @Override + public String replaceReferences(String text) { + listener.clearElementListeners(); // Remove all previous listeners before adding new ones + dispatch = false; + String result = super.replaceReferences(text); + dispatch = true; + return result; + } + + /** + * Returns the String replacement for the given element + */ + @Override + protected String getReplacement(EObject elementToReplace, String cachedValue) { + if (elementToReplace == null) { + return UNKNOWN_ELEMENT; + } + + if (elementToReplace.eIsProxy()) { + return PROXY_ELEMENT; + } + + if (elementToReplace instanceof NamedElement) { + NamedElement target = (NamedElement) elementToReplace; + + if (installListeners()) { + + if (!target.eAdapters().contains(listener)) { + // Listen on value changes (NamedElement#name) + listener.listenOnElement(target); + } + + if (!target.eResource().eAdapters().contains(listener)) { + // Listen on resource changes (Deletion) + listener.listenOnElement(target.eResource()); + } + + if (target.eContainer() != null && !target.eContainer().eAdapters().contains(listener)) { + // Listen on the contents of the parent element (Deletion) + listener.listenOnElement(target.eContainer()); + } + } + + if (target.getName() == null) { + return "UNNAMED"; + } else { + return UMLLabelInternationalization.getInstance().getLabel(target); + } + } + + if (cachedValue == null) { + return UNKNOWN_ELEMENT; + } + + return cachedValue + " (Missing)"; + } + + private boolean dispatch = true; + + private boolean installListeners() { + return !this.listener.listeners.isEmpty(); + } + + public void addListener(Adapter listener) { + this.listener.addListener(listener); + } + + public void removeListener(Adapter listener) { + this.listener.removeListener(listener); + } + + public void dispose() { + this.listener.dispose(); + this.resourceSet = null; + this.baseResource = null; + } + + private class ChangeDispatcher extends AdapterImpl { + + private final Set<Adapter> listeners = new HashSet<Adapter>(); + + private final Set<Notifier> listenOnElements = new HashSet<Notifier>(); + + @Override + public void notifyChanged(Notification msg) { + // A change occurred on one of the referenced elements + try { + if (dispatch && isValidNotification(msg)) { + for (Adapter listener : listeners) { + try { + listener.notifyChanged(msg); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + // The current implementation is not strict. This will lead to useless refreshes + // (e.g. each time the contents of the parent change, or when the name of the parent changes) + // The NameReferencesHelper should probably handle its own listeners, and call a + // refresh/listener method when updated, to be more precise + boolean isValidNotification(Notification msg) { + if (!listenOnElements.contains(msg.getNotifier())) { + Object notifierObject = msg.getNotifier(); + if (notifierObject instanceof Notifier) { + ((Notifier) notifierObject).eAdapters().remove(this); + } + return false; + } + + // Name of a NamedElement + if (msg.getFeature() == UMLPackage.eINSTANCE.getNamedElement_Name()) { + return true; + } + + // Resource contents + if (msg.getNotifier() instanceof Resource) { + return true; + } + + // Parent contents + Object feature = msg.getFeature(); + if (feature instanceof EReference) { + if (((EReference) feature).isContainment()) { + return true; + } + } + + return false; + } + + public void addListener(Adapter listener) { + listeners.add(listener); + } + + public void removeListener(Adapter listener) { + listeners.remove(listener); + } + + private void listenOnElement(Notifier element) { + if (element.eAdapters().contains(this)) { + return; + } + + listenOnElements.add(element); + element.eAdapters().add(this); + } + + private void clearElementListeners() { + List<Notifier> notifiers = new LinkedList<Notifier>(listenOnElements); + for (Notifier notifier : notifiers) { + notifier.eAdapters().remove(this); + } + listenOnElements.clear(); + } + + public void dispose() { + listeners.clear(); + clearElementListeners(); + } + } + +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLLabelProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLLabelProvider.java index 371c9efe2ab..be1bc75f6d8 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLLabelProvider.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLLabelProvider.java @@ -9,6 +9,7 @@ * Contributors: * Patrick Tessier (CEA LIST) - Initial API and implementation * Christian W. Damus (CEA) - bug 425270 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * /*****************************************************************************/ package org.eclipse.papyrus.uml.tools.providers; @@ -17,10 +18,12 @@ import java.util.Iterator; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.gmf.runtime.notation.DecorationNode; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.emf.utils.TextReferencesHelper; import org.eclipse.papyrus.infra.ui.emf.providers.EMFLabelProvider; +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; import org.eclipse.papyrus.uml.tools.Activator; import org.eclipse.papyrus.uml.tools.namereferences.NameReferencesHelper; import org.eclipse.papyrus.uml.tools.utils.ImageUtil; @@ -36,7 +39,6 @@ import org.eclipse.uml2.uml.InstanceSpecification; import org.eclipse.uml2.uml.InstanceValue; import org.eclipse.uml2.uml.LiteralNull; import org.eclipse.uml2.uml.LiteralString; -import org.eclipse.uml2.uml.MultiplicityElement; import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Operation; import org.eclipse.uml2.uml.OperationTemplateParameter; @@ -51,7 +53,6 @@ import org.eclipse.uml2.uml.Type; import org.eclipse.uml2.uml.UMLPackage; import org.eclipse.uml2.uml.ValueSpecification; import org.eclipse.uml2.uml.edit.UMLEditPlugin; -import org.eclipse.uml2.uml.edit.providers.MultiplicityElementItemProvider; import org.eclipse.uml2.uml.util.UMLUtil; /** @@ -157,12 +158,12 @@ public class UMLLabelProvider extends EMFLabelProvider implements ILabelProvider appendString(text, "/"); //$NON-NLS-1$ } - final String label = property.getLabel(shouldTranslate()); + final String label = UMLLabelInternationalization.getInstance().getLabel(property, shouldTranslate()); if (!UML2Util.isEmpty(label)) { appendString(text, label); } else if (property.getAssociation() != null && type != null) { - final String typeName = type.getName(); + final String typeName = UMLLabelInternationalization.getInstance().getLabel(type, shouldTranslate()); if (!UML2Util.isEmpty(typeName)) { if(property instanceof ExtensionEnd){ @@ -307,14 +308,16 @@ public class UMLLabelProvider extends EMFLabelProvider implements ILabelProvider if (value != null) { if (((NamedElement) element).isSetName() && null != ((NamedElement) element).getName()) { - return ((NamedElement) element).getName() + "=" + value; //$NON-NLS-1$ + return UMLLabelInternationalization.getInstance().getLabel(((NamedElement) element), shouldTranslate()) + "=" + value; //$NON-NLS-1$ } else { + // TODO: Maybe use labelInternationalization? But how qualifiedName must be set? return value; } } else { if (((NamedElement) element).isSetName() && null != ((NamedElement) element).getName()) { - return ((NamedElement) element).getName(); + return UMLLabelInternationalization.getInstance().getLabel(((NamedElement) element), shouldTranslate()); } else { + // TODO: Maybe use labelInternationalization? But how qualifiedName must be set? return ""; //$NON-NLS-1$ } } @@ -339,7 +342,7 @@ public class UMLLabelProvider extends EMFLabelProvider implements ILabelProvider String out = ""; if (templateParam.getParameteredElement() instanceof NamedElement) { NamedElement namedElement = (NamedElement) templateParam.getParameteredElement(); - out = namedElement.getName() + ": " + namedElement.eClass().getName(); + out = UMLLabelInternationalization.getInstance().getLabel(namedElement, shouldTranslate()) + ": " + namedElement.eClass().getName(); } if (templateParam instanceof OperationTemplateParameter) { @@ -351,7 +354,7 @@ public class UMLLabelProvider extends EMFLabelProvider implements ILabelProvider if (!((ClassifierTemplateParameter) templateParam).getConstrainingClassifiers().isEmpty()) { out = out + ">"; for (int i = 0; i < ((ClassifierTemplateParameter) templateParam).getConstrainingClassifiers().size(); i++) { - out = out + ((ClassifierTemplateParameter) templateParam).getConstrainingClassifiers().get(i).getName(); + out = out + UMLLabelInternationalization.getInstance().getLabel(((ClassifierTemplateParameter) templateParam).getConstrainingClassifiers().get(i), shouldTranslate()); if (i < ((ClassifierTemplateParameter) templateParam).getConstrainingClassifiers().size() - 1) { out = out + ", "; } @@ -362,7 +365,7 @@ public class UMLLabelProvider extends EMFLabelProvider implements ILabelProvider if (templateParam.getDefault() instanceof Operation) { out = out + "=" + displayOperation((Operation) templateParam.getDefault()); } else if (templateParam.getDefault() instanceof NamedElement) { - out = out + "=" + ((NamedElement) templateParam.getDefault()).getName(); + out = out + "=" + UMLLabelInternationalization.getInstance().getLabel(((NamedElement) templateParam.getDefault()), shouldTranslate()); } return out; } @@ -374,10 +377,10 @@ public class UMLLabelProvider extends EMFLabelProvider implements ILabelProvider String out = ""; TemplateParameterSubstitution substitution = (TemplateParameterSubstitution) element; if (substitution.getFormal() != null && substitution.getFormal().getParameteredElement() instanceof NamedElement) { - out = out + ((NamedElement) substitution.getFormal().getParameteredElement()).getName(); + out = out + UMLLabelInternationalization.getInstance().getLabel(((NamedElement) substitution.getFormal().getParameteredElement()), shouldTranslate()); } if (substitution.getActual() instanceof NamedElement) { - out = out + " -> " + ((NamedElement) substitution.getActual()).getName() + "\n"; + out = out + " -> " + UMLLabelInternationalization.getInstance().getLabel(((NamedElement) substitution.getActual()), shouldTranslate()) + "\n"; } return out; } @@ -471,11 +474,11 @@ public class UMLLabelProvider extends EMFLabelProvider implements ILabelProvider * @return the label */ protected String displayOperation(Operation op) { - String out = op.getName() + "("; + String out = UMLLabelInternationalization.getInstance().getLabel(op, shouldTranslate()) + "("; Iterator<Parameter> iter = op.getOwnedParameters().iterator(); while (iter.hasNext()) { Parameter param = iter.next(); - out = out + param.getName(); + out = out + UMLLabelInternationalization.getInstance().getLabel(param, shouldTranslate()); if (!param.equals(op.getOwnedParameters().get(op.getOwnedParameters().size() - 1))) { out = out + ", "; } diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLMetaclassContentProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLMetaclassContentProvider.java index 94890932e8f..699c9e61d61 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLMetaclassContentProvider.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLMetaclassContentProvider.java @@ -9,6 +9,7 @@ * * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ package org.eclipse.papyrus.uml.tools.providers; @@ -19,6 +20,7 @@ import java.util.List; import org.eclipse.papyrus.infra.widgets.providers.AbstractFilteredContentProvider; import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; import org.eclipse.papyrus.uml.tools.utils.ElementUtil; import org.eclipse.uml2.uml.Class; import org.eclipse.uml2.uml.Element; @@ -57,11 +59,11 @@ public class UMLMetaclassContentProvider extends AbstractFilteredContentProvider public int compare(Class firstClass, Class secondClass) { // Use default lexicographically sorter of String based on Class name - String firstName = firstClass.getName(); + String firstName = UMLLabelInternationalization.getInstance().getLabel(firstClass); if (firstName == null) { return 0; } - return firstName.compareTo(secondClass.getName()); + return firstName.compareTo(UMLLabelInternationalization.getInstance().getLabel(secondClass)); } }); diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLMetaclassLabelProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLMetaclassLabelProvider.java index 8734dc10802..90372dfde59 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLMetaclassLabelProvider.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLMetaclassLabelProvider.java @@ -1,78 +1,80 @@ -/*****************************************************************************
- * Copyright (c) 2013 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.providers;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * Label provider for UML Metaclass
- *
- * @author Vincent Lorenzo
- *
- */
-public class UMLMetaclassLabelProvider extends UMLEClassLabelProvider {
-
- /**
- *
- * @see org.eclipse.papyrus.uml.tools.providers.UMLFilteredLabelProvider#accept(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public boolean accept(Object element) {
- if (element instanceof Class) {
- return ((Class) element).isMetaclass();
- }
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider#getText(org.eclipse.emf.ecore.EObject)
- *
- * @param element
- * @return
- */
- @Override
- protected String getText(final EObject element) {
- return ((Class) element).getName();
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider#getImage(org.eclipse.emf.ecore.EObject)
- *
- * @param element
- * @return
- */
- @Override
- protected Image getImage(EObject element) {
- EClass umlEClass = null;
- if (element instanceof Class) {
- EClassifier classifier = UMLPackage.eINSTANCE.getEClassifier(((Class) element).getName());
- if (classifier instanceof EClass) {
- umlEClass = (EClass) classifier;
- return super.getImage(umlEClass);
- }
- }
- return null;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2013 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: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.providers; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * Label provider for UML Metaclass + * + * @author Vincent Lorenzo + * + */ +public class UMLMetaclassLabelProvider extends UMLEClassLabelProvider { + + /** + * + * @see org.eclipse.papyrus.uml.tools.providers.UMLFilteredLabelProvider#accept(java.lang.Object) + * + * @param element + * @return + */ + @Override + public boolean accept(Object element) { + if (element instanceof Class) { + return ((Class) element).isMetaclass(); + } + return false; + } + + /** + * + * @see org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider#getText(org.eclipse.emf.ecore.EObject) + * + * @param element + * @return + */ + @Override + protected String getText(final EObject element) { + return UMLLabelInternationalization.getInstance().getLabel(((Class) element)); + } + + /** + * + * @see org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider#getImage(org.eclipse.emf.ecore.EObject) + * + * @param element + * @return + */ + @Override + protected Image getImage(EObject element) { + EClass umlEClass = null; + if (element instanceof Class) { + EClassifier classifier = UMLPackage.eINSTANCE.getEClassifier(((Class) element).getName()); + if (classifier instanceof EClass) { + umlEClass = (EClass) classifier; + return super.getImage(umlEClass); + } + } + return null; + } + +}
\ No newline at end of file |