Changeset 6159
- Timestamp:
- 2003-12-08T14:35:46+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java
r6051 r6159 37 37 import org.greenstone.gatherer.Gatherer; 38 38 import org.greenstone.gatherer.collection.BasicCollectionConfiguration; 39 import org.greenstone.gatherer.util.Utility;40 39 import org.greenstone.gatherer.gui.SimpleMenuBar; 41 40 import org.greenstone.gatherer.gui.ModalDialog; 41 import org.greenstone.gatherer.util.StaticStrings; 42 import org.greenstone.gatherer.util.Utility; 42 43 43 44 public class NewCollectionDetailsPrompt 44 45 extends ModalDialog { 46 47 static public boolean titleClashes(String title) { 48 File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path)); 49 File children[] = collection_directory.listFiles(); 50 for(int i = 0; children != null && i < children.length; i++) { 51 if(children[i].isDirectory()) { 52 BasicCollectionConfiguration other_collection = new BasicCollectionConfiguration(new File(children[i], Utility.CONFIG_DIR)); 53 if(other_collection.getName().equalsIgnoreCase(title)) { 54 return true; 55 } 56 other_collection = null; 57 } 58 } 59 return false; 60 } 61 45 62 private boolean cancelled; 46 63 private File base_final; … … 91 108 if(metadata_directory.exists() || collection_name.equals(Utility.COLLECTION_DLS) || collection_name.equals(Utility.COLLECTION_DEMO)) { 92 109 // Add to model. 93 Item item = new Item(possible_collections[i], collect ion_name);110 Item item = new Item(possible_collections[i], collect_cfg); 94 111 if(!base_collection_model.contains(item)) { 95 112 base_collection_model.add(item); 96 113 } 97 114 } 115 collection_name = null; 116 collect_cfg = null; 98 117 // Else not a collection we know how to retrieve the metadata set for. 99 118 } … … 277 296 while(i < title_final.length() && name_buffer.length() < 8) { 278 297 char c = title_final.charAt(i); 279 if(!Character.isWhitespace(c)) { 280 name_buffer.append(Character.toLowerCase(c)); 298 // Arg. We need a few more tests than just whitespace 299 if(Character.isLetterOrDigit(c)) { 300 name_buffer.append(Character.toLowerCase(c)); 281 301 } 282 302 i++; … … 335 355 file = file.getParentFile(); 336 356 BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(new File(file, Utility.META_DIR)); 337 Item item = new Item(file, collect_cfg .getName());357 Item item = new Item(file, collect_cfg); 338 358 base_collection.addItem(item); 339 359 base_collection.setSelectedItem(item); 360 collect_cfg = null; 340 361 } 341 362 } … … 372 393 } 373 394 374 375 376 395 private class CreateListener 396 implements ActionListener { 397 377 398 public void actionPerformed(ActionEvent event) { 378 // Validate. 379 title_final = title.getText(); 380 if(title_final.length() == 0) { 381 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE); 399 // Validate. 400 title_final = title.getText(); 401 if(title_final.length() == 0) { 402 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE); 403 title.setForeground(Gatherer.config.getColor("coloring.error_foreground", false)); 404 title.setBackground(Gatherer.config.getColor("coloring.error_background", false)); 405 return; 406 } 407 // We must ensure that the collection title is unique. This is a pain in the nether regions as we are forced to load the collect.cfg of each other collection in turn looking for a conflicting title 408 else { 409 if(titleClashes(title_final)) { 410 if(JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Clash"), Dictionary.get("General.Warning"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.NO_OPTION) { 382 411 title.setForeground(Gatherer.config.getColor("coloring.error_foreground", false)); 383 412 title.setBackground(Gatherer.config.getColor("coloring.error_background", false)); 384 413 return; 385 }386 // We must ensure that the collection title is unique. This is a pain in the nether regions as we are forced to load the collect.cfg of each other collection in turn looking for a conflicting title387 else {388 File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));389 File children[] = collection_directory.listFiles();390 for(int i = 0; children != null && i < children.length; i++) {391 if(children[i].isDirectory()) {392 BasicCollectionConfiguration other_collection = new BasicCollectionConfiguration(new File(children[i], Utility.CONFIG_DIR));393 if(other_collection.getName().equalsIgnoreCase(title_final)) {394 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Clash"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);395 title.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));396 title.setBackground(Gatherer.config.getColor("coloring.error_background", false));397 return;398 }399 other_collection = null;400 }401 }402 }403 404 /* Suppress filename405 name_final = file.getText();406 if(name_final.length() > 0) {407 // Determine if this filename is already in use.408 File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));409 File children[] = collection_directory.listFiles();410 for(int i = 0; children != null && i < children.length; i++) {411 if(children[i].getName().equals(name_final)) {412 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);413 file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));414 file.setBackground(Gatherer.config.getColor("coloring.error_background", false));415 return;416 414 } 417 415 } 418 416 } 419 else { 420 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE); 421 file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false)); 422 file.setBackground(Gatherer.config.getColor("coloring.error_background", false)); 423 return; 424 } 417 /* Suppress filename 418 name_final = file.getText(); 419 if(name_final.length() > 0) { 420 // Determine if this filename is already in use. 421 File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path)); 422 File children[] = collection_directory.listFiles(); 423 for(int i = 0; children != null && i < children.length; i++) { 424 if(children[i].getName().equals(name_final)) { 425 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE); 426 file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false)); 427 file.setBackground(Gatherer.config.getColor("coloring.error_background", false)); 428 return; 429 } 430 } 431 } 432 else { 433 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE); 434 file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false)); 435 file.setBackground(Gatherer.config.getColor("coloring.error_background", false)); 436 return; 437 } 425 438 */ 426 439 /* Suppress email 427 email_final = address.getText() + "@" + host.getText();428 if(email_final.length() == 0 || email_final.startsWith("@") || email_final.endsWith("@")) {429 430 431 432 433 434 435 }440 email_final = address.getText() + "@" + host.getText(); 441 if(email_final.length() == 0 || email_final.startsWith("@") || email_final.endsWith("@")) { 442 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Email_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE); 443 address.setForeground(Gatherer.config.getColor("coloring.error_foreground", false)); 444 address.setBackground(Gatherer.config.getColor("coloring.error_background", false)); 445 host.setForeground(Gatherer.config.getColor("coloring.error_foreground", false)); 446 host.setBackground(Gatherer.config.getColor("coloring.error_background", false)); 447 return; 448 } 436 449 */ 437 450 description_final = description.getText(); … … 445 458 Item item_final = (Item) base_collection.getSelectedItem(); 446 459 base_final = item_final.getFile(); 447 460 448 461 cancelled = false; 449 462 450 463 self.dispose(); 451 464 } 452 465 } 453 466 454 467 private class DescriptionListener 455 468 extends KeyAdapter { … … 464 477 private class Item 465 478 implements Comparable { 479 private BasicCollectionConfiguration config; 466 480 private File file; 467 481 private String name; 482 public Item(File file, BasicCollectionConfiguration config) { 483 this.config = config; 484 this.file = file; 485 this.name = null; 486 } 468 487 public Item(File file, String name) { 488 this.config = null; 469 489 this.file = file; 470 490 this.name = name; … … 480 500 } 481 501 public String toString() { 502 if(name == null && config != null) { 503 StringBuffer title_buffer = new StringBuffer(config.getName()); 504 title_buffer.append(StaticStrings.SPACE_CHARACTER); 505 title_buffer.append(StaticStrings.OPEN_PARENTHESIS_CHARACTER); 506 title_buffer.append(config.getShortName()); 507 title_buffer.append(StaticStrings.CLOSE_PARENTHESIS_CHARACTER); 508 name = title_buffer.toString(); 509 title_buffer = null; 510 } 482 511 return name; 483 512 }
Note:
See TracChangeset
for help on using the changeset viewer.