View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
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   * Created by The eXo Platform SARL
35   * Author : Nguyen Anh Vu
36   *          anhvurz90@gmail.com
37   * Oct 27, 2009
38   * 10:22:38 AM
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  }