Changeset 4444
- Timestamp:
- 2003-06-03T11:19:35+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/table/GTableModel.java
r4366 r4444 277 277 if(0 <= row && row < current_metadata.size()) { 278 278 Metadata entry = (Metadata) current_metadata.get(row); 279 280 279 ///ystem.err.println("There are " + file_nodes.length + " selected files."); 280 ///ystem.err.println("This metadata is attached to " + entry.getCount() + " of them."); 281 281 if(entry.getCount() == file_nodes.length) { 282 282 return true; … … 292 292 // First check whether this record is one of those that we have showing. 293 293 if(file_nodes != null && file_node != null && ArrayTools.contains(file_nodes, file_node)) { 294 294 // Brute force solution... rebuild the table. 295 295 if(file_nodes != null && file_nodes.length > 0) { 296 296 current_metadata.clear(); … … 299 299 builder.start(); 300 300 } 301 302 /*303 // If old metadata has been removed then remove it. Update the unassigned list if necessary (first checking if there are other metadata entries with the same element, and furthermore if the were inherited metadata being supressed).304 if(old_data != null) {305 System.err.println("Remove: " + old_data);306 // Determine the level of this metadata307 ArrayList modified_metadata = null;308 if(old_data.isFileLevel()) {309 modified_metadata = file_metadata;310 }311 else {312 modified_metadata = inherited_metadata;313 }314 315 int index = -1;316 if((index = modified_metadata.indexOf(old_data)) != -1) {317 Metadata data = (Metadata) modified_metadata.get(index);318 data.dec();319 // If we just removed the last occurance of this metadata, delete it320 if(data.getCount() == 0) {321 remove(modified_metadata, data);322 // If there are no further occurances of the element of this entry, add entry to unassigned_metadata.323 boolean found = false;324 ElementWrapper element = data.getElement();325 // Search the current metadata326 for(int i = 0; i < modified_metadata.size(); i++) {327 Metadata sibling = (Metadata) modified_metadata.get(i);328 if(sibling.getElement().equals(element)) {329 found = true;330 }331 }332 // And the inherited metadata if we haven't already333 if(modified_metadata != inherited_metadata) {334 for(int i = 0; !found && i < inherited_metadata.size(); i++) {335 Metadata sibling = (Metadata) inherited_metadata.get(i);336 if(sibling.getElement().equals(element)) {337 found = true;338 }339 }340 }341 // If we get this far and still haven't found a match then we do something very tricky. We retrieve all of the metadata for the parent file and notice any inherited nodes that were previously overwritten by the metadata entry we removed. The reason we use the parent is that we can't just assume that the GDMDocument changes occured before this method was called. Thus our about-to-be-removed overwritting metadata may still be in effect if we just called getMetadata for this file.342 if(!found) {343 ArrayList parent_metadatum = Gatherer.c_man.getCollection().gdm.getMetadata((file_node.getFile()).getParentFile());344 // For each piece of parent metadata345 for(int i = parent_metadatum.size(); i > 0; i--) {346 Metadata parent_metadata = (Metadata) parent_metadatum.get(i - 1);347 // If we found some previously suppressed metadata then add it and say we found something.348 if(!inherited_metadata.contains(parent_metadata)) {349 ///ystem.err.println("Restoring overwritten inherited metadata: " + parent_metadata);350 found = true;351 parent_metadata.setCount(1);352 parent_metadata.setFileLevel(false); // Has to be folder level doesn't it.353 add(inherited_metadata, parent_metadata);354 }355 }356 // Run this getMetadata again to restore all of the file level and source file entries (they would have changed to reflect the parents call.357 Gatherer.c_man.getCollection().gdm.getMetadata(file_node.getFile());358 }359 // And only then, if we haven't found a substitute, may we add a null metadata.360 if(!found) {361 add(unassigned_metadata, new Metadata(data.getElement()));362 }363 }364 }365 }366 // If new metadata has been assigned, remove its entry from the unassigned metadata list. Furthermore add the new entry to either the file or folder metadata list depending on its level. Remember to rebuild the common metadata lists.367 if(new_data != null) {368 ///ystem.err.println("Add: " + new_data);369 // Create dummy 'unassigned' metadata from the new metadata and remove it from the unassigned list (if its even there)370 remove(unassigned_metadata, new Metadata(new_data.getElement()));371 // Determine if we are adding the new node at the file or folder level.372 ArrayList modified_metadata = null;373 if(new_data.isFileLevel()) {374 modified_metadata = file_metadata;375 // If its file metadata, and its set to overwrite, then we need to remove any row it would overwrite.376 if(new_data.accumulates()) {377 // All good.378 }379 else {380 // Remove any entries in the inherited_metadata that would be overwritten381 ElementWrapper element = new_data.getElement();382 for(int i = 0; i < inherited_metadata.size(); i++) {383 Metadata sibling = (Metadata) inherited_metadata.get(i);384 if(sibling.getElement().equals(element)) {385 inherited_metadata.remove(sibling);386 }387 }388 }389 }390 else {391 modified_metadata = inherited_metadata;392 }393 // And add it.394 int index = -1;395 if((index = modified_metadata.indexOf(new_data)) == -1) {396 add(modified_metadata, new_data);397 new_data.setCount(1);398 }399 else {400 Metadata data = (Metadata) modified_metadata.get(index);401 data.inc();402 data = null;403 }404 modified_metadata = null;405 }406 // As a current visible table is most likely affected, update the table component. We do this by calling changeView so as to also update any compound list.407 //changeView(current_view);408 */409 }410 else {411 ///ystem.err.println("FileNodes = " + file_nodes);412 ///ystem.err.println("FileNode = " + file_node);413 301 } 414 302 } … … 487 375 488 376 public void run() { 489 Vector elements = Gatherer.c_man.getCollection().msm.getElements(); 490 // Show some visual indication that building is occuring. 491 //assigned_metadata_view.setEnabled(false); 492 //unassigned_metadata_view.setEnabled(false); 493 //activity_bar.setMaximum(file_nodes.length + elements.size()); 494 //activity_bar.setValue(0); 495 //activity_bar.setString(Gatherer.dictionary.get("MetaEdit.Building")); 496 //long start = System.currentTimeMillis(); 497 498 ArrayList known_elements = new ArrayList(); // Elements that have metadata assigned. 499 for(int i = 0; i < file_nodes.length; i++) { 500 File current_file = file_nodes[i].getFile(); 501 // The current assigned metadata for this file. 502 ArrayList metadatum = Gatherer.c_man.getCollection().gdm.getAllMetadata(current_file); 503 for(int j = 0; j < metadatum.size(); j++) { 504 Metadata data = (Metadata) metadatum.get(j); 505 // Determine the target list by the metadata level 506 ArrayList modified_metadata; 507 if(data.isFileLevel()) { 508 modified_metadata = file_metadata; 377 if(Gatherer.c_man != null && Gatherer.c_man.ready()) { 378 Vector elements = Gatherer.c_man.getCollection().msm.getElements(); 379 // Show some visual indication that building is occuring. 380 //assigned_metadata_view.setEnabled(false); 381 //unassigned_metadata_view.setEnabled(false); 382 //activity_bar.setMaximum(file_nodes.length + elements.size()); 383 //activity_bar.setValue(0); 384 //activity_bar.setString(Gatherer.dictionary.get("MetaEdit.Building")); 385 //long start = System.currentTimeMillis(); 386 387 ArrayList known_elements = new ArrayList(); // Elements that have metadata assigned. 388 for(int i = 0; i < file_nodes.length; i++) { 389 File current_file = file_nodes[i].getFile(); 390 // The current assigned metadata for this file. 391 ArrayList metadatum = Gatherer.c_man.getCollection().gdm.getAllMetadata(current_file); 392 for(int j = 0; j < metadatum.size(); j++) { 393 Metadata data = (Metadata) metadatum.get(j); 394 // Determine the target list by the metadata level 395 ArrayList modified_metadata; 396 if(data.isFileLevel()) { 397 modified_metadata = file_metadata; 398 } 399 else { 400 showInheritedMetadataWarning(); 401 modified_metadata = inherited_metadata; 402 } 403 int index = -1; 404 // Don't show hidden metadata 405 // If the given metadata already exists in our list of modified metadata then increment its commonality count. 406 if((index = modified_metadata.indexOf(data)) != -1) { 407 data = (Metadata) modified_metadata.get(index); 408 ///ystem.err.println("Increasing count:" + element); 409 data.inc(); 410 // If the table shown is stale, refresh it. 411 //if((modified_metadata == file_metadata && current_view == SHOW_FILE) || (modified_metadata == inherited_metadata && current_view == SHOW_INHERITED)) { 412 // fireTableRowsUpdated(index, index); 413 //} 414 // We may have to update a compound list 415 //else if(current_view == SHOW_ALL || current_view == SHOW_ASSIGNED) { 416 if((index = current_metadata.indexOf(data)) == -1) { 417 fireTableRowsUpdated(index, index); 418 } 419 //} 420 } 421 // Ensure the metadata's element is in our list of showable elements. 422 else if(contains(elements, data.getElement())) { 423 ///ystem.err.println("Setting count to one: " + element); 424 data.setCount(1); 425 index = add(modified_metadata, data); // Add to assigned metadata. 426 known_elements.add(data.getElement()); 427 // If the table shown is stale, refresh it. 428 //if((modified_metadata == file_metadata && current_view == SHOW_FILE) || (modified_metadata == inherited_metadata && current_view == SHOW_INHERITED)) { 429 // fireTableRowsInserted(index, index); 430 //} 431 // We may have to update a compound list 432 //else if(current_view == SHOW_ALL || current_view == SHOW_ASSIGNED) { 433 if((index = current_metadata.indexOf(data)) == -1) { 434 index = add(current_metadata, data); 435 fireTableRowsInserted(index, index); 436 } 437 else { 438 fireTableRowsUpdated(index, index); 439 } 440 //} 441 } 442 else { 443 ///ystem.err.println("No.\n***** Cannot match element so it must be hidden, right? *****"); 444 } 509 445 } 510 else { 511 showInheritedMetadataWarning(); 512 modified_metadata = inherited_metadata; 513 } 514 int index = -1; 515 // Don't show hidden metadata 516 // If the given metadata already exists in our list of modified metadata then increment its commonality count. 517 if((index = modified_metadata.indexOf(data)) != -1) { 518 data = (Metadata) modified_metadata.get(index); 519 ///ystem.err.println("Increasing count:" + element); 520 data.inc(); 521 // If the table shown is stale, refresh it. 522 //if((modified_metadata == file_metadata && current_view == SHOW_FILE) || (modified_metadata == inherited_metadata && current_view == SHOW_INHERITED)) { 523 // fireTableRowsUpdated(index, index); 446 //activity_bar.setValue(activity_bar.getValue() + 1); 447 Gatherer.g_man.metaedit_pane.validateMetadataTable(); 448 } 449 // Add entries for the currently unassigned metadata. You can determine these as the difference between elements and known_elements. 450 for(int k = 0; k < elements.size(); k++) { 451 // For each key. 452 ElementWrapper element = (ElementWrapper) elements.get(k); 453 if(!known_elements.contains(element)) { 454 Metadata data = new Metadata(element); 455 int index = add(unassigned_metadata, data); 456 // Inform everyone that the model has changed, but only if it affects the current view. 457 //if(current_view == SHOW_UNASSIGNED) { 458 // fireTableRowsInserted(index, index); 524 459 //} 525 // We may have to update a compound list 526 //else if(current_view == SHOW_ALL || current_view == SHOW_ASSIGNED) { 527 if((index = current_metadata.indexOf(data)) == -1) { 528 fireTableRowsUpdated(index, index); 529 } 530 //} 531 } 532 // Ensure the metadata's element is in our list of showable elements. 533 else if(contains(elements, data.getElement())) { 534 ///ystem.err.println("Setting count to one: " + element); 535 data.setCount(1); 536 index = add(modified_metadata, data); // Add to assigned metadata. 537 known_elements.add(data.getElement()); 538 // If the table shown is stale, refresh it. 539 //if((modified_metadata == file_metadata && current_view == SHOW_FILE) || (modified_metadata == inherited_metadata && current_view == SHOW_INHERITED)) { 540 // fireTableRowsInserted(index, index); 541 //} 542 // We may have to update a compound list 543 //else if(current_view == SHOW_ALL || current_view == SHOW_ASSIGNED) { 460 //else if(current_view == SHOW_ALL) { 544 461 if((index = current_metadata.indexOf(data)) == -1) { 545 462 index = add(current_metadata, data); … … 547 464 } 548 465 else { 549 fireTableRowsUpdated(index, index); 466 fireTableRowsUpdated(index, index); 550 467 } 551 468 //} 552 469 } 553 else { 554 ///ystem.err.println("No.\n***** Cannot match element so it must be hidden, right? *****"); 555 } 556 } 557 //activity_bar.setValue(activity_bar.getValue() + 1); 558 Gatherer.g_man.metaedit_pane.validateMetadataTable(); 559 } 560 // Add entries for the currently unassigned metadata. You can determine these as the difference between elements and known_elements. 561 for(int k = 0; k < elements.size(); k++) { 562 // For each key. 563 ElementWrapper element = (ElementWrapper) elements.get(k); 564 if(!known_elements.contains(element)) { 565 Metadata data = new Metadata(element); 566 int index = add(unassigned_metadata, data); 567 // Inform everyone that the model has changed, but only if it affects the current view. 568 //if(current_view == SHOW_UNASSIGNED) { 569 // fireTableRowsInserted(index, index); 570 //} 571 //else if(current_view == SHOW_ALL) { 572 if((index = current_metadata.indexOf(data)) == -1) { 573 index = add(current_metadata, data); 574 fireTableRowsInserted(index, index); 575 } 576 else { 577 fireTableRowsUpdated(index, index); 578 } 579 //} 580 } 581 //activity_bar.setValue(activity_bar.getValue() + 1); 582 Gatherer.g_man.metaedit_pane.validateMetadataTable(); 583 } 584 //long end = System.currentTimeMillis(); 585 ///ystem.err.println("Took " + (end - start) + "ms to build table."); 586 //assigned_metadata_view.setEnabled(true); 587 //unassigned_metadata_view.setEnabled(true); 588 //activity_bar.setValue(activity_bar.getMaximum()); 589 //activity_bar.setString(Gatherer.dictionary.get("MetaEdit.Ready")); 590 Collections.sort(current_metadata, MSMUtils.METADATA_COMPARATOR); 591 fireTableDataChanged(); 592 // Finally complete 470 //activity_bar.setValue(activity_bar.getValue() + 1); 471 Gatherer.g_man.metaedit_pane.validateMetadataTable(); 472 } 473 //long end = System.currentTimeMillis(); 474 ///ystem.err.println("Took " + (end - start) + "ms to build table."); 475 //assigned_metadata_view.setEnabled(true); 476 //unassigned_metadata_view.setEnabled(true); 477 //activity_bar.setValue(activity_bar.getMaximum()); 478 //activity_bar.setString(Gatherer.dictionary.get("MetaEdit.Ready")); 479 Collections.sort(current_metadata, MSMUtils.METADATA_COMPARATOR); 480 fireTableDataChanged(); 481 } 482 else { 483 484 } 485 // Finally complete (even if we didn't do anything). 593 486 complete = true; 594 595 if( selected_metadata != null) {487 // If in the in between we've been asked to select a certain metadata, we action that now. 488 if(getRowCount() > 0 && selected_metadata != null) { 596 489 setSelectedMetadata(selected_metadata); 597 490 }
Note:
See TracChangeset
for help on using the changeset viewer.