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 javax.swing.*; 8 9 import com.ca.directory.jxplorer.*; 10 import com.ca.commons.cbutil.*; 11 12 20 public class DeleteFilterGUI extends CBDialog 21 { 22 SearchModel searchModel = new SearchModel(); 23 JList list; 24 MainMenu mainMenu; 25 ArrayList filterNames; 26 JXplorer jxplorer = null; 27 28 private static Logger log = Logger.getLogger(DeleteFilterGUI.class.getName()); 29 30 35 public DeleteFilterGUI(JXplorer jxplorer) 36 { 37 super(jxplorer, CBIntText.get("Delete Search Filter"), HelpIDs.SEARCH_DELETE_FILTER); 38 this.jxplorer = jxplorer; 39 mainMenu = jxplorer.getMainMenu(); 40 41 filterNames = searchModel.getFilterNames(SearchModel.ALLFILTERS); 42 43 display.addln(new JLabel(CBIntText.get("Select a Search Filter to Delete:"))); 44 45 display.makeWide(); 46 display.add(getScrollList(filterNames.toArray(), filterNames.toArray())); 47 48 CBButton btnDelete = new CBButton(CBIntText.get("Delete"), CBIntText.get("Delete the selected filters.")); 49 btnDelete.addActionListener(new ActionListener(){ 50 public void actionPerformed(ActionEvent e){ 51 delete(); 52 }}); 53 54 buttonPanel.removeAll(); 56 57 buttonPanel.add(btnDelete); 59 buttonPanel.add(Cancel); 60 buttonPanel.add(Help); 61 62 btnDelete.setToolTipText(CBIntText.get("Click here to delete the selected filter.")); 63 Cancel.setToolTipText(CBIntText.get("Click here to exit.")); 64 Help.setToolTipText(CBIntText.get("Click here for Help.")); 65 66 setSize(300, 200); 67 68 CBUtility.center(this, jxplorer); 69 } 70 71 77 protected JScrollPane getScrollList(Object [] items, Object [] toolTips) 78 { 79 final Object [] names = items; 80 final Object [] toolTps = toolTips; 81 82 list = new JList(names) 83 { 84 public String getToolTipText(MouseEvent e) { 86 int index = locationToIndex(e.getPoint()); 87 if (-1 < index) 88 return toolTps[index].toString(); 89 else 90 return null; 91 } 92 }; 93 94 list.setSelectionMode(0); 95 list.setSelectionModel(new CBSingleSelectionModel(list)); list.setToolTipText(""); 97 98 JScrollPane sp = new JScrollPane(list); 99 sp.setPreferredSize(new Dimension(250, 100)); 100 sp.setMinimumSize(new Dimension(250, 100)); 101 sp.setAlignmentX(LEFT_ALIGNMENT); 102 103 return sp; 104 } 105 106 113 public void delete() 114 { 115 if(filterNames.size()<=0) 116 return; 117 118 if(list.getSelectedIndex() ==-1) 119 { 120 int response = JOptionPane.showConfirmDialog(this, CBIntText.get("No filter selected. Try again?"), CBIntText.get("No Filter Selected"), JOptionPane.YES_NO_OPTION); 121 122 if (response == JOptionPane.NO_OPTION) { 124 setVisible(false); 125 dispose(); 126 return; 127 } 128 else 129 { 130 return; 131 } 132 } 133 134 Object value = list.getSelectedValue(); 135 136 int response; 137 138 boolean text = false; 139 140 if (searchModel.isTextFilter(value.toString())) 141 text = true; 142 143 if (!text) 144 { 145 ArrayList dependantFilters = searchModel.getDependants(value); 147 String [] names = (String [])dependantFilters.toArray(new String [dependantFilters.size()]); 148 StringBuffer buffy = new StringBuffer (); 149 150 for(int i=1;i<names.length;i++) { 152 buffy.append(names[i].substring(names[i].indexOf(".")+1)); 153 buffy.append("\n"); 154 } 155 156 if (names.length==1) { 158 response = JOptionPane.showConfirmDialog(this, CBIntText.get("Are you sure you want to delete: ''{0}'' ?", 159 new String [] {value.toString()}), 160 CBIntText.get("Delete Information"), JOptionPane.YES_NO_OPTION); 161 } 162 else { 164 response = JOptionPane.showConfirmDialog(this, CBIntText.get("Deleting ''{0}'' will also delete these dependant filters: ''{1}''\nDo you want to continue?\n\n", 165 new String [] {value.toString(), buffy.toString()}), 166 CBIntText.get("Delete Information"), JOptionPane.YES_NO_OPTION); 167 } 168 169 if (response == JOptionPane.YES_OPTION) 170 { 171 searchModel.removeFilters(names); 172 173 mainMenu.updateSearchMenu(); 175 try 176 { 177 for(int i=0; i<names.length; i++) 178 { 179 filterNames.remove(names[i].substring(names[i].indexOf(".")+1)); 180 log.info("Deleted search filter: " + names[i].substring(names[i].indexOf(".")+1)); 181 } 182 183 list.setListData(filterNames.toArray()); 184 } 185 catch(Exception e) 186 { 187 log.warning("No selection to remove."); 188 } 189 } 190 } 191 else 192 { 193 response = JOptionPane.showConfirmDialog(this, CBIntText.get("Are you sure you want to delete: ''{0}'' ?", new String [] {value.toString()}), 194 CBIntText.get("Delete Information"), JOptionPane.YES_NO_OPTION); 195 196 if (response == JOptionPane.YES_OPTION) 197 { 198 searchModel.removeFilter("JXTextFilter."+value.toString()); 199 200 mainMenu.updateSearchMenu(); 202 try 203 { 204 filterNames.remove(value.toString().substring(value.toString().indexOf(".")+1)); 205 log.info("Deleted search filter: " + value.toString().substring(value.toString().indexOf(".")+1)); 206 207 list.setListData(filterNames.toArray()); 208 } 209 catch(Exception e) 210 { 211 log.warning("No selection to remove."); 212 } 213 } 214 } 215 216 jxplorer.getTree().setSearchGUI(null); 218 jxplorer.getSearchTree().setSearchGUI(null); 219 jxplorer.getSchemaTree().setSearchGUI(null); 220 } 221 } 222 | Popular Tags |