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.UIActionBarActionRealNodeListener;
31  import org.exoplatform.ecm.webui.utils.Utils;
32  import org.exoplatform.web.application.ApplicationMessage;
33  import org.exoplatform.webui.config.annotation.ComponentConfig;
34  import org.exoplatform.webui.config.annotation.EventConfig;
35  import org.exoplatform.webui.core.UIApplication;
36  import org.exoplatform.webui.core.UIComponent;
37  import org.exoplatform.webui.event.Event;
38  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
39  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
40  
41  /**
42   * Created by The eXo Platform SAS
43   * Author : eXoPlatform
44   *          nicolas.filotto@exoplatform.com
45   * 6 mai 2009
46   */
47  @ComponentConfig(
48       events = {
49         @EventConfig(listeners = ManageHiddenActionComponent.ManageHiddenActionListener.class)
50       }
51   )
52  public class ManageHiddenActionComponent extends UIComponent {
53  
54    private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[]{new IsNotRootNodeFilter(),
55        new CanSetPropertyFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter()});
56  
57    @UIExtensionFilters
58    public List<UIExtensionFilter> getFilters() {
59      return FILTERS;
60    }
61  
62    public static class ManageHiddenActionListener extends UIActionBarActionRealNodeListener<ManageHiddenActionComponent> {
63      public void processEvent(Event<ManageHiddenActionComponent> event) throws Exception {
64        UIActionBar uiActionBar = event.getSource().getAncestorOfType(UIActionBar.class);
65        UIJCRExplorer uiExplorer = uiActionBar.getAncestorOfType(UIJCRExplorer.class);
66        Node selectedNode = uiExplorer.getRealCurrentNode();
67        UIApplication uiApp = uiActionBar.getAncestorOfType(UIApplication.class);
68        if(selectedNode.isNodeType(Utils.EXO_HIDDENABLE)) {
69          selectedNode.removeMixin(Utils.EXO_HIDDENABLE);
70          selectedNode.save();
71          uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.removed-hidden-mixin", null));
72          
73          uiExplorer.updateAjax(event);
74        } else if(selectedNode.canAddMixin(Utils.EXO_HIDDENABLE)){
75          selectedNode.addMixin(Utils.EXO_HIDDENABLE);
76          selectedNode.save();
77          uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.added-hidden-mixin", null));
78          
79          uiExplorer.updateAjax(event);
80        }
81      }
82    }
83  }