1 package com.ca.directory.jxplorer.search; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.util.*; 6 import java.util.logging.Logger ; 7 import java.util.logging.Level ; 8 import javax.swing.*; 9 10 import com.ca.commons.cbutil.*; 11 12 13 14 28 29 public class JoinFilterPanel extends CBPanel 30 { 31 CBPanel panel = new CBPanel(); 32 JCheckBox notCheckBox; 33 static final String [] andOrArray = new String [] {CBIntText.get("And"), CBIntText.get("Or")}; 34 static final int AND=0, OR=1; 35 JLabel[] andOrLabel = new JLabel[50]; 36 CBJComboBox[] filterCombo = new CBJComboBox[50]; 37 CBJComboBox andOrCombo; 38 CBButton[] btnEdit = new CBButton[50]; 39 int rowCount=0, labelCount=0; 40 SearchModel searchModel = new SearchModel(); 41 42 private static Logger log = Logger.getLogger(JoinFilterPanel.class.getName()); 43 44 45 50 51 public JoinFilterPanel(CBButton btnEdit) 52 { 53 notCheckBox = new JCheckBox(CBIntText.get("Not")); 54 notCheckBox.setToolTipText(CBIntText.get("Not this filter")); 55 56 makeLight(); 57 add(notCheckBox); 58 59 newLine(); 60 61 makeHeavy(); 62 63 add(new JScrollPane(panel)); 64 makeLight(); 65 66 addFilterRow(btnEdit); 67 } 68 69 70 71 82 83 protected void addFilterRow(CBButton btnEdit) 84 { 85 if (rowCount < 50) 86 { 87 panel.newLine(); 88 panel.makeLight(); 89 90 93 94 if (rowCount==0) 95 { 96 panel.add(andOrCombo = new CBJComboBox(andOrArray)); andOrCombo.setPreferredSize(new Dimension(50, 20)); 98 andOrCombo.setVisible(false); 99 } 100 101 104 105 else if (rowCount==1) 106 { 107 panel.add(andOrCombo= new CBJComboBox(andOrArray)); 109 andOrCombo.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ 111 try 112 { 113 for(int i=0; i<labelCount;i++) 114 andOrLabel[i].setText(andOrCombo.getSelectedItem().toString()); 115 } 116 catch(Exception ee) 117 { 118 log.log(Level.WARNING, "Problem updating the 'And/Or' labels in the Join tab of the search dialog:", ee); 119 } 120 }}); 121 andOrCombo.setPreferredSize(new Dimension(50, 20)); 122 } 123 124 127 128 else if (rowCount >1) 129 { 130 andOrLabel[labelCount] = new JLabel(); try 132 { 133 andOrLabel[labelCount].setText(andOrCombo.getSelectedItem().toString()); 134 } 135 catch(Exception e) 136 { 137 andOrLabel[labelCount].setText(" "); 138 log.log(Level.WARNING, "Problem updating the 'And/Or' labels in the Join tab of the search dialog:", e); 139 } 140 panel.add(andOrLabel[labelCount]); 141 labelCount++; } 143 144 panel.makeWide(); 145 146 ArrayList list = searchModel.getFilterNames(SearchModel.BUILDJOIN); 147 148 Object listOb[] = list.toArray(); 149 Arrays.sort(listOb, new SearchModel.StringComparator()); 151 panel.add(filterCombo[rowCount] = new CBJComboBox(listOb)); filterCombo[rowCount].setPreferredSize(new Dimension(140, 20)); 153 filterCombo[rowCount].setRenderer(new CBBasicComboBoxRenderer(listOb)); 154 155 panel.makeLight(); 156 157 panel.add(btnEdit); 158 159 rowCount++; panel.revalidate(); 161 } 162 } 163 164 165 166 172 173 protected void updateFilterCombo(String item) 174 { 175 ArrayList list = searchModel.getFilterNames(SearchModel.ALLFILTERS); 176 list.add(item); 177 178 for(int i=0; i<rowCount; i++) 179 { 180 filterCombo[i].setRenderer(new CBBasicComboBoxRenderer(list.toArray())); 181 filterCombo[i].addItem(item); 182 } 183 } 184 185 186 187 192 193 protected void removeFilterRow(CBButton btnEdit) 194 { 195 if (rowCount > 1) 196 { 197 rowCount--; 199 if(rowCount==1) 200 panel.remove(andOrCombo); 201 202 panel.remove(filterCombo[rowCount]); 203 panel.remove(btnEdit); 204 205 if (rowCount>1) 206 { 207 labelCount--; panel.remove(andOrLabel[labelCount]); 209 } 210 211 panel.repaint(); 212 } 213 214 panel.revalidate(); 215 } 216 217 218 219 225 226 protected boolean isFilterValid() 227 { 228 try 229 { 230 for(int i=0; i<rowCount; i++) 231 { 232 String name = filterCombo[i].getSelectedItem().toString(); 233 234 if(name.trim().length()<=0) 235 return false; 237 if (rowCount>=2) 238 { 239 String andOr = andOrCombo.getSelectedItem().toString(); 240 241 if(andOr.trim().length()<=0) return false; 243 } 244 } 245 } 246 catch(Exception e) 247 { 248 return false; 249 } 250 return true; 251 } 252 253 254 255 261 262 protected String getFilter() 263 { 264 StringBuffer buffy = new StringBuffer (); 265 266 for(int i=0;i<rowCount;i++) buffy.append("JXFilter." + filterCombo[i].getSelectedItem().toString()); 268 269 if (rowCount>=2) 270 { 271 switch (andOrCombo.getSelectedIndex()) 272 { 273 case AND: { buffy.insert(0, "&"); break; } case OR : { buffy.insert(0, "|"); break; } } 276 } 277 278 if (notCheckBox.isSelected()) 279 buffy.insert(0, "!"); 281 return buffy.toString(); 282 } 283 284 285 286 292 293 protected String getFilterComboValue(int row) 294 { 295 try 296 { 297 return filterCombo[row].getSelectedItem().toString(); 298 } 299 catch(Exception e) 300 { 301 return null; 302 } 303 } 304 305 306 307 316 317 protected boolean displayFilter(ArrayList list, String value) 318 { 319 boolean not = value.startsWith("!"); int andOr=-1; 321 if(value.indexOf("&")<2 && value.indexOf("&")>-1) andOr=AND; 323 else if(value.indexOf("|")<2 && value.indexOf("|")>-1) andOr=OR; 325 else 326 return false; 327 328 setItems(not, andOr); 330 String [] names = (String [])list.toArray(new String [list.size()]); 332 for(int i=0; i<names.length; i++) setItems(names[i], i); 334 335 return true; 336 } 337 338 339 340 346 347 protected void setItems(String filter, int row) 348 { 349 filterCombo[row].setSelectedItem(filter); 350 panel.revalidate(); 351 } 352 353 354 355 362 363 protected void setItems(boolean not, int index) 364 { 365 notCheckBox.setSelected(not); 366 if(index==-1) 367 index=0; andOrCombo.setSelectedIndex(index); 369 panel.revalidate(); 370 } 371 } 372 373 | Popular Tags |