From ac9d794d6b00e400282ca4775ccab55d17fd0f48 Mon Sep 17 00:00:00 2001
From: Nils Christian Ehmke <nie@informatik.uni-kiel.de>
Date: Thu, 2 Aug 2012 15:07:29 +0200
Subject: [PATCH] Some bug fixing

---
 .../beans/view/CurrentAnalysisEditorBean.java | 38 ++++++++++++-------
 .../webgui/beans/view/CurrentCockpitBean.java | 16 +++++++-
 .../beans/view/CurrentCockpitEditorBean.java  | 25 ++++++++----
 .../beans/view/CurrentControllerBean.java     | 15 +++++++-
 .../src/main/webapp/AnalysisEditor.xhtml      | 11 +++---
 Kieker.WebGUI/src/main/webapp/Cockpit.xhtml   |  1 +
 .../src/main/webapp/CockpitEditor.xhtml       |  3 +-
 .../src/main/webapp/Controller.xhtml          |  1 +
 8 files changed, 82 insertions(+), 28 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 43854f8d..f9a217b0 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
@@ -186,21 +186,33 @@ public final class CurrentAnalysisEditorBean {
 	public void setProjectName(final String newName) {
 		synchronized (this) {
 			// Remember the given parameters
-			this.project = ProjectsBean.getInstance().openProject(newName);
 			this.projectName = newName;
-			this.getConnectionsFromProject();
+		}
+	}
 
-			if (this.project != null) {
-				// Remember the current time! This is important for the later comparison of the time stamps.
-				this.resetTimeStamp();
-				// Update the class loader
-				this.reloadClassLoader();
-				// Add the libraries within the lib-folder to the current model
-				this.addLibrariesToModel();
-				// Load the available readers, filters and repositories
-				this.loadToolPalette();
-				// Load the hashmaps to get the plugins and ports
-				this.intializeHashMaps();
+	/**
+	 * This method initializes the bean by using the current project name to load the project. <b>Do not call this method manually. It will only be accessed by
+	 * JSF.</b>
+	 */
+	public void initalize() {
+		synchronized (this) {
+			// Make sure that the initialization will only be done for the init request.
+			if (!FacesContext.getCurrentInstance().isPostback()) {
+				this.project = ProjectsBean.getInstance().openProject(this.projectName);
+				this.getConnectionsFromProject();
+
+				if (this.project != null) {
+					// Remember the current time! This is important for the later comparison of the time stamps.
+					this.resetTimeStamp();
+					// Update the class loader
+					this.reloadClassLoader();
+					// Add the libraries within the lib-folder to the current model
+					this.addLibrariesToModel();
+					// Load the available readers, filters and repositories
+					this.loadToolPalette();
+					// Load the hashmaps to get the plugins and ports
+					this.intializeHashMaps();
+				}
 			}
 		}
 	}
diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitBean.java
index d0e935f5..fc39b684 100644
--- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitBean.java
+++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitBean.java
@@ -22,6 +22,7 @@ package kieker.webgui.beans.view;
 
 import javax.faces.bean.ManagedBean;
 import javax.faces.bean.ViewScoped;
+import javax.faces.context.FacesContext;
 
 import kieker.analysis.display.AbstractDisplay;
 import kieker.analysis.display.HtmlText;
@@ -86,11 +87,24 @@ public class CurrentCockpitBean {
 	public void setProjectName(final String newName) {
 		synchronized (this) {
 			// Remember the given parameters
-			this.project = ProjectsBean.getInstance().openProject(newName);
 			this.projectName = newName;
 		}
 	}
 
+	/**
+	 * This method initializes the bean by using the current project name to load the project. <b>Do not call this method manually. It will only be accessed by
+	 * JSF.</b>
+	 */
+	public void initalize() {
+		synchronized (this) {
+			// Make sure that the initialization will only be done for the init request.
+			if (!FacesContext.getCurrentInstance().isPostback()) {
+				// Remember the given parameters
+				this.project = ProjectsBean.getInstance().openProject(this.projectName);
+			}
+		}
+	}
+
 	/**
 	 * This method delivers the project name stored in this bean.
 	 * 
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 c8795ae7..7ea200d4 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
@@ -95,6 +95,24 @@ public class CurrentCockpitEditorBean {
 		// No code necessary
 	}
 
+	/**
+	 * This method initializes the bean by using the current project name to load the project. <b>Do not call this method manually. It will only be accessed by
+	 * JSF.</b>
+	 */
+	public void initalize() {
+		synchronized (this) {
+			// Make sure that the initialization will only be done for the init request.
+			if (!FacesContext.getCurrentInstance().isPostback()) {
+				// Remember the given parameters
+				this.project = ProjectsBean.getInstance().openProject(this.projectName);
+				if (this.project != null) {
+					// Remember the current time! This is important for the later comparison of the time stamps.
+					this.resetTimeStamp();
+				}
+			}
+		}
+	}
+
 	/**
 	 * This method delivers the project stored in this bean.
 	 * 
@@ -114,14 +132,7 @@ public class CurrentCockpitEditorBean {
 	 */
 	public void setProjectName(final String newName) {
 		synchronized (this) {
-			// Remember the given parameters
-			this.project = ProjectsBean.getInstance().openProject(newName);
 			this.projectName = newName;
-
-			if (this.project != null) {
-				// Remember the current time! This is important for the later comparison of the time stamps.
-				this.resetTimeStamp();
-			}
 		}
 	}
 
diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentControllerBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentControllerBean.java
index 6e54a55b..2f430062 100644
--- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentControllerBean.java
+++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentControllerBean.java
@@ -82,11 +82,24 @@ public class CurrentControllerBean {
 	public void setProjectName(final String newName) {
 		synchronized (this) {
 			// Remember the given parameters
-			this.project = ProjectsBean.getInstance().openProject(newName);
 			this.projectName = newName;
 		}
 	}
 
+	/**
+	 * This method initializes the bean by using the current project name to load the project. <b>Do not call this method manually. It will only be accessed by
+	 * JSF.</b>
+	 */
+	public void initalize() {
+		synchronized (this) {
+			// Make sure that the initialization will only be done for the init request.
+			if (!FacesContext.getCurrentInstance().isPostback()) {
+				// Remember the given parameters
+				this.project = ProjectsBean.getInstance().openProject(this.projectName);
+			}
+		}
+	}
+
 	/**
 	 * This method delivers the project stored in this bean.
 	 * 
diff --git a/Kieker.WebGUI/src/main/webapp/AnalysisEditor.xhtml b/Kieker.WebGUI/src/main/webapp/AnalysisEditor.xhtml
index dda68a94..e868bde9 100644
--- a/Kieker.WebGUI/src/main/webapp/AnalysisEditor.xhtml
+++ b/Kieker.WebGUI/src/main/webapp/AnalysisEditor.xhtml
@@ -1,16 +1,17 @@
 <?xml version='1.0' encoding='UTF-8' ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
 <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:p="http://primefaces.org/ui"
       xmlns:c="http://java.sun.com/jsp/jstl/core">
-
     <f:metadata>
-        <f:viewParam name="projectName" value="#{currentAnalysisEditorBean.projectName}"/>
+        <f:viewParam id="projectNameParam" name="projectName" value="#{currentAnalysisEditorBean.projectName}"/>
+        <f:event type="preRenderView" listener="#{currentAnalysisEditorBean.initalize()}"  />
     </f:metadata>
-    
+
     <h:head>
         <title>Kieker.WebGUI</title>
         <link rel="stylesheet" type="text/css" href="../css/Common.css" />
@@ -36,7 +37,7 @@
                         <p:toolbarGroup align="left">
                             <h:outputText styleClass="kieker-title" value="Kieker &raquo; #{stringBean.shortenLongName(currentAnalysisEditorBean.projectName, 30)}"/>
                         </p:toolbarGroup>
-                       <p:toolbarGroup align="right">
+                        <p:toolbarGroup align="right">
                             <p:commandButton styleClass="perspective-button" icon="ui-icon-home" action="ProjectOverview.xhtml" />
                             <p:separator/>
                             <p:button styleClass="perspective-button" icon="ui-icon-wrench" value="Analysis Editor" style="white-space: none" disabled="true"/>
@@ -135,7 +136,7 @@
                             </p:inplace>  
                             <p:inplace editor="true" rendered="#{stringBean.checkString(property)}" >  
                                 <p:inputText value="#{currentAnalysisEditorBean.selectedPlugin.name}" />
-                                 <p:ajax event="save" update=":centerForm" />
+                                <p:ajax event="save" update=":centerForm" />
                             </p:inplace>  
                         </p:column>                       
                     </p:dataTable>
diff --git a/Kieker.WebGUI/src/main/webapp/Cockpit.xhtml b/Kieker.WebGUI/src/main/webapp/Cockpit.xhtml
index 81fc009f..9471e489 100644
--- a/Kieker.WebGUI/src/main/webapp/Cockpit.xhtml
+++ b/Kieker.WebGUI/src/main/webapp/Cockpit.xhtml
@@ -9,6 +9,7 @@
 
      <f:metadata>
          <f:viewParam name="projectName" value="#{currentCockpitBean.projectName}"/>
+         <f:event type="preRenderView" listener="#{currentCockpitBean.initalize()}"  />
     </f:metadata>
     
     <h:head>
diff --git a/Kieker.WebGUI/src/main/webapp/CockpitEditor.xhtml b/Kieker.WebGUI/src/main/webapp/CockpitEditor.xhtml
index 0bc9097a..76ff71d9 100644
--- a/Kieker.WebGUI/src/main/webapp/CockpitEditor.xhtml
+++ b/Kieker.WebGUI/src/main/webapp/CockpitEditor.xhtml
@@ -9,6 +9,7 @@
 
      <f:metadata>
          <f:viewParam name="projectName" value="#{currentCockpitEditorBean.projectName}"/>
+         <f:event type="preRenderView" listener="#{currentCockpitEditorBean.initalize()}"  />
     </f:metadata>
     
     <h:head>
@@ -48,7 +49,7 @@
                             <p:menuitem styleClass="element-with-whitespace" icon="ui-icon-document" value="  New View" onclick="newViewDialog.show()" ajax="true"/>
                             <p:separator/>
                             <p:menuitem styleClass="element-with-whitespace" icon="ui-icon-disk" value="  Save Project" update=":messages" ajax="true" action="#{currentCockpitEditorBean.saveProject(false)}" disabled="#{empty currentCockpitEditorBean.project}"/>
-                            <p:menuitem styleClass="element-with-whitespace" icon="ui-icon-disk" value="  Save Project As" update=":messages" ajax="true" disabled="#{empty currentAnalysisEditorBean.project}"/>
+                            <p:menuitem styleClass="element-with-whitespace" icon="ui-icon-disk" value="  Save Project As" update=":messages" ajax="true" disabled="#{empty currentCockpitEditorBean.project}"/>
                             <p:separator/>
                             <p:menuitem styleClass="element-with-whitespace" icon="ui-icon-refresh" value="  Reload Project" ajax="true" disabled="#{empty currentCockpitEditorBean.project or true}"/>
                             <p:separator/>
diff --git a/Kieker.WebGUI/src/main/webapp/Controller.xhtml b/Kieker.WebGUI/src/main/webapp/Controller.xhtml
index c77e44f2..ea1132a6 100644
--- a/Kieker.WebGUI/src/main/webapp/Controller.xhtml
+++ b/Kieker.WebGUI/src/main/webapp/Controller.xhtml
@@ -9,6 +9,7 @@
 
      <f:metadata>
          <f:viewParam name="projectName" value="#{currentControllerBean.projectName}"/>
+           <f:event type="preRenderView" listener="#{currentControllerBean.initalize()}"  />
     </f:metadata>
     
     <h:head>
-- 
GitLab