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

Modified the dashboard.

parent e0d04ce9
No related branches found
No related tags found
No related merge requests found
...@@ -22,57 +22,140 @@ package kieker.webgui.beans.session; ...@@ -22,57 +22,140 @@ package kieker.webgui.beans.session;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
import javax.annotation.PostConstruct;
import javax.faces.application.Application;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped; import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import kieker.webgui.beans.application.ProjectsBean; import kieker.webgui.beans.application.ProjectsBean;
import kieker.webgui.beans.request.StringToIDBean; import kieker.webgui.beans.application.ProjectsBean.Widget;
import org.primefaces.model.DashboardColumn; import org.primefaces.component.dashboard.Dashboard;
import org.primefaces.component.panel.Panel;
import org.primefaces.event.DashboardReorderEvent;
import org.primefaces.model.DashboardModel; import org.primefaces.model.DashboardModel;
import org.primefaces.model.DefaultDashboardColumn; import org.primefaces.model.DefaultDashboardColumn;
import org.primefaces.model.DefaultDashboardModel; import org.primefaces.model.DefaultDashboardModel;
/** /**
* This bean can be used to handle an instance of {@link Dashboard} including a list of {@code Widget}. It makes sure that new widget-instances can be added
* dynamically.
* *
* @author Nils Christian Ehmke * @author Nils Christian Ehmke
*/ */
@ManagedBean
@SessionScoped @SessionScoped
@ManagedBean
public class DashboardBean implements Serializable { public class DashboardBean implements Serializable {
private final DashboardModel model; /**
private final List<ProjectsBean.Widget> widgets; * This is the prefix used to the widgets within the component.
*/
private static final String WIDGET_ID_PREFIX = "widget_";
/**
* This is the dashboard to be controlled by this instance.
*/
private Dashboard dashboard;
/**
* This is the model used to fill the dasboard.
*/
private DashboardModel dashboardModel;
/**
* This is the list containing all widgets.
*/
private final List<Widget> widgets = new ArrayList<ProjectsBean.Widget>();
/**
* Creates a new instance of this class.
*/
public DashboardBean() { public DashboardBean() {
this.model = new DefaultDashboardModel(); // No code necessary.
this.widgets = new ArrayList<ProjectsBean.Widget>(); }
@PostConstruct
public void init() {
final FacesContext fc = FacesContext.getCurrentInstance();
final Application application = fc.getApplication();
// Add three columns for the model
this.dashboardModel = new DefaultDashboardModel();
this.dashboardModel.addColumn(new DefaultDashboardColumn());
this.dashboardModel.addColumn(new DefaultDashboardColumn());
this.dashboardModel.addColumn(new DefaultDashboardColumn());
this.dashboard = (Dashboard) application.createComponent(fc, "org.primefaces.component.Dashboard", "org.primefaces.component.DashboardRenderer");
this.dashboard.setId("dashboard");
this.dashboard.setModel(this.dashboardModel);
this.addChildren();
}
/**
* This method can be used to update the UI children of the dashboard.
*/
private void addChildren() {
synchronized (this) {
// Clear the list with the children to avoid double IDs.
this.dashboard.getChildren().clear();
final FacesContext fc = FacesContext.getCurrentInstance();
final Application application = fc.getApplication();
// Run through all widgets and add a panel for each of them.
for (int i = 0; i < this.widgets.size(); i++) {
final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
panel.setId(DashboardBean.WIDGET_ID_PREFIX + i);
panel.setHeader(this.widgets.get(i).getName());
panel.setClosable(true);
panel.setToggleable(true);
final DashboardColumn column1 = new DefaultDashboardColumn(); this.dashboard.getChildren().add(panel);
final DashboardColumn column2 = new DefaultDashboardColumn();
final DashboardColumn column3 = new DefaultDashboardColumn();
this.model.addColumn(column1); final HtmlOutputText text = new HtmlOutputText();
this.model.addColumn(column2); text.setId("t" + DashboardBean.WIDGET_ID_PREFIX + i);
this.model.addColumn(column3); text.setValue(this.widgets.get(i).getType());
panel.getChildren().add(text);
}
}
}
/**
* Delivers the currently stored dashboard.
*
* @return The dashboard.
*/
public Dashboard getDashboard() {
this.addChildren();
return this.dashboard;
} }
public DashboardModel getModel() { public void setDashboard(final Dashboard dashboard) {
return this.model; this.dashboard = dashboard;
} }
public void addWidget(final ProjectsBean.Widget widget) { /**
final FacesContext context = FacesContext.getCurrentInstance(); * Adds a new widget to the list.
final StringToIDBean idBean = context.getApplication().evaluateExpressionGet(context, "#{stringToIDBean}", StringToIDBean.class); *
synchronized (this.widgets) { * @param widget
this.widgets.add(widget); * The widget to be add to the bean.
this.model.getColumn(0).addWidget(idBean.stringToID(widget.toString())); */
public void addWidget(final Widget widget) {
// Add the widget and add it to the model as well.
synchronized (this) {
this.widgets.add(widget);
this.dashboardModel.getColumn(new Random().nextInt(3)).addWidget(DashboardBean.WIDGET_ID_PREFIX + (this.widgets.size() - 1));
} }
// Update the UI
this.addChildren();
} }
public List<ProjectsBean.Widget> getWidgets() { public void handleReorder(final DashboardReorderEvent event) {
return this.widgets; // Nothing to do yet
this.addChildren();
} }
} }
...@@ -47,16 +47,13 @@ ...@@ -47,16 +47,13 @@
<p:layoutUnit position="center"> <p:layoutUnit position="center">
<h:form id="centerForm"> <h:form id="centerForm">
<ui:repeat value="#{dashboardBean.widgets}" var="widget"> <p:dashboard id="dashboard" binding="#{dashboardBean.dashboard}">
<p:panel id="widget" header="#{widget.name}">
</p:dashboard>
</p:panel>
<p:poll interval="2" update="widget"/>
</ui:repeat>
</h:form> </h:form>
</p:layoutUnit> </p:layoutUnit>
<p:layoutUnit style="overflow:visible;" position="west" size="200" resizable="true" collapsible="true" header="Plugins"> <p:layoutUnit position="west" size="200" resizable="true" collapsible="true" header="Plugins">
<h:form id="pluginsForm"> <h:form id="pluginsForm">
<p:accordionPanel value="#{analysisControllerBean.pluginMap.keySet().toArray()}" var="plugin" multiple="true" activeIndex=""> <p:accordionPanel value="#{analysisControllerBean.pluginMap.keySet().toArray()}" var="plugin" multiple="true" activeIndex="">
<p:tab title="#{plugin.name}"> <p:tab title="#{plugin.name}">
......
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