Skip to content
Snippets Groups Projects
Commit 478db60a authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Used "Managed properties" for better code

parent da00fd8a
No related branches found
No related tags found
No related merge requests found
Showing
with 122 additions and 55 deletions
......@@ -27,7 +27,6 @@ import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.el.ELResolver;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.ApplicationScoped;
......@@ -216,15 +215,4 @@ public final class ProjectsBean {
private static void showMessage(final Severity severity, final String msg) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, "", msg));
}
/**
* Delivers the one and only bean instance of the {@link ProjectsBean}.
*
* @return The bean instance.
*/
public static ProjectsBean getInstance() {
// Get the resolver and find the projects bean via name
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
return (ProjectsBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null, "projectsBean");
}
}
......@@ -35,6 +35,7 @@ import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
......@@ -163,6 +164,9 @@ public final class CurrentAnalysisEditorBean {
*/
private final List<ConnectionFilterToRepository> filter2repositoryConnections = new ArrayList<ConnectionFilterToRepository>();
@ManagedProperty(value = "#{projectsBean}")
private ProjectsBean projectsBean;
/**
* Creates a new instance of this class.
*/
......@@ -170,6 +174,14 @@ public final class CurrentAnalysisEditorBean {
// No code necessary
}
public ProjectsBean getProjectsBean() {
return this.projectsBean;
}
public void setProjectsBean(final ProjectsBean projectsBean) {
this.projectsBean = projectsBean;
}
/**
* This method delivers the project stored in this bean.
*
......@@ -202,7 +214,7 @@ public final class CurrentAnalysisEditorBean {
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.project = this.projectsBean.openProject(this.projectName);
this.getConnectionsFromProject();
if (this.project != null) {
......
......@@ -34,6 +34,7 @@ import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
......@@ -176,6 +177,9 @@ public final class CurrentAnalysisEditorBeanV2 {
*/
private final List<ConnectionFilterToRepository> filter2repositoryConnections = new ArrayList<ConnectionFilterToRepository>();
@ManagedProperty(value = "#{projectsBean}")
private ProjectsBean projectsBean;
/**
* Creates a new instance of this class.
*/
......@@ -194,6 +198,14 @@ public final class CurrentAnalysisEditorBeanV2 {
}
}
public ProjectsBean getProjectsBean() {
return this.projectsBean;
}
public void setProjectsBean(final ProjectsBean projectsBean) {
this.projectsBean = projectsBean;
}
/**
* This method sets the project stored within this bean and returns the new page for the navigation - depending on the given values.
*
......@@ -209,7 +221,7 @@ public final class CurrentAnalysisEditorBeanV2 {
public void initialize() {
synchronized (this) {
this.project = ProjectsBean.getInstance().openProject(this.projectName);
this.project = this.projectsBean.openProject(this.projectName);
this.getConnectionsFromProject();
if (this.project != null) {
......
......@@ -21,6 +21,7 @@
package kieker.webgui.beans.view;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
......@@ -60,6 +61,9 @@ public class CurrentCockpitBean {
*/
private MIView activeView;
@ManagedProperty(value = "#{projectsBean}")
private ProjectsBean projectsBean;
/**
* Creates a new instance of this class.
*/
......@@ -78,6 +82,14 @@ public class CurrentCockpitBean {
}
}
public ProjectsBean getProjectsBean() {
return this.projectsBean;
}
public void setProjectsBean(final ProjectsBean projectsBean) {
this.projectsBean = projectsBean;
}
/**
* This method sets the project stored within this bean and returns the new page for the navigation.
*
......@@ -100,7 +112,7 @@ public class CurrentCockpitBean {
// 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.project = this.projectsBean.openProject(this.projectName);
}
}
}
......
......@@ -29,6 +29,7 @@ import java.util.UUID;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
......@@ -87,6 +88,8 @@ public class CurrentCockpitEditorBean {
* This is the currently selected view.
*/
private MIView activeView;
@ManagedProperty(value = "#{projectsBean}")
private ProjectsBean projectsBean;
/**
* Creates a new instance of this class.
......@@ -95,6 +98,14 @@ public class CurrentCockpitEditorBean {
// No code necessary
}
public ProjectsBean getProjectsBean() {
return this.projectsBean;
}
public void setProjectsBean(final ProjectsBean projectsBean) {
this.projectsBean = projectsBean;
}
/**
* 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>
......@@ -104,7 +115,7 @@ public class CurrentCockpitEditorBean {
// 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.project = this.projectsBean.openProject(this.projectName);
if (this.project != null) {
// Remember the current time! This is important for the later comparison of the time stamps.
this.resetTimeStamp();
......
......@@ -25,6 +25,7 @@ import java.io.IOException;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
......@@ -65,6 +66,8 @@ public class CurrentControllerBean {
* This is the actual model instance. It is the in-memory-model of the current (session) user.
*/
private MIProject project;
@ManagedProperty(value = "#{projectsBean}")
private ProjectsBean projectsBean;
/**
* Creates a new instance of this class.
......@@ -73,6 +76,14 @@ public class CurrentControllerBean {
// No code necessary
}
public ProjectsBean getProjectsBean() {
return this.projectsBean;
}
public void setProjectsBean(final ProjectsBean projectsBean) {
this.projectsBean = projectsBean;
}
/**
* This method sets the project stored within this bean and returns the new page for the navigation.
*
......@@ -95,7 +106,7 @@ public class CurrentControllerBean {
// 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.project = this.projectsBean.openProject(this.projectName);
}
}
}
......
......@@ -20,7 +20,9 @@
package kieker.webgui.converter;
import javax.el.ELResolver;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
......@@ -35,6 +37,8 @@ import kieker.webgui.beans.view.CurrentAnalysisEditorBean;
* @author Nils Christian Ehmke
* @version 1.0
*/
@ViewScoped
@ManagedBean
@FacesConverter(value = MIPluginStringConverter.NAME)
public class MIPluginStringConverter implements Converter {
/**
......@@ -42,6 +46,9 @@ public class MIPluginStringConverter implements Converter {
*/
public static final String NAME = "kieker.webgui.converter.MIPluginStringConverter";
@ManagedProperty(value = "#{currentAnalysisEditorBean}")
private CurrentAnalysisEditorBean bean;
/**
* Creates a new instance of this class.
*/
......@@ -49,25 +56,25 @@ public class MIPluginStringConverter implements Converter {
/* No code necessary. */
}
public CurrentAnalysisEditorBean getBean() {
return this.bean;
}
public void setBean(final CurrentAnalysisEditorBean bean) {
this.bean = bean;
}
@Override
public Object getAsObject(final FacesContext fc, final UIComponent uic, final String string) {
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
final CurrentAnalysisEditorBean bean = (CurrentAnalysisEditorBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null,
"currentAnalysisEditorBean");
return bean.getPluginByID(string);
return this.bean.getPluginByID(string);
}
@Override
public String getAsString(final FacesContext fc, final UIComponent uic, final Object o) {
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
final CurrentAnalysisEditorBean bean = (CurrentAnalysisEditorBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null,
"currentAnalysisEditorBean");
if (o == null) {
return "";
} else {
return Integer.toString(bean.getPluginID((MIPlugin) o));
return Integer.toString(this.bean.getPluginID((MIPlugin) o));
}
}
}
......@@ -20,7 +20,9 @@
package kieker.webgui.converter;
import javax.el.ELResolver;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
......@@ -35,6 +37,8 @@ import kieker.webgui.beans.view.CurrentAnalysisEditorBean;
* @author Nils Christian Ehmke
* @version 1.0
*/
@ViewScoped
@ManagedBean
@FacesConverter(value = MIPortStringConverter.NAME)
public class MIPortStringConverter implements Converter {
/**
......@@ -42,6 +46,9 @@ public class MIPortStringConverter implements Converter {
*/
public static final String NAME = "kieker.webgui.converter.MIPortStringConverter";
@ManagedProperty(value = "#{currentAnalysisEditorBean}")
private CurrentAnalysisEditorBean bean;
/**
* Creates a new instance of this class.
*/
......@@ -49,25 +56,25 @@ public class MIPortStringConverter implements Converter {
/* No code necessary. */
}
public CurrentAnalysisEditorBean getBean() {
return this.bean;
}
public void setBean(final CurrentAnalysisEditorBean bean) {
this.bean = bean;
}
@Override
public Object getAsObject(final FacesContext fc, final UIComponent uic, final String string) {
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
final CurrentAnalysisEditorBean bean = (CurrentAnalysisEditorBean) el.getValue(FacesContext.getCurrentInstance()
.getELContext(), null, "currentAnalysisEditorBean");
return bean.getPortByID(string);
return this.bean.getPortByID(string);
}
@Override
public String getAsString(final FacesContext fc, final UIComponent uic, final Object o) {
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
final CurrentAnalysisEditorBean bean = (CurrentAnalysisEditorBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null,
"currentAnalysisEditorBean");
if (o == null) {
return "";
} else {
return Integer.toString(bean.getPortID((MIPort) o));
return Integer.toString(this.bean.getPortID((MIPort) o));
}
}
}
......@@ -20,7 +20,9 @@
package kieker.webgui.converter;
import javax.el.ELResolver;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
......@@ -35,6 +37,8 @@ import kieker.webgui.beans.view.CurrentAnalysisEditorBean;
* @author Nils Christian Ehmke
* @version 1.0
*/
@ViewScoped
@ManagedBean
@FacesConverter(value = MIRepositoryStringConverter.NAME)
public class MIRepositoryStringConverter implements Converter {
/**
......@@ -42,6 +46,9 @@ public class MIRepositoryStringConverter implements Converter {
*/
public static final String NAME = "kieker.webgui.converter.MIRepositoryStringConverter";
@ManagedProperty(value = "#{currentAnalysisEditorBean}")
private CurrentAnalysisEditorBean bean;
/**
* Creates a new instance of this class.
*/
......@@ -49,25 +56,25 @@ public class MIRepositoryStringConverter implements Converter {
/* No code necessary. */
}
public CurrentAnalysisEditorBean getBean() {
return this.bean;
}
public void setBean(final CurrentAnalysisEditorBean bean) {
this.bean = bean;
}
@Override
public Object getAsObject(final FacesContext fc, final UIComponent uic, final String string) {
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
final CurrentAnalysisEditorBean bean = (CurrentAnalysisEditorBean) el.getValue(FacesContext.getCurrentInstance()
.getELContext(), null, "currentAnalysisEditorBean");
return bean.getRepositoryByID(string);
return this.bean.getRepositoryByID(string);
}
@Override
public String getAsString(final FacesContext fc, final UIComponent uic, final Object o) {
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
final CurrentAnalysisEditorBean bean = (CurrentAnalysisEditorBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null,
"currentAnalysisEditorBean");
if (o == null) {
return "";
} else {
return Integer.toString(bean.getRepositoryID((MIRepository) o));
return Integer.toString(this.bean.getRepositoryID((MIRepository) o));
}
}
}
......@@ -29,7 +29,7 @@
value="#{empty connection.source ? 'N/A' : connection.source.name}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu converter="kieker.webgui.converter.MIPluginStringConverter"
<p:selectOneMenu converter="#{mIPluginStringConverter}"
value="#{connection.source}" effectDuration="100">
<f:selectItem value="#{null}" itemLabel="N/A" itemValue="#{null}" />
<f:selectItems
......@@ -49,7 +49,7 @@
</f:facet>
<f:facet name="input">
<h:form id="outputPortsList">
<p:selectOneMenu rendered="#{not empty connection.source}" converter="kieker.webgui.converter.MIPortStringConverter"
<p:selectOneMenu rendered="#{not empty connection.source}" converter="#{mIPortStringConverter}"
value="#{connection.outputPort}" effectDuration="100">
<f:selectItem value="#{null}" itemLabel="N/A"
itemValue="#{null}" />
......@@ -69,7 +69,7 @@
value="#{empty connection.destination ? 'N/A' : connection.destination.name}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu converter="kieker.webgui.converter.MIPluginStringConverter"
<p:selectOneMenu converter="#{mIPluginStringConverter}"
value="#{connection.destination}" effectDuration="100">
<f:selectItem value="#{null}" itemLabel="N/A"
itemValue="#{null}" />
......@@ -89,7 +89,7 @@
</f:facet>
<f:facet name="input">
<h:form id="inputPortsList">
<p:selectOneMenu rendered="#{not empty connection.destination}" converter="kieker.webgui.converter.MIPortStringConverter"
<p:selectOneMenu rendered="#{not empty connection.destination}" converter="#{mIPortStringConverter}"
value="#{connection.inputPort}" effectDuration="100">
<f:selectItem value="#{null}" itemLabel="N/A"
itemValue="#{null}" />
......@@ -132,7 +132,7 @@
<h:outputText value="#{empty connection.destination ? 'N/A' : connection.destination.name}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu converter="kieker.webgui.converter.MIRepositoryStringConverter"
<p:selectOneMenu converter="#{mIRepositoryStringConverter}"
value="#{connection.destination}" effectDuration="100">
<f:selectItem value="#{null}" itemLabel="N/A"
itemValue="#{null}" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment