Ignore:
Timestamp:
2004-10-13T14:48:20+13:00 (20 years ago)
Author:
mdewsnip
Message:

Finally committing the (many) changes to the GLI to use the new metadata code... I hope this doesn't have too many bugs in it and committing it now doesn't stuff anyone up! (Katherine said I could commit it, so blame her if anything goes wrong).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r8243 r8313  
    3838import org.greenstone.gatherer.gui.LongProgressBar;
    3939import org.greenstone.gatherer.gui.tree.DragTree;
     40import org.greenstone.gatherer.metadata.MetadataValue;
     41import org.greenstone.gatherer.metadata.MetadataXMLFileManager;
    4042import org.greenstone.gatherer.util.ArrayTools;
    4143import org.greenstone.gatherer.util.DragComponent;
     
    397399                        if(job.type == FileJob.COPY) {
    398400                        // A copy is undone with a delete, so it doesn't really matter where the file originally came from (we're not moving it back there, but into the recycle bin). You may also notice we don't make use of the target parent record. This is because no undo action needs this information, and even if it did it could simply ask for records parent!
    399                         // Gatherer.c_man.undo.addUndo(job.ID(), UndoManager.FILE_COPY, null, null, job.target, directory_record, job.undo);
    400401                        }
    401402                        else {
    402403                        // Movements however do need a source and source parent so the file can be moved back to the correct place.
    403                         // Gatherer.c_man.undo.addUndo(job.ID(), UndoManager.FILE_MOVE, job.source, (FileNode)origin_node.getParent(), job.target, directory_record, job.undo);
    404404                        }
    405405                    }
     
    431431                    // Show warning.
    432432                    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.File_Not_Found_Message", source_file.getName()), Dictionary.get("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE);
    433                 // Force refresh of source folder.
     433                    // Force refresh of source folder.
    434434                    source_model.refresh(new TreePath(((FileNode)origin_node.getParent()).getPath()));
    435435                }
    436436               
    437437                // We can't have been cancelled, and we must have created a new FileNode during the above phase, before we can handle metadata.
    438                 if(!cancel_action && new_node != null) {
    439                 /* Time to handle any existing metadata. */
    440                 // If the directory came from inside our collection...
     438                if (!cancel_action && new_node != null) {
     439                    /* Time to handle any existing metadata. */
     440                    // If the directory came from inside our collection...
    441441                    if (job.source.toString().equals("Collection")) {
    442                     ///ystem.err.println("Move within collection...");
    443                     // we just retrieve the metadata attached to the origin node...
    444                     ArrayList existing_metadata = Gatherer.c_man.getCollection().gdm.getMetadataOnly(source_file);
    445                     ///atherer.println("Existing metadata for " + origin_node + ": " + gdm.toString(existing_metadata));
    446                     // then assign this remainder to the new folder.
    447                     ///ystem.err.println("New metadata: " + gdm.toString(existing_metadata));
    448                     Gatherer.c_man.getCollection().gdm.addMetadata(new_node, existing_metadata);
    449                     existing_metadata = null;
    450                     }
    451                 // If it came from the recycle bin retrieve the metadata from there, once again remembering to account for inherited metadata
    452 //                      else if (job.source.toString().equals("Undo")) {
    453 //                      // Retrieve metadata from the recycle bin
    454 //                      ArrayList existing_metadata = Gatherer.c_man.undo.getMetadata(source_file);
    455 //                      // then assign this remainder to the new folder.
    456 //                      Gatherer.c_man.getCollection().gdm.addMetadata(new_node, existing_metadata);
    457 //                      existing_metadata = null;
    458 //                      }
    459                 // Otherwise if it came from the workspace use the MSMs parsers to search for folder level metadata (such as metadata.xml or marc records).
     442                    // System.err.println("Move within collection...");
     443
     444                    // Get the non-folder level metadata assigned to the origin node...
     445                    ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToFile(source_file);
     446                    // ...and remove it from the original node and assign it to the new folder
     447                    for (int i = 0; i < assigned_metadata.size(); i++) {
     448                        MetadataValue metadata_value = (MetadataValue) assigned_metadata.get(i);
     449                        MetadataXMLFileManager.removeMetadata(origin_node, metadata_value);
     450                        MetadataXMLFileManager.addMetadata(new_node, metadata_value);
     451                    }
     452                    }
     453                    // If it came from the workspace search for metadata assigned to the file
    460454                    else if (job.source.toString().equals("Workspace")) {
    461                     cancel_action = !Gatherer.c_man.getCollection().msm.searchForMetadata(new_node, origin_node, job.folder_level);
     455                    ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToExternalFile(origin_node.getFile());
     456                    for (int i = 0; i < assigned_metadata.size(); i++) {
     457                        MetadataValue metadata_value = (MetadataValue) assigned_metadata.get(i);
     458                        MetadataXMLFileManager.addMetadata(new_node, metadata_value);
     459                    }   
    462460                    }
    463461                }
     
    475473            }
    476474
    477             // If the source is an empty directory or a file. Don't do anything to the root node of a tree.
     475            // If the source is a file or an empty directory (but not the root node of a tree)
    478476            File[] child_list = source_file.listFiles();
    479             if(source_file.isFile() || (child_list != null && (child_list.length == 0 || (child_list.length == 1 && child_list[0].getName().equals(Utility.METADATA_XML))) && origin_node.getParent() != null)) {
    480                 ///atherer.println("File or empty directory.");
    481                 // Delete any metadata.xml still in the directory.
    482                 if(child_list != null && child_list.length == 1) {
    483                 child_list[0].delete();
    484                 }
    485 
    486                 ///atherer.println("Origin is file or is directory and is empty.");
    487                 // update status area
     477            if (source_file.isFile() || (child_list != null && child_list.length == 0 && origin_node.getParent() != null)) {
     478                // System.err.println("Deleting file: " + source_file.getAbsolutePath());
     479
     480                // Update status area
    488481                String args[] = new String[1];
    489                 // args[0] = "" + (queue.size() + 1) + "";
    490482                args[0] = Utility.formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width);
    491483                file_status.setText(Dictionary.get("FileActions.Deleting", args));
    492                 args = null;
    493 
    494                 // Remove its metadata
    495                 ArrayList metadatum = null;
    496 //                  if(job.source == Gatherer.c_man.undo) {
    497 //                  Gatherer.c_man.undo.addMetadata(target_file, metadatum);
    498 //                  }
    499 //                  else {
    500                 metadatum = Gatherer.c_man.getCollection().gdm.removeMetadata(origin_node.getFile());
    501                 // }
    502                 // determine its parent node
    503                 FileNode parent_record = (FileNode)origin_node.getParent();
     484
     485                // If it is a metadata.xml file, we must unload it
     486                if (source_file.getName().equals(Utility.METADATA_XML)) {
     487                MetadataXMLFileManager.unloadMetadataXMLFile(source_file);
     488                }
     489
     490                // Remove the metadata assigned directly to the file
     491                ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToFile(origin_node.getFile());
     492                for (int i = 0; i < assigned_metadata.size(); i++) {
     493                MetadataValue metadata_value = (MetadataValue) assigned_metadata.get(i);
     494                MetadataXMLFileManager.removeMetadata(origin_node, metadata_value);
     495                }
     496
    504497                // Remove from model
    505                 if(parent_record != null) {
     498                FileNode parent_record = (FileNode) origin_node.getParent();
     499                if (parent_record != null) {
    506500                SynchronizedTreeModelTools.removeNodeFromParent(source_model, origin_node);
    507501                }
    508                 // If we are deleting
    509                 File recycled_file = null;
    510                 FileNode recycled_parent = null;
    511                 // delete the source file
     502
     503                // Delete the source file
    512504                Utility.delete(source_file);
    513505            }
Note: See TracChangeset for help on using the changeset viewer.