Changeset 5992


Ignore:
Timestamp:
2003-11-25T16:19:15+13:00 (20 years ago)
Author:
jmt12
Message:

MSMEvents are now created including an integer to specify what user action caused them - thus I am able to differentiate between assigns and replaces later on

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/MetadataSetManager.java

    r5794 r5992  
    244244    }
    245245
     246/** Fire a metadata value changed message, whose id is to be generated now, and whose action code is -1, off to all registered listeners. */
     247    public void fireMetadataChanged(FileNode node, Metadata old_data, Metadata new_data) {
     248    fireMetadataChanged(System.currentTimeMillis(), node, old_data, new_data, -1);
     249    }
     250
    246251    /** Fire a metadata value changed message, whose id is to be generated now, off to all registered listeners. */
    247     public void fireMetadataChanged(FileNode node, Metadata old_data, Metadata new_data) {
     252    public void fireMetadataChanged(FileNode node, Metadata old_data, Metadata new_data, int action) {
    248253    fireMetadataChanged(System.currentTimeMillis(), node, old_data, new_data);
    249254    }
     
    251256    /** Fire a metadata value changed message off to all registered listeners. */
    252257    public void fireMetadataChanged(long id, FileNode node, Metadata old_data, Metadata new_data) {
     258    fireMetadataChanged(id, node, old_data, new_data, -1);
     259    }
     260
     261    public void fireMetadataChanged(long id, FileNode node, Metadata old_data, Metadata new_data, int action) {
    253262    if(old_data != null) {
    254263        old_data.getElement().dec();
     
    259268    ///ystem.err.println("Metadata changed: " + record + " > '" + old_data + "' -> '" + new_data + "'");
    260269    // Create a new MSMEvent based on the record.
    261     MSMEvent event = new MSMEvent(this, id, node, old_data, new_data);
     270    MSMEvent event = new MSMEvent(this, id, node, old_data, new_data, action);
    262271    // Then send it to all the listeners.
    263272    for(int i = 0; i < listeners.size(); i++) {
     
    900909    // Reset undo buffer
    901910    undo_buffer.clear();
    902     // Simplier than the others. Simply remove the metadata.
     911    // Simplier than the others. Simply remove the metadata. Note that we only bother prompting if there is more than one
    903912    int action = MetaEditPrompt.CONFIRM;
     913    if(records.length == 1) {
     914        action = MetaEditPrompt.REMOVE;
     915    }
    904916    // Now remove metadata from the selected file nodes.
    905917    for(int i = 0; action != MetaEditPrompt.CANCEL && i < records.length; i++) {
     
    10481060    // And update the old with it.
    10491061    if(action == -1) {
     1062        //Note that we only bother prompting if there is more than one
    10501063        action = MetaEditPrompt.CONFIRM;
     1064        if(records.length == 1) {
     1065        action = MetaEditPrompt.OVERWRITE;
     1066        }
    10511067    }
    10521068    // And then update each selection file node.
     
    10781094    // Super special exception for accumulate all action. We are going to add this metadata anyway, regardless of whats already there, so just add it.
    10791095    if(action == MetaEditPrompt.ACCUMULATE_ALL || action == MetaEditPrompt.OVERWRITE_ALL) {
    1080         fireMetadataChanged(id, record, null, data);
     1096        fireMetadataChanged(id, record, null, data, action - 1); // Transform action to accumulate or overwrite
    10811097    }
    10821098    else {
     
    11151131            if(old_data.getElement().equals(data.getElement()) && old_data.isFileLevel()) {
    11161132                // We have a match. Remove this metadata.
    1117                 fireMetadataChanged(id, record, old_data, null);
     1133                fireMetadataChanged(id, record, old_data, null, MetaEditPrompt.REMOVE);
    11181134                // Add it to our undo buffer.
    11191135                undo.add(old_data);
     
    11311147        if((user_action == MetaEditPrompt.ACCUMULATE || user_action == MetaEditPrompt.ACCUMULATE_ALL || user_action == MetaEditPrompt.OVERWRITE || user_action == MetaEditPrompt.OVERWRITE_ALL) && !metadata.contains(data)) {
    11321148            ///ystem.err.println("Adding metadata " + data);
    1133             fireMetadataChanged(id, record, null, data);
     1149            fireMetadataChanged(id, record, null, data, ((user_action == MetaEditPrompt.ACCUMULATE || user_action == MetaEditPrompt.ACCUMULATE_ALL) ? MetaEditPrompt.ACCUMULATE : MetaEditPrompt.OVERWRITE));
    11341150            // The last element in undo is the new element.
    11351151            undo.add(data);
     
    11931209        }
    11941210        if(action == MetaEditPrompt.REMOVE_ALL || user_action == MetaEditPrompt.REMOVE) {
    1195         fireMetadataChanged(id, record, data, null);
     1211        fireMetadataChanged(id, record, data, null, MetaEditPrompt.REMOVE);
    11961212        undo.add(data);
    11971213        }
     
    12151231    // If there is no undo then we can't do anything, but there should be
    12161232    if(undo != null && undo.size() > 0) {
    1217                 // The last piece of data in an add actions undo buffer is the metadata that was added
     1233        // The last piece of data in an add actions undo buffer is the metadata that was added
    12181234        Metadata data = (Metadata) undo.remove(undo.size() - 1);
    1219                 // Remove the data
    1220         fireMetadataChanged(id, record, data, null);
    1221                 // If we removed other metadata when adding this metadata restore it too
     1235        // Remove the data
     1236        fireMetadataChanged(id, record, data, null, MetaEditPrompt.REMOVE);
     1237        // If we removed other metadata when adding this metadata restore it too
    12221238        for(int i = 0; i < undo.size(); i++) {
    12231239        Metadata old_data = (Metadata) undo.get(i);
    1224         fireMetadataChanged(id, record, null, old_data);
     1240        fireMetadataChanged(id, record, null, old_data, MetaEditPrompt.ACCUMULATE);
    12251241        }
    12261242    }
     
    12351251    // Ensure that we have something to undo
    12361252    if(undo != null && undo.size() == 1) {
    1237                 // The undo buffer should contain exactly one entry, the metadata removed
     1253        // The undo buffer should contain exactly one entry, the metadata removed
    12381254        Metadata data = (Metadata) undo.get(0);
    1239         fireMetadataChanged(id, record, null, data);
     1255        fireMetadataChanged(id, record, null, data, MetaEditPrompt.ACCUMULATE);
    12401256    }
    12411257    }
     
    12501266        Metadata old_data = (Metadata) undo.get(0);
    12511267        Metadata new_data = (Metadata) undo.get(1);
    1252         fireMetadataChanged(id, record, new_data, null);
     1268        fireMetadataChanged(id, record, new_data, null, MetaEditPrompt.REMOVE);
    12531269        if(old_data != new_data) { // Correct reference comparison
    1254         fireMetadataChanged(id, record, null, old_data);
     1270        fireMetadataChanged(id, record, null, old_data, MetaEditPrompt.ACCUMULATE);
    12551271        }
    12561272    }
     
    12781294    if(metadata.contains(old_data)) {
    12791295        ArrayList undo = new ArrayList();
    1280                 // If we are to prompt the user, do so.
     1296        // If we are to prompt the user, do so.
    12811297        if(action == MetaEditPrompt.CONFIRM) {
    12821298        MetaEditPrompt mep = new MetaEditPrompt(MetaEditPrompt.UPDATE_PROMPT, multiple_selection, record.getFile(), old_data.getElement().toString(), old_data.getValue(), new_data.getValue());
     
    12921308        // If this is file level then we can do a normal replace
    12931309        if(file_level) {
    1294             fireMetadataChanged(id, record, old_data, new_data);
     1310            fireMetadataChanged(id, record, old_data, new_data, MetaEditPrompt.OVERWRITE);
    12951311            undo.add(old_data);
    12961312            undo.add(new_data);
     
    12981314        // Otherwise we are dealing with someone attempting to override inherited metadata, so we actually fire an add. To this end we add new data twice to the undo buffer, thus we can detect if this has happened.
    12991315        else {
    1300             fireMetadataChanged(id, record, null, new_data);
     1316            fireMetadataChanged(id, record, null, new_data, MetaEditPrompt.OVERWRITE);
    13011317            undo.add(new_data);
    13021318            undo.add(new_data);
Note: See TracChangeset for help on using the changeset viewer.