Changeset 5992
- Timestamp:
- 2003-11-25T16:19:15+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/MetadataSetManager.java
r5794 r5992 244 244 } 245 245 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 246 251 /** 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) { 248 253 fireMetadataChanged(System.currentTimeMillis(), node, old_data, new_data); 249 254 } … … 251 256 /** Fire a metadata value changed message off to all registered listeners. */ 252 257 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) { 253 262 if(old_data != null) { 254 263 old_data.getElement().dec(); … … 259 268 ///ystem.err.println("Metadata changed: " + record + " > '" + old_data + "' -> '" + new_data + "'"); 260 269 // 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); 262 271 // Then send it to all the listeners. 263 272 for(int i = 0; i < listeners.size(); i++) { … … 900 909 // Reset undo buffer 901 910 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 903 912 int action = MetaEditPrompt.CONFIRM; 913 if(records.length == 1) { 914 action = MetaEditPrompt.REMOVE; 915 } 904 916 // Now remove metadata from the selected file nodes. 905 917 for(int i = 0; action != MetaEditPrompt.CANCEL && i < records.length; i++) { … … 1048 1060 // And update the old with it. 1049 1061 if(action == -1) { 1062 //Note that we only bother prompting if there is more than one 1050 1063 action = MetaEditPrompt.CONFIRM; 1064 if(records.length == 1) { 1065 action = MetaEditPrompt.OVERWRITE; 1066 } 1051 1067 } 1052 1068 // And then update each selection file node. … … 1078 1094 // Super special exception for accumulate all action. We are going to add this metadata anyway, regardless of whats already there, so just add it. 1079 1095 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 1081 1097 } 1082 1098 else { … … 1115 1131 if(old_data.getElement().equals(data.getElement()) && old_data.isFileLevel()) { 1116 1132 // We have a match. Remove this metadata. 1117 fireMetadataChanged(id, record, old_data, null );1133 fireMetadataChanged(id, record, old_data, null, MetaEditPrompt.REMOVE); 1118 1134 // Add it to our undo buffer. 1119 1135 undo.add(old_data); … … 1131 1147 if((user_action == MetaEditPrompt.ACCUMULATE || user_action == MetaEditPrompt.ACCUMULATE_ALL || user_action == MetaEditPrompt.OVERWRITE || user_action == MetaEditPrompt.OVERWRITE_ALL) && !metadata.contains(data)) { 1132 1148 ///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)); 1134 1150 // The last element in undo is the new element. 1135 1151 undo.add(data); … … 1193 1209 } 1194 1210 if(action == MetaEditPrompt.REMOVE_ALL || user_action == MetaEditPrompt.REMOVE) { 1195 fireMetadataChanged(id, record, data, null );1211 fireMetadataChanged(id, record, data, null, MetaEditPrompt.REMOVE); 1196 1212 undo.add(data); 1197 1213 } … … 1215 1231 // If there is no undo then we can't do anything, but there should be 1216 1232 if(undo != null && undo.size() > 0) { 1217 1233 // The last piece of data in an add actions undo buffer is the metadata that was added 1218 1234 Metadata data = (Metadata) undo.remove(undo.size() - 1); 1219 1220 fireMetadataChanged(id, record, data, null );1221 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 1222 1238 for(int i = 0; i < undo.size(); i++) { 1223 1239 Metadata old_data = (Metadata) undo.get(i); 1224 fireMetadataChanged(id, record, null, old_data );1240 fireMetadataChanged(id, record, null, old_data, MetaEditPrompt.ACCUMULATE); 1225 1241 } 1226 1242 } … … 1235 1251 // Ensure that we have something to undo 1236 1252 if(undo != null && undo.size() == 1) { 1237 1253 // The undo buffer should contain exactly one entry, the metadata removed 1238 1254 Metadata data = (Metadata) undo.get(0); 1239 fireMetadataChanged(id, record, null, data );1255 fireMetadataChanged(id, record, null, data, MetaEditPrompt.ACCUMULATE); 1240 1256 } 1241 1257 } … … 1250 1266 Metadata old_data = (Metadata) undo.get(0); 1251 1267 Metadata new_data = (Metadata) undo.get(1); 1252 fireMetadataChanged(id, record, new_data, null );1268 fireMetadataChanged(id, record, new_data, null, MetaEditPrompt.REMOVE); 1253 1269 if(old_data != new_data) { // Correct reference comparison 1254 fireMetadataChanged(id, record, null, old_data );1270 fireMetadataChanged(id, record, null, old_data, MetaEditPrompt.ACCUMULATE); 1255 1271 } 1256 1272 } … … 1278 1294 if(metadata.contains(old_data)) { 1279 1295 ArrayList undo = new ArrayList(); 1280 1296 // If we are to prompt the user, do so. 1281 1297 if(action == MetaEditPrompt.CONFIRM) { 1282 1298 MetaEditPrompt mep = new MetaEditPrompt(MetaEditPrompt.UPDATE_PROMPT, multiple_selection, record.getFile(), old_data.getElement().toString(), old_data.getValue(), new_data.getValue()); … … 1292 1308 // If this is file level then we can do a normal replace 1293 1309 if(file_level) { 1294 fireMetadataChanged(id, record, old_data, new_data );1310 fireMetadataChanged(id, record, old_data, new_data, MetaEditPrompt.OVERWRITE); 1295 1311 undo.add(old_data); 1296 1312 undo.add(new_data); … … 1298 1314 // 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. 1299 1315 else { 1300 fireMetadataChanged(id, record, null, new_data );1316 fireMetadataChanged(id, record, null, new_data, MetaEditPrompt.OVERWRITE); 1301 1317 undo.add(new_data); 1302 1318 undo.add(new_data);
Note:
See TracChangeset
for help on using the changeset viewer.