Changeset 11314
- Timestamp:
- 2006-03-08T17:17:07+13:00 (18 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/file
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/file/FileManager.java
r11246 r11314 51 51 import org.greenstone.gatherer.util.Utility; 52 52 53 54 53 /** Manages the moving of files within a separate thread. 55 54 * @author John Thompson, NZDL Project, University of Waikato … … 368 367 } 369 368 } 369 370 public void replaceCollectionFile(CollectionTree collection_tree, CollectionTreeNode collection_tree_node) 371 { 372 // This must go in a separate thread because we need the progress bar to work (remote Greenstone server) 373 new ReplaceTask(collection_tree, collection_tree_node).start(); 374 } 375 376 377 private class ReplaceTask 378 extends Thread 379 { 380 private CollectionTree collection_tree = null; 381 private CollectionTreeNode collection_tree_node = null; 382 383 public ReplaceTask(CollectionTree collection_tree, CollectionTreeNode collection_tree_node) 384 { 385 this.collection_tree = collection_tree; 386 this.collection_tree_node = collection_tree_node; 387 } 388 389 public void run() 390 { 391 JFileChooser file_chooser = new JFileChooser(); 392 file_chooser.setDialogTitle(Dictionary.get("ReplacePrompt.Title")); 393 File new_file = null; 394 int return_val = file_chooser.showOpenDialog(null); 395 if(return_val == JFileChooser.APPROVE_OPTION) { 396 new_file = file_chooser.getSelectedFile(); 397 } 398 399 if (new_file == null) { 400 return; 401 } 402 403 // make up a node for the file to bring in 404 WorkspaceTreeNode source_node = new WorkspaceTreeNode(new_file); 405 406 File target_directory = collection_tree_node.getFile().getParentFile(); 407 CollectionTreeNode new_collection_tree_node = new CollectionTreeNode(new File(target_directory, new_file.getName())); 408 // copy the new file in - but don't bring metadata 409 file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, (FileNode)collection_tree_node.getParent(), FileJob.COPY_FILE_ONLY); 410 // do a replace of old file with new file 411 file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE); 412 413 } 414 } 415 370 416 } 417 418 419 420 -
trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java
r11242 r11314 479 479 480 480 // Copy the non-folder level metadata assigned to the original file to the new file 481 ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToExternalFile(source_file); 482 MetadataXMLFileManager.addMetadata((CollectionTreeNode) new_target_node, assigned_metadata); 481 if (file_job.type == FileJob.COPY) { 482 // do metadata too 483 ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToExternalFile(source_file); 484 MetadataXMLFileManager.addMetadata((CollectionTreeNode) new_target_node, assigned_metadata); 485 } 483 486 } 484 487 … … 536 539 MetadataXMLFileManager.addMetadata((CollectionTreeNode) new_target_node, assigned_metadata); 537 540 } 538 541 542 /** all this does is move the metadata, and delete the source */ 543 private void doFileReplace(FileJob file_job) { 544 FileNode source_node = file_job.getOrigin(); 545 FileNode target_node = file_job.getDestination(); 546 547 File source_file = source_node.getFile(); 548 File target_file = target_node.getFile(); 549 // Move the non-folder level metadata assigned to the original file to the new file 550 CollectionTreeNode new_target_node = new CollectionTreeNode(target_file); 551 ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToFile(source_file); 552 MetadataXMLFileManager.removeMetadata((CollectionTreeNode) source_node, assigned_metadata); 553 MetadataXMLFileManager.addMetadata((CollectionTreeNode) new_target_node, assigned_metadata); 554 555 // now delete the original 556 doFileDelete(file_job); 557 } 539 558 540 559 private void processFileJob(FileJob file_job) … … 562 581 file_status.setText(Dictionary.get("FileActions.Deleting", formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width))); 563 582 doEmptyDirectoryDelete(file_job); 583 return; 564 584 } 565 585 … … 575 595 doDirectoryDelete(file_job); 576 596 } 597 return; 577 598 } 578 599 579 600 // Copy job 580 if (file_job.type == FileJob.COPY ) {601 if (file_job.type == FileJob.COPY || file_job.type == FileJob.COPY_FILE_ONLY) { 581 602 file_status.setText(Dictionary.get("FileActions.Copying", formatPath("FileActions.Copying", source_file.getAbsolutePath(), file_status.getSize().width))); 582 603 if (source_file.isFile()) { … … 588 609 doDirectoryCopy(file_job); 589 610 } 611 return; 590 612 } 591 613 … … 601 623 doDirectoryMove(file_job); 602 624 } 603 } 625 return; 626 } 627 // Replace job 628 if (file_job.type == FileJob.REPLACE) { 629 file_status.setText(Dictionary.get("FileActions.Replacing", formatPath("FileActions.Replacing", source_file.getAbsolutePath(), file_status.getSize().width))); 630 doFileReplace(file_job); 631 return; 632 } 633 634 635 636 604 637 } 605 638
Note:
See TracChangeset
for help on using the changeset viewer.