Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Philipp Steghöfer2020-12-09 13:31:47 +0000
committerJan-Philipp Steghöfer2020-12-09 13:37:52 +0000
commitdf0ee7bb76f7ece0dc134f541ddad462ac1cb41f (patch)
treea2b4339f8bd3243b589cfb2a2fe789f90f220ef9
parentb5b8c5605e9d7f003602f3b65b9d5d273ba6714b (diff)
downloadorg.eclipse.capra-df0ee7bb76f7ece0dc134f541ddad462ac1cb41f.tar.gz
org.eclipse.capra-df0ee7bb76f7ece0dc134f541ddad462ac1cb41f.tar.xz
org.eclipse.capra-df0ee7bb76f7ece0dc134f541ddad462ac1cb41f.zip
Improved visualisation of artifacts in views by removing line breaks
This patch fixes several issues with artifact names that contain line. Line breaks caused problems in some of the visualisations such as the PlantUML view. This patch fixes this issue by removing line breaks in three different places: * the ArtifactHelper.getArtifactLabel() method, used, e.g., by the matrix view; * the Connections.getLabel() and Connections.getOriginLabel() methods which are used by the PlantUML view; and * the OfficeHandler.getDisplayName() methods which fixes issues in the OfficeView. Change-Id: I884271ebcd8d34533445e6ee15833eda2d684709
-rw-r--r--bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/ArtifactHelper.java9
-rw-r--r--bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java7
-rw-r--r--bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/Connections.java15
3 files changed, 21 insertions, 10 deletions
diff --git a/bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/ArtifactHelper.java b/bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/ArtifactHelper.java
index 8fd8c96b..8706105b 100644
--- a/bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/ArtifactHelper.java
+++ b/bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/ArtifactHelper.java
@@ -27,7 +27,8 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
public class ArtifactHelper {
- private static final String CHARACTERS_TO_BE_REMOVED = "[\", \']";
+ private static final String QUOTE_CHARACTERS = "[\"\']";
+ private static final String NEWLINE_CHARACTERS = "[\r\n]+";
private EObject artifactModel;
@@ -44,6 +45,10 @@ public class ArtifactHelper {
// IArtifactHandler<?>.
private static Collection<? extends IArtifactHandler<?>> handlers = ExtensionPointHelper.getArtifactHandlers();
+ private String sanitize(String input) {
+ return input.replaceAll(QUOTE_CHARACTERS, " ").replaceAll(NEWLINE_CHARACTERS, " ");
+ }
+
/**
* @param artifactModel
*/
@@ -147,7 +152,7 @@ public class ArtifactHelper {
}
// remove unwanted characters like ", '
if (artifactLabel != null) {
- return artifactLabel.replaceAll(CHARACTERS_TO_BE_REMOVED, " ");
+ return sanitize(artifactLabel);
} else {
// This can happen if the trace model contains elements for which
// the artifact handler is not available.
diff --git a/bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java b/bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java
index e3ee3bf3..e8366a5b 100644
--- a/bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java
+++ b/bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java
@@ -40,7 +40,7 @@ public class OfficeHandler extends AbstractArtifactHandler<CapraOfficeObject> {
// an EObject, or if it is Adaptable to an EObject
ArtifactMetaModelAdapter adapter = ExtensionPointHelper.getArtifactWrapperMetaModelAdapter().get();
EObject wrapper = adapter.createArtifact(artifactModel, this.getClass().getName(), officeObject.getUri(),
- officeObject.getData(), officeObject.getUri());
+ this.getDisplayName(officeObject), officeObject.getUri());
return wrapper;
}
@@ -56,13 +56,14 @@ public class OfficeHandler extends AbstractArtifactHandler<CapraOfficeObject> {
@Override
public String getDisplayName(CapraOfficeObject officeObject) {
- int minAllowed = Activator.getDefault().getPreferenceStore()
- .getInt(OfficePreferences.CHAR_COUNT);
+ int minAllowed = Activator.getDefault().getPreferenceStore().getInt(OfficePreferences.CHAR_COUNT);
String text = officeObject.toString();
int textLength = Math.min(text.length(), minAllowed);
if (textLength == minAllowed) {
text = text.substring(0, textLength) + "...";
}
+ // Remove new lines
+ text = text.replaceAll("\\R+", " ");
return text;
}
diff --git a/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/Connections.java b/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/Connections.java
index 6d5f273f..4b501bfb 100644
--- a/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/Connections.java
+++ b/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/Connections.java
@@ -34,11 +34,12 @@ import com.google.common.base.Strings;
* Helper class for generating PlantUML diagrams from a collection of
* {@link Connection}
*
- * @author Anthony Anjorin, Salome Maro
+ * @author Anthony Anjorin, Salome Maro, Jan-Philipp Steghöfer
*/
public class Connections {
- private static final String CHARACTERS_TO_BE_REMOVED = "[\", \']";
+ private static final String QUOTE_CHARACTERS = "[\"\']";
+ private static final String NEWLINE_CHARACTERS = "[\r\n]+";
private List<Connection> connections;
private EObject origin;
@@ -48,7 +49,11 @@ public class Connections {
private Map<String, String> id2Location;
private ArtifactHelper artifactHelper;
-
+
+ private String sanitize(String input) {
+ return input.replaceAll(QUOTE_CHARACTERS, " ").replaceAll(NEWLINE_CHARACTERS, " ");
+ }
+
Connections(List<Connection> connections, List<EObject> selectedObjects, EObject artifactModel) {
this.artifactHelper = new ArtifactHelper(artifactModel);
this.connections = connections;
@@ -78,7 +83,7 @@ public class Connections {
}
public String originLabel() {
- return id2Label.get(object2Id.get(origin));
+ return sanitize(id2Label.get(object2Id.get(origin)));
}
public String originLocation() {
@@ -101,7 +106,7 @@ public class Connections {
}
public String label(String id) {
- return id2Label.get(id);
+ return sanitize(id2Label.get(id));
}
public String location(String id) {

Back to the top