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.search;
18  
19  import javax.jcr.Node;
20  import javax.jcr.NodeIterator;
21  import javax.jcr.Session;
22  
23  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
24  import org.exoplatform.ecm.webui.tree.selectone.UIOneTaxonomySelector;
25  import org.exoplatform.ecm.webui.utils.Utils;
26  import org.exoplatform.services.cms.BasePath;
27  import org.exoplatform.services.cms.impl.DMSConfiguration;
28  import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
29  import org.exoplatform.webui.config.annotation.ComponentConfig;
30  import org.exoplatform.webui.core.UIContainer;
31  import org.exoplatform.webui.core.UIPopupContainer;
32  import org.exoplatform.webui.core.UIPopupWindow;
33  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
34  
35  /**
36   * Created by The eXo Platform SARL
37   * Author : Dang Van Minh
38   *          minh.dang@exoplatform.com
39   * Dec 27, 2006
40   * 2:04:24 PM
41   */
42  @ComponentConfig(lifecycle = UIContainerLifecycle.class)
43  public class UISearchContainer extends UIContainer {
44  
45    final static public String METADATA_POPUP = "MetadataPopup" ;
46    final static public String NODETYPE_POPUP = "NodeTypePopup" ;
47    final static public String SAVEQUERY_POPUP = "SaveQueryPopup" ;
48    final static public String CATEGORY_POPUP = "CategoryPopup" ;
49  
50    public UISearchContainer() throws Exception {
51      addChild(UISimpleSearch.class, null, null);
52      UIPopupContainer popup = addChild(UIPopupContainer.class, null, METADATA_POPUP);
53      popup.getChild(UIPopupWindow.class).setId(METADATA_POPUP + "_Popup");
54    }
55  
56    public void initMetadataPopup(String fieldName) throws Exception {
57      UIPopupContainer uiPopup = getChild(UIPopupContainer.class) ;
58      uiPopup.getChild(UIPopupWindow.class).setId(fieldName + METADATA_POPUP) ;
59      UISelectPropertyForm uiSelectForm = createUIComponent(UISelectPropertyForm.class, null, null) ;
60      uiSelectForm.setFieldName(fieldName) ;
61      uiPopup.getChild(UIPopupWindow.class).setShowMask(true);
62      uiPopup.activate(uiSelectForm, 500, 450) ;
63    }
64  
65    public void initNodeTypePopup() throws Exception {
66      UIPopupContainer uiPopup = getChild(UIPopupContainer.class) ;
67      uiPopup.getChild(UIPopupWindow.class).setId(NODETYPE_POPUP) ;
68      UINodeTypeSelectForm uiSelectForm = createUIComponent(UINodeTypeSelectForm.class, null, null) ;
69      uiPopup.getChild(UIPopupWindow.class).setShowMask(true);
70      uiPopup.activate(uiSelectForm, 400, 400) ;
71      uiSelectForm.setRenderNodeTypes() ;
72    }
73  
74    public void initCategoryPopup() throws Exception {
75      /* Get UIJCRExplorer object*/
76      UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class);
77      /* Get repository name */
78      String repository = uiExplorer.getRepositoryName();
79      DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class);
80      String workspaceName = dmsConfiguration.getConfig().getSystemWorkspace();
81      NodeHierarchyCreator nodeHierarchyCreator = uiExplorer.getApplicationComponent(NodeHierarchyCreator.class);
82      uiExplorer.setIsHidePopup(true);
83      /* Create Category panel in Search function */
84      UICategoryManagerSearch uiCategoryManagerSearch = uiExplorer.createUIComponent(UICategoryManagerSearch.class, null, null);
85      UIOneTaxonomySelector uiOneTaxonomySelector = uiCategoryManagerSearch.getChild(UIOneTaxonomySelector.class);
86      uiOneTaxonomySelector.setIsDisable(workspaceName, true);
87      String rootTreePath = nodeHierarchyCreator.getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH);
88      Session session = uiExplorer.getSessionByWorkspace(workspaceName);
89      Node rootTree = (Node) session.getItem(rootTreePath);
90      NodeIterator childrenIterator = rootTree.getNodes();
91      while (childrenIterator.hasNext()) {
92        Node childNode = childrenIterator.nextNode();
93        rootTreePath = childNode.getPath();
94        break;
95      }
96      uiOneTaxonomySelector.setRootNodeLocation(repository, workspaceName, rootTreePath);
97      uiOneTaxonomySelector.setExceptedNodeTypesInPathPanel(new String[] {Utils.EXO_SYMLINK});
98      uiOneTaxonomySelector.init(uiExplorer.getSystemProvider());
99      UIConstraintsForm uiConstraintsForm = findFirstComponentOfType(UIConstraintsForm.class);
100     uiOneTaxonomySelector.setSourceComponent(uiConstraintsForm, new String[] {UIConstraintsForm.CATEGORY_TYPE});
101     UIPopupContainer UIPopupContainer = getChild(UIPopupContainer.class);
102     UIPopupContainer.getChild(UIPopupWindow.class).setId(CATEGORY_POPUP) ;
103     UIPopupContainer.activate(uiCategoryManagerSearch, 650, 500);
104   }
105 
106   public void initSaveQueryPopup(String statement, boolean isSimpleSearch, String queryType) throws Exception {
107     UIPopupContainer uiPopup = getChild(UIPopupContainer.class) ;
108     uiPopup.getChild(UIPopupWindow.class).setId(SAVEQUERY_POPUP) ;
109     UISaveQueryForm uiSaveQueryForm = createUIComponent(UISaveQueryForm.class, null, null) ;
110     uiSaveQueryForm.setStatement(statement) ;
111     uiSaveQueryForm.setSimpleSearch(isSimpleSearch) ;
112     uiSaveQueryForm.setQueryType(queryType) ;
113     uiPopup.getChild(UIPopupWindow.class).setShowMask(true);
114     uiPopup.activate(uiSaveQueryForm, 420, 200) ;
115   }
116 }