Changeset 22605 for main/trunk/gli/src/org/greenstone/gatherer/gui
- Timestamp:
- 2010-08-11T21:28:34+12:00 (14 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java
r19438 r22605 506 506 } 507 507 else { 508 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, null); 508 // if there was no open collection, then write out the collect dir path for next time 509 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), 510 true, Gatherer.getCollectDirectoryPath()); // null 509 511 } 510 512 … … 646 648 } 647 649 650 public void refreshWorkspaceTreeGreenstoneCollections() 651 { 652 refreshWorkspaceTree(WorkspaceTree.LIBRARY_CONTENTS_CHANGED); 653 } 648 654 649 655 /** Specifies whether a certain tab is enabled or not. */ -
main/trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java
r18947 r22605 34 34 import javax.swing.event.*; 35 35 import javax.swing.text.*; 36 import javax.swing.filechooser.FileFilter; 37 import javax.swing.filechooser.FileView; 36 38 import org.greenstone.gatherer.Configuration; 37 39 import org.greenstone.gatherer.Dictionary; … … 39 41 import org.greenstone.gatherer.collection.BasicCollectionConfiguration; 40 42 import org.greenstone.gatherer.remote.RemoteGreenstoneServer; 43 import org.greenstone.gatherer.util.JarTools; 41 44 import org.greenstone.gatherer.util.StaticStrings; 42 45 import org.greenstone.gatherer.util.Utility; … … 45 48 extends ModalDialog { 46 49 47 48 49 static public boolean titleClashes(String title, File current_config_file) { 50 51 static public boolean titleClashes(String collectDir, String title, File current_config_file) { 50 52 // An empty collection title never clashes with anything. It may look ugly in the final collection but there is nothing wrong with having no title for a particular language. 51 53 if(title == null || title.length() == 0) { 52 54 return false; 53 55 } 54 File collect_directory = new File( Gatherer.getCollectDirectoryPath());56 File collect_directory = new File(collectDir); 55 57 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 56 58 File children[] = collect_directory.listFiles(); … … 72 74 73 75 private boolean cancelled; 76 private boolean collectDirChanged; 74 77 private File base_final; 78 private JButton chdir_button; 75 79 private JButton create_button; 76 80 private JComboBox base_collection; … … 79 83 private JTextArea description; 80 84 private JTextField title; 85 private String collectBasePath; 86 private String newCollectPath; 81 87 private String description_final; 82 88 private String title_final=""; 89 83 90 static private Dimension COMPONENT_SIZE = new Dimension(230, 25); 84 91 /** The size of this new collection dialog box. */ … … 94 101 this.setComponentOrientation(Dictionary.getOrientation()); 95 102 this.self = this; 103 newCollectPath = Gatherer.getCollectDirectoryPath(); 104 collectBasePath = null; 105 collectDirChanged = false; 106 96 107 // Setup 97 108 setJMenuBar(new SimpleMenuBar("creatingacollection")); … … 101 112 // Model building. Build a model of all of the collections in the gsdl collect directory with the appropriate directories. 102 113 Vector base_collection_model = new Vector(); 103 // need to modify this to base a coll on any collection from any site 104 if (Gatherer.GS3 && !Gatherer.isGsdlRemote) { 105 File sites_dir = new File(Gatherer.getSitesDirectoryPath()); 106 File [] sites = sites_dir.listFiles(); 107 for (int i=0; i<sites.length; i++) { 108 File collect_directory = new File(sites_dir + File.separator + sites[i].getName() + File.separator + "collect"); 109 if (collect_directory.exists()) { 110 addCollectionsToModel(base_collection_model, collect_directory, sites[i].getName()); 111 } 112 } 113 } else { 114 File collect_directory = new File(Gatherer.getCollectDirectoryPath()); 115 addCollectionsToModel(base_collection_model, collect_directory, null); 116 } 117 118 // Sort the result. 119 Collections.sort(base_collection_model); 120 base_collection_model.add(0, new Item(null, Dictionary.get("NewCollectionPrompt.NewCollection"))); 114 setupBaseCollections(base_collection_model, null); // if no collect directory passed in: use default collect directory 115 121 116 122 117 // Creation … … 190 185 button_pane.setComponentOrientation(Dictionary.getOrientation()); 191 186 create_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip")); 187 chdir_button = new GLIButton(Dictionary.get("General.CD"), Dictionary.get("General.CD_Tooltip")); 192 188 JButton cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip")); 193 189 194 190 // Connection 191 chdir_button.addActionListener(new ChangeDirListener()); 192 if(Gatherer.isGsdlRemote) { // for client GLI disable changing directories 193 chdir_button.setEnabled(false); 194 } else { // can't base collections on any in OTHER collect dirs in client GLI 195 base_collection.addActionListener(new OtherCollectionsListener()); 196 } 195 197 cancel_button.addActionListener(new CancelListener()); 196 198 create_button.addActionListener(new CreateListener()); … … 238 240 239 241 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 240 button_pane.setLayout(new GridLayout(1,2)); 242 button_pane.setLayout(new GridLayout(1,3)); 243 button_pane.add(chdir_button); 241 244 button_pane.add(create_button); 242 245 button_pane.add(cancel_button); … … 327 330 public String getTitle() { 328 331 return title_final; 332 } 333 334 private void setupBaseCollections(Vector base_collection_model, String collectDirectory) { 335 336 File collect_directory = null; 337 if(collectDirectory != null) { 338 collect_directory = new File(collectDirectory); 339 } 340 341 // need to modify this to base a coll on any collection from any site 342 if (Gatherer.GS3 && !Gatherer.isGsdlRemote) { 343 File sites_dir = new File(Gatherer.getSitesDirectoryPath()); 344 File [] sites = sites_dir.listFiles(); 345 for (int i=0; i<sites.length; i++) { 346 if(collect_directory == null) { 347 collect_directory = new File(sites_dir + File.separator + sites[i].getName() + File.separator + "collect"); 348 } 349 if (collect_directory.exists()) { 350 addCollectionsToModel(base_collection_model, collect_directory, sites[i].getName()); 351 } 352 } 353 } else { 354 if(collect_directory == null) { // if no collect directory passed in: use default collect directory 355 collect_directory = new File(Gatherer.getCollectDirectoryPath()); 356 } 357 addCollectionsToModel(base_collection_model, collect_directory, null); 358 } 359 360 // Sort the result. 361 Collections.sort(base_collection_model); 362 base_collection_model.add(0, new Item(null, Dictionary.get("NewCollectionPrompt.NewCollection"))); 363 364 // last item allows one to open up collections from other collect folders to base the new one on 365 if(!Gatherer.isGsdlRemote) { // Not yet implemented for client GLI 366 base_collection_model.add(new Item(null, Dictionary.get("NewCollectionPrompt.OtherCollections"))); 367 } 329 368 } 330 369 … … 363 402 } 364 403 404 private class OtherCollectionsListener implements ActionListener { 405 406 // the JComboBox listener will receive an ActionEvent 407 // when a selection has been made 408 409 public void actionPerformed(ActionEvent event) { 410 411 // If the Other Collections item was selected (which is the last one in the list) 412 if(base_collection.getSelectedIndex() == base_collection.getItemCount()-1) { 413 414 // open a filechooser in whatever is the current collect directory 415 // within the NewCollectionDetailsPrompt's settings 416 if(collectBasePath == null) { 417 collectBasePath = newCollectPath; 418 } 419 420 JFileChooser chooser = new JFileChooser(collectBasePath); 421 chooser.setFileView(new CollectionFileView()); 422 chooser.setDialogTitle(Dictionary.get("NewCollectionPrompt.ChooseACollection")); 423 chooser.setApproveButtonText(Dictionary.get("NewCollectionPrompt.Select")); 424 425 // to prevent the user from traversing into collection folders, 426 // need to: 427 // - NOT set the filechooser to Directories only, but files and directories 428 // (so that they can still select directories) 429 // - add a filefilter that accepts only directories (i.e. rejects files) 430 // - remove the accept all filter 431 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 432 //chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 433 chooser.setFileFilter(new CollectionFileFilter()); 434 chooser.setAcceptAllFileFilterUsed(false); 435 436 int returnVal = chooser.showOpenDialog(NewCollectionDetailsPrompt.this); 437 if(returnVal == JFileChooser.APPROVE_OPTION) { 438 439 File selectedFile = chooser.getSelectedFile(); 440 441 // don't bother reloading if nothing has changed 442 if(collectBasePath.equals(selectedFile.getAbsolutePath() + File.separator)) { 443 // don't want Other Collections... selected 444 base_collection.setSelectedIndex(0); 445 } else { 446 447 // If the selected directory is a collection folder get its collect dir, 448 // make collectBasePath the collect dir, and select the collection itself 449 String cfg = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 450 boolean isCollection = false; 451 while(new File(selectedFile, cfg).exists()) { // while loop handles collectgroup 452 selectedFile = selectedFile.getParentFile(); 453 isCollection = true; 454 } // else may be a collect dir, in which case leave it as it is again 455 456 // found collect directory for base collections 457 collectBasePath = selectedFile.getAbsolutePath()+File.separator; 458 459 // change the available collections to base this collection on 460 base_collection.removeAllItems(); 461 Vector base_collection_model = new Vector(); 462 setupBaseCollections(base_collection_model, collectBasePath); 463 for(int i = 0; i < base_collection_model.size(); i++) { 464 Item item = (Item)base_collection_model.get(i); 465 base_collection.addItem(item); 466 467 // select the originally chosen collection, if any, in the combobox 468 if(isCollection && chooser.getSelectedFile().equals(item.getFile())) { 469 base_collection.setSelectedIndex(i); 470 } 471 } 472 473 // But if the user selected a collect group, set combobox to New Collection 474 if(!isCollection) { 475 // if it was a collectgroup, nothing new would be selected, set to New Coll 476 if(base_collection.getSelectedIndex() == base_collection.getItemCount()-1) { 477 base_collection.setSelectedIndex(0); 478 } 479 } 480 481 } 482 483 } else { // cancelled out of dialog, so jump to New Collection 484 base_collection.setSelectedIndex(0); 485 } 486 } 487 } 488 } 489 490 private class ChangeDirListener implements ActionListener { 491 public void actionPerformed(ActionEvent event) { 492 String oldCollectPath = newCollectPath; 493 JFileChooser chooser = new JFileChooser(newCollectPath); 494 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 495 chooser.setDialogTitle(Dictionary.get("General.ChooseCollectDirectory")); 496 497 int returnVal = chooser.showOpenDialog(NewCollectionDetailsPrompt.this); 498 if(returnVal == JFileChooser.APPROVE_OPTION) { 499 newCollectPath = chooser.getSelectedFile().getAbsolutePath() + File.separator; 500 501 // Must NOT change the available collections to base this collection on here. 502 // It will change any collection the user previously chose to base the newcoll on. 503 504 // will be used to test for duplicate collection names in current collect dir 505 collectDirChanged = newCollectPath.equals(oldCollectPath) ? false : true; 506 } 507 } 508 } 509 365 510 private class CancelListener 366 511 implements ActionListener { … … 387 532 // 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 388 533 else { 389 if(titleClashes(title_final, null)) { 534 String collectDir = collectDirChanged ? newCollectPath : Gatherer.getCollectDirectoryPath(); 535 if(titleClashes(collectDir, title_final, null)) { 390 536 JOptionPane jOptionPane=new JOptionPane(); 391 537 jOptionPane.setComponentOrientation(Dictionary.getOrientation()); … … 395 541 } 396 542 } 543 } 544 545 // going through with collection creation 546 if(collectDirChanged) { 547 Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(), newCollectPath); 548 // will tell the server that the collect directory has changed and that 549 // the workspace needs to be refreshed (Documents in Greenstone Collections) 397 550 } 398 551 … … 435 588 } 436 589 public int compareTo(Object other) { 437 return toString().toLowerCase().compareTo(other.toString().toLowerCase()); 590 if(this == null && other == null) { 591 return 0; 592 } 593 else if(other == null) { 594 return 1; 595 } 596 else if(this == null) { 597 return -1; 598 } 599 else { 600 return toString().toLowerCase().compareTo(other.toString().toLowerCase()); 601 } 438 602 } 439 603 public boolean equals(Object other) { … … 450 614 } 451 615 } 616 617 /** FileFilter for the Filechooser to choose the collection to base the new one on: 618 * Only displays directories. */ 619 private class CollectionFileFilter extends FileFilter { 620 public boolean accept(File f) { 621 return f.isDirectory(); 622 } 623 public String getDescription() { 624 return "greenstone collection view"; //return "directories only"; 625 } 626 } 627 628 /** Folders that can be used as a base collection have a special icon */ 629 private class CollectionFileView extends FileView { 630 final String configfile_name; 631 final ImageIcon COLLECTION_ICON = JarTools.getImage("gsCollection.gif", true); 632 633 private File previous = null; 634 private boolean previousWasCollection = false; 635 636 public CollectionFileView() { 637 configfile_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 638 } 639 640 // A human readable description of the file. 641 public String getDescription(File f) { 642 if(!f.equals(previous)) { 643 previous = f; 644 // no idea if it's a collection or not, calculate this next time 645 previousWasCollection = false; 646 } 647 return null; // FilewView superclass will handle it 648 } 649 650 // The icon that represents this file in the JFileChooser. 651 public Icon getIcon(File f) { 652 653 if(f.equals(previous) && previousWasCollection) { 654 return COLLECTION_ICON; 655 } 656 657 if(isCollectionBase(f)) { 658 return COLLECTION_ICON; 659 } 660 661 return null; // FileView superclass will do the default 662 } 663 664 // The name of the file. 665 public String getName(File f) { 666 if(!f.equals(previous)) { 667 previous = f; 668 // no idea if it's a collection or not, calculate this next time 669 previousWasCollection = false; 670 } 671 return f.getName(); 672 } 673 674 // A human readable description of the type of the file. 675 public String getTypeDescription(File f) { 676 if(f.equals(previous) && previousWasCollection) { 677 return "collection"; 678 } 679 if(isCollectionBase(f)) { 680 return "collection"; 681 } 682 // else 683 return "not a collection"; 684 } 685 686 // Whether the directory is traversable or not. 687 public Boolean isTraversable(File f) { 688 if(f.equals(previous) && previousWasCollection) { 689 return Boolean.FALSE; 690 } 691 692 if(isCollectionBase(f)) { 693 return Boolean.FALSE; 694 } 695 696 if(f.isFile()) { // not traversable 697 return Boolean.FALSE; 698 } 699 // any other kind of directory is traversable 700 return Boolean.TRUE; 701 } 702 703 704 /** returns false for collect groups and collect dirs. */ 705 private boolean isCollectionBase(File f) { 706 previous = f; 707 previousWasCollection = false; 708 709 if(!f.isFile()) { 710 // If the directory has a etc/collect.cfg file then it looks like a collection 711 File collect_cfg_file = new File(f, configfile_name); 712 if (collect_cfg_file.exists()) { 713 // Check for group coll: Check the collect.cfg for collectgroup=true 714 BasicCollectionConfiguration config = new BasicCollectionConfiguration(collect_cfg_file); 715 if (!config.getCollectGroup().equals("true")) { 716 previousWasCollection = true; 717 } 718 } 719 } 720 return previousWasCollection; 721 } 722 723 } 452 724 } 453 725 -
main/trunk/gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java
r22357 r22605 58 58 private int result; 59 59 private JButton cancel_button; 60 private JButton chdir_button; 60 61 private JButton open_button; 61 62 private JList collection_list; … … 63 64 private JPanel description_pane; 64 65 private String filename; 66 private String newCollectPath; 65 67 66 68 public OpenCollectionDialog() { … … 70 72 setSize(SIZE); 71 73 setTitle(Dictionary.get("OpenCollectionDialog.Title")); 72 74 newCollectPath = Gatherer.getCollectDirectoryPath(); 75 73 76 // Creation 74 77 JPanel content_pane = (JPanel) getContentPane(); … … 103 106 open_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Open"), Dictionary.get("OpenCollectionDialog.Open_Tooltip")); 104 107 open_button.setEnabled(false); 105 108 chdir_button = new GLIButton(Dictionary.get("General.CD"), Dictionary.get("General.CD_Tooltip")); 106 109 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip")); 107 110 108 111 // Connection 112 chdir_button.addActionListener(new ChangeDirListener()); 113 if(Gatherer.isGsdlRemote) { // disable changing directories for client GLI 114 chdir_button.setEnabled(false); 115 } 109 116 cancel_button.addActionListener(new CancelListener()); 110 117 open_button.addActionListener(new OpenListener()); … … 137 144 center_pane.add(description_pane); 138 145 139 button_pane.setLayout(new GridLayout(1,4)); 140 JPanel tmp =new JPanel(); 141 tmp.setComponentOrientation(Dictionary.getOrientation()); 142 button_pane.add(tmp); 146 button_pane.setLayout(new GridLayout(1,3)); 147 button_pane.add(chdir_button); 143 148 button_pane.add(open_button); 144 149 button_pane.add(cancel_button); … … 164 169 public String getFileName() { 165 170 return this.filename; 171 } 172 173 private class ChangeDirListener implements ActionListener { 174 public void actionPerformed(ActionEvent event) { 175 JFileChooser chooser = new JFileChooser(newCollectPath); 176 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 177 chooser.setDialogTitle(Dictionary.get("General.ChooseCollectDirectory")); 178 int returnVal = chooser.showOpenDialog(OpenCollectionDialog.this); 179 if(returnVal == JFileChooser.APPROVE_OPTION) { 180 String oldCollectPath = newCollectPath; 181 newCollectPath = chooser.getSelectedFile().getAbsolutePath() + File.separator; 182 183 if(!newCollectPath.equals(oldCollectPath)) { 184 // reload the list of available collections using this new path 185 CollectionListModel listModel = (CollectionListModel)collection_list.getModel(); 186 listModel.reload(newCollectPath); 187 collection_list.repaint(); 188 } 189 } 190 } 166 191 } 167 192 … … 268 293 public CollectionListModel() { 269 294 data = new TreeSet(); 270 File collect_directory = new File(Gatherer.getCollectDirectoryPath()); 295 reload(Gatherer.getCollectDirectoryPath()); 296 } 297 298 // to be called when the collection directory has changed 299 public void reload(String collectDirectoryPath) { 300 data.clear(); 301 File collect_directory = new File(collectDirectoryPath); 271 302 if (!collect_directory.exists()) { 272 303 collect_directory = null; … … 276 307 load_collection_configs(data,collect_directory); 277 308 309 // list size/contents has changed, this listmodel must notify the 310 // encapsulating JList, else it won't be able to display longer lists 311 fireContentsChanged(this, 0, data.size()); 278 312 } 279 313 … … 389 423 OpenCollectionDialog.this.dispose(); 390 424 } 425 426 Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(), newCollectPath); 427 // will tell the server that the collect directory has changed and that 428 // the workspace needs to be refreshed (Documents in Greenstone Collections) 391 429 } 392 430 } -
main/trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java
r20961 r22605 68 68 private JButton apply_button; 69 69 private JButton cancel_button; 70 private JButton chdir_button; 70 71 private JButton ok_button; 71 72 private JCheckBox show_file_size_checkbox; … … 92 93 private JTextField program_field; 93 94 private JTextField proxy_host_field; 95 private JTextField collect_dir_field; 96 94 97 private Preferences self; 95 98 … … 298 301 } 299 302 } 303 304 JPanel collect_dir_pane = new JPanel(); 305 collect_dir_pane.setComponentOrientation(Dictionary.getOrientation()); 306 collect_dir_pane.setPreferredSize(ROW_SIZE); 307 JLabel collect_dir_label = new JLabel(Dictionary.get("Preferences.Connection.CollectDirectory")); 308 collect_dir_label.setPreferredSize(LABEL_SIZE); 309 collect_dir_label.setComponentOrientation(Dictionary.getOrientation()); 310 collect_dir_field = new JTextField(Gatherer.getCollectDirectoryPath()); 311 //collect_dir_field = new JTextField(Configuration.getString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true)); 312 collect_dir_field.setCaretPosition(0); 313 collect_dir_field.setToolTipText(Dictionary.get("Preferences.Connection.CollectDirectory_Tooltip")); 314 collect_dir_field.setEditable(false); 315 JButton chdir_button = new GLIButton(Dictionary.get("General.CD"), Dictionary.get("General.CD_Tooltip")); 316 chdir_button.addActionListener(new ChangeDirListener()); 317 if(Gatherer.isGsdlRemote) { // disable changing directories for client GLI 318 chdir_button.setEnabled(false); 319 } 300 320 301 321 boolean currently_enabled = Configuration.get("general.use_proxy", true); … … 370 390 } 371 391 392 collect_dir_pane.setLayout(new BorderLayout()); 393 collect_dir_pane.add(collect_dir_label, BorderLayout.LINE_START); 394 collect_dir_pane.add(collect_dir_field, BorderLayout.CENTER); 395 collect_dir_pane.add(chdir_button, BorderLayout.LINE_END); 396 372 397 proxy_host_pane.setLayout(new BorderLayout()); 373 398 proxy_host_pane.add(proxy_host_label, BorderLayout.LINE_START); … … 389 414 connection_pane.add(servlet_pane); 390 415 } 416 connection_pane.add(collect_dir_pane); 417 391 418 connection_pane.add(use_proxy_checkbox); 392 419 connection_pane.add(proxy_host_pane); … … 731 758 } 732 759 760 private class ChangeDirListener implements ActionListener { 761 public void actionPerformed(ActionEvent event) { 762 JFileChooser chooser = new JFileChooser(collect_dir_field.getText()); 763 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 764 int returnVal = chooser.showOpenDialog(Preferences.this); 765 if(returnVal == JFileChooser.APPROVE_OPTION) { 766 collect_dir_field.setText(chooser.getSelectedFile().getAbsolutePath() + File.separator); 767 } // else collect_dir_field text remains as it is 768 } 769 } 733 770 734 771 private class OKButtonListener … … 826 863 Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem()); 827 864 } 865 866 // collect directory change 867 String newCollectPath = collect_dir_field.getText(); 868 if(!newCollectPath.endsWith(File.separator)) { 869 newCollectPath += File.separator; 870 } 871 Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(), newCollectPath); 872 // will tell the server that the collect directory has changed and that 873 // the workspace needs to be refreshed (Documents in Greenstone Collections) 874 828 875 829 876 Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
Note:
See TracChangeset
for help on using the changeset viewer.