Guest User

Untitled

a guest
Apr 15th, 2018
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.95 KB | None | 0 0
  1. package ru.omnicomm.pegasus.gadgets.movementsummaryreportgadget.client;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.Set;
  8.  
  9. import ru.omnicomm.pegasus.gadgets.movementsummaryreportgadget.client.dao.ReportTableData;
  10.  
  11.  
  12. import com.extjs.gxt.ui.client.data.BaseModel;
  13. import com.extjs.gxt.ui.client.data.BaseModelData;
  14. import com.extjs.gxt.ui.client.data.ModelData;
  15. import com.extjs.gxt.ui.client.dnd.ListViewDragSource;
  16. import com.extjs.gxt.ui.client.dnd.ListViewDropTarget;
  17. import com.extjs.gxt.ui.client.store.ListStore;
  18. import com.extjs.gxt.ui.client.store.StoreSorter;
  19. import com.extjs.gxt.ui.client.widget.CheckBoxListView;
  20. import com.extjs.gxt.ui.client.widget.HorizontalPanel;
  21. import com.extjs.gxt.ui.client.widget.LayoutContainer;
  22. import com.extjs.gxt.ui.client.widget.Text;
  23. import com.extjs.gxt.ui.client.widget.VerticalPanel;
  24. import com.extjs.gxt.ui.client.widget.button.Button;
  25. import com.extjs.gxt.ui.client.widget.form.CheckBox;
  26. import com.extjs.gxt.ui.client.widget.form.ComboBox;
  27. import com.extjs.gxt.ui.client.widget.form.DateField;
  28. import com.extjs.gxt.ui.client.widget.form.FormPanel;
  29. import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
  30. import com.extjs.gxt.ui.client.dnd.DND.Feedback;
  31. import com.extjs.gxt.ui.client.event.ButtonEvent;
  32. import com.extjs.gxt.ui.client.event.SelectionListener;
  33. import com.extjs.gxt.ui.client.widget.Dialog;
  34. import com.google.gwt.core.client.GWT;
  35.  
  36. public final class SettingsPanel extends Dialog {
  37.  
  38.     /**  Количество минут в одном часе. */
  39.     private final static int MINUTES = 60;
  40.     /** Кличество часов в сутках. */
  41.     private final static int HOURS = 24;
  42.    
  43.     private final Constants constants = (Constants) GWT.create(Constants.class);
  44.    
  45.     private CheckBoxListView<ModelData> columnView = new CheckBoxListView<ModelData>();
  46.     private DateField startDate = new DateField();
  47.     private ComboBox<Hour> startHour = new ComboBox<Hour>();
  48.     private ComboBox<Minute> startMinute = new ComboBox<Minute>();
  49.     private DateField endDate = new DateField();
  50.     private ComboBox<Hour> endHour = new ComboBox<Hour>();
  51.     private ComboBox<Minute> endMinute = new ComboBox<Minute>();
  52.    
  53.     public SettingsPanel() {
  54.         super();
  55.        
  56.         setWidth(270);
  57.        
  58.         VerticalPanel vPanel = new VerticalPanel();
  59.         vPanel.setSpacing(10);
  60.         vPanel.setBorders(false);
  61.        
  62.         //Колонки    
  63.         Text columnTxt = new Text("Колонки таблицы");
  64.         vPanel.add(columnTxt);
  65.        
  66.         ListStore<ModelData> columnStore = new ListStore<ModelData>();
  67.         columnStore.add(getListModel());
  68.                
  69.         columnView.setStore(columnStore);
  70.         columnView.setDisplayProperty("columnName");
  71.         columnView.setWidth(230);
  72.         columnView.setSelectOnOver(true);
  73.         List<ModelData> elems = columnView.getStore().getModels();
  74.         for (ModelData elem: elems) {
  75.             columnView.setChecked(elem, true);
  76.         }
  77.         ListViewDragSource listViewDragSource = new ListViewDragSource(columnView);
  78.          
  79.         ListViewDropTarget target = new ListViewDropTarget(columnView);  
  80.         target.setAllowSelfAsSource(true);  
  81.         target.setFeedback(Feedback.INSERT);
  82.        
  83.         vPanel.add(columnView);
  84.        
  85.         //Период
  86.        
  87.         Text periodTxt = new Text("Период по умолчанию");
  88.         vPanel.add(periodTxt);
  89.        
  90.         HorizontalPanel startDatePanel = new HorizontalPanel();
  91.        
  92.         Text startTxt = new Text("с");
  93.         startTxt.setWidth(40);
  94.         startDatePanel.add(startTxt);
  95.                
  96.         //дата
  97.         startDate.setWidth(90);
  98.         startDatePanel.add(startDate);
  99.        
  100. //      TimeField startTime = new TimeField();
  101. //      startTime.setWidth(60);
  102. //      startTime.setTypeAhead(true);
  103. //      startTime.setTriggerAction(TriggerAction.ALL);
  104. //      startDatePanel.add(startTime); 
  105.    
  106.         // часы
  107.         ListStore<Hour> hours = new ListStore<Hour>();
  108.         hours.add(getHours());
  109.         // минуты
  110.         ListStore<Minute> minutes = new ListStore<Minute>();
  111.         minutes.add(getMinutes());
  112.        
  113.         //часы
  114.         startHour.setStore(hours);
  115.         startHour.setDisplayField("hour");
  116.         startHour.setTypeAhead(true);
  117.         startHour.setTriggerAction(TriggerAction.ALL);
  118.         startHour.setWidth(50);
  119.         startDatePanel.add(startHour);
  120.        
  121.         //минуты
  122.         startMinute.setStore(minutes);
  123.         startMinute.setDisplayField("minute");
  124.         startMinute.setTypeAhead(true);
  125.         startMinute.setTriggerAction(TriggerAction.ALL);
  126.         startMinute.setWidth(50);
  127.         startDatePanel.add(startMinute);
  128.        
  129.         vPanel.add(startDatePanel);
  130.            
  131.         HorizontalPanel endDatePanel = new HorizontalPanel();
  132.        
  133.         Text endTxt = new Text("по");
  134.         endTxt.setWidth(40);
  135.         endDatePanel.add(endTxt);
  136.        
  137.         endDate.setWidth(90);
  138.         endDatePanel.add(endDate);
  139.        
  140. //      TimeField finTime = new TimeField();
  141. //      finTime.setWidth(60);
  142. //      finTime.setTypeAhead(true);
  143. //      finTime.setTriggerAction(TriggerAction.ALL);
  144. //      finDatePanel.add(finTime); 
  145.        
  146.         // часы
  147.         endHour.setStore(hours);
  148.         endHour.setDisplayField("hour");
  149.         endHour.setTypeAhead(true);
  150.         endHour.setTriggerAction(TriggerAction.ALL);
  151.         endHour.setWidth(50);
  152.         endDatePanel.add(endHour);
  153.        
  154.         // минуты
  155.         endMinute.setStore(minutes);
  156.         endMinute.setDisplayField("minute");
  157.         endMinute.setTypeAhead(true);
  158.         endMinute.setTriggerAction(TriggerAction.ALL);
  159.         endMinute.setWidth(50);
  160.         endDatePanel.add(endMinute);
  161.        
  162.         vPanel.add(endDatePanel);
  163.        
  164.         //критерии фильтрации поиска ТС
  165.         Text criteriaTxt = new Text("Критерии фильтрации поиска ТС");
  166.         vPanel.add(criteriaTxt);
  167.        
  168.         CheckBox criteriaShow = new CheckBox();
  169.         criteriaShow.setBoxLabel("Показать");
  170.         vPanel.add(criteriaShow);
  171.        
  172.         //формат сохраняемого файла
  173.        
  174.         Text formatTxt = new Text("Формат сохраняемого файла");
  175.         vPanel.add(formatTxt); 
  176.  
  177.         ListStore<ExportType> types = new ListStore<ExportType>();  
  178.         types.add(getExportTypes());       
  179.        
  180.         ComboBox<ExportType> exportCombo = new ComboBox<ExportType>();
  181.         exportCombo.setStore(types);
  182.         exportCombo.setDisplayField("typeName");
  183.         exportCombo.setTriggerAction(TriggerAction.ALL);
  184.         exportCombo.setWidth(230);
  185.        
  186.         vPanel.add(exportCombo);
  187.        
  188.         //адрес по умолчанию
  189.        
  190.         Text contactTxt = new Text("Адрес по умолчанию");
  191.         vPanel.add(contactTxt);
  192.  
  193.         ListStore<UserContact> contacts = new ListStore<UserContact>();  
  194.         contacts.add(getUserContacts());       
  195.        
  196.         ComboBox<UserContact> contactCombo = new ComboBox<UserContact>();
  197.         contactCombo.setStore(contacts);
  198.         contactCombo.setDisplayField("user");
  199.         contactCombo.setTriggerAction(TriggerAction.ALL);
  200.         contactCombo.setWidth(230);
  201.         contactCombo.setSelectOnFocus(true);
  202.                
  203.         vPanel.add(contactCombo);
  204.        
  205. //        setHideOnButtonClick(true);
  206.        
  207.        
  208.        
  209.         add(vPanel);
  210.     }
  211.  
  212.     @Override
  213.     public void show() {
  214.         setChecks();
  215. //      setOrder();
  216.         super.show();      
  217.     }
  218.    
  219.     @Override
  220.     protected void createButtons() {
  221.        
  222.         Button okButton = new Button("Ok");
  223.         okButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
  224.           public void componentSelected(ButtonEvent ce) {
  225.                  
  226.               //колонки
  227.               List<String> visibleColumnsId = new ArrayList<String>();
  228.               List<String> allColumns = new ArrayList<String>();
  229.               for (ModelData elem: columnView.getStore().getModels()) {
  230.                   if (columnView.getChecked().contains(elem)) {
  231.                       visibleColumnsId.add((String)elem.get("columnId"));
  232.                   }
  233.                   allColumns.add((String)elem.get("columnId"));
  234.               }
  235.    
  236.               ServiceLocator.getReportTable().setVisibleColumns(visibleColumnsId);
  237.               ServiceLocator.getReportTable().setColumnOrder(allColumns);
  238.              
  239. /*            DateHourMinute start = new DateHourMinute(startDate.getValue(),startHour.getValue(),startMinute.getValue());
  240.               DateHourMinute end = new DateHourMinute(endDate.getValue(),endHour.getValue(),endMinute.getValue());
  241.              
  242.               ServiceLocator.getDateIntervalCriteria().setPeriod(start, end);*/
  243.              
  244.               hide();
  245.           }
  246.  
  247.       });
  248.  
  249.       addButton(okButton);
  250.        
  251.     }  
  252.    
  253.     private void setChecks() {
  254.         List<String> visibleColumns = ServiceLocator.getReportTable().getVisibleColumns();
  255.         for (ModelData elem : columnView.getStore().getModels()) {
  256.             if (visibleColumns.contains(elem.get("columnId"))) {
  257.                 columnView.setChecked(elem, true);
  258.             } else {
  259.                 columnView.setChecked(elem, false);
  260.             }
  261.         }
  262.     }
  263.    
  264. //  private void setOrder() {
  265. //      List<String> order = ServiceLocator.getReportTable().getColumnOrder();
  266. //  //  columnView.getStore().getModels().
  267. //
  268. //  }
  269.    
  270.     public List<ListModel> getListModel() {
  271.         List<ListModel> listModel = new ArrayList<ListModel>();
  272.                
  273.         // for exampls
  274.  
  275.         listModel.add(new ListModel("numRow", constants.numRow()));
  276.         listModel.add(new ListModel("number", constants.number()));
  277.         listModel.add(new ListModel("driver", constants.driver()));
  278.         listModel.add(new ListModel("run", constants.run()));
  279.         listModel.add(new ListModel("averageSpeed", constants.averageSpeed()));
  280.         listModel.add(new ListModel("maximumSpeed", constants.maximumSpeed()));
  281.         listModel.add(new ListModel("movementTime", constants.movementTime()));
  282.         listModel.add(new ListModel("downTime", constants.downTime()));
  283.         listModel.add(new ListModel("absenceDate", constants.absenceDate()));
  284.        
  285.         return listModel;
  286.     }  
  287.    
  288.     private static List<Hour> getHours() {
  289.         List<Hour> hours = new ArrayList<Hour>();
  290.  
  291.         for (int i = 0; i < HOURS; i++) {
  292.             hours.add(new Hour(String.valueOf(i)));
  293.         }
  294.        
  295.         return hours;
  296.     }
  297.  
  298.     private static List<Minute> getMinutes() {
  299.         List<Minute> minutes = new ArrayList<Minute>();
  300.  
  301.         for (int i = 0; i < MINUTES; i++) {
  302.             minutes.add(new Minute(String.valueOf(i)));
  303.         }
  304.        
  305.         return minutes;
  306.     }
  307.    
  308.    
  309.     private static List<ExportType> getExportTypes() {
  310.         List<ExportType> exportTypes = new ArrayList<ExportType>();
  311.        
  312.         exportTypes.add(new ExportType("Microsoft Word .docx"));
  313.         exportTypes.add(new ExportType("Microsoft Excell .xlsx"));
  314.         exportTypes.add(new ExportType("Adobe Acrobat .pdf"));
  315.         exportTypes.add(new ExportType("Rich Text Format .RTF"));
  316.         exportTypes.add(new ExportType("XML-документ .xml"));
  317.         exportTypes.add(new ExportType("Веб-страница .html"));
  318.        
  319.         return exportTypes;
  320.     }
  321.    
  322.     // TODO: откуда загружать e-mail ?
  323.     private static List<UserContact> getUserContacts() {
  324.         List<UserContact> contacs = new ArrayList<UserContact>();
  325.        
  326.         contacs.add(new UserContact("Петров <petrov@gmail.com>"));
  327.         contacs.add(new UserContact("Сидоров <sidoroff@ya.ru>"));
  328.         contacs.add(new UserContact("Ленский <lensk@gmail.com>"));
  329.         contacs.add(new UserContact("Онегин <zhenya.o@gmail.com>"));
  330.         contacs.add(new UserContact("Ларина <tanya777@mail.ru>"));
  331.        
  332.         return contacs;
  333.     }
  334.    
  335. }
  336.  
  337. class ListModel extends BaseModel {
  338.    
  339. //  private SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
  340.  
  341.  
  342.     public ListModel() {
  343.     }
  344.    
  345.     public ListModel(String columnId, String columnName) {     
  346.         set("columnId", columnId);
  347.         set("columnName", columnName);     
  348.     }
  349.  
  350.     public String getColumnId() {
  351.         return get("columnId");
  352.     }
  353.    
  354.     public void setColumnId(String columnId) {
  355.         set("columnId", columnId);
  356.     }  
  357.    
  358.     public String getColumnName() {
  359.         return get("columnName");
  360.     }
  361.    
  362.     public void setColumnName(String columnName) {
  363.         set("columnName", columnName);
  364.     }
  365.    
  366. }
  367.  
  368.  
  369. class ExportType extends BaseModelData {
  370.    
  371.     public ExportType() {      
  372.     }
  373.    
  374.     public ExportType(String typeName) {
  375.         setTypeName(typeName);
  376.     }
  377.    
  378.     public String getTypeName() {
  379.         return get("typeName");
  380.     }
  381.    
  382.     public void setTypeName(String typeName) {
  383.         set("typeName",typeName);
  384.     }
  385. }
  386.  
  387.  
  388. class UserContact extends BaseModelData {
  389.    
  390.     public UserContact() {     
  391.     }
  392.    
  393.     public UserContact(String user) {
  394.         setUser(user);
  395.     }
  396.    
  397.     public String getUser() {
  398.         return get("user");
  399.     }
  400.    
  401.     public void setUser(String user) {
  402.         set("user",user);
  403.     }
  404. }
Add Comment
Please, Sign In to add comment