1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.component.explorer.control;
18
19 import org.exoplatform.ecm.jcr.model.Preference;
20 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
21 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet;
22 import org.exoplatform.webui.config.annotation.ComponentConfig;
23 import org.exoplatform.webui.config.annotation.EventConfig;
24 import org.exoplatform.webui.core.UIPopupComponent;
25 import org.exoplatform.webui.core.UIPopupContainer;
26 import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
27 import org.exoplatform.webui.event.Event;
28 import org.exoplatform.webui.event.Event.Phase;
29 import org.exoplatform.webui.event.EventListener;
30 import org.exoplatform.webui.form.UIForm;
31 import org.exoplatform.webui.form.input.UICheckBoxInput;
32
33
34
35
36
37
38
39
40 @ComponentConfig(
41 lifecycle = UIFormLifecycle.class,
42 template = "system:/groovy/webui/form/UIFormWithTitle.gtmpl",
43 events = {
44 @EventConfig(listeners = UIAllItemsPreferenceForm.SaveActionListener.class),
45 @EventConfig(listeners = UIAllItemsPreferenceForm.CancelActionListener.class, phase = Phase.DECODE)
46 }
47 )
48 public class UIAllItemsPreferenceForm extends UIForm implements UIPopupComponent {
49
50 final static public String FIELD_SHOW_OWNED_BY_USER_DOC = "showOwnedByUser";
51 final static public String FIELD_SHOW_FAVOURITES = "showFavourites";
52 final static public String FIELD_SHOW_HIDDENS = "showHiddens";
53
54 public UIAllItemsPreferenceForm() throws Exception {
55 addUIFormInput(new UICheckBoxInput(FIELD_SHOW_OWNED_BY_USER_DOC, FIELD_SHOW_OWNED_BY_USER_DOC, null));
56 addUIFormInput(new UICheckBoxInput(FIELD_SHOW_FAVOURITES, FIELD_SHOW_FAVOURITES, null));
57 addUIFormInput(new UICheckBoxInput(FIELD_SHOW_HIDDENS, FIELD_SHOW_HIDDENS, null));
58 }
59
60 public void activate() {
61 }
62
63 public void deActivate() {
64 }
65
66 public void update(Preference pref) {
67 getUICheckBoxInput(FIELD_SHOW_OWNED_BY_USER_DOC).setChecked(pref.isShowOwnedByUserDoc());
68 getUICheckBoxInput(FIELD_SHOW_FAVOURITES).setChecked(pref.isShowFavouriteDoc());
69 getUICheckBoxInput(FIELD_SHOW_HIDDENS).setChecked(pref.isShowHiddenDoc());
70 }
71
72 static public class SaveActionListener extends EventListener<UIAllItemsPreferenceForm> {
73 public void execute(Event<UIAllItemsPreferenceForm> event) throws Exception {
74 UIAllItemsPreferenceForm uiForm = event.getSource();
75 UIJCRExplorerPortlet uiExplorerPortlet = uiForm.getAncestorOfType(UIJCRExplorerPortlet.class);
76 UIJCRExplorer uiExplorer = uiExplorerPortlet.findFirstComponentOfType(UIJCRExplorer.class);
77 Preference pref = uiExplorer.getPreference();
78 pref.setShowOwnedByUserDoc(
79 uiForm.getUICheckBoxInput(FIELD_SHOW_OWNED_BY_USER_DOC).isChecked());
80 pref.setShowFavouriteDoc(
81 uiForm.getUICheckBoxInput(FIELD_SHOW_FAVOURITES).isChecked());
82 pref.setShowHiddenDoc(
83 uiForm.getUICheckBoxInput(FIELD_SHOW_HIDDENS).isChecked());
84 uiExplorer.refreshExplorer();
85 uiExplorerPortlet.setRenderedChild(UIJCRExplorer.class);
86 }
87 }
88
89 static public class CancelActionListener extends EventListener<UIAllItemsPreferenceForm> {
90 public void execute(Event<UIAllItemsPreferenceForm> event) throws Exception {
91 UIAllItemsPreferenceForm uiForm = event.getSource();
92 UIJCRExplorerPortlet uiExplorerPortlet = uiForm.getAncestorOfType(UIJCRExplorerPortlet.class);
93 UIJCRExplorer uiExplorer = uiExplorerPortlet.findFirstComponentOfType(UIJCRExplorer.class);
94 uiExplorer.getChild(UIPopupContainer.class).cancelPopupAction();
95 }
96 }
97
98 }