Changeset 4651


Ignore:
Timestamp:
2003-06-13T15:43:55+12:00 (21 years ago)
Author:
mdewsnip
Message:

Fairly substantial changes, including a totally new ModelBuilder. The table should now be much more consistent, calculate commonness much better, and not have any race conditions when building. Still don't think it's perfect tho' - the ModelBuilder thread stuff is a little ugly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/table/GTableModel.java

    r4627 r4651  
    4848    extends AbstractTableModel
    4949    implements MSMListener {
     50
    5051    /** The source for the data currently shown in the table. May be any of the other three metadata lists, or the union of all of them. */
    51     private ArrayList current_metadata    = new ArrayList();
    52     /** The metadata currently assigned at the file level. */
    53     private ArrayList file_metadata       = null; // new ArrayList();
    54     /** The metadata currently assigned at the folder level. */
    55     private ArrayList inherited_metadata  = null; // new ArrayList();
    56     /** The metadata currently unassigned. */
    57     private ArrayList unassigned_metadata = null; // new ArrayList();
     52    private ArrayList current_metadata = new ArrayList();
    5853    /** The file nodes this model is built upon. */
    59     private FileNode[] file_nodes;
    60     /** The current view. */
    61     //private int current_view;
    62 
    63      //private JToggleButton assigned_metadata_view;
    64      //private JToggleButton unassigned_metadata_view;
    65 
    66      /** An icon showing the current state of the table build. */
    67      //private JProgressBar activity_bar;
    68      /** The table this model is being displayed in. */
    69     private JTable table;
    70 
    71     private ModelBuilder builder;
    72 
    73     static final public int SHOW_ALL         = 0;
    74     static final public int SHOW_ASSIGNED    = 1;
    75     static final public int SHOW_FILE        = 2;
    76     static final public int SHOW_INHERITED   = 3;
    77     static final public int SHOW_UNASSIGNED  = 4;
     54    private FileNode[] file_nodes = null;
     55    /** The table this model is being displayed in. */
     56    private JTable table = null;
     57
     58    private ModelBuilder builder = null;
     59
    7860    static final private String[] COLUMN_NAMES = {"", Gatherer.dictionary.get("Metadata.Element"),  Gatherer.dictionary.get("Metadata.Value")};
    7961
     62
    8063    public GTableModel(JTable table) {
    81     this.builder = null;
    82     this.file_metadata = current_metadata;
    83     this.inherited_metadata = current_metadata;
    8464    this.table = table;
    85     this.unassigned_metadata = current_metadata;
    86     //changeView();
    8765    // Register this model with the msm manager.
    88     if(Gatherer.c_man.ready()) {
     66    if (Gatherer.c_man.ready()) {
    8967        Gatherer.c_man.getCollection().msm.addMSMListener(this);
    9068    }
    9169    }
     70
    9271
    9372    public GTableModel(JTable table, FileNode[] file_nodes) {
    9473    this(table);
    9574    this.file_nodes = file_nodes;
    96     if(file_nodes != null && file_nodes.length > 0) {
    97                 // Create model builder
     75    if (file_nodes != null && file_nodes.length > 0) {
     76        // Create model builder
    9877        builder = new ModelBuilder();
    9978        builder.start();
     
    10180    }
    10281
    103     /** The default constructor creates a new empty model with the current view set to an emtpy 'all metadata'. */
    104     /*
    105       public GTableModel(JTable table, JToggleButton assigned_metadata_view, JToggleButton unassigned_metadata_view, JProgressBar activity_bar) {
    106       this.activity_bar = activity_bar;
    107       this.assigned_metadata_view = assigned_metadata_view;
    108       this.builder = null;
    109       this.table = table;
    110       this.unassigned_metadata_view = unassigned_metadata_view;
    111       changeView();
    112       // Register this model with the msm manager.
    113       if(Gatherer.c_man.ready()) {
    114       Gatherer.c_man.getCollection().msm.addMSMListener(this);
    115       }
    116       }
    117     */
    118 
    119      /** This constuctor starts by creating an empty model then, using a separate model builder thread, builds a model from the given files. */
    120      /*
    121      public GTableModel(JTable table, JToggleButton assigned_metadata_view, JToggleButton unassigned_metadata_view, JProgressBar activity_bar, FileNode[] file_nodes) {
    122           this(table, assigned_metadata_view, unassigned_metadata_view, activity_bar);
    123           this.file_nodes = file_nodes;
    124           if(file_nodes != null && file_nodes.length > 0) {
    125                 // Create model builder
    126                 builder = new ModelBuilder();
    127                 builder.start();
    128           }
    129      }
    130      */
    131 
    132     public void changeView() {
    133     changeView(SHOW_ALL);
    134     }
    135 
    136     /*
    137      public void changeView() {
    138           boolean show_assigned = assigned_metadata_view.isSelected();
    139           boolean show_unassigned = unassigned_metadata_view.isSelected();
    140           if(show_assigned && show_unassigned) {
    141                 changeView(SHOW_ALL);
    142           }
    143           else if(show_assigned) {
    144                 changeView(SHOW_ASSIGNED);
    145           }
    146           else { // Show unassigned
    147                 changeView(SHOW_UNASSIGNED);
    148           }
    149      }
    150      */
    151 
    152      /** Change the current view by changing the model that the table is currently based on. */
    153     public void changeView(int view) {
    154     //current_view = view;
    155     /*
    156       switch(view) {
    157       case SHOW_ASSIGNED:
    158                 ///ystem.err.println("Show assigned");
    159                 current_metadata = new ArrayList();
    160                 current_metadata.addAll(file_metadata);
    161                 current_metadata.addAll(inherited_metadata);
    162                 Collections.sort(current_metadata, MSMUtils.METADATA_COMPARATOR);
    163                 break;
    164                 case SHOW_FILE:
    165                 ///ystem.err.println("Show file");
    166                 current_metadata = file_metadata;
    167                 break;
    168                 case SHOW_INHERITED:
    169                 ///ystem.err.println("Show inherited");
    170                 current_metadata = inherited_metadata;
    171                 break;
    172                 case SHOW_UNASSIGNED:
    173                 ///ystem.err.println("Show unassigned");
    174                 current_metadata = unassigned_metadata;
    175                 break;
    176                 default:
    177                 // SHOW_ALL
    178                 System.err.println("Show all");
    179                 // Create a new array from the three other arrays.
    180                 current_metadata = new ArrayList();
    181                 current_metadata.addAll(file_metadata);
    182                 current_metadata.addAll(inherited_metadata);
    183                 current_metadata.addAll(unassigned_metadata);
    184                 Collections.sort(current_metadata, MSMUtils.METADATA_COMPARATOR);
    185                 }
    186                 // Inform everyone that the model has changed.
    187                 fireTableDataChanged();
    188     */
    189     }
    190 
    191     /** Called whenever an element in a set is added, edited or removed from the metadata set manager. We listen for this just incase the name of one of the elements currently shown changes. After that the table will be up to date, as the element references are otherwise live. */
    192     public void elementChanged(MSMEvent event) {
    193     MSMAction profile = event.getProfile();
    194     if(profile != null) {
    195                 // Retrieve the elements new name (thats hopefully what will be returned by getValue()).
    196         String name = profile.getTarget();
    197         int row = 0;
    198         for( ; row < current_metadata.size(); row++) {
    199         if(getValueAt(row, 0).equals(name)) {
    200             fireTableCellUpdated(row, 0);
    201         }
    202         }
    203         name = null;
    204     }
    205     profile = null;
    206     event = null;
    207     }
    20882
    20983    /** Returns the number of columns in this table. */
     
    21286    }
    21387
    214     /** Returns the data class of the specified column. */
    215     public Class getColumnClass(int col) {
    216     if(col == 2) {
    217         return JButton.class;
    218     }
    219     return String.class;
    220     }
    22188
    22289    /** Retrieves the name of the specified column. */
    22390    public String getColumnName(int col) {
    224     return COLUMN_NAMES[col];
    225     }
    226 
    227     /* Called to retrieve the Metadata record that matches a certain row. Usually caused by the user selectiong a row in the table. It synchronized so that the model doesn't up and change while we're trying to retrieve the indicated element. */
    228     public synchronized Metadata getMetadataAtRow(int row) {
    229     if(0 <= row && row < current_metadata.size()) {
    230         return (Metadata) current_metadata.get(row);
    231     }
    232     return null;
    233     }
     91    return COLUMN_NAMES[col];
     92    }
     93
    23494
    23595    /** Returns the number of rows in this table. */
     
    23797    return current_metadata.size();
    23898    }
     99
    239100
    240101    /** Returns the cell value at a given row and column as an Object. */
     
    252113        case 1:
    253114            ElementWrapper element = m.getElement();
    254             if(element != null) {
     115            if (element != null) {
    255116            result = element.toString();
    256117            }
     
    259120            result = m.getValue();
    260121            break;
    261         case 3:
    262             result = (m.isFileLevel() ? "true" : "false");
     122        }
     123        }
     124    }
     125    return result;
     126    }
     127
     128
     129    /** Returns the data class of the specified column. */
     130//      private Class getColumnClass(int col) {
     131//      if(col == 2) {
     132//          return JButton.class;
     133//      }
     134//      return String.class;
     135//      }
     136
     137
     138    /* Called to retrieve the Metadata record that matches a certain row. Usually caused by the user selectiong a row in the table. It synchronized so that the model doesn't up and change while we're trying to retrieve the indicated element. */
     139    public synchronized Metadata getMetadataAtRow(int row) {
     140    if(0 <= row && row < current_metadata.size()) {
     141        return (Metadata) current_metadata.get(row);
     142    }
     143    return null;
     144    }
     145
     146
     147    public void selectMetadataWhenBuildingComplete(Metadata metadatum)
     148    {
     149    // If there is no builder or no data then there is no point...
     150    if (builder == null || metadatum == null) {
     151        return;
     152    }
     153
     154    // If building is not complete, ask the builder to select the metadata when finished
     155    if (!builder.complete) {
     156        builder.select_exact_metadata = metadatum;
     157    }
     158    // Otherwise, select the appropriate row in the table
     159    else {
     160        for (int i = 0; i < current_metadata.size(); i++) {
     161        // Find the matching piece of metadata
     162        if (current_metadata.get(i).equals(metadatum)) {
     163            // We have to put the selection task onto the AWT thread
     164            SelectionTask task = new SelectionTask(i);
     165            SwingUtilities.invokeLater(task);
     166            return;
     167        }
     168        }
     169    }
     170    }
     171
     172
     173    public void selectClosestMetadataWhenBuildingComplete(Metadata metadatum)
     174    {
     175    // If there is no builder or no data then there is no point...
     176    if (builder == null || metadatum == null) {
     177        return;
     178    }
     179
     180    // If building is not complete, ask the builder to select the metadata when finished
     181    if (!builder.complete) {
     182        builder.select_closest_metadata = metadatum;
     183    }
     184    // Otherwise, select the appropriate row in the table
     185    else {
     186        // Find the position in the list where the piece of metadata should be
     187        Comparator metadata_comparator = MSMUtils.METADATA_COMPARATOR;
     188        int i = 0;
     189        for (i = 0; i < current_metadata.size(); i++) {
     190        if (metadata_comparator.compare(metadatum, current_metadata.get(i)) <= 0) {
    263191            break;
    264192        }
    265193        }
    266     }
    267     return result;
    268     }
    269      
    270     /** Allows access to this models current view. */
    271     public int getView() {
    272     return SHOW_ALL; //current_view;
    273     }
    274 
    275     /** Determine if the given metadata is common to all selected file nodes given the context of the current view. */
    276     public boolean isCommon(int row) {
    277     if(0 <= row && row < current_metadata.size()) {
    278         Metadata entry = (Metadata) current_metadata.get(row);
    279         // System.err.println("Of the " + file_nodes.length + " selected files, " + entry + " is attached to " + entry.getCount() + " of them.");
    280         // System.err.println("There are " + file_nodes.length + " selected files.");
    281         // System.err.println("This metadata is attached to " + entry.getCount() + " of them.");
    282         if(entry.getCount() == file_nodes.length) {
    283         return true;
    284         }
    285     }
    286     return false;
    287     }
     194
     195        // Ensure the position is within the current metadata
     196        if (i >= current_metadata.size()) {
     197        i = current_metadata.size() - 1;
     198        }
     199
     200        // Select the same row as before, except if it would select a different element
     201        ElementWrapper element = metadatum.getElement();
     202        Metadata newly_selected_metadatum = (Metadata) current_metadata.get(i);
     203        if (!newly_selected_metadatum.getElement().equals(element)) {
     204        // Try one row previous
     205        i--;
     206        newly_selected_metadatum = (Metadata) current_metadata.get(i);
     207        if (!newly_selected_metadatum.getElement().equals(element)) {
     208            Gatherer.println("Could not find suitable row to select!");
     209            return;
     210        }
     211        }
     212
     213        // We have to put the selection task onto the AWT thread
     214        SelectionTask task = new SelectionTask(i);
     215        SwingUtilities.invokeLater(task);
     216    }
     217    }
     218
     219
     220    /** Little utility class for selecting a row in the table, on the AWT thread. */
     221    private class SelectionTask
     222    extends Thread {
     223
     224    private int selected_row;
     225
     226    SelectionTask(int selected_row) {
     227        this.selected_row = selected_row;
     228    }
     229
     230    public void run() {
     231        Rectangle bounds = table.getCellRect(selected_row, 0, true);
     232        table.scrollRectToVisible(bounds);
     233        table.setRowSelectionInterval(selected_row, selected_row);
     234    }
     235    }
     236
     237
     238    /** Called whenever an element in a set is added, edited or removed from the metadata set manager. We listen for this just incase the name of one of the elements currently shown changes. After that the table will be up to date, as the element references are otherwise live. */
     239    public void elementChanged(MSMEvent event) {
     240    MSMAction profile = event.getProfile();
     241    if(profile != null) {
     242        // Retrieve the element's new name (hopefully returned by getValue()).
     243        String name = profile.getTarget();
     244        for(int row = 0; row < current_metadata.size(); row++) {
     245        if(getValueAt(row, 0).equals(name)) {
     246            fireTableCellUpdated(row, 0);
     247        }
     248        }
     249        name = null;
     250    }
     251    profile = null;
     252    event = null;
     253    }
     254
    288255
    289256    /** Whenever there is a metadata change we must determine if there are any changes to our various lists of metadata, and also if there is any need to refresh the table currently being viewed. */
     
    295262        // Brute force solution... rebuild the table.
    296263        if(file_nodes != null && file_nodes.length > 0) {
    297         current_metadata.clear();
     264        Metadata select_exact_metadata = null;
     265        Metadata select_closest_metadata = null;
     266        boolean had_warning = false;
     267        // If there is a current builder...
     268        if (builder != null) {
     269            // ...and it is still building...
     270            if (!builder.complete) {
     271            select_exact_metadata = builder.select_exact_metadata;
     272            select_closest_metadata = builder.select_closest_metadata;
     273            had_warning = builder.had_warning;
     274            // ...kill it...
     275            builder.kill();
     276            }
     277            // ...and wait until it dies
     278            while (!builder.complete) { }
     279        }
     280
    298281        // Create model builder
    299282        builder = new ModelBuilder();
    300283        builder.start();
    301         }
    302     }
    303     }
     284        builder.select_exact_metadata = select_exact_metadata;
     285        builder.select_closest_metadata = select_closest_metadata;
     286        builder.had_warning = had_warning;
     287        }
     288    }
     289    }
     290
    304291
    305292    /** Called whenever a set is added or removed from the metadata set manager. */
     
    308295    }
    309296
    310     public Rectangle setSelectedMetadata(Metadata data) {
    311     Rectangle bounds = null;
    312     if (builder != null) {
    313         if(builder.complete) {
    314         for(int i = 0; i < getRowCount(); i++) {
    315             if(getMetadataAtRow(i).equals(data)) {
    316             // System.err.println("Found matching metadata at row " + i + " (of " + getRowCount() + " rows)");
    317             // bounds = table.getCellRect(i, 0, true);
    318             // table.scrollRectToVisible(bounds);
    319             SelectionTask task = new SelectionTask(i);
    320             SwingUtilities.invokeLater(task);
    321             break;
    322             }
    323         }
    324         }
    325         else {
    326         builder.selected_metadata = data;
    327         }
    328     }
    329     return bounds;
    330     }
    331 
    332     private class SelectionTask
    333     extends Thread {
    334     private int selected_row;
    335     SelectionTask(int selected_row) {
    336         this.selected_row = selected_row;
    337     }
    338     public void run() {
    339         Rectangle bounds = table.getCellRect(selected_row, 0, true);
    340         table.scrollRectToVisible(bounds);
    341         table.setRowSelectionInterval(selected_row, selected_row);
    342         ///ystem.err.println("Done setRowSelectionInterval...");
    343     }
    344     }
    345 
    346     public int size() {
    347     return file_nodes.length;
    348     }
    349297
    350298    /** Called when the value tree of a certain element has changed significantly but, although we display metadata values, we only care about those coming through metadataChanged() events. */
     
    352300    // Don't care. Tra-la-la-la-la.
    353301    }
     302
     303
     304    /** Determine if the given metadata is common to all selected file nodes given the context of the current view. */
     305    private boolean isCommon(int row) {
     306    if(0 <= row && row < current_metadata.size()) {
     307        Metadata entry = (Metadata) current_metadata.get(row);
     308        // System.err.println("Of the " + file_nodes.length + " selected files, " + entry + " is attached to " + entry.getCount() + " of them.");
     309        if (entry.getCount() == file_nodes.length) {
     310        return true;
     311        }
     312    }
     313    return false;
     314    }
     315
    354316
    355317    /** Alphabetically inserts the new_metadata in the target vector. */
     
    368330    }
    369331
    370     /** Remove a certain piece of data from a certain vector. */
    371     private void remove(ArrayList target, Metadata old_metadata) {
    372     if(target != null) {
    373         for(int i = 0; i < target.size(); i++) {
    374         Metadata current_metadata = (Metadata) target.get(i);
    375         if(current_metadata.equals(old_metadata)) {
    376             target.remove(current_metadata);
    377             return;
    378         }
    379         }
    380     }
    381     }
    382 
    383332
    384333    private class ModelBuilder
     
    386335
    387336    public boolean complete = false;
    388     public Metadata selected_metadata = null;;
     337    public Metadata select_exact_metadata = null;
     338    public Metadata select_closest_metadata = null;
    389339    private boolean had_warning = false;
     340    private volatile boolean killed = false;
    390341
    391342    public void run()
    392343    {
    393344        if (!Gatherer.c_man.ready()) {
    394         System.err.println("Not ready!");
     345        Gatherer.println("Not ready!");
    395346        return;
    396347        }
    397348
    398         // System.err.println("Building metadata model...");
     349        // System.err.println("\nBuilding metadata model...");
    399350        Vector elements = Gatherer.c_man.getCollection().msm.getElements();
    400351        ArrayList known_elements = new ArrayList();
    401352        current_metadata.clear();
    402353
    403         for (int i = 0; i < file_nodes.length; i++) {
     354        for (int i = 0; i < file_nodes.length && !killed; i++) {
    404355        File current_file = file_nodes[i].getFile();
    405         // System.err.println("File: " + current_file);
     356        // System.err.println("File " + i + " (of " + file_nodes.length + "): " + current_file);
    406357
    407358        // Get the currently assigned metadata for this file
    408359        ArrayList metadata = Gatherer.c_man.getCollection().gdm.getAllMetadata(current_file);
    409         for (int j = 0; j < metadata.size(); j++) {
     360        for (int j = 0; j < metadata.size() && !killed; j++) {
    410361            Metadata metadatum = (Metadata) metadata.get(j);
    411362            ElementWrapper element = metadatum.getElement();
     
    441392
    442393        // Make sure each element has a piece of metadata (even if blank)
    443         for (int i = 0; i < elements.size(); i++) {
     394        for (int i = 0; i < elements.size() && !killed; i++) {
    444395        ElementWrapper element = (ElementWrapper) elements.get(i);
    445396        // System.err.println("Element: " + element);
     
    457408
    458409        // Sort the metadata and update the table
    459         Gatherer.g_man.metaedit_pane.validateMetadataTable();
    460         Collections.sort(current_metadata, MSMUtils.METADATA_COMPARATOR);
    461         fireTableDataChanged();
     410        if (!killed) {
     411        Gatherer.g_man.metaedit_pane.validateMetadataTable();
     412        Collections.sort(current_metadata, MSMUtils.METADATA_COMPARATOR);
     413        fireTableDataChanged();
     414        }
    462415
    463416        // Processing complete
     
    465418
    466419        // If while processing we've been asked to select a certain metadata, do it now
    467         if (selected_metadata != null) {
    468         setSelectedMetadata(selected_metadata);
    469         }
     420        if (!killed) {
     421        if (select_exact_metadata != null) {
     422            selectMetadataWhenBuildingComplete(select_exact_metadata);
     423        }
     424        else if (select_closest_metadata != null) {
     425            selectClosestMetadataWhenBuildingComplete(select_closest_metadata);
     426        }
     427        }
     428    }
     429
     430
     431    public synchronized void kill()
     432    {
     433        killed = true;
     434        notify();
    470435    }
    471436
     
    487452    }
    488453    }
    489 
    490 
    491     private class OldModelBuilder
    492     extends Thread {
    493 
    494     public boolean had_warning = false;
    495 
    496     public boolean complete = false;
    497 
    498     public Metadata selected_metadata = null;;
    499          
    500     public void run() {
    501         if(Gatherer.c_man != null && Gatherer.c_man.ready()) {
    502         Vector elements = Gatherer.c_man.getCollection().msm.getElements();
    503         // Show some visual indication that building is occuring.
    504         //assigned_metadata_view.setEnabled(false);
    505         //unassigned_metadata_view.setEnabled(false);
    506         //activity_bar.setMaximum(file_nodes.length + elements.size());
    507         //activity_bar.setValue(0);
    508         //activity_bar.setString(Gatherer.dictionary.get("MetaEdit.Building"));
    509         //long start = System.currentTimeMillis();
    510        
    511         ArrayList known_elements = new ArrayList(); // Elements that have metadata assigned.
    512         for(int i = 0; i < file_nodes.length; i++) {
    513             File current_file = file_nodes[i].getFile();
    514 
    515             // The current assigned metadata for this file.
    516             ArrayList metadatum = Gatherer.c_man.getCollection().gdm.getAllMetadata(current_file);
    517             for(int j = 0; j < metadatum.size(); j++) {
    518             Metadata data = (Metadata) metadatum.get(j);
    519             // Determine the target list by the metadata level
    520             ArrayList modified_metadata;
    521             if(data.isFileLevel()) {
    522                 modified_metadata = file_metadata;
    523             }
    524             else {
    525                 showInheritedMetadataWarning();
    526                 modified_metadata = inherited_metadata;
    527             }
    528             int index = -1;
    529             // Don't show hidden metadata
    530             // If the given metadata already exists in our list of modified metadata then increment its commonality count.
    531             if((index = modified_metadata.indexOf(data)) != -1) {
    532                 data = (Metadata) modified_metadata.get(index);
    533                 ///ystem.err.println("Increasing count:" + element);
    534                 data.inc();
    535                 // If the table shown is stale, refresh it.
    536                 //if((modified_metadata == file_metadata && current_view == SHOW_FILE) || (modified_metadata == inherited_metadata && current_view == SHOW_INHERITED)) {
    537                 // fireTableRowsUpdated(index, index);
    538                 //}
    539                 // We may have to update a compound list
    540                 //else if(current_view == SHOW_ALL || current_view == SHOW_ASSIGNED) {
    541                 if((index = current_metadata.indexOf(data)) == -1) {
    542                 fireTableRowsUpdated(index, index);
    543                 }
    544                 //}
    545             }
    546             // Ensure the metadata's element is in our list of showable elements.
    547             else if(contains(elements, data.getElement())) {
    548                 ///ystem.err.println("Setting count to one: " + element);
    549                 data.setCount(1);
    550                 index = add(modified_metadata, data); // Add to assigned metadata.
    551                 known_elements.add(data.getElement());
    552                 // If the table shown is stale, refresh it.
    553                 //if((modified_metadata == file_metadata && current_view == SHOW_FILE) || (modified_metadata == inherited_metadata && current_view == SHOW_INHERITED)) {
    554                 //   fireTableRowsInserted(index, index);
    555                 //}
    556                 // We may have to update a compound list
    557                 //else if(current_view == SHOW_ALL || current_view == SHOW_ASSIGNED) {
    558                 if((index = current_metadata.indexOf(data)) == -1) {
    559                 index = add(current_metadata, data);
    560                 fireTableRowsInserted(index, index);
    561                 }
    562                 else {
    563                 fireTableRowsUpdated(index, index); 
    564                 }
    565                 //}
    566             }
    567             else {
    568                 ///ystem.err.println("No.\n***** Cannot match element so it must be hidden, right? *****");
    569             }
    570             }
    571             //activity_bar.setValue(activity_bar.getValue() + 1);
    572             Gatherer.g_man.metaedit_pane.validateMetadataTable();
    573         }
    574                 // Add entries for the currently unassigned metadata. You can determine these as the difference between elements and known_elements.
    575         // System.err.println("Number of elements: " + elements.size());
    576         // System.err.println("Number of known elements: " + known_elements.size());
    577         for(int k = 0; k < elements.size(); k++) {
    578             // For each key.
    579             ElementWrapper element = (ElementWrapper) elements.get(k);
    580             // System.err.println("Element " + k + ": " + element);
    581             if(!known_elements.contains(element)) {
    582             Metadata data = new Metadata(element);
    583             int index = add(unassigned_metadata, data);
    584             // Inform everyone that the model has changed, but only if it affects the current view.
    585             //if(current_view == SHOW_UNASSIGNED) {
    586             //  fireTableRowsInserted(index, index);
    587             //}
    588             //else if(current_view == SHOW_ALL) {
    589             if((index = current_metadata.indexOf(data)) == -1) {
    590                 // System.err.println("Adding " + data + " to " + current_metadata);
    591                 index = add(current_metadata, data);
    592                 fireTableRowsInserted(index, index);
    593             }
    594             else {
    595                 fireTableRowsUpdated(index, index);
    596             }
    597             //}
    598             }
    599             //activity_bar.setValue(activity_bar.getValue() + 1);
    600             Gatherer.g_man.metaedit_pane.validateMetadataTable();
    601         }
    602         //long end = System.currentTimeMillis();
    603         ///ystem.err.println("Took " + (end - start) + "ms to build table.");
    604         //assigned_metadata_view.setEnabled(true);
    605         //unassigned_metadata_view.setEnabled(true);
    606         //activity_bar.setValue(activity_bar.getMaximum());
    607         //activity_bar.setString(Gatherer.dictionary.get("MetaEdit.Ready"));
    608         Collections.sort(current_metadata, MSMUtils.METADATA_COMPARATOR);
    609         fireTableDataChanged();
    610         }
    611         else {
    612 
    613         }
    614         // Finally complete (even if we didn't do anything).
    615         complete = true;
    616         // If in the in between we've been asked to select a certain metadata, we action that now.
    617         if(getRowCount() > 0 && selected_metadata != null) {
    618         setSelectedMetadata(selected_metadata);
    619         }
    620     }
    621 
    622     /** For some reason contains doesn't always work. It appear not to use equals() properly, as ElementWrappers need to compare themselves by their string content as other data members are nearly always different even between to ElementWrappers generated from the same DOM Element. */
    623     private boolean contains(Vector elements, ElementWrapper element) {
    624         if(element != null) {
    625         for(int i = 0; i < elements.size(); i++) {
    626             if(element.equals(elements.get(i))) {
    627             return true;
    628             }
    629         }
    630         }
    631         return false;
    632     }
    633 
    634     private void showInheritedMetadataWarning() {
    635         if(!had_warning) {
    636         had_warning = true;
    637         Runnable task = new Runnable() {
    638             public void run() {
    639                 WarningDialog dialog = new WarningDialog("warning.InheritedMetadata", false);
    640                 dialog.display();
    641                 dialog.dispose();
    642                 dialog = null;
    643             }
    644             };
    645         SwingUtilities.invokeLater(task);
    646         }
    647     }
    648     }
    649454}
Note: See TracChangeset for help on using the changeset viewer.