UISelectDocumentTemplateTitle.java

  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. import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIDocumentFormController;
  19. import org.exoplatform.ecm.webui.component.explorer.popup.actions.UISelectDocumentForm;
  20. import org.exoplatform.webui.config.annotation.ComponentConfig;
  21. import org.exoplatform.webui.config.annotation.EventConfig;
  22. import org.exoplatform.webui.core.UIComponent;
  23. import org.exoplatform.webui.event.Event;
  24. import org.exoplatform.webui.event.EventListener;

  25. /**
  26.  * Created by The eXo Platform SAS Author :
  27.  *  eXoPlatform dongpd@exoplatform.com
  28.  * Feb 2, 2013
  29.  */
  30. @ComponentConfig(template = "app:/groovy/webui/component/explorer/UISelectDocumentTemplateTitle.gtmpl", events = {
  31.     @EventConfig(listeners = UISelectDocumentTemplateTitle.ChangeViewActionListener.class),
  32.     @EventConfig(listeners = UISelectDocumentTemplateTitle.CancelActionListener.class) })
  33. public class UISelectDocumentTemplateTitle extends UIComponent {

  34.   private final static String THUMBNAIL_VIEW_TEMPLATE       =
  35.     "app:/groovy/webui/component/explorer/UISelectDocumentFormThumbnailView.gtmpl";

  36.   private final static String LIST_VIEW_TEMPLATE            =
  37.     "app:/groovy/webui/component/explorer/UISelectDocumentFormListView.gtmpl";

  38.   static public class ChangeViewActionListener extends EventListener<UISelectDocumentTemplateTitle> {
  39.     private static final String THUMBNAIL_VIEW_TYPE = "ThumbnailView";

  40.     public void execute(Event<UISelectDocumentTemplateTitle> event) throws Exception {
  41.       String viewType = event.getRequestContext().getRequestParameter(OBJECTID);
  42.       UISelectDocumentTemplateTitle uiTemplateTitle = event.getSource();
  43.       UIWorkingArea uiWorkingArea = uiTemplateTitle.getAncestorOfType(UIWorkingArea.class);
  44.       UISelectDocumentForm uiSelectForm =
  45.           uiWorkingArea.getChild(UIDocumentWorkspace.class)
  46.             .getChild(UIDocumentFormController.class)
  47.             .getChild(UISelectDocumentForm.class);
  48.       UIJCRExplorer uiExplorer = uiSelectForm.getAncestorOfType(UIJCRExplorer.class);
  49.       if (viewType.equals(THUMBNAIL_VIEW_TYPE)) {
  50.         uiSelectForm.setTemplate(THUMBNAIL_VIEW_TEMPLATE);
  51.       } else {
  52.         uiSelectForm.setTemplate(LIST_VIEW_TEMPLATE);
  53.       }
  54.       uiExplorer.updateAjax(event);
  55.     }
  56.   }
  57.  
  58.   static public class CancelActionListener extends EventListener<UISelectDocumentTemplateTitle> {
  59.     public void execute(Event<UISelectDocumentTemplateTitle> event) throws Exception {
  60.       UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
  61.       if (uiExplorer != null) {
  62.         UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class);
  63.         UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
  64.         if (uiDocumentWorkspace.getChild(UIDocumentFormController.class) != null) {
  65.           uiDocumentWorkspace.removeChild(UIDocumentFormController.class);
  66.         } else
  67.           uiExplorer.cancelAction();
  68.         uiExplorer.updateAjax(event);
  69.       }
  70.     }
  71.   }
  72. }