Changeset 4660
- Timestamp:
- 2003-06-13T16:58:59+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java
r4366 r4660 43 43 import org.greenstone.gatherer.Gatherer; 44 44 import org.greenstone.gatherer.collection.Collection; 45 import org.greenstone.gatherer.gui.ModalDialog; 46 import org.greenstone.gatherer.gui.SimpleMenuBar; 45 47 import org.greenstone.gatherer.util.ArrayTools; 48 import org.greenstone.gatherer.util.GSDLSiteConfig; 46 49 import org.greenstone.gatherer.util.Utility; 47 50 /** This class provides the functionality to delete current collections from the GSDLHOME/collect/ directory. The user chooses the collection from a list, where each entry also displays details about itself, confirms the delete of a collection by checking a checkbox then presses the ok button to actually delete the collection. … … 50 53 */ 51 54 public class DeleteCollectionPrompt 52 extends JDialog {55 extends ModalDialog { 53 56 /** The currently selected collection for deletion. */ 54 private Collection collection = null;57 private CollectionEntry collection = null; 55 58 /** The model behind the list. */ 56 59 private DefaultListModel list_model = null; … … 73 76 /** A string array used to pass arguments to the phrase retrieval method. */ 74 77 private String args[] = null; 78 79 private boolean current_coll_deleted = false; 75 80 /** The size of the delete prompt screen. */ 76 81 public static final Dimension SIZE = new Dimension(500, 500); … … 82 87 */ 83 88 public DeleteCollectionPrompt() { 84 super( );89 super(Gatherer.g_man); 85 90 this.close_button = new JButton(get("General.Close", null)); 86 91 this.confirmation = new JCheckBox(get("Confirm_Delete", null)); … … 95 100 this.setSize(SIZE); 96 101 this.setTitle(get("Title", null)); 102 this.setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at 97 103 close_button.addActionListener(new CloseButtonListener()); 98 104 confirmation.addActionListener(new ConfirmationCheckBoxListener()); … … 121 127 prompt = null; 122 128 } 123 /** This method causes the modal prompt to be displayed. */ 124 public void display() { 129 /** This method causes the modal prompt to be displayed. 130 * returns true if it has deleted the collection that is currently open*/ 131 public boolean display() { 125 132 // Central pane 126 133 JPanel list_pane = new JPanel(new BorderLayout()); … … 163 170 Dimension screen_size = Gatherer.config.screen_size; 164 171 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 165 this.show(); 172 this.setVisible(true); // blocks until the dialog is killed 173 return current_coll_deleted; 174 166 175 } 167 176 /** Shows a delete complete prompt. … … 194 203 * @param location The path to the serialized collection. 195 204 */ 196 public Collection loadCollection(File file) {197 Collection col = null;198 try {199 FileInputStream fis = new FileInputStream(file);200 BufferedInputStream bin = new BufferedInputStream(fis);201 ObjectInputStream input = new ObjectInputStream(bin);202 col = (Collection) input.readObject();203 input.close();204 input = null;205 bin.close();206 bin = null;207 fis.close();208 fis = null;209 }210 catch (Exception error) {211 error.printStackTrace();212 }213 return col;214 }205 // public Collection loadCollection(File file) { 206 // Collection col = null; 207 // try { 208 // FileInputStream fis = new FileInputStream(file); 209 // BufferedInputStream bin = new BufferedInputStream(fis); 210 // ObjectInputStream input = new ObjectInputStream(bin); 211 // col = (Collection) input.readObject(); 212 // input.close(); 213 // input = null; 214 // bin.close(); 215 // bin = null; 216 // fis.close(); 217 // fis = null; 218 // } 219 // catch (Exception error) { 220 // error.printStackTrace(); 221 // } 222 // return col; 223 // } 215 224 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections. 216 225 * @see org.greenstone.gatherer.Configuration … … 224 233 File collect_directory = new File(collect_directory_name); 225 234 if(collect_directory.exists()) { 226 227 235 // Now for each child directory see if it contains a .col file and 236 // if so try to load it.. 228 237 File collections[] = collect_directory.listFiles(); 229 238 ArrayTools.sort(collections); 230 239 for(int i = 0; collections != null && i < collections.length; i++) { 231 File children[] = collections[i].listFiles(); 232 for(int j = 0; children != null && j < children.length; j++) { 233 if(children[j].getAbsolutePath().endsWith(".col")) { 234 Collection col = loadCollection(children[j]); 235 // If we've actually loaded 236 if(col != null) { 237 list_model.addElement(col); 238 } 240 File config_file = Utility.findConfigFile(collections[i]); 241 if (config_file != null) { 242 CollectionConfiguration config = new CollectionConfiguration(config_file); 243 if (config != null) { 244 CollectionEntry col = new CollectionEntry(collections[i].getName(), config); 245 list_model.addElement(col); 239 246 } 247 248 //File children[] = collections[i].listFiles(); 249 //for(int j = 0; children != null && j < children.length; j++) { 250 //if(children[j].getAbsolutePath().endsWith(".col")) { 251 //Collection col = loadCollection(children[j]); 252 // If we've actually loaded 253 //if(col != null) { 254 // list_model.addElement(col); 255 //} 256 //} 240 257 } 241 258 } … … 263 280 if(!list.isSelectionEmpty()) { 264 281 confirmation.setEnabled(true); 265 collection = (Collection ) list.getSelectedValue();282 collection = (CollectionEntry) list.getSelectedValue(); 266 283 args = new String[4]; 267 284 args[0] = collection.getTitle(); 268 285 args[1] = collection.getName(); 269 args[2] = collection.get Email();286 args[2] = collection.getCreator(); 270 287 args[3] = collection.getDescription(); 271 288 details.setText(get("Details", args)); 289 details.setCaretPosition(0); 272 290 } 273 291 else { … … 302 320 */ 303 321 public void actionPerformed(ActionEvent event) { 304 // Delete the selected collection. 322 // Delete the selected collection. 323 324 // first of all we must release it from the local library 325 if(Gatherer.config.exec_file != null) { 326 ///ystem.err.println("Local Library Found!"); 327 Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName()); 328 } 329 305 330 File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); 306 331 if(Utility.delete(delete_me)) { 332 if (collection.getName().equals(Gatherer.c_man.getCollection().getName())) { 333 current_coll_deleted = true; 334 } 335 307 336 resultPrompt(true); 308 337 list_model.removeElement(collection); … … 318 347 } 319 348 } 349 350 private class CollectionEntry { 351 352 private String name = null; 353 private CollectionConfiguration config = null; 354 355 public CollectionEntry(String name, CollectionConfiguration config) { 356 this.name = name; 357 this.config = config; 358 } 359 360 public String getName() { 361 return name; 362 } 363 364 public String getTitle() { 365 return config.getName(); 366 } 367 368 public String getCreator() { 369 return config.getCreator(); 370 } 371 372 public String getDescription() { 373 return config.getDescription(); 374 } 375 376 public String toString() { 377 return config.getName(); 378 379 } 380 } 320 381 } 321 382
Note:
See TracChangeset
for help on using the changeset viewer.