Changeset 4545


Ignore:
Timestamp:
2003-06-11T09:37:48+12:00 (21 years ago)
Author:
mdewsnip
Message:

Removed caching of the "x files and y directories selected" details. In some cases this value was not being flushed when the selection changed, so an invalid value was returned. The value is now calculated when it is needed - a little less efficient, but much less error-prone.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/DragTreeSelectionModel.java

    r4514 r4545  
    5252    private int type               = -1;
    5353
    54     private String suffix = null;
    55 
    5654    private TreePath temp_path     = null;
    5755    private TreePath temp_paths[]  = null;
     
    7573        temp_path = null;
    7674        super.addSelectionPath(path);
    77         suffix = null;     
    7875    }
    7976    }
     
    8784        temp_paths = null;
    8885        super.setSelectionPaths(paths);
    89         suffix = null;
    9086    }         
    9187    }
    9288     
    9389    public String getDetails() {
    94     if(suffix == null) {
    95         int file_count = 0;
    96         int folder_count = 0;
    97         for(int i = 0; selection != null && i < selection.length; i++) {
    98         TreeNode node = (TreeNode) selection[i].getLastPathComponent();
    99         if(node.isLeaf()) {
    100             file_count++;
    101         }
    102         else {
    103             folder_count++;
    104         }
    105         }
    106                 // Update the metaaudit_suffix
    107         String args[] = null;
    108         if(file_count > 0 && folder_count > 0) {
    109         if(file_count > 1 && folder_count > 1) {
    110             args = new String[2];
    111             args[0] = String.valueOf(file_count);
    112             args[1] = String.valueOf(folder_count);
    113             suffix = Gatherer.dictionary.get("FileActions.Selected", args);
    114         }
    115         else if(file_count > 1) {
    116             args = new String[1];
    117             args[0] = String.valueOf(file_count);
    118             suffix = Gatherer.dictionary.get("FileActions.Files_And_Directory_Selected", args);
    119         }
    120         else if(folder_count > 1) {
    121             args = new String[1];
    122             args[0] = String.valueOf(folder_count);
    123             suffix = Gatherer.dictionary.get("FileActions.File_And_Directories_Selected", args);
    124         }
    125         else {
    126             suffix = Gatherer.dictionary.get("FileActions.File_And_Directory_Selected");
    127         }
    128         }
    129         else if(file_count > 0) {
    130         if(file_count > 1) {
    131             args = new String[1];
    132             args[0] = String.valueOf(file_count);
    133             suffix = Gatherer.dictionary.get("FileActions.Files_Selected", args);
    134         }
    135         else if(file_count == 1) {
    136             suffix = Gatherer.dictionary.get("FileActions.File_Selected");
    137         }
    138         }
    139         else if(folder_count > 0) {
    140         if(folder_count > 1) {
    141             args = new String[1];
    142             args[0] = String.valueOf(folder_count);
    143             suffix = Gatherer.dictionary.get("FileActions.Directories_Selected", args);
    144         }
    145         else {
    146             suffix = Gatherer.dictionary.get("FileActions.Directory_Selected");
    147         }
     90    String suffix = null;
     91    int file_count = 0;
     92    int folder_count = 0;
     93    for(int i = 0; selection != null && i < selection.length; i++) {
     94        TreeNode node = (TreeNode) selection[i].getLastPathComponent();
     95        if(node.isLeaf()) {
     96        file_count++;
    14897        }
    14998        else {
    150         suffix = null;
    151         }
    152         args = null;
    153     }
     99        folder_count++;
     100        }
     101    }
     102
     103    // Update the metaaudit_suffix
     104    String args[] = null;
     105    if(file_count > 0 && folder_count > 0) {
     106        if(file_count > 1 && folder_count > 1) {
     107        args = new String[2];
     108        args[0] = String.valueOf(file_count);
     109        args[1] = String.valueOf(folder_count);
     110        suffix = Gatherer.dictionary.get("FileActions.Selected", args);
     111        }
     112        else if(file_count > 1) {
     113        args = new String[1];
     114        args[0] = String.valueOf(file_count);
     115        suffix = Gatherer.dictionary.get("FileActions.Files_And_Directory_Selected", args);
     116        }
     117        else if(folder_count > 1) {
     118        args = new String[1];
     119        args[0] = String.valueOf(folder_count);
     120        suffix = Gatherer.dictionary.get("FileActions.File_And_Directories_Selected", args);
     121        }
     122        else {
     123        suffix = Gatherer.dictionary.get("FileActions.File_And_Directory_Selected");
     124        }
     125    }
     126    else if(file_count > 0) {
     127        if(file_count > 1) {
     128        args = new String[1];
     129        args[0] = String.valueOf(file_count);
     130        suffix = Gatherer.dictionary.get("FileActions.Files_Selected", args);
     131        }
     132        else if(file_count == 1) {
     133        suffix = Gatherer.dictionary.get("FileActions.File_Selected");
     134        }
     135    }
     136    else if(folder_count > 0) {
     137        if(folder_count > 1) {
     138        args = new String[1];
     139        args[0] = String.valueOf(folder_count);
     140        suffix = Gatherer.dictionary.get("FileActions.Directories_Selected", args);
     141        }
     142        else {
     143        suffix = Gatherer.dictionary.get("FileActions.Directory_Selected");
     144        }
     145    }
     146    args = null;
     147
    154148    return suffix;
    155149    }
     
    204198        }
    205199        this.type = this.NONE;
    206         suffix = null;
    207200        break;
    208201    case 1: // this.SET
     
    216209        }
    217210        this.type = this.NONE;
    218         suffix = null;
    219211        break;
    220212    }
     
    234226        temp_path = null;
    235227        super.setSelectionPath(path);
    236         suffix = null;
    237228    }
    238229    }
     
    246237        temp_paths = null;
    247238        super.setSelectionPaths(paths);
    248         suffix = null;
    249239    }
    250240    }
     
    282272        }
    283273        }
    284                 // Now we check the current selection against the first node in our new selection
     274        // Now we check the current selection against the first node in our new selection
    285275        if(appropriate && check_current) {
    286276        appropriate = isAppropriate(paths[0]);
Note: See TracChangeset for help on using the changeset viewer.