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.popup.admin;
18  
19  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
20  import org.exoplatform.services.log.ExoLogger;
21  import org.exoplatform.services.log.Log;
22  import org.exoplatform.webui.application.WebuiRequestContext;
23  import org.exoplatform.webui.config.annotation.ComponentConfig;
24  import org.exoplatform.webui.core.UIContainer;
25  import org.exoplatform.webui.core.UIPageIterator;
26  import org.exoplatform.webui.core.UIPopupComponent;
27  import org.exoplatform.webui.core.UIPopupWindow;
28  
29  /**
30   * Created by The eXo Platform SARL
31   * Author : Dang Van Minh
32   *          minh.dang@exoplatform.com
33   * Nov 8, 2006
34   * 9:39:58 AM
35   */
36  @ComponentConfig(template = "system:/groovy/webui/core/UITabPane.gtmpl")
37  public class UIActionManager extends UIContainer implements UIPopupComponent {
38  
39    private static final Log LOG = ExoLogger.getLogger(UIActionManager.class.getName());
40  
41    public UIActionManager() throws Exception {
42      addChild(UIActionListContainer.class, null, null);
43      addChild(UIActionContainer.class, null, null).setRendered(false);
44    }
45  
46    public void activate() {
47      try {
48        UIActionTypeForm uiActionTypeForm = findFirstComponentOfType(UIActionTypeForm.class);
49        uiActionTypeForm.update();
50        UIActionList uiActionList = findFirstComponentOfType(UIActionList.class);
51        uiActionList.updateGrid(getAncestorOfType(UIJCRExplorer.class).getCurrentNode(),
52                              uiActionList.getChild(UIPageIterator.class).getCurrentPage());
53      } catch (Exception e) {
54        if (LOG.isErrorEnabled()) {
55          LOG.error("Unexpected error!", e.getMessage());
56        }
57      }
58    }
59  
60    /**
61     * Remove lock if node is locked for editing
62     */
63    public void deActivate() {
64      try {
65        UIActionForm uiForm = findFirstComponentOfType(UIActionForm.class);
66        if (uiForm != null) {
67          uiForm.releaseLock();
68        }
69      } catch (Exception e) {
70        if (LOG.isErrorEnabled()) {
71          LOG.error("Unexpected error!", e.getMessage());
72        }
73      }
74    }
75  
76    @Override
77    public void processRender(WebuiRequestContext context) throws Exception {
78      UIPopupWindow uiPopup = getAncestorOfType(UIPopupWindow.class);
79      if (uiPopup != null && !uiPopup.isShow()) {
80        uiPopup.setShowMask(true);
81        deActivate();
82      }
83      super.processRender(context);
84    }
85  
86    public void setDefaultConfig() throws Exception {
87      UIActionContainer uiActionContainer = getChild(UIActionContainer.class);
88      UIActionTypeForm uiActionType = uiActionContainer.getChild(UIActionTypeForm.class);
89      uiActionType.setDefaultActionType();
90      Class[] renderClasses = { UIActionTypeForm.class, UIActionForm.class };
91      uiActionContainer.setRenderedChildrenOfTypes(renderClasses);
92    }
93  
94  }