1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.component.admin.drives;
18
19 import java.util.Collections;
20 import java.util.Comparator;
21 import java.util.List;
22 import java.util.MissingResourceException;
23
24 import org.exoplatform.services.cms.drives.DriveData;
25 import org.exoplatform.services.cms.views.ManageViewService;
26 import org.exoplatform.services.cms.views.ViewConfig;
27 import org.exoplatform.web.application.ApplicationMessage;
28 import org.exoplatform.webui.application.WebuiRequestContext;
29 import org.exoplatform.webui.exception.MessageException;
30 import org.exoplatform.webui.form.UIFormInputSet;
31 import org.exoplatform.webui.form.input.UICheckBoxInput;
32
33
34
35
36
37
38
39 public class UIViewsInputSet extends UIFormInputSet {
40
41 public UIViewsInputSet(String name) throws Exception {
42 super(name);
43 }
44
45 public String getViewsSelected() throws Exception {
46 StringBuilder selectedView = new StringBuilder() ;
47 List<ViewConfig> views_ = getApplicationComponent(ManageViewService.class).getAllViews();
48 for(ViewConfig view : views_){
49 String viewName= view.getName() ;
50 boolean checked = getUICheckBoxInput(viewName).isChecked() ;
51 if(checked){
52 if(selectedView.length() > 0) selectedView.append(", ") ;
53 selectedView.append(viewName) ;
54 }
55 }
56 if(selectedView.length() < 1 ) {
57 throw new MessageException(new ApplicationMessage("UIDriveForm.msg.drive-views-invalid",
58 null, ApplicationMessage.WARNING)) ;
59 }
60 return selectedView.toString() ;
61 }
62
63 private void clear() throws Exception {
64
65 List<ViewConfig> views_ = getApplicationComponent(ManageViewService.class).getAllViews();
66 Collections.sort(views_, new ViewComparator());
67 for(ViewConfig view : views_){
68 String viewName = view.getName() ;
69 if(getUICheckBoxInput(viewName) != null) {
70 getUICheckBoxInput(viewName).setChecked(false) ;
71 }else{
72 addUIFormInput(new UICheckBoxInput(viewName, viewName, null)) ;
73 }
74
75 }
76 }
77
78 static public class ViewComparator implements Comparator<ViewConfig> {
79 public int compare(ViewConfig v1, ViewConfig v2) throws ClassCastException {
80 WebuiRequestContext webReqContext = WebuiRequestContext.getCurrentInstance();
81 String displayName1, displayName2;
82 try {
83 displayName1 = webReqContext.getApplicationResourceBundle().getString("UIDriveForm.label." + v1.getName());
84 } catch(MissingResourceException mre) {
85 displayName1 = v1.getName();
86 }
87 try {
88 displayName2 = webReqContext.getApplicationResourceBundle().getString("UIDriveForm.label." + v2.getName());
89 } catch(MissingResourceException mre) {
90 displayName2 = v2.getName();
91 }
92 return displayName1.compareToIgnoreCase(displayName2);
93 }
94 }
95
96 public void update(DriveData drive) throws Exception {
97 clear() ;
98 if( drive == null) return ;
99 String views = drive.getViews() ;
100 String[] array = views.split(",") ;
101 for(String view: array){
102 getUICheckBoxInput(view.trim()).setChecked(true) ;
103 }
104 }
105 }