Changeset 22605 for main/trunk/gli/src/org/greenstone/gatherer/file
- Timestamp:
- 2010-08-11T21:28:34+12:00 (14 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer/file
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.