diff options
Diffstat (limited to 'plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org')
3 files changed, 72 insertions, 11 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/Decoration.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/Decoration.java index 03394f9be3a..4d4c4014959 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/Decoration.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/Decoration.java @@ -18,7 +18,6 @@ package org.eclipse.papyrus.infra.services.decoration.util; import java.util.List; -import org.apache.commons.lang.WordUtils; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IDecoration; @@ -121,6 +120,7 @@ public class Decoration implements IPapyrusDecoration { /** * @return the type (corresponding to marker type) */ + @Override public String getType() { return type; } @@ -132,6 +132,7 @@ public class Decoration implements IPapyrusDecoration { * @see org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration#getMessage() */ + @Override public String getMessage() { return message; } @@ -145,6 +146,7 @@ public class Decoration implements IPapyrusDecoration { * @see org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration#setMessage(java.lang.String) */ + @Override public void setMessage(String message) { this.message = message; } @@ -176,6 +178,7 @@ public class Decoration implements IPapyrusDecoration { * @return the decoration image * @see org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration#getDecorationImage() */ + @Override public ImageDescriptor getDecorationImageForGE() { return decorationImageForGE; } @@ -187,6 +190,7 @@ public class Decoration implements IPapyrusDecoration { * the new decoration image * @see org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration#setDecorationImageForGE(org.eclipse.jface.resource.ImageDescriptor) */ + @Override public void setDecorationImageForGE(ImageDescriptor decorationImageForGE) { this.decorationImageForGE = decorationImageForGE; } @@ -197,6 +201,7 @@ public class Decoration implements IPapyrusDecoration { * @return the decoration image * @see org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration#getDecorationImage() */ + @Override public ImageDescriptor getDecorationImageForME() { return decorationImageForME; } @@ -208,6 +213,7 @@ public class Decoration implements IPapyrusDecoration { * the new decoration image * @see org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration#setDecorationImageForGE(org.eclipse.jface.resource.ImageDescriptor) */ + @Override public void setDecorationImageForME(ImageDescriptor decorationImageForME) { this.decorationImageForME = decorationImageForME; } @@ -219,6 +225,7 @@ public class Decoration implements IPapyrusDecoration { * @return the position * @see org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration#getPosition() */ + @Override public PreferedPosition getPosition() { return position; } @@ -232,6 +239,7 @@ public class Decoration implements IPapyrusDecoration { * @see org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration#setPosition(org.eclipse.papyrus.infra.services.decoration.util.Decoration.PreferedPosition) */ + @Override public void setPosition(PreferedPosition position) { this.position = position; } @@ -240,6 +248,7 @@ public class Decoration implements IPapyrusDecoration { * @return the decoration position as enumerated by constants in IDecoration from JFace * (TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, UNDERLAY */ + @Override public int getPositionForJFace() { switch (position) { case NORTH_WEST: @@ -287,7 +296,7 @@ public class Decoration implements IPapyrusDecoration { message += "\n"; //$NON-NLS-1$ } if (decoration.getMessage() != null) { - message += WordUtils.wrap(decoration.getMessage(), 100, "\n ", true); //$NON-NLS-1$ + message += "- " + StringUtils.stringWrap(decoration.getMessage(), 100, "\n "); //$NON-NLS-1$ //$NON-NLS-2$ } } } @@ -304,6 +313,7 @@ public class Decoration implements IPapyrusDecoration { * * @return the priority */ + @Override public int getPriority() { return priority; } @@ -314,6 +324,7 @@ public class Decoration implements IPapyrusDecoration { * @param priority * the new priority */ + @Override public void setPriority(int priority) { this.priority = priority; } diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/DecorationUtils.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/DecorationUtils.java index e4de77510ff..e21053b28d1 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/DecorationUtils.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/DecorationUtils.java @@ -18,7 +18,6 @@ package org.eclipse.papyrus.infra.services.decoration.util; import java.util.HashMap; import java.util.Map; -import org.apache.commons.lang.WordUtils; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; @@ -57,7 +56,7 @@ public class DecorationUtils { } EObject eObject = EMFHelper.getEObject(element); - eObjects = new BasicEList<EObject>(); + eObjects = new BasicEList<>(); this.element = element; if (eObject != null) { @@ -83,7 +82,7 @@ public class DecorationUtils { if (eObject == null) { throw new IllegalArgumentException("The decorated EObject shall not be null"); //$NON-NLS-1$ } - eObjects = new BasicEList<EObject>(); + eObjects = new BasicEList<>(); eObjects.add(eObject); } @@ -121,8 +120,8 @@ public class DecorationUtils { public EList<IPapyrusDecoration> getDecorations(DecorationService decorationService, boolean navigateToParents) { Map<String, Decoration> decorations = getDecorations(decorationService); // child decorations are organized in a map indexed by the decoration type - EList<IPapyrusDecoration> foundDecorations = new BasicEList<IPapyrusDecoration>(); - Map<String, EList<IPapyrusDecoration>> childDecorationMap = new HashMap<String, EList<IPapyrusDecoration>>(); + EList<IPapyrusDecoration> foundDecorations = new BasicEList<>(); + Map<String, EList<IPapyrusDecoration>> childDecorationMap = new HashMap<>(); if (decorations != null) { for (Decoration decoration : decorations.values()) { EObject eObjectOfDecorator = decoration.getElement(); @@ -148,7 +147,7 @@ public class DecorationUtils { EList<IPapyrusDecoration> childDecorations = childDecorationMap.get(type); if (childDecorations == null) { // does not exist yet => create - childDecorations = new BasicEList<IPapyrusDecoration>(); + childDecorations = new BasicEList<>(); childDecorationMap.put(type, childDecorations); } childDecorations.add(decoration); @@ -188,8 +187,8 @@ public class DecorationUtils { * @param decorationService * the decoration service * @return the decoration message - * - * @deprecated, use {@link Decoration#getMessageFromDecorations(DecorationService, Object)} instead of this method + * + * @deprecated, use {@link Decoration#getMessageFromDecorations(DecorationService, Object)} instead of this method */ @Deprecated public String getDecorationMessage(DecorationService decorationService) { @@ -203,7 +202,7 @@ public class DecorationUtils { if (message.length() > 0) { message += "\n"; //$NON-NLS-1$ } - message += "- " + WordUtils.wrap(decoration.getMessage(), 100, "\n ", true); //$NON-NLS-1$ //$NON-NLS-2$ + message += "- " + StringUtils.stringWrap(decoration.getMessage(), 100, "\n "); //$NON-NLS-1$ //$NON-NLS-2$ } } return (message.length() > 0) ? message : null; diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/StringUtils.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/StringUtils.java new file mode 100755 index 00000000000..51430a501bd --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.decoration/src/org/eclipse/papyrus/infra/services/decoration/util/StringUtils.java @@ -0,0 +1,51 @@ +/***************************************************************************** + * Copyright (c) 2022 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.services.decoration.util; + +/** + * This class provides useful methods for String + * + * @since 3.1 + */ +class StringUtils { + + /** + * replace WordUtils.wrap of Apache + * code found on https://stackoverflow.com/questions/4212675/wrap-the-string-after-a-number-of-characters-word-wise-in-java + * + * @param s + * the message + * @param length + * number of carters per line + * @param separator + * the line separator + * @return + * the wrapped string + */ + static String stringWrap(String s, int length, String separator) { + String message = ""; //$NON-NLS-1$ + int position = 0; + for (String token : s.split(" ", -1)) { //$NON-NLS-1$ + if (message.length() - position + token.length() > length) { + message = message + separator + token; + position = message.length() + 1; + } else { + message += (message.isEmpty() ? "" : " ") + token; //$NON-NLS-1$ //$NON-NLS-2$ + } + } + return message; + } +} |