From c8d3f6104fb94979f1722f7f7687f6833e2b9653 Mon Sep 17 00:00:00 2001
From: Nils Christian Ehmke <nie@informatik.uni-kiel.de>
Date: Fri, 31 Aug 2012 16:06:47 +0200
Subject: [PATCH] Continued with the FlowEditor integration; Code Quality

---
 .../beans/view/CurrentAnalysisEditorBean.java | 32 ++++++++++++++++
 .../view/CurrentAnalysisEditorBeanV2.java     | 37 ++++++++++++++++---
 .../beans/view/CurrentCockpitEditorBean.java  | 11 ++++++
 .../src/main/webapp/AnalysisEditor_V2.xhtml   | 10 ++++-
 4 files changed, 83 insertions(+), 7 deletions(-)

diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBean.java
index f6169826..3620b05c 100644
--- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBean.java
+++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBean.java
@@ -174,10 +174,21 @@ public final class CurrentAnalysisEditorBean {
 		// No code necessary
 	}
 
+	/**
+	 * Getter for the attribute {@link CurrentAnalysisEditorBean#projectsBean}.
+	 * 
+	 * @return Delivers the value of the attribute.
+	 */
 	public ProjectsBean getProjectsBean() {
 		return this.projectsBean;
 	}
 
+	/**
+	 * Setter for the attribute {@link CurrentAnalysisEditorBean#projectsBean}.
+	 * 
+	 * @param projectsBean
+	 *            The new value of the attribute.
+	 */
 	public void setProjectsBean(final ProjectsBean projectsBean) {
 		this.projectsBean = projectsBean;
 	}
@@ -485,6 +496,13 @@ public final class CurrentAnalysisEditorBean {
 		}
 	}
 
+	/**
+	 * Searches for input ports within the given class and returns them.
+	 * 
+	 * @param clazz
+	 *            The class to be analyzed.
+	 * @return A list containing the available input ports.
+	 */
 	public List<InputPort> getInputPorts(final Class<?> clazz) {
 		final ArrayList<InputPort> result = new ArrayList<InputPort>();
 
@@ -500,6 +518,13 @@ public final class CurrentAnalysisEditorBean {
 		return result;
 	}
 
+	/**
+	 * Searches for output ports within the given class and returns them.
+	 * 
+	 * @param clazz
+	 *            The class to be analyzed.
+	 * @return A list containing the available output ports.
+	 */
 	public List<OutputPort> getOutputPorts(final Class<?> clazz) {
 		final ArrayList<OutputPort> result = new ArrayList<OutputPort>();
 
@@ -516,6 +541,13 @@ public final class CurrentAnalysisEditorBean {
 		return result;
 	}
 
+	/**
+	 * Searches for repository ports within the given class and returns them.
+	 * 
+	 * @param clazz
+	 *            The class to be analyzed.
+	 * @return A list containing the available repository ports.
+	 */
 	public List<RepositoryPort> getRepositoryPorts(final Class<?> clazz) {
 		final ArrayList<RepositoryPort> result = new ArrayList<RepositoryPort>();
 
diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBeanV2.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBeanV2.java
index 9815160c..97fdc0a3 100644
--- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBeanV2.java
+++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBeanV2.java
@@ -219,10 +219,21 @@ public final class CurrentAnalysisEditorBeanV2 {
 		}
 	}
 
+	/**
+	 * Getter for the attribute {@link CurrentAnalysisEditorBeanV2#projectsBean}.
+	 * 
+	 * @return Delivers the value of the attribute.
+	 */
 	public ProjectsBean getProjectsBean() {
 		return this.projectsBean;
 	}
 
+	/**
+	 * Setter for the attribute {@link CurrentAnalysisEditorBeanV2#projectsBean}.
+	 * 
+	 * @param projectsBean
+	 *            The new value of the attribute.
+	 */
 	public void setProjectsBean(final ProjectsBean projectsBean) {
 		this.projectsBean = projectsBean;
 	}
@@ -240,6 +251,9 @@ public final class CurrentAnalysisEditorBeanV2 {
 		}
 	}
 
+	/**
+	 * This method initializes this bean, based on the project name and everything.
+	 */
 	public void initialize() {
 		synchronized (this) {
 			this.project = this.projectsBean.openProject(this.projectName);
@@ -616,7 +630,7 @@ public final class CurrentAnalysisEditorBeanV2 {
 		// Make sure that the graph exists in the first place
 		context.execute(CurrentAnalysisEditorBeanV2.JS_CMD_INIT_GRAPH);
 		// Initialize the listener for the clicks on the components
-		context.execute("graph.addListener(\"onClick\", function(node,info,e){document.getElementById('hiddenNode:clickedNodeID').value = node.id;document.getElementById('hiddenNode:link').click();});");
+		context.execute("graph.addListener(\"onClick\", nodeClickListener);");
 
 		// Paint all necessary components
 		this.initializeGraphPlugins();
@@ -642,20 +656,33 @@ public final class CurrentAnalysisEditorBeanV2 {
 		// TODO Now the connections between filters and repositories
 	}
 
+	private String clickedNodeID;
+	private String clickedNodeType;
+
 	public void setClickedNodeID(final String id) {
-		System.out.println("clicked: " + id);
+		this.clickedNodeID = id;
 	}
 
 	public String getClickedNodeID() {
-		return "";
+		return this.clickedNodeID;
 	}
 
 	public void setClickedNodeType(final String type) {
-		System.out.println("clicked: " + type);
+		this.clickedNodeType = type;
 	}
 
 	public String getClickedNodeType() {
-		return "";
+		return this.clickedNodeType;
+	}
+
+	public void nodeClicked() {
+		if (this.clickedNodeType.equalsIgnoreCase("Filter") || this.clickedNodeType.equalsIgnoreCase("Reader")) {
+			// Try to find the ID as a filter/reader
+			this.setSelectedPlugin(this.pluginMap.get(Integer.parseInt(this.clickedNodeID)));
+		} else {
+			// Try to find the ID as a repository
+			this.setSelectedRepository(this.repositoryMap.get(Integer.parseInt(this.clickedNodeID)));
+		}
 	}
 
 	/**
diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitEditorBean.java
index 45e9fe51..a6df7f6b 100644
--- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitEditorBean.java
+++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitEditorBean.java
@@ -98,10 +98,21 @@ public class CurrentCockpitEditorBean {
 		// No code necessary
 	}
 
+	/**
+	 * Getter for the attribute {@link CurrentCockpitEditorBean#projectsBean}.
+	 * 
+	 * @return Delivers the value of the attribute.
+	 */
 	public ProjectsBean getProjectsBean() {
 		return this.projectsBean;
 	}
 
+	/**
+	 * Setter for the attribute {@link CurrentCockpitEditorBean#projectsBean}.
+	 * 
+	 * @param projectsBean
+	 *            The new value of the attribute.
+	 */
 	public void setProjectsBean(final ProjectsBean projectsBean) {
 		this.projectsBean = projectsBean;
 	}
diff --git a/Kieker.WebGUI/src/main/webapp/AnalysisEditor_V2.xhtml b/Kieker.WebGUI/src/main/webapp/AnalysisEditor_V2.xhtml
index b999aa28..b3ddba4b 100644
--- a/Kieker.WebGUI/src/main/webapp/AnalysisEditor_V2.xhtml
+++ b/Kieker.WebGUI/src/main/webapp/AnalysisEditor_V2.xhtml
@@ -27,6 +27,12 @@
             window.onload = function() {
                 document.getElementById('hidden:link').onclick();
             }
+            
+            nodeClickListener = function(node, info, e) {
+                document.getElementById('hiddenNodeProperties:clickedNodeID').value = node.id;
+                document.getElementById('hiddenNodeProperties:clickedNodeType').value = node.data.$nodeType;
+                document.getElementById('hiddenNodeProperties:cmdBtnSelection').click();
+            }
         </script>
     </h:head>
 
@@ -36,10 +42,10 @@
                 <f:ajax event="click" listener="#{currentAnalysisEditorBeanV2.initializeGraph()}" />
             </h:commandLink>
         </h:form>
-        <h:form id="hiddenNode" style="display:none">
+        <h:form id="hiddenNodeProperties" style="display:none">
             <h:inputHidden id="clickedNodeID" value="#{currentAnalysisEditorBeanV2.clickedNodeID}"/>
             <h:inputHidden id="clickedNodeType" value="#{currentAnalysisEditorBeanV2.clickedNodeType}"/>
-            <p:commandButton id="link" ajax="true" value="submit"/>
+            <p:commandButton id="cmdBtnSelection" ajax="true" action="#{currentAnalysisEditorBeanV2.nodeClicked()}" update=":propertiesForm" value="submit"/>
         </h:form>
 
         <p:layout id="layout" fullPage="true">
-- 
GitLab