1 5 package org.exoplatform.portlets.communication.message.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.communication.message.*; 13 import org.exoplatform.services.indexing.*; 14 19 public class UIAdvancedSearch extends UISimpleForm { 20 static final public String SEARCH_ACTION = "search" ; 21 22 private UIStringInput subjectInput_ ; 23 private UIStringInput fromInput_ ; 24 private UIStringInput toInput_ ; 25 private UIStringInput bodyInput_ ; 26 private List uiFolderInput_ ; 27 private UICheckBox uiSearchByFlagInput_ ; 28 private UISelectBox uiFlagInput_ ; 29 private UICheckBox uiSearchByDateRangeInput_ ; 30 private UIDateInput uiFromDateImput_ ; 31 private UIDateInput uiToDateImput_ ; 32 33 public UIAdvancedSearch(MessageService mservice, 34 IndexingService iservice) throws Exception { 35 super("advancedSearchForm", "post", null) ; 36 setId("UIAdvancedSearch") ; 37 setClazz("UIAdvancedSearch"); 38 setRendererType("SimpleFormButtonRenderer") ; 39 uiFolderInput_ = new ArrayList() ; 40 subjectInput_ = new UIStringInput("subject", "") ; 41 fromInput_ = new UIStringInput("from", "") ; 42 toInput_ = new UIStringInput("to", "") ; 43 bodyInput_ = new UIStringInput("body", "") ; 44 String [] flag = mservice.getSupportedFlags() ; 45 List options = new ArrayList() ; 46 for(int i = 0; i < flag.length ; i++) { 47 options.add(new SelectItem(flag[i], flag[i])); 48 } 49 uiSearchByFlagInput_ = new UICheckBox("searchByFlag", "true"); 50 uiFlagInput_= new UISelectBox("flag", "", options); 51 uiFromDateImput_ = new UIDateInput("fromDate", new GregorianCalendar(2004, 0, 1).getTime() ) ; 52 uiSearchByDateRangeInput_ = new UICheckBox("searchByDate", "true"); 53 uiToDateImput_ = new UIDateInput("toDate", new Date()) ; 54 addActionListener(SearchActionListener.class, SEARCH_ACTION) ; 55 } 56 57 public void changeAccount(UIAccount uiAccount) { 58 getChildren().clear() ; 59 getRows().clear() ; 60 uiFolderInput_.clear() ; 61 add(new HeaderRow(). 62 add(new Cell("#{UIAdvancedSearch.header.search-terms}"). 63 addColspan("2"))); 64 add(new Row(). 65 add(new LabelCell("#{UIAdvancedSearch.label.subject}")). 66 add(new ComponentCell(this, subjectInput_))); 67 add(new Row(). 68 add(new LabelCell("#{UIAdvancedSearch.label.from}")). 69 add(new ComponentCell(this, fromInput_))); 70 add(new Row(). 71 add(new LabelCell("#{UIAdvancedSearch.label.to}")). 72 add(new ComponentCell(this, toInput_))); 73 add(new Row(). 74 add(new LabelCell("#{UIAdvancedSearch.label.message-body}")). 75 add(new ComponentCell(this, bodyInput_))); 76 add(new HeaderRow(). 77 add(new Cell("#{UIAdvancedSearch.header.search-options}"). 78 addColspan("2"))); 79 add(new Row(). 80 add(new Cell("#{UIAdvancedSearch.label.search-in}"). 81 addColspan("2"))); 82 List folders = uiAccount.getFolders() ; 83 for(int i = 0; i < folders.size(); i++) { 84 Folder folder =(Folder) folders.get(i) ; 85 UICheckBox uiFolder = new UICheckBox(folder.getName(), folder.getId()); 86 uiFolder.setSelect(true) ; 87 add(new Row(). 88 add(new ListComponentCell(). 89 add(this, uiFolder). 90 add(folder.getLabel()). 91 addColspan("2").addClazz("indent-2"))) ; 92 uiFolderInput_.add(uiFolder) ; 93 } 94 95 add(new Row(). 96 add(new ListComponentCell(). 97 add(this, uiSearchByFlagInput_). 98 add("#{UIAdvancedSearch.label.show-message-with-flag}"). 99 add(this , uiFlagInput_).addClazz("indent-2"). 100 addColspan("2"))) ; 101 102 add(new Row(). 103 add(new ListComponentCell(). 104 add(this, uiSearchByDateRangeInput_). 105 add("#{UIAdvancedSearch.label.received-sent-date-range}"). 106 addColspan("2").addClazz("indent-2"))) ; 107 108 add(new Row(). 109 add(new ListComponentCell(). 110 add("#{UIAdvancedSearch.label.from-date}"). 111 add(this, uiFromDateImput_). 112 addColspan("2").addClazz("indent-2"))) ; 113 add(new Row(). 114 add(new ListComponentCell(). 115 add("#{UIAdvancedSearch.label.to-date}"). 116 add(this, uiToDateImput_). 117 addColspan("2").addClazz("indent-2"))) ; 118 add(new Row(). 119 add(new ListComponentCell(). 120 add("<div style='float: right'>"). 121 add(new FormButton("#{UIAdvancedSearch.button.search}", SEARCH_ACTION)). 122 add("</div>"). 123 addColspan("2"))) ; 124 } 125 126 static public class SearchActionListener extends ExoActionListener { 127 public void execute(ExoActionEvent event) throws Exception { 128 UIAdvancedSearch uiForm = (UIAdvancedSearch) event.getSource(); 129 List inputs = new ArrayList() ; 130 StringBuffer folderTerm = new StringBuffer () ; 131 for(int i = 0; i < uiForm.uiFolderInput_.size() ; i++) { 132 UICheckBox uiCheckBox = (UICheckBox) uiForm.uiFolderInput_.get(i) ; 133 if(uiCheckBox.getSelect()) { 134 if(folderTerm.length() > 0) folderTerm.append(" OR ") ; 135 folderTerm.append(uiCheckBox.getValue()) ; 136 } 137 } 138 if(folderTerm.length() == 0) { 139 return ; 141 } 142 inputs.add(new SingleFieldSearchInput(MessageIndexerPlugin.FOLDER_ID_FIELD, folderTerm.toString())) ; 143 String value = uiForm.subjectInput_.getValue() ; 144 if(value.length() > 0) { 145 inputs.add(new SingleFieldSearchInput(MessageIndexerPlugin.SUBJECT_FIELD, value)) ; 146 } 147 value = uiForm.fromInput_.getValue() ; 148 if(value.length() > 0) { 149 inputs.add(new SingleFieldSearchInput(MessageIndexerPlugin.FROM_FIELD, value)) ; 150 } 151 value = uiForm.toInput_.getValue() ; 152 if(value.length() > 0) { 153 inputs.add(new SingleFieldSearchInput(MessageIndexerPlugin.TO_FIELD, value)) ; 154 } 155 value = uiForm.bodyInput_.getValue() ; 156 if(value.length() > 0) { 157 inputs.add(new SingleFieldSearchInput(MessageIndexerPlugin.BODY_FIELD, value)) ; 158 } 159 160 if(uiForm.uiSearchByDateRangeInput_.getSelect()) { 161 Date from = uiForm.uiFromDateImput_.getValue() ; 162 Date to = uiForm.uiToDateImput_.getValue() ; 163 inputs.add(new RangeFieldSearchInput(MessageIndexerPlugin.RECEIVED_DATE_FIELD, from, to)) ; 164 } 165 166 UISummary uiSummary = (UISummary) uiForm.getAncestorOfType(UISummary.class) ; 167 uiSummary.advancedSearch(inputs, null) ; 168 } 169 } 170 } | Popular Tags |