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 e5b1db14293673094e025e5ef3974c7372a2d509..5748e3c7d7023224abb09e202e2675ad89dd875c 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 @@ -168,9 +168,6 @@ public class CurrentCockpitEditorBean { // Now add the entries from the current view if (this.activeView != null) { - final FacesContext fc = FacesContext.getCurrentInstance(); - final Application application = fc.getApplication(); - // Add a panel for every display connector we have this.currId = 0; @@ -179,31 +176,11 @@ public class CurrentCockpitEditorBean { final DashboardColumn column = this.dashboard.getModel().getColumn(col); for (final MIDisplayConnector connector : displayConnectors) { - final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer"); - panel.setId("displayConnector_" + Integer.toString(this.connectors.get(connector))); - panel.setHeader(connector.getName()); - panel.setClosable(true); - panel.setToggleable(false); - - final AjaxBehavior behaviour = new AjaxBehavior(); - behaviour.setProcess("@this"); - behaviour.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl() { - - @Override - public void processAjaxBehavior(final AjaxBehaviorEvent event) throws AbortProcessingException { - System.out.println(((Panel) event.getSource()).getId()); - } - - }); - panel.addClientBehavior("close", behaviour); - - this.getDashboard().getChildren().add(panel); + final Panel panel = this.createPanelFromDisplayConnector(connector); + this.dashboard.getChildren().add(panel); column.addWidget(panel.getId()); - final HtmlOutputText text = new HtmlOutputText(); - text.setValue(connector.getDisplay().getName()); - panel.getChildren().add(text); this.currId++; } } @@ -238,6 +215,10 @@ public class CurrentCockpitEditorBean { // Update the class loader and the specific classes used within various methods in this bean this.fillDashboard(); + + if (!this.project.getViews().isEmpty()) { + this.setActiveView(this.project.getViews().get(0)); + } } this.unsavedModifications = false; @@ -413,6 +394,50 @@ public class CurrentCockpitEditorBean { this.setModificationsFlag(); } + private Panel createPanelFromDisplayConnector(final MIDisplayConnector connector) { + final FacesContext fc = FacesContext.getCurrentInstance(); + final Application application = fc.getApplication(); + final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer"); + final String id = this.displayConnectorToID(connector); + + // Set the usual properties of the panel + panel.setId(id); + panel.setHeader(connector.getName()); + panel.setClosable(true); + panel.setToggleable(false); + + final HtmlOutputText text = new HtmlOutputText(); + text.setValue(connector.getDisplay().getName()); + panel.getChildren().add(text); + + // The following code makes sure that the application detects the close event + final AjaxBehavior behaviour = new AjaxBehavior(); + behaviour.setProcess("@this"); + behaviour.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl() { + + private static final long serialVersionUID = 1L; + + @Override + public void processAjaxBehavior(final AjaxBehaviorEvent event) throws AbortProcessingException { + CurrentCockpitEditorBean.this.panelCloseEvent(event); + } + + }); + panel.addClientBehavior("close", behaviour); + + return panel; + } + + private void panelCloseEvent(final AjaxBehaviorEvent event) { + if (CurrentCockpitEditorBean.this.activeView != null) { + final String id = ((Panel) event.getSource()).getId(); + final MIDisplayConnector connector = CurrentCockpitEditorBean.this.idToDisplayConnector(id); + + CurrentCockpitEditorBean.this.activeView.getDisplayConnectors().remove(connector); + CurrentCockpitEditorBean.this.saveLayoutOfCurrentView(); + } + } + /** * This method adds the given display to the currently active view. If no view exists, this method does nothing. * @@ -427,22 +452,10 @@ public class CurrentCockpitEditorBean { this.activeView.getDisplayConnectors().add(connector); // Now add it to the dashboard as well - final FacesContext fc = FacesContext.getCurrentInstance(); - final Application application = fc.getApplication(); - - final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer"); - panel.setId(this.displayConnectorToID(connector)); - panel.setHeader(connector.getName()); - panel.setClosable(true); - panel.setToggleable(false); - + final Panel panel = this.createPanelFromDisplayConnector(connector); this.getDashboard().getChildren().add(panel); final DashboardColumn column = this.dashboardModel.getColumn(0); column.addWidget(panel.getId()); - final HtmlOutputText text = new HtmlOutputText(); - text.setValue(display.getName()); - - panel.getChildren().add(text); this.currId++; this.setModificationsFlag();