From 53d6af754d7d91ebe07bb6c37bd35cc0999ff444 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Wed, 22 May 2013 10:20:12 +0200 Subject: [PATCH] Improved the handling of new edges. --- .../view/CurrentAnalysisEditorGraphBean.java | 68 +++++++++++-------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java index b1d76118..6b44b5f6 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java @@ -36,6 +36,7 @@ import kieker.webgui.web.beans.session.UserBean; import org.primefaces.context.RequestContext; import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -114,8 +115,10 @@ public class CurrentAnalysisEditorGraphBean { private static final String JS_CMD_LOAD_FROM_LAYOUT = "graph.loadPositions('%s')"; private static final String JS_CMD_RENAME_NODE = "graph.setNodeData('%s', {'name' : '%s'})"; - private final Registry<MIRepositoryConnector> repositoryPortMap = new Registry<MIRepositoryConnector>(); - private final Registry<MIPort> filterPortMap = new Registry<MIPort>(); + /** + * We store both instance of MIRepositoryConnector and MIPort in this map. This is necessary as we have to find the correct port when an edge has been created. + */ + private final Registry<EObject> portMap = new Registry<EObject>(); private final Registry<MIAnalysisComponent> componentMap = new Registry<MIAnalysisComponent>(); private CurrentAnalysisEditorBean currentAnalysisEditorBean; @@ -330,26 +333,37 @@ public class CurrentAnalysisEditorGraphBean { public void edgeCreated() { // Get the parameters final Object[] parameters = GlobalPropertiesBean.convertObjectsFromParameterMap(PARAMETER_NAMES_ADD_AND_REMOVE_EDGES, PARAMETER_TYPES_ADD_AND_REMOVE_EDGES); - final String sourcePortID = ((String) parameters[0]).split("\\.")[1]; - final String targetPortID = ((String) parameters[1]).split("\\.")[1]; + final String sourceIDAsStr = ((String) parameters[0]).split("\\.")[0]; + final String sourcePortIDAsStr = ((String) parameters[0]).split("\\.")[1]; + final String targetIDAsStr = ((String) parameters[1]).split("\\.")[0]; + final String targetPortIDAsStr = ((String) parameters[1]).split("\\.")[1]; - // Now search the correct components try { - if (REPOSITORY_INPUT_PORT.equals(targetPortID)) { - // This is a special case: An edge between a filter and a repository - final MIRepositoryConnector sourcePort = this.repositoryPortMap.get(Integer.parseInt(sourcePortID)); - final String targetID = ((String) parameters[1]).split("\\.")[0]; - final MIAnalysisComponent targetRepo = this.componentMap.get(Integer.parseInt(targetID.substring(2))); - if ((sourcePort != null) && (targetRepo instanceof MIRepository) && (this.currentAnalysisEditorBean != null)) { - this.currentAnalysisEditorBean.edgeCreated(sourcePort, (MIRepository) targetRepo); - } - } else { - // This is the normal case: An edge between two filters - final MIPort sourcePort = this.filterPortMap.get(Integer.parseInt(sourcePortID)); - final MIPort targetPort = this.filterPortMap.get(Integer.parseInt(targetPortID)); - - if ((sourcePort != null) && (targetPort != null) && (this.currentAnalysisEditorBean != null)) { - this.currentAnalysisEditorBean.edgeCreated((MIOutputPort) sourcePort, (MIInputPort) targetPort); + // Convert the IDs + final int sourceID = Integer.parseInt(sourceIDAsStr.substring(2)); + final int sourcePortID = Integer.parseInt(sourcePortIDAsStr); + final int targetID = Integer.parseInt(targetIDAsStr.substring(2)); + + this.componentMap.get(sourceID); + final MIAnalysisComponent target = this.componentMap.get(targetID); + + // There are only two allowed cases: A connection between two filters with regular ports and a connection between a filter and a repository using the + // repository ports. + if (!REPOSITORY_INPUT_PORT.equals(sourcePortIDAsStr)) { + // Source is not the special port of a repository + final EObject sourcePort = this.portMap.get(sourcePortID); + if (REPOSITORY_INPUT_PORT.equals(targetPortIDAsStr)) { + // Target is the special port of a repository + if (sourcePort instanceof MIRepositoryConnector) { + this.currentAnalysisEditorBean.edgeCreated((MIRepositoryConnector) sourcePort, (MIRepository) target); + } + } else { + // Target is not the special port of a repository + final int targetPortID = Integer.parseInt(targetPortIDAsStr); + final EObject targetPort = this.portMap.get(targetPortID); + if ((sourcePort instanceof MIOutputPort) && (targetPort instanceof MIInputPort)) { + this.currentAnalysisEditorBean.edgeCreated((MIOutputPort) sourcePort, (MIInputPort) targetPort); + } } } } catch (final NumberFormatException ex) { @@ -372,7 +386,7 @@ public class CurrentAnalysisEditorGraphBean { try { if (CurrentAnalysisEditorGraphBean.REPOSITORY_INPUT_PORT.equals(targetPortID)) { // This is a special case: An edge between a filter and a repository - final MIRepositoryConnector sourcePort = this.repositoryPortMap.get(Integer.parseInt(sourcePortID)); + final MIRepositoryConnector sourcePort = (MIRepositoryConnector) this.portMap.get(Integer.parseInt(sourcePortID)); final String targetID = ((String) parameters[1]).split("\\.")[0]; final MIAnalysisComponent targetRepo = this.componentMap.get(Integer.parseInt(targetID.substring(2))); if ((sourcePort != null) && (targetRepo instanceof MIRepository) && (this.currentAnalysisEditorBean != null)) { @@ -380,8 +394,8 @@ public class CurrentAnalysisEditorGraphBean { } } else { // This is the normal case: An edge between two filters - final MIPort sourcePort = this.filterPortMap.get(Integer.parseInt(sourcePortID)); - final MIPort targetPort = this.filterPortMap.get(Integer.parseInt(targetPortID)); + final MIPort sourcePort = (MIPort) this.portMap.get(Integer.parseInt(sourcePortID)); + final MIPort targetPort = (MIPort) this.portMap.get(Integer.parseInt(targetPortID)); if ((sourcePort != null) && (targetPort != null) && (this.currentAnalysisEditorBean != null)) { this.currentAnalysisEditorBean.edgeRemoved((MIOutputPort) sourcePort, (MIInputPort) targetPort); @@ -511,7 +525,7 @@ public class CurrentAnalysisEditorGraphBean { builder.append(','); } - builder.append(String.format(JS_TEMPLATE_PORT, CurrentAnalysisEditorGraphBean.simpleEscape(port.getName()), this.filterPortMap.get(port), + builder.append(String.format(JS_TEMPLATE_PORT, CurrentAnalysisEditorGraphBean.simpleEscape(port.getName()), this.portMap.get(port), CurrentAnalysisEditorGraphBean.simpleEscape(port.getName()))); } @@ -537,7 +551,7 @@ public class CurrentAnalysisEditorGraphBean { builder.append(','); } - builder.append(String.format(JS_TEMPLATE_PORT, CurrentAnalysisEditorGraphBean.simpleEscape(port.getName()), this.repositoryPortMap.get(port), + builder.append(String.format(JS_TEMPLATE_PORT, CurrentAnalysisEditorGraphBean.simpleEscape(port.getName()), this.portMap.get(port), CurrentAnalysisEditorGraphBean.simpleEscape(port.getName()))); } @@ -576,7 +590,7 @@ public class CurrentAnalysisEditorGraphBean { * @return The ID for the port within the graph */ private String assembleGraphPortID(final MIPlugin plugin, final MIPort port) { - return "id" + this.componentMap.get(plugin) + "." + this.filterPortMap.get(port); + return "id" + this.componentMap.get(plugin) + "." + this.portMap.get(port); } /** @@ -589,7 +603,7 @@ public class CurrentAnalysisEditorGraphBean { * @return The ID for the port within the graph */ private Object assembleGraphPortID(final MIPlugin plugin, final MIRepositoryConnector port) { - return "id" + this.componentMap.get(plugin) + "." + this.repositoryPortMap.get(port); + return "id" + this.componentMap.get(plugin) + "." + this.portMap.get(port); } /** -- GitLab