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.admin;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.exoplatform.services.log.Log;
23  import org.exoplatform.services.log.ExoLogger;
24  import org.exoplatform.webui.config.annotation.ComponentConfig;
25  import org.exoplatform.webui.core.UIComponent;
26  import org.exoplatform.webui.core.UIContainer;
27  import org.exoplatform.webui.ext.UIExtension;
28  import org.exoplatform.webui.ext.UIExtensionManager;
29  import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent;
30  
31  /**
32   * Created by The eXo Platform SARL
33   * Author : Dang Van Minh
34   *          minh.dang@exoplatform.com
35   * Sep 19, 2006
36   * 8:26:51 AM
37   */
38  @ComponentConfig(
39      template = "app:/groovy/webui/component/admin/UIECMAdminControlPanel.gtmpl"
40  )
41  public class UIECMAdminControlPanel extends UIContainer {
42  
43    /**
44     * Logger.
45     */
46    private static final Log LOG  = ExoLogger.getLogger(UIECMAdminControlPanel.class.getName());
47  
48    public static final String EXTENSION_TYPE = "org.exoplatform.ecm.dms.UIECMAdminControlPanel";
49  
50    private List<UIAbstractManagerComponent> managers = new ArrayList<UIAbstractManagerComponent>();
51  
52    public UIECMAdminControlPanel() throws Exception {}
53    public List<?> getEvents() { return getComponentConfig().getEvents() ; }
54  
55    void initialize() throws Exception {
56      UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class);
57      List<UIExtension> extensions = manager.getUIExtensions(EXTENSION_TYPE);
58      if (extensions == null) {
59        return;
60      }
61      for (UIExtension extension : extensions) {
62        UIComponent component = manager.addUIExtension(extension, null, this);
63        if (component instanceof UIAbstractManagerComponent) {
64          // You can access to the given extension and the extension is valid
65          UIAbstractManagerComponent uiAbstractManagerComponent = (UIAbstractManagerComponent) component;
66          uiAbstractManagerComponent.setUIExtensionName(extension.getName());
67          uiAbstractManagerComponent.setUIExtensionCategory(extension.getCategory());
68          managers.add(uiAbstractManagerComponent);
69        } else if (component != null) {
70          // You can access to the given extension but the extension is not valid
71          if (LOG.isWarnEnabled()) {
72            LOG.warn("All the extension '" + extension.getName() + "' of type '" + EXTENSION_TYPE
73              + "' must be associated to a component of type " + UIAbstractManagerComponent.class);
74          }
75          removeChild(component.getClass());
76        }
77      }
78    }
79  
80    List<UIAbstractManagerComponent> getManagers() {
81      return managers;
82    }
83  
84    void unregister(UIAbstractManagerComponent component) {
85      managers.remove(component);
86    }
87  
88    /**
89     * Check whether a specified category is the same to category of current render manager item.
90     *
91     * @param currentCategory Current Category
92     * @param categories List of categories of side blocks
93     * @param managersGroup Contain managers groups
94     * @return true: the same, false: not the same
95     */
96    public boolean isSameCategoryWithCurrentRenderedManager (String currentCategory,
97                                                             ArrayList<String> categories,
98                                                             ArrayList<ArrayList<UIAbstractManagerComponent>> managersGroup) {
99      int i = 0;
100     UIECMAdminWorkingArea workingArea = this.getAncestorOfType(UIECMAdminPortlet.class).getChild(UIECMAdminWorkingArea.class);
101     String currentRenderId = workingArea.getRenderedCompId();
102     for(String category : categories) {
103       if (category.equals(currentCategory)) {
104         ArrayList<UIAbstractManagerComponent> groups = managersGroup.get(i);
105         for(UIAbstractManagerComponent group : groups) {
106           String extensionName =   group.getUIExtensionName();
107           if (extensionName.equals(currentRenderId))
108             return true;
109         }
110       }
111       i++;
112     }
113     return false;
114   }
115 }