View Javadoc
1   /*
2    * Copyright (C) 2003-2009 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.control.action;
18  
19  import java.util.Arrays;
20  import java.util.List;
21  
22  import javax.jcr.Node;
23  
24  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
25  import org.exoplatform.ecm.webui.component.explorer.control.UIActionBar;
26  import org.exoplatform.ecm.webui.component.explorer.control.filter.CanSetPropertyFilter;
27  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter;
28  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter;
29  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotRootNodeFilter;
30  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener;
31  import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIRelationManager;
32  import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIRelationsAddedList;
33  import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector;
34  import org.exoplatform.ecm.webui.utils.Utils;
35  import org.exoplatform.services.cms.relations.RelationsService;
36  import org.exoplatform.services.cms.templates.TemplateService;
37  import org.exoplatform.services.jcr.RepositoryService;
38  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
39  import org.exoplatform.webui.config.annotation.ComponentConfig;
40  import org.exoplatform.webui.config.annotation.EventConfig;
41  import org.exoplatform.webui.core.UIComponent;
42  import org.exoplatform.webui.core.UIPopupContainer;
43  import org.exoplatform.webui.event.Event;
44  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
45  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
46  
47  /**
48   * Created by The eXo Platform SAS
49   * Author : eXoPlatform
50   *          nicolas.filotto@exoplatform.com
51   * 6 mai 2009
52   */
53  @ComponentConfig(
54       events = {
55         @EventConfig(listeners = ManageRelationsActionComponent.ManageRelationsActionListener.class)
56       }
57   )
58  public class ManageRelationsActionComponent extends UIComponent {
59  
60    private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {
61        new IsNotRootNodeFilter(), new IsCheckedOutFilter(), new CanSetPropertyFilter(),
62        new IsNotLockedFilter()                         });
63  
64    @UIExtensionFilters
65    public List<UIExtensionFilter> getFilters() {
66      return FILTERS;
67    }
68  
69    public static class ManageRelationsActionListener extends UIActionBarActionListener<ManageRelationsActionComponent> {
70      public void processEvent(Event<ManageRelationsActionComponent> event) throws Exception {
71        UIActionBar uiActionBar = event.getSource().getAncestorOfType(UIActionBar.class);
72        UIJCRExplorer uiExplorer = uiActionBar.getAncestorOfType(UIJCRExplorer.class);
73        uiExplorer.setIsHidePopup(true);
74        RepositoryService repoService = uiActionBar.getApplicationComponent(RepositoryService.class);
75        UIRelationManager uiRelationManager =
76          uiExplorer.createUIComponent(UIRelationManager.class, null, null);
77        RelationsService relateService =
78          uiActionBar.getApplicationComponent(RelationsService.class);
79        UIRelationsAddedList uiRelateAddedList =
80          uiRelationManager.getChild(UIRelationsAddedList.class);
81        List<Node> relations = relateService.getRelations(uiExplorer.getCurrentNode(), WCMCoreUtils.getUserSessionProvider());
82        uiRelateAddedList.updateGrid(relations, 1);
83        String repository = uiActionBar.getAncestorOfType(UIJCRExplorer.class).getRepositoryName();
84        String defaultWsName = repoService.getCurrentRepository().getConfiguration().getDefaultWorkspaceName();
85        UIOneNodePathSelector uiNodePathSelector = uiRelationManager.getChild(UIOneNodePathSelector.class);
86        uiNodePathSelector.setIsDisable(defaultWsName, false);
87        uiNodePathSelector.setRootNodeLocation(repository, defaultWsName, "/");
88        TemplateService tservice = uiActionBar.getApplicationComponent(TemplateService.class);
89        List<String> documentNodeType = tservice.getDocumentTemplates();
90        String [] arrAcceptedNodeTypes = new String[documentNodeType.size()];
91        documentNodeType.toArray(arrAcceptedNodeTypes) ;
92        uiNodePathSelector.setAcceptedNodeTypesInPathPanel(arrAcceptedNodeTypes);
93        uiNodePathSelector.setIsShowSystem(false);
94        uiNodePathSelector.setAcceptedNodeTypesInTree(new String[] {Utils.NT_UNSTRUCTURED, Utils.NT_FOLDER});
95        uiNodePathSelector.init(uiExplorer.getSessionProvider());
96        uiNodePathSelector.setSourceComponent(uiRelateAddedList, null);
97        UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class);
98        UIPopupContainer.activate(uiRelationManager, 710, 500);
99        event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer);
100     }
101   }
102 }