1 5 package org.exoplatform.faces.search.component; 6 7 import java.util.*; 8 import org.exoplatform.faces.core.component.*; 9 import org.exoplatform.faces.core.component.model.*; 10 import org.exoplatform.faces.core.event.ExoActionEvent; 11 import org.exoplatform.faces.core.event.ExoActionListener; 12 import org.exoplatform.services.indexing.*; 13 18 public class UIAdvancedSearch extends UISimpleForm { 19 static final public String SEARCH_ACTION = "search" ; 20 21 private UIStringInput documentInput_ ; 22 private UIStringInput titleInput_ ; 23 private UIStringInput descriptionInput_ ; 24 private UIStringInput authorInput_ ; 25 private List uiModulesInput_ ; 26 27 public UIAdvancedSearch(IndexingService iservice) throws Exception { 28 super("aSearchForm", "post", null) ; 29 setId("UIAdvancedSearch") ; 30 setClazz("UIAdvancedSearch"); 31 setRendererType("SimpleFormButtonRenderer") ; 32 titleInput_ = new UIStringInput("title", "") ; 33 authorInput_ = new UIStringInput("author", "") ; 34 descriptionInput_ = new UIStringInput("description", "") ; 35 documentInput_ = new UIStringInput("document", "") ; 36 37 add(new HeaderRow(). 38 add(new Cell("#{UIAdvancedSearch.header.search-terms}"). 39 addColspan("2"))); 40 add(new Row(). 41 add(new LabelCell("#{UIAdvancedSearch.label.document}")). 42 add(new ComponentCell(this, documentInput_))); 43 add(new Row(). 44 add(new LabelCell("#{UIAdvancedSearch.label.title}")). 45 add(new ComponentCell(this, titleInput_))); 46 add(new Row(). 47 add(new LabelCell("#{UIAdvancedSearch.label.description}")). 48 add(new ComponentCell(this, descriptionInput_))); 49 add(new Row(). 50 add(new LabelCell("#{UIAdvancedSearch.label.author}")). 51 add(new ComponentCell(this, authorInput_))); 52 add(new HeaderRow(). 53 add(new Cell("#{UIAdvancedSearch.header.search-options}"). 54 addColspan("2"))); 55 56 uiModulesInput_ = new ArrayList() ; 57 Iterator i = iservice.getIndexerPlugins().iterator(); 58 while(i.hasNext()) { 59 IndexerPlugin plugin =(IndexerPlugin) i.next() ; 60 UICheckBox uiModule = new UICheckBox(plugin.getPluginIdentifier(), "true"); 61 uiModule.setSelect(true) ; 62 add(new Row(). 63 add(new ListComponentCell(). 64 add(this, uiModule). 65 add("#{UIAdvancedSearch." +plugin.getPluginIdentifier() + ".module}"). 66 addColspan("2").addClazz("indent-2"))) ; 67 uiModulesInput_.add(uiModule) ; 68 } 69 add(new Row(). 70 add(new ListComponentCell(). 71 add("<div style='float: right'>"). 72 add(new FormButton("#{UIAdvancedSearch.button.search}", SEARCH_ACTION)). 73 add("</div>"). 74 addColspan("2"))) ; 75 76 addActionListener(SearchActionListener.class, SEARCH_ACTION) ; 77 } 78 79 static public class SearchActionListener extends ExoActionListener { 80 public void execute(ExoActionEvent event) throws Exception { 81 UIAdvancedSearch uiForm = (UIAdvancedSearch) event.getSource(); 82 List selectModules = new ArrayList() ; 83 for(int i = 0; i < uiForm.uiModulesInput_.size(); i++) { 84 UICheckBox uiBox = (UICheckBox) uiForm.uiModulesInput_.get(i) ; 85 if(uiBox.getSelect()) { 86 selectModules.add(uiBox.getName()) ; 87 } 88 } 89 90 List inputs = new ArrayList() ; 91 String value = uiForm.titleInput_.getValue() ; 92 if(value.length() > 0) { 93 inputs.add(new SingleFieldSearchInput(IndexingService.TITLE_FIELD, value)) ; 94 } 95 value = uiForm.authorInput_.getValue() ; 96 if(value.length() > 0) { 97 inputs.add(new SingleFieldSearchInput(IndexingService.AUTHOR_FIELD, value)) ; 98 } 99 value = uiForm.documentInput_.getValue() ; 100 if(value.length() > 0) { 101 inputs.add(new SingleFieldSearchInput(IndexingService.DOCUMENT_FIELD, value)) ; 102 } 103 UISearcher uiSearcher = (UISearcher) uiForm.getParent() ; 104 uiSearcher.advancedSearch(inputs, selectModules) ; 105 } 106 } 107 } | Popular Tags |