View Javadoc
1   /*
2    * Copyright (C) 2003-2013 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (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 Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero 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;
18  
19  import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIDocumentFormController;
20  import org.exoplatform.ecm.webui.component.explorer.popup.actions.UISelectDocumentForm;
21  import org.exoplatform.webui.config.annotation.ComponentConfig;
22  import org.exoplatform.webui.config.annotation.EventConfig;
23  import org.exoplatform.webui.core.UIComponent;
24  import org.exoplatform.webui.event.Event;
25  import org.exoplatform.webui.event.EventListener;
26  
27  /**
28   * Created by The eXo Platform SAS Author :
29   *  eXoPlatform dongpd@exoplatform.com
30   * Feb 2, 2013
31   */
32  @ComponentConfig(template = "app:/groovy/webui/component/explorer/UISelectDocumentTemplateTitle.gtmpl", events = {
33      @EventConfig(listeners = UISelectDocumentTemplateTitle.ChangeViewActionListener.class),
34      @EventConfig(listeners = UISelectDocumentTemplateTitle.CancelActionListener.class) })
35  public class UISelectDocumentTemplateTitle extends UIComponent {
36  
37    private final static String THUMBNAIL_VIEW_TEMPLATE       =
38      "app:/groovy/webui/component/explorer/UISelectDocumentFormThumbnailView.gtmpl";
39  
40    private final static String LIST_VIEW_TEMPLATE            =
41      "app:/groovy/webui/component/explorer/UISelectDocumentFormListView.gtmpl";
42  
43    static public class ChangeViewActionListener extends EventListener<UISelectDocumentTemplateTitle> {
44      private static final String THUMBNAIL_VIEW_TYPE = "ThumbnailView";
45  
46      public void execute(Event<UISelectDocumentTemplateTitle> event) throws Exception {
47        String viewType = event.getRequestContext().getRequestParameter(OBJECTID);
48        UISelectDocumentTemplateTitle uiTemplateTitle = event.getSource();
49        UIWorkingArea uiWorkingArea = uiTemplateTitle.getAncestorOfType(UIWorkingArea.class);
50        UISelectDocumentForm uiSelectForm = 
51            uiWorkingArea.getChild(UIDocumentWorkspace.class)
52              .getChild(UIDocumentFormController.class)
53              .getChild(UISelectDocumentForm.class);
54        UIJCRExplorer uiExplorer = uiSelectForm.getAncestorOfType(UIJCRExplorer.class);
55        if (viewType.equals(THUMBNAIL_VIEW_TYPE)) {
56          uiSelectForm.setTemplate(THUMBNAIL_VIEW_TEMPLATE);
57        } else {
58          uiSelectForm.setTemplate(LIST_VIEW_TEMPLATE);
59        }
60        uiExplorer.updateAjax(event);
61      }
62    }
63    
64    static public class CancelActionListener extends EventListener<UISelectDocumentTemplateTitle> {
65      public void execute(Event<UISelectDocumentTemplateTitle> event) throws Exception {
66        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
67        if (uiExplorer != null) {
68          UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class);
69          UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
70          if (uiDocumentWorkspace.getChild(UIDocumentFormController.class) != null) {
71            uiDocumentWorkspace.removeChild(UIDocumentFormController.class);
72          } else
73            uiExplorer.cancelAction();
74          uiExplorer.updateAjax(event);
75        }
76      }
77    }
78  }