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.upload;
18  
19  import org.exoplatform.ecm.webui.component.explorer.UIConfirmMessage;
20  import org.exoplatform.webui.config.annotation.ComponentConfig;
21  import org.exoplatform.webui.config.annotation.EventConfig;
22  import org.exoplatform.webui.core.UIPopupWindow;
23  import org.exoplatform.webui.event.Event;
24  import org.exoplatform.webui.event.EventListener;
25  
26  /**
27   * Created by The eXo Platform SARL
28   * Author : Dang Van Minh
29   *          minh.dang@exoplatform.com
30   * Oct 1, 2009
31   * 3:46:19 AM
32   */
33  @ComponentConfig(
34      template = "classpath:groovy/ecm/webui/UIConfirmMessage.gtmpl",
35      events = {
36          @EventConfig(listeners = UIUploadBehaviorWithSameName.ReplaceDataActionListener.class),
37          @EventConfig(listeners = UIUploadBehaviorWithSameName.BackActionListener.class),
38          @EventConfig(listeners = UIUploadBehaviorWithSameName.KeepfileActionListener.class)
39      }
40  )
41  public class UIUploadBehaviorWithSameName extends UIConfirmMessage {
42  
43    public UIUploadBehaviorWithSameName() throws Exception {
44    }
45  
46    public String[] getActions() { return new String[] {"ReplaceData", "Back", "Keepfile"}; }
47  
48    static  public class ReplaceDataActionListener extends EventListener<UIUploadBehaviorWithSameName> {
49      public void execute(Event<UIUploadBehaviorWithSameName> event) throws Exception {
50        UIUploadBehaviorWithSameName uiUploadBehavior = event.getSource();
51        UIPopupWindow uiPopup = uiUploadBehavior.getParent();
52        uiPopup.setShowMask(true);
53        UIUploadManager uiUploadManager = uiPopup.getParent();
54        UIUploadForm uiForm = uiUploadManager.getChild(UIUploadForm.class);
55        uiForm.doUpload(event, false);
56        if (uiUploadManager.getChildById(UIUploadManager.SAMENAME_POPUP) != null) {
57          uiUploadManager.removeChildById(UIUploadManager.SAMENAME_POPUP);
58        }
59        event.getRequestContext().addUIComponentToUpdateByAjax(uiUploadManager);
60      }
61    }
62  
63    static  public class BackActionListener extends EventListener<UIUploadBehaviorWithSameName> {
64      public void execute(Event<UIUploadBehaviorWithSameName> event) throws Exception {
65        UIUploadBehaviorWithSameName uiUploadBehavior = event.getSource();
66        UIPopupWindow uiPopup = uiUploadBehavior.getParent();
67        uiPopup.setRendered(false);
68        uiPopup.setShow(false);
69        event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup.getParent());
70      }
71    }
72  
73    static  public class KeepfileActionListener extends EventListener<UIUploadBehaviorWithSameName> {
74      public void execute(Event<UIUploadBehaviorWithSameName> event) throws Exception {
75        UIUploadBehaviorWithSameName uiUploadBehavior = event.getSource();
76        UIPopupWindow uiPopup = uiUploadBehavior.getParent();
77        uiPopup.setShowMask(true);
78        UIUploadManager uiUploadManager = uiPopup.getParent();
79        UIUploadForm uiForm = uiUploadManager.getChild(UIUploadForm.class);
80        uiForm.doUpload(event, true);
81        event.getRequestContext().addUIComponentToUpdateByAjax(uiUploadManager);
82      }
83    }
84  }
85