Changeset 22605
- Timestamp:
- 2010-08-11T21:28:34+12:00 (14 years ago)
- Location:
- main/trunk/gli
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/classes/dictionary.properties
r22341 r22605 526 526 #***** FileActions ***** 527 527 FileActions.Calculating_Size:Calculating total size of selected files 528 FileActions.ChooseDestinationDirectory:Choose destination directory 528 529 FileActions.Copying:Copying {0} 529 530 FileActions.Could_Not_Delete:Could not delete {0} … … 615 616 General.Cancel:Cancel 616 617 General.Cancel_Tooltip:Cancel the changes (will not undo any that have been applied already) 618 General.CD:Change Dir... 619 General.CD_Tooltip:Browse to a different collect directory 620 General.ChooseCollectDirectory:Choose your collect directory... 617 621 General.Close:Close 618 622 General.Close_Tooltip:Close this dialog box … … 735 739 #***** Menu Options ***** 736 740 Menu.Collapse:Close Folder 741 Menu.Copy_Collection:Copy this collection to... 737 742 Menu.Edit:Edit 738 743 Menu.Edit_Copy:Copy (ctrl-c) … … 756 761 Menu.Help_About:About... 757 762 Menu.Metadata_View:Assigned Metadata for the {0} 763 Menu.Move_Collection:Move this collection to... 758 764 Menu.Open_Externally:Open in external program 759 765 #******************** … … 861 867 NewCollectionPrompt.Base_Collection:Base this collection on: 862 868 NewCollectionPrompt.Base_Collection_Tooltip:Select an existing collection to base the new collection on 869 NewCollectionPrompt.ChooseACollection:Choose a collection 863 870 NewCollectionPrompt.Collection_Description:Description of content: 864 871 NewCollectionPrompt.Collection_Name:Collection folder: … … 870 877 NewCollectionPrompt.Instructions:To create a new collection fill out the fields below. 871 878 NewCollectionPrompt.NewCollection:-- New Collection -- 879 NewCollectionPrompt.OtherCollections:-- Other Collections... -- 880 NewCollectionPrompt.Select:Select 872 881 NewCollectionPrompt.Title:Create a new Collection. 873 882 NewCollectionPrompt.Title_Clash:The title you have chosen for your collection is already in use. Continue? … … 918 927 Preferences.Connection.Library_Path_Tooltip_GS3:The URL of the Greenstone web-server 919 928 Preferences.Connection.Library_Path_Connection_Failure:Failed to connect. Check that the Greenstone server at {0} is running. 929 Preferences.Connection.CollectDirectory:Collect Directory: 930 Preferences.Connection.CollectDirectory_Tooltip:The path to the collect directory you want to work with. 920 931 Preferences.Connection.ProgramCommand:Preview Command: 921 932 Preferences.Connection.ProgramCommand_Tooltip:The launch command for the program used to view the collection preview. Remember to use %1 as the placeholder for the collection address, and to use speechmarks where necessary. -
main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r21965 r22605 497 497 if (no_load || open_collection_file_path.equals("")) { 498 498 open_collection_file_path = null; 499 } 499 // collectDirectoryHasChanged(); // make sure gsdlsite.cfg's collecthome defaults to GS' collect 500 } 501 502 // If opening a collection outside the standard GS collect folder, need 503 // to open the non-standard collect folder that the collection resides in 504 if (open_collection_file_path != null && 505 !open_collection_file_path.startsWith(getCollectDirectoryPath())) { 506 File collectFolder = null; 507 if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder 508 collectFolder = new File(open_collection_file_path); 509 } else { 510 // the filepath is a gli.col file. To get the collect folder: the 1st level 511 // up is collection folder, 2 two levels up is the containing collect folder 512 collectFolder = new File(open_collection_file_path).getParentFile().getParentFile(); 513 } 514 515 // Need to deal with colgroups as well: while there's an etc/collect.cfg in the current 516 // collectFolder, move one level up 517 String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 518 if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup 519 collectFolder = collectFolder.getParentFile(); 520 521 } 522 setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder 523 } 524 500 525 } 501 526 catch (Exception exception) { … … 761 786 System.err.println("Error: Unable to make directory: " + gli_user_directory); 762 787 } 788 } 789 790 791 public static void collectDirectoryHasChanged(String oldCollectPath, String newCollectPath) { 792 if(oldCollectPath.equals(newCollectPath)) { 793 return; // nothing to be done 794 } 795 796 // first save any open collection in the *old* location 797 if(Gatherer.c_man.getCollection() != null) { 798 Gatherer.setCollectDirectoryPath(oldCollectPath); // go back to current collection's location 799 Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first 800 } 801 802 // change to new collect path 803 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), 804 true, newCollectPath); 805 Gatherer.setCollectDirectoryPath(newCollectPath); 806 807 808 // refresh the Documents in Greenstone Collections 809 //WorkspaceTreeModel.refreshGreenstoneCollectionsNode(); 810 Gatherer.g_man.refreshWorkspaceTreeGreenstoneCollections(); 811 812 // The web server needs to be told where a new (non-standard) collecthome home is. 813 // The web server reads collecthome from cgi-bin/gsdlsite.cfg, where the property 814 // collecthome can be specified if a non-standard collecthome is to be used. If no 815 // such property is specified in the file, then it assumes the standard GS collecthome. 816 // This method does nothing for a remote Greenstone. 817 if(Gatherer.isGsdlRemote) { 818 return; 819 } 820 821 String gsdlsitecfg = ""; 822 if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg 823 gsdlsitecfg = Configuration.gsdl3_path + File.separator + "WEB-INF" 824 + File.separator + "cgi" + File.separator + "gsdl3site.cfg"; 825 } else { // cgi-bin/gsdlsite.cfg 826 gsdlsitecfg = Configuration.gsdl_path + File.separator 827 + "cgi-bin" + File.separator + "gsdlsite.cfg"; 828 } 829 830 // non-destructive update of gsdl(3)site.cfg (comments preserved) 831 Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", Gatherer.getCollectDirectoryPath()); 763 832 } 764 833 -
main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r22467 r22605 402 402 */ 403 403 public void closeCollection() { 404 if (collection == null) { 405 return; 406 } 404 407 DebugStream.println("Close collection: " + collection.getName()); 405 408 … … 1154 1157 public void loadCollection(String collection_file_path) 1155 1158 { 1159 if(new File(collection_file_path).isDirectory()) { // collect folder instead of previously-opened collection 1160 Gatherer.setMenuBarEnabled(true); 1161 return; // nothing else to be done, no collection to open 1162 } 1163 1156 1164 // Display a modal progress popup to indicate that the collection is being loaded 1157 1165 ModalProgressPopup load_collection_progress_popup = new ModalProgressPopup(Dictionary.get("CollectionManager.Loading_Collection"), Dictionary.get("CollectionManager.Loading_Collection_Please_Wait")); … … 1552 1560 // If there was an open collection last session, reopen it 1553 1561 if (Gatherer.open_collection_file_path != null) { 1554 1555 1562 // Load the collection now 1563 loadCollection(Gatherer.open_collection_file_path); 1556 1564 } 1557 1565 -
main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java
r22410 r22605 62 62 static private FileQueue file_queue = null; 63 63 64 public static int FILE_TYPE = 0; 65 public static int FOLDER_TYPE = 1; 64 public static final int COPY = 0; 65 public static final int MOVE = 1; 66 67 public static final int FILE_TYPE = 0; 68 public static final int FOLDER_TYPE = 1; 66 69 protected static File startup_directory = null; 67 70 … … 129 132 } 130 133 134 /** For moving and copying of folders. */ 135 public void action(File sourceFolder, File targetFolder, int operation) { 136 (new SimpleFileTask(sourceFolder, targetFolder, operation)).start(); 137 } 138 131 139 132 140 /** Retrieves the file queue object. */ … … 136 144 } 137 145 146 /** Performs the simple file task of moving or copying folders. */ 147 private class SimpleFileTask 148 extends Thread 149 { 150 private File sourceFolder; 151 private File targetFolder; 152 int operation; // MOVE or COPY 153 154 public SimpleFileTask(File sourceFolder, File targetFolder, int operation) 155 { 156 this.sourceFolder = sourceFolder; 157 this.targetFolder = targetFolder; 158 this.operation = operation; 159 } 160 161 162 public void run() 163 { 164 // check if we're moving or overwriting the current collection 165 String currentColPath = Gatherer.getCollectDirectoryPath()+CollectionManager.getLoadedCollectionName(); 166 if(currentColPath.equals(sourceFolder.getAbsolutePath()) 167 || currentColPath.equals(targetFolder.getAbsolutePath())) { 168 Gatherer.g_man.saveThenCloseCurrentCollection(); 169 } 170 171 // if moving, try a simple move operation (if it works, it 172 // shouldn't take long at all and doesn't need a progress bar) 173 if(operation == MOVE && sourceFolder.renameTo(targetFolder)) { 174 //System.err.println("**** A simple renameTo() worked."); 175 WorkspaceTreeModel.refreshGreenstoneCollectionsNode(); 176 return; 177 } 178 179 // Reset the progress bar and set it to indeterminate while calculating its size 180 GProgressBar progress_bar = file_queue.getProgressBar(); 181 progress_bar.reset(); 182 progress_bar.setIndeterminate(true); 183 184 String status = "FileActions.Moving"; 185 if(operation == COPY) { 186 status = "FileActions.Copying"; 187 } 188 progress_bar.setString(Dictionary.get(status)); 189 file_queue.getFileStatus().setText(Dictionary.get(status, 190 file_queue.formatPath(status, 191 sourceFolder.getAbsolutePath(), 192 file_queue.getFileStatus().getSize().width))); 193 194 // do the move or copy operation 195 try { 196 //System.err.println("**** Copying " + sourceFolder + " to: " + targetFolder); 197 file_queue.copyDirectoryContents(sourceFolder, targetFolder); 198 } catch(Exception e) { 199 JOptionPane.showMessageDialog(Gatherer.g_man, e.getMessage(), 200 "Can't perform file operation", JOptionPane.ERROR_MESSAGE); 201 202 progress_bar.setIndeterminate(false); 203 progress_bar.clear(); 204 return; 205 } 206 207 // if moving, delete the original source folder and 208 // update the docs in GS collections node in the workspace tree 209 210 if(operation == MOVE) { 211 Utility.delete(sourceFolder); 212 WorkspaceTreeModel.refreshGreenstoneCollectionsNode(); 213 } 214 215 216 progress_bar.setIndeterminate(false); 217 progress_bar.clear(); 218 file_queue.getFileStatus().setText(Dictionary.get("FileActions.No_Activity")); 219 progress_bar.setString(Dictionary.get("FileActions.No_Activity")); 220 } 221 } 138 222 139 223 private class FileTask -
main/trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java
r12115 r22605 162 162 * @return A path <strong>String</strong> no longer than width. 163 163 */ 164 private String formatPath(String key, String raw, int width)164 String formatPath(String key, String raw, int width) // package access 165 165 { 166 166 JLabel label = new JLabel(Dictionary.get(key, raw)); -
main/trunk/gli/src/org/greenstone/gatherer/file/WorkspaceTree.java
r22410 r22605 39 39 import org.greenstone.gatherer.gui.CreateShortcutPrompt; 40 40 import org.greenstone.gatherer.gui.tree.DragTree; 41 import org.greenstone.gatherer.util.Utility; 41 42 42 43 … … 217 218 private JMenuItem rename = null; 218 219 private JMenuItem replace = null; 220 private JMenuItem copy_collection = null; 221 private JMenuItem move_collection = null; 219 222 220 223 … … 343 346 // Or map any other level directories 344 347 else { 348 // --- Options for Documents In Greenstone Collections (greenstone_collections_node) --- 349 // all subfolder of Documents In Greenstone Collections can be copied and moved 350 WorkspaceTreeNode secondLevelNode = (WorkspaceTreeNode) path.getPathComponent(1); 351 352 if (secondLevelNode.toString().equals(Dictionary.get("Tree.World"))) { 353 // Can move and copy the collection folders across 354 copy_collection = new JMenuItem(Dictionary.get("Menu.Copy_Collection"), KeyEvent.VK_P); 355 copy_collection.addActionListener(this); 356 add(copy_collection); 357 358 move_collection = new JMenuItem(Dictionary.get("Menu.Move_Collection"), KeyEvent.VK_M); 359 move_collection.addActionListener(this); 360 add(move_collection); 361 } 362 345 363 create_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S); 346 364 create_shortcut.addActionListener(this); … … 386 404 Gatherer.f_man.openFileInExternalApplication(node.getFile()); 387 405 } 406 407 // Copy or move a collection from Documents in Greenstone Collections 408 else if (source == move_collection || source == copy_collection) { 409 410 JFileChooser chooser = new JFileChooser(Gatherer.getCollectDirectoryPath()); 411 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 412 chooser.setDialogTitle(Dictionary.get("FileActions.ChooseDestinationDirectory")); 413 int returnVal = chooser.showOpenDialog(Gatherer.g_man.gather_pane); 414 415 if(returnVal == JFileChooser.APPROVE_OPTION) { 416 417 // the node that the user rightclicked on ends up 418 // being the col's import folder 419 File sourceFolder = node.getFile(); 420 if(sourceFolder.getName().equals("import")) { 421 sourceFolder = sourceFolder.getParentFile(); 422 } 423 String target = chooser.getSelectedFile().getAbsolutePath(); 424 File targetFolder = new File(target+File.separator+sourceFolder.getName()); 425 426 // some sanity checks 427 if(targetFolder.equals(sourceFolder)) { // directory has not changed. No copy/move performed 428 JOptionPane.showMessageDialog(Gatherer.g_man, 429 "Can't move " + sourceFolder + " " + "to itself\n(" + targetFolder + ").", 430 "Source and destination directories are the same", 431 JOptionPane.ERROR_MESSAGE); 432 return; 433 } else if(targetFolder.exists()) { // option to overwrite or not 434 if(JOptionPane.showConfirmDialog(Gatherer.g_man, 435 "Directory " + targetFolder + " already exists. Overwrite?", 436 "Destination directory already exists", 437 JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { 438 return; 439 } 440 // else can overwrite: delete the existing targetfolder before copying/moving 441 Utility.delete(targetFolder); 442 } 443 444 int operation = (source == move_collection) ? FileManager.MOVE : FileManager.COPY; 445 Gatherer.f_man.action(sourceFolder, targetFolder, operation); 446 } 447 } 388 448 } 389 449 } -
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()); -
main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java
r20446 r22605 459 459 return new_name; 460 460 } 461 462 463 /** Write out a property line--a (property, value) pair--to the gsdl(3)site.cfg file. 464 * If the file already contains the line as-is, it is not re-written. 465 * If the file doesn't contain the line, it is appended. 466 * If the file contained a different value for the property, the line is corrected 467 * and the file is written out. 468 * Not using the Properties class, as we want to keep the file's contents in the 469 * same order and preserve all the comments in as they're meant to help the user. 470 */ 471 public static void updatePropertyConfigFile(String filename, String propertyName, String propertyValue) { 472 BufferedReader fin = null; 473 BufferedWriter fout = null; 474 StringBuffer contents = new StringBuffer(); 475 String insertLine = propertyName+"\t"+propertyValue+"\n"; // new line after every propertyLine 476 boolean found = false; 477 try { 478 fin = new BufferedReader(new FileReader(filename)); 479 String line = ""; 480 while((line = fin.readLine()) != null) { 481 if(line.startsWith(propertyName)) { // won't match comment 482 found = true; 483 if(line.equals(insertLine)) { // file is already correct, nothing to do 484 fin.close(); 485 fin = null; 486 break; 487 } else { 488 contents.append(insertLine); 489 } 490 491 } else { // any other line 492 contents.append(line); 493 contents.append("\n"); // ensures the required new line at end of file 494 } 495 } 496 497 if(fin != null) { // need to write something out to the file 498 fin.close(); 499 fin = null; 500 501 // if collecthome wasn't already specified in the file, append it 502 if(!found) { 503 fout = new BufferedWriter(new FileWriter(filename, true)); // append mode 504 fout.write(insertLine, 0, insertLine.length()); 505 } else { 506 507 fout = new BufferedWriter(new FileWriter(filename)); // hopefully this will overwrite 508 fout.write(contents.toString(), 0, contents.length()); 509 } 510 511 fout.close(); 512 fout = null; 513 } // else the file is fine 514 } catch(IOException e) { 515 System.err.println("*** Could not update file: " + filename); 516 System.err.println("with the " + propertyName + " property set to " + propertyValue); 517 System.err.println("Exception occurred: " + e.getMessage()); 518 } finally { 519 try { 520 if(fin != null) { 521 fin.close(); 522 fin = null; 523 } 524 if(fout != null) { 525 fout.close(); 526 fout = null; 527 } 528 } catch(IOException ioe) { 529 fin = null; 530 fout = null; 531 } 532 533 } 534 535 } 461 536 462 537 }
Note:
See TracChangeset
for help on using the changeset viewer.