View Javadoc
1   /*
2    * Copyright (C) 2003-2007 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;
18  
19  import org.exoplatform.ecm.webui.component.explorer.rightclick.manager.DeleteManageComponent;
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.core.UIPopupComponent;
24  import org.exoplatform.webui.core.UIPopupWindow;
25  import org.exoplatform.webui.event.Event;
26  import org.exoplatform.webui.event.EventListener;
27  
28  /**
29   * Created by The eXo Platform SARL
30   * Author : Dang Van Minh
31   *          minh.dang@exoplatform.com
32   * Sep 18, 2008 9:52:55 AM
33   */
34  @ComponentConfig(
35      template = "classpath:groovy/ecm/webui/UIConfirmMessage.gtmpl",
36      events = {
37          @EventConfig(listeners = UIConfirmMessage.OKActionListener.class),
38          @EventConfig(listeners = UIConfirmMessage.CloseActionListener.class)
39  
40      }
41  )
42  public class UIConfirmMessage extends UIComponent implements UIPopupComponent {
43  
44    private String messageKey_;
45    private String[] args_ = {};
46    protected boolean isOK_ = false;
47    protected String nodePath_;
48    private boolean isNodeInTrash = false;
49  
50    public UIConfirmMessage() throws Exception {
51    }
52  
53    public void setMessageKey(String messageKey) { messageKey_ = messageKey; }
54  
55    public String getMessageKey() { return messageKey_; }
56  
57    public void setArguments(String[] args) { args_ = args; }
58  
59    public String[] getArguments() { return args_; }
60  
61    public boolean isOK() { return isOK_; }
62  
63    public void setNodePath(String nodePath) { nodePath_ = nodePath; }
64  
65    public String[] getActions() {
66      return new String[] {"OK", "Close"};
67    }
68    
69    public boolean isNodeInTrash() {
70      return isNodeInTrash;
71    }
72  
73    public void setNodeInTrash(boolean isNodeInTrash) {
74      this.isNodeInTrash = isNodeInTrash;
75    }
76  
77    static  public class OKActionListener extends EventListener<UIConfirmMessage> {
78      public void execute(Event<UIConfirmMessage> event) throws Exception {
79        UIConfirmMessage uiConfirm = event.getSource();
80        UIJCRExplorer uiExplorer = uiConfirm.getAncestorOfType(UIJCRExplorer.class);
81        UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class);
82        
83        if (uiConfirm.isNodeInTrash()) {
84          uiWorkingArea.getChild(DeleteManageComponent.class).doDeleteWithoutTrash(uiConfirm.nodePath_, event);
85        } else {
86          uiWorkingArea.getChild(DeleteManageComponent.class).doDelete(uiConfirm.nodePath_, event);
87        }
88        
89        uiConfirm.isOK_ = true;
90        UIPopupWindow popupAction = uiConfirm.getAncestorOfType(UIPopupWindow.class) ;
91        popupAction.setShow(false) ;
92        event.getRequestContext().addUIComponentToUpdateByAjax(popupAction);
93      }
94    }
95  
96    static  public class CloseActionListener extends EventListener<UIConfirmMessage> {
97      public void execute(Event<UIConfirmMessage> event) throws Exception {
98        UIConfirmMessage uiConfirm = event.getSource();
99        uiConfirm.isOK_ = false;
100       UIPopupWindow popupAction = uiConfirm.getAncestorOfType(UIPopupWindow.class) ;
101       popupAction.setShow(false) ;
102       event.getRequestContext().addUIComponentToUpdateByAjax(popupAction);
103       event.getRequestContext().getJavascriptManager().require("SHARED/uiFileView", "uiFileView").
104       addScripts("uiFileView.UIFileView.clearCheckboxes();");
105     }
106   }
107 
108   public void activate() {
109 
110   }
111 
112   public void deActivate() {
113 
114   }
115 }