Guest User

Untitled

a guest
Sep 7th, 2014
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.15 KB | None | 0 0
  1. package com.calldesk.cqp.jsf;
  2.  
  3. import javax.faces.bean.ManagedBean;
  4. import javax.faces.bean.SessionScoped;
  5. import javax.faces.component.html.HtmlInputText;
  6. import javax.faces.component.html.HtmlOutputLabel;
  7. import javax.faces.component.html.HtmlPanelGrid;
  8. import javax.faces.context.FacesContext;
  9. import javax.faces.event.ActionEvent;
  10. import org.primefaces.component.dashboard.Dashboard;
  11. import org.primefaces.component.panel.Panel;
  12. import org.primefaces.event.CloseEvent;
  13. import org.primefaces.model.DashboardColumn;
  14. import org.primefaces.model.DashboardModel;
  15. import org.primefaces.model.DefaultDashboardColumn;
  16. import org.primefaces.model.DefaultDashboardModel;
  17.  
  18. import com.calldesk.cqp.form.Form;
  19. import com.calldesk.cqp.form.FormItem;
  20.  
  21. @ManagedBean
  22. @SessionScoped
  23. public class MonitoringFormDashboard {
  24.  
  25.     private Dashboard dashboard;
  26.     private Form form;
  27.    
  28.     private FormItem newField;
  29.    
  30.     public MonitoringFormDashboard() {
  31.         FacesContext fc = FacesContext.getCurrentInstance();
  32.         dashboard = (Dashboard) fc.getApplication().createComponent(fc, "org.primefaces.component.Dashboard", "org.primefaces.component.DashboardRenderer");
  33.         dashboard.setId("formDashboard");
  34.        
  35.         this.newField = new FormItem("", 0);
  36.        
  37.         /* TEST */
  38.         form = new Form("TestForm");
  39.         /* END TEST */
  40.     }
  41.  
  42.     private void buildModel() {
  43.         DashboardModel model = new DefaultDashboardModel();
  44.        
  45.         DashboardColumn column = new DefaultDashboardColumn();
  46.         model.addColumn(column);
  47.        
  48.         FacesContext fc = FacesContext.getCurrentInstance();
  49.        
  50.         for(FormItem item : form) {
  51.             Panel panel = (Panel) fc.getApplication().createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
  52.             panel.setId("panel_"+item.hashCode());
  53.             panel.setHeader(" * Clique e arraste para ordenar * ");
  54.             panel.setClosable(true);
  55.            
  56.             this.dashboard.getChildren().add(panel);
  57.             this.dashboard.getModel().getColumn(0).addWidget(panel.getId());
  58.            
  59.             HtmlPanelGrid grid = new HtmlPanelGrid();
  60.             grid.setCellspacing("5");
  61.             grid.setColumns(2);
  62.            
  63.             HtmlOutputLabel label = new HtmlOutputLabel();
  64.             label.setValue(item.getName());
  65.             label.setFor("inputText_" + item.hashCode());
  66.            
  67.             HtmlInputText inputText = new HtmlInputText();
  68.             inputText.setId("inputText_" + item.hashCode());
  69.            
  70.             grid.getChildren().add(label);
  71.             grid.getChildren().add(inputText);
  72.            
  73.             panel.getChildren().add(grid);
  74.         }
  75.        
  76.         dashboard.setModel(model);
  77.     }
  78.    
  79.     public void handleClose(CloseEvent event) {
  80.        
  81.     }
  82.    
  83.     public void addField(ActionEvent event) {
  84.         this.form.addItem(newField);
  85.         newField.setName("");
  86.         newField.setType(0);
  87.     }
  88.    
  89.     public String getNewFieldName() {
  90.         return this.newField.getName();
  91.     }
  92.    
  93.     public String getNewFieldType() {
  94.         return ""+this.newField.getType();
  95.     }
  96.    
  97.     public void setNewFieldName(String name) {
  98.         this.newField.setName(name);
  99.     }
  100.    
  101.     public void setNewFieldType(String type) {
  102.         this.newField.setType(Integer.parseInt(type));
  103.     }
  104.    
  105.     public Dashboard getDashboard() {
  106.         this.buildModel();
  107.         return this.dashboard;
  108.     }
  109.    
  110.     public void setDashboard(Dashboard dashboard) {
  111.         this.dashboard = dashboard;
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment