From 0ab61bf681d1139c7ac3163b5d81e3ddf3127024 Mon Sep 17 00:00:00 2001
From: Nils Christian Ehmke <nie@informatik.uni-kiel.de>
Date: Mon, 10 Dec 2012 22:32:49 +0100
Subject: [PATCH] Continued with the cockpit editor.

---
 .../beans/view/CurrentCockpitEditorBean.java  | 27 ++++++++++++++++---
 .../lang/CockpitEditorPage_de.properties      |  4 ++-
 .../lang/CockpitEditorPage_en.properties      |  4 ++-
 .../main/webapp/pages/CockpitEditorPage.xhtml | 16 ++++++++++-
 4 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java
index 8253cddf..53885179 100644
--- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java
+++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java
@@ -19,6 +19,7 @@ package kieker.webgui.web.beans.view;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 import javax.faces.application.Application;
 import javax.faces.application.FacesMessage;
@@ -39,6 +40,7 @@ import kieker.analysis.model.analysisMetaModel.MIView;
 import kieker.analysis.model.analysisMetaModel.impl.MAnalysisMetaModelFactory;
 import kieker.common.logging.Log;
 import kieker.common.logging.LogFactory;
+import kieker.monitoring.core.registry.Registry;
 import kieker.webgui.common.exception.NewerProjectException;
 import kieker.webgui.common.exception.ProjectLoadException;
 import kieker.webgui.common.exception.ProjectNotExistingException;
@@ -89,6 +91,9 @@ public final class CurrentCockpitEditorBean {
 	@Autowired
 	private GlobalPropertiesBean globalPropertiesBean;
 
+	private final Registry<MIDisplayConnector> connectors = new Registry<MIDisplayConnector>();
+	private MIDisplayConnector selectedNode = null;
+
 	/**
 	 * Creates a new instance of this class. <b>Do not call this constructor manually. It will only be accessed by Spring.</b>
 	 */
@@ -98,6 +103,10 @@ public final class CurrentCockpitEditorBean {
 		this.createDashboard();
 	}
 
+	public MIDisplayConnector getSelectedNode() {
+		return this.selectedNode;
+	}
+
 	/**
 	 * Creates the initial dashboard object.
 	 */
@@ -135,7 +144,7 @@ public final class CurrentCockpitEditorBean {
 			this.currId = 0;
 			for (final MIDisplayConnector connector : connectors) {
 				final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
-				panel.setId("displayConnectorPanel_" + this.currId);
+				panel.setId("displayConnector_" + Integer.toString(this.connectors.get(connector)));
 				panel.setHeader(connector.getName());
 				panel.setClosable(true);
 				panel.setToggleable(false);
@@ -350,7 +359,7 @@ public final class CurrentCockpitEditorBean {
 			final Application application = fc.getApplication();
 
 			final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
-			panel.setId("displayConnectorPanel_" + this.currId);
+			panel.setId("displayConnector_" + Integer.toString(this.connectors.get(connector)));
 			panel.setHeader(connector.getName());
 			panel.setClosable(true);
 			panel.setToggleable(false);
@@ -372,12 +381,24 @@ public final class CurrentCockpitEditorBean {
 	 * @param event
 	 *            The onChange-event.
 	 */
-	public void onChange(final TabChangeEvent event) {
+	public synchronized void onChange(final TabChangeEvent event) {
 		if (event.getData() instanceof MIView) {
 			this.setActiveView((MIView) event.getData());
 		}
 	}
 
+	public synchronized void nodeSelected() {
+		final Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
+
+		final String fullID = paramMap.get("id");
+		final String shortID = fullID.substring(fullID.indexOf(':') + "displayConnector_".length() + 1);
+
+		final MIDisplayConnector connector = this.connectors.get(Integer.parseInt(shortID));
+		if (connector != null) {
+			this.selectedNode = connector;
+		}
+	}
+
 	/**
 	 * This method checks whether a display connector with the given name exists already.
 	 * 
diff --git a/Kieker.WebGUI/src/main/resources/lang/CockpitEditorPage_de.properties b/Kieker.WebGUI/src/main/resources/lang/CockpitEditorPage_de.properties
index bdab2198..870ad76d 100644
--- a/Kieker.WebGUI/src/main/resources/lang/CockpitEditorPage_de.properties
+++ b/Kieker.WebGUI/src/main/resources/lang/CockpitEditorPage_de.properties
@@ -8,4 +8,6 @@
 selectView = Ansicht Selektieren
 copyView = Ansicht Kopieren
 renameView = Ansicht Umbenennen
-deleteView = Ansicht Löschen
\ No newline at end of file
+deleteView = Ansicht Löschen
+
+name = Name
\ No newline at end of file
diff --git a/Kieker.WebGUI/src/main/resources/lang/CockpitEditorPage_en.properties b/Kieker.WebGUI/src/main/resources/lang/CockpitEditorPage_en.properties
index 99b6681c..71f62abf 100644
--- a/Kieker.WebGUI/src/main/resources/lang/CockpitEditorPage_en.properties
+++ b/Kieker.WebGUI/src/main/resources/lang/CockpitEditorPage_en.properties
@@ -8,4 +8,6 @@
 selectView = Select View
 copyView = Copy View
 renameView = Rename View
-deleteView = Delete View
\ No newline at end of file
+deleteView = Delete View
+
+name = Name
\ No newline at end of file
diff --git a/Kieker.WebGUI/src/main/webapp/pages/CockpitEditorPage.xhtml b/Kieker.WebGUI/src/main/webapp/pages/CockpitEditorPage.xhtml
index a8b1cbfc..2e5a6b1f 100644
--- a/Kieker.WebGUI/src/main/webapp/pages/CockpitEditorPage.xhtml
+++ b/Kieker.WebGUI/src/main/webapp/pages/CockpitEditorPage.xhtml
@@ -31,6 +31,12 @@
                 <link rel="stylesheet" type="text/css" href="${root}/css/CockpitEditorPage.css" />
             </ui:define>
 
+            <ui:define name="furtherForms">
+                <h:form id="hidden" style="display:none">
+                    <p:remoteCommand autoRun="false" name="nodeSelected" action="#{currentCockpitEditorBean.nodeSelected()}" update=":propertiesForm" />
+                </h:form>
+            </ui:define>
+
             <!-- Those are the menu bar entries left from the help-submenu. -->
             <ui:define name="furtherMenuBarEntries">
                 <p:submenu  label="#{localizedMessages.file}">
@@ -51,6 +57,12 @@
             <ui:define name="centerContent">
                 <h:form id="centerForm">
                     <ui:fragment rendered="#{not empty currentCockpitEditorBean.activeView}">
+                        <!-- The following is a workaround necessary due to a bug in Primefaces. -->
+                        <script type="text/javascript">  
+                            $('.ui-panel').click(function(event) {
+                                nodeSelected([{name : 'id', value : event.currentTarget.id}]);
+                            });
+                        </script>
                         <h:outputText value="Description: "/>  
                         <p:inplace id="basic" editor="true">  
                             <p:inputText value="#{currentCockpitEditorBean.activeView.description}" />  
@@ -95,11 +107,13 @@
                 <!-- This is the component presenting the available properties. -->
                 <p:layoutUnit style="font-size: 12px" position="south" size="150" header="#{localizedMessages.properties}" resizable="true" collapsible="true">
                     <h:form id="propertiesForm" >
-                        <p:dataTable editable="true" var="property" rowIndexVar="rowIndex" emptyMessage="#{localizedMessages.noPropertiesAvailable}">
+                        <p:dataTable editable="true" var="property" value="[1]" rowIndexVar="rowIndex" emptyMessage="#{localizedMessages.noPropertiesAvailable}" rendered="#{not empty currentCockpitEditorBean.selectedNode}">
                             <p:column headerText="#{localizedMessages.property}" style="width:125px"> 
+                                <h:outputText id="nameProperty" value="#{localizedCockpitEditorPageMessages.name}" rendered="#{rowIndex == 1}"/>
                             </p:column>                
 
                             <p:column headerText="#{localizedMessages.value}" style="width:125px">
+                                <h:outputText value="#{currentCockpitEditorBean.selectedNode.name}" />
                             </p:column>                       
                         </p:dataTable>
                     </h:form>
-- 
GitLab