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

Further development of the cockpit editor

parent 8cd0a325
No related branches found
No related tags found
No related merge requests found
...@@ -168,9 +168,6 @@ public class CurrentCockpitEditorBean { ...@@ -168,9 +168,6 @@ public class CurrentCockpitEditorBean {
// Now add the entries from the current view // Now add the entries from the current view
if (this.activeView != null) { if (this.activeView != null) {
final FacesContext fc = FacesContext.getCurrentInstance();
final Application application = fc.getApplication();
// Add a panel for every display connector we have // Add a panel for every display connector we have
this.currId = 0; this.currId = 0;
...@@ -179,31 +176,11 @@ public class CurrentCockpitEditorBean { ...@@ -179,31 +176,11 @@ public class CurrentCockpitEditorBean {
final DashboardColumn column = this.dashboard.getModel().getColumn(col); final DashboardColumn column = this.dashboard.getModel().getColumn(col);
for (final MIDisplayConnector connector : displayConnectors) { for (final MIDisplayConnector connector : displayConnectors) {
final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer"); final Panel panel = this.createPanelFromDisplayConnector(connector);
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);
this.dashboard.getChildren().add(panel);
column.addWidget(panel.getId()); column.addWidget(panel.getId());
final HtmlOutputText text = new HtmlOutputText();
text.setValue(connector.getDisplay().getName());
panel.getChildren().add(text);
this.currId++; this.currId++;
} }
} }
...@@ -238,6 +215,10 @@ public class CurrentCockpitEditorBean { ...@@ -238,6 +215,10 @@ public class CurrentCockpitEditorBean {
// Update the class loader and the specific classes used within various methods in this bean // Update the class loader and the specific classes used within various methods in this bean
this.fillDashboard(); this.fillDashboard();
if (!this.project.getViews().isEmpty()) {
this.setActiveView(this.project.getViews().get(0));
}
} }
this.unsavedModifications = false; this.unsavedModifications = false;
...@@ -413,6 +394,50 @@ public class CurrentCockpitEditorBean { ...@@ -413,6 +394,50 @@ public class CurrentCockpitEditorBean {
this.setModificationsFlag(); 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. * 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 { ...@@ -427,22 +452,10 @@ public class CurrentCockpitEditorBean {
this.activeView.getDisplayConnectors().add(connector); this.activeView.getDisplayConnectors().add(connector);
// Now add it to the dashboard as well // Now add it to the dashboard as well
final FacesContext fc = FacesContext.getCurrentInstance(); final Panel panel = this.createPanelFromDisplayConnector(connector);
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);
this.getDashboard().getChildren().add(panel); this.getDashboard().getChildren().add(panel);
final DashboardColumn column = this.dashboardModel.getColumn(0); final DashboardColumn column = this.dashboardModel.getColumn(0);
column.addWidget(panel.getId()); column.addWidget(panel.getId());
final HtmlOutputText text = new HtmlOutputText();
text.setValue(display.getName());
panel.getChildren().add(text);
this.currId++; this.currId++;
this.setModificationsFlag(); this.setModificationsFlag();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment