Changeset 4440


Ignore:
Timestamp:
2003-05-30T15:48:16+12:00 (21 years ago)
Author:
mdewsnip
Message:

When importing a metadata set, user is asked to choose between "all values", "subjects only", and "no values" only when there exist some MDV files to read values from.

File:
1 edited

Legend:

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

    r4422 r4440  
    527527    // 1. Parse the new file.
    528528    MetadataSet mds_new = new MetadataSet(mds_file);
    529     // Display a prompt asking how much of the value structure the user wishes to import.
    530529    if(user_driven) {
    531         ExportMDSPrompt imdsp = new ExportMDSPrompt(this, false);
    532         int result = imdsp.display();
    533         if(result == ExportMDSPrompt.EXPORT) { // Here export means the user didn't cancel.
    534         switch(imdsp.getSelectedCondition()) {
    535         case MetadataSet.NO_VALUES:
    536             mds_new = new MetadataSet(mds_new, MetadataSet.NO_VALUES);
    537             break;
    538         case MetadataSet.SUBJECTS_ONLY:
    539             mds_new = new MetadataSet(mds_new, MetadataSet.SUBJECTS_ONLY);
    540             break;
    541         default: // ALL_VALUES
    542             // Don't do anything.
    543         }
    544         }
    545         else {
    546         mds_new = null;
    547         }
    548         imdsp.dispose();
    549         imdsp = null;
     530        // Display a prompt asking how much of the value structure the user wishes to import.
     531        // ...but only if there are some MDV files to read values from
     532        FilenameFilter mdv_filter = new MDVFilenameFilter(mds_new.getNamespace());
     533        File[] mdv_files = mds_file.getParentFile().listFiles(mdv_filter);
     534        if (mdv_files.length > 0) {
     535        ExportMDSPrompt imdsp = new ExportMDSPrompt(this, false);
     536        int result = imdsp.display();
     537        if(result == ExportMDSPrompt.EXPORT) { // Here export means the user didn't cancel.
     538            switch(imdsp.getSelectedCondition()) {
     539            case MetadataSet.NO_VALUES:
     540            mds_new = new MetadataSet(mds_new, MetadataSet.NO_VALUES);
     541            break;
     542            case MetadataSet.SUBJECTS_ONLY:
     543            mds_new = new MetadataSet(mds_new, MetadataSet.SUBJECTS_ONLY);
     544            break;
     545            default: // ALL_VALUES
     546            // Don't do anything.
     547            }
     548        }
     549        else {
     550            mds_new = null;
     551        }
     552        imdsp.dispose();
     553        imdsp = null;
     554        }
    550555    }
    551556    // Carry on importing the new collection
     
    575580    // else we cancelled for some reason.
    576581    return false;
     582    }
     583
     584
     585    /** Accepts .mdv files for a certain metadata set. */
     586    private class MDVFilenameFilter implements FilenameFilter
     587    {
     588    private String mds_namespace = null;
     589
     590    public MDVFilenameFilter(String mds_namespace)
     591    {
     592        this.mds_namespace = mds_namespace.toLowerCase();
     593    }
     594
     595    public boolean accept(File dir, String name)
     596    {
     597        String copy = name.toLowerCase();
     598        if (copy.startsWith(mds_namespace) && copy.endsWith(".mdv")) {
     599        return true;
     600        }
     601
     602        return false;
     603    }
    577604    }
    578605
Note: See TracChangeset for help on using the changeset viewer.