Revision 702 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultScriptingFolder.java

View differences:

DefaultScriptingFolder.java
7 7
import java.util.ArrayList;
8 8
import java.util.List;
9 9
import java.util.Arrays;
10
import java.util.Collections;
10 11
import java.util.Comparator;
12
import java.util.HashSet;
13
import java.util.Set;
11 14

  
12 15
import org.apache.commons.io.FileUtils;
13 16
import org.apache.commons.io.FilenameUtils;
......
62 65
    }
63 66

  
64 67
    @Override
68
    public List<File> getFiles() {
69
        List<File> l = new ArrayList<>();
70
        l.add(this.getFile());
71
        return l;
72
    }
73

  
74
    @Override
65 75
    public ScriptingFolder getParent() {
66 76
        ScriptingFolder parent = super.getParent();
67 77
        if (parent != null) {
......
142 152
                return "inf".equalsIgnoreCase(ext);
143 153
            }
144 154
        });
155
        Set<File> filesAdded = new HashSet<>();
145 156
        if (files != null) {
146
            Arrays.sort(files, new Comparator<File>() {
147
                @Override
148
                public int compare(File f1, File f2) {
149
                    if (f1.isDirectory() && !f2.isDirectory()) {
150
                        return -1;
151
                    } else if (!f1.isDirectory() && f2.isDirectory()) {
152
                        return 1;
153
                    } else {
154
                        return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());
155
                    }
156
                }
157
            });
157
//            Arrays.sort(files, new Comparator<File>() {
158
//                @Override
159
//                public int compare(File f1, File f2) {
160
//                    if (f1.isDirectory() && !f2.isDirectory()) {
161
//                        return -1;
162
//                    } else if (!f1.isDirectory() && f2.isDirectory()) {
163
//                        return 1;
164
//                    } else {
165
//                        return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());
166
//                    }
167
//                }
168
//            });
158 169
            for (File f : files) {
159 170
                try {
160 171
                    ScriptingUnit unit = this.getUnit(f);
172
                    filesAdded.addAll(unit.getFiles());
161 173
                    ol.add(unit);
162 174
                } catch (Exception ex) {
163 175
                    logger.warn("Can't create unit from file '" + f.getAbsolutePath() + "'.",ex);
164 176
                }
165 177
            }
166 178
        }
179
        files = this.folder.listFiles(new FilenameFilter() {
180
            @Override
181
            public boolean accept(File arg0, String arg1) {
182
                File f = new File(arg0, arg1);
183
                if (!f.canRead() || f.isHidden()) {
184
                    return false;
185
                }
186
                if (f.isDirectory()) {
187
                    return true;
188
                }
189
                return true;
190
            }
191
        });
192
        if (files != null) {
193
            for (File f : files) {
194
                try {
195
                    String extension = FilenameUtils.getExtension(f.getName());
196
                    if( "inf".equalsIgnoreCase(extension) || "class".equalsIgnoreCase(extension) ) {
197
                        continue;
198
                    }
199
                    if( !filesAdded.contains(f) ) {
200
                        ScriptingUnit unit = this.manager.createExternalFile(this, f.getName());
201
                        filesAdded.addAll(unit.getFiles());
202
                        ol.add(unit);
203
                    } 
204
                } catch (Exception ex) {
205
                    logger.warn("Can't create unit from file '" + f.getAbsolutePath() + "'.",ex);
206
                }
207
            }
208
        }
209
        Collections.sort(ol, new Comparator<ScriptingUnit>() {
210

  
211
            @Override
212
            public int compare(ScriptingUnit o1, ScriptingUnit o2) {
213
                if( o1 instanceof ScriptingFolder ) {
214
                    if( ! (o2 instanceof ScriptingFolder) ) {
215
                        return -1;
216
                    }
217
                } else if( o2 instanceof ScriptingFolder ) { 
218
                    return 1;
219
                }
220
                return o1.getId().compareToIgnoreCase(o2.getId());
221
            }
222
        });
167 223
        return ol;
168 224
    }
169 225

  

Also available in: Unified diff