Index: DefaultScriptingFolder.java
===================================================================
--- DefaultScriptingFolder.java	(revision 467)
+++ DefaultScriptingFolder.java	(revision 468)
@@ -5,9 +5,7 @@
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Arrays;
 import java.util.Comparator;
 
@@ -15,190 +13,222 @@
 import org.apache.commons.io.FilenameUtils;
 import org.gvsig.scripting.ScriptingFolder;
 import org.gvsig.scripting.ScriptingManager;
-import org.gvsig.scripting.ScriptingScript;
 import org.gvsig.scripting.ScriptingUnit;
 import org.ini4j.Ini;
-import org.python.core.util.FileUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+public class DefaultScriptingFolder extends AbstractUnit implements ScriptingFolder {
 
-public class DefaultScriptingFolder extends AbstractUnit implements ScriptingFolder{
+    private static final Logger logger = LoggerFactory.getLogger(DefaultScriptingFolder.class);
+    protected File folder;
 
-	private static final Logger logger = LoggerFactory.getLogger(DefaultScriptingFolder.class);
-	protected File folder;
+    public DefaultScriptingFolder(ScriptingFolder parent, ScriptingManager manager) {
+        this(parent, manager, (File) null);
+    }
 
-	public DefaultScriptingFolder(ScriptingFolder parent, ScriptingManager manager) {
-		this(parent, manager,(File)null);
-	}
+    public DefaultScriptingFolder(ScriptingFolder parent, ScriptingManager manager, File folder) {
+        super(parent, ScriptingManager.UNIT_FOLDER, manager, null);
+        this.folder = folder;
+        if (folder != null) {
+            this.setId(folder.getName());
+        }
+    }
 
-	public DefaultScriptingFolder(ScriptingFolder parent, ScriptingManager manager, File folder) {
-		super(parent, ScriptingManager.UNIT_FOLDER, manager, null);
-		this.folder = folder;
-		if( folder != null ) {
-			this.setId(folder.getName());
-		}
-	}
-	
-	public DefaultScriptingFolder(ScriptingFolder parent, ScriptingManager manager, URL folder) {
-		super(parent, ScriptingManager.UNIT_FOLDER, manager, null);
-		if(!folder.getProtocol().equalsIgnoreCase("file")){
-			throw new RuntimeException("Protocol URL not supported");
-		}
-		File f = new File(folder.getPath());
-		this.setId(f.getName());
-		this.folder = f;
-	}
+    public DefaultScriptingFolder(ScriptingFolder parent, ScriptingManager manager, URL folder) {
+        super(parent, ScriptingManager.UNIT_FOLDER, manager, null);
+        if (!folder.getProtocol().equalsIgnoreCase("file")) {
+            throw new RuntimeException("Protocol URL not supported");
+        }
+        File f = new File(folder.getPath());
+        this.setId(f.getName());
+        this.folder = f;
+    }
 
-	public void create(ScriptingFolder folder, String id) {
-		this.getFile().mkdir();
-	}
-	
-	public File getFile(){
-		return this.folder;
-	}	
-	
-	public ScriptingFolder getParent() {
-		ScriptingFolder parent = super.getParent();
-		if( parent != null ) {
-			return parent;
-		}
-		return new DefaultScriptingFolder(null, manager, this.folder.getParentFile());
-	}
-	
-	private String getTypenameFromInf(File file) {
-		Ini inf = null;
-		try {
-			inf = new Ini(file);
-		} catch (Exception e) {
-			logger.warn("Can't load 'inf' file '"+file.getAbsolutePath()+"'.",e);
-		}
-		String typename = inf.get("Unit", "type");
-		if( typename == null ) {
-			typename = ScriptingManager.UNIT_SCRIPT;
-		}
-		return typename;
-	}
-	
-	public Unit getUnit(File afile) {
-		Unit unit=null;
-		
-		File file = null;
-		if( afile.isAbsolute() ) {
-			file = afile.getAbsoluteFile();
-		} else {
-			file = new File( this.getFile(),afile.getPath());
-		}
-		
-		String id = FilenameUtils.getBaseName(afile.getAbsolutePath());
-		ScriptingFolder parent = null;
-		if( FilenameUtils.equalsNormalizedOnSystem(this.getFile().getAbsolutePath(), file.getParentFile().getAbsolutePath() )  ) {
-			parent = this;
-		} else {
-			parent = new DefaultScriptingFolder(null, manager, file.getParentFile());
-		}
+    @Override
+    public void create(ScriptingFolder folder, String id) {
+        this.getFile().mkdir();
+    }
 
-		if (file.isDirectory()){
-			unit = (Unit) this.manager.createUnit(ScriptingManager.UNIT_FOLDER, parent, id);
-			
-		} else if( file.isFile() ) {
-			if( !file.getName().endsWith(".inf") ) {
-				file = new File( file.getParentFile(),
-						FilenameUtils.getBaseName(file.getName())+".inf");
-			}
-			if( !file.exists() ) {
-				logger.warn("Can't get Unit, file '"+file.getAbsolutePath()+"' not exists.");
-				return null;
-			}
-			unit = (Unit) this.manager.createUnit(getTypenameFromInf(file), parent, id);
-		}
-		return unit;
-	}
+    @Override
+    public File getFile() {
+        return this.folder;
+    }
 
+    @Override
+    public ScriptingFolder getParent() {
+        ScriptingFolder parent = super.getParent();
+        if (parent != null) {
+            return parent;
+        }
+        return new DefaultScriptingFolder(null, manager, this.folder.getParentFile());
+    }
+
+    private String getTypenameFromInf(File file) {
+        if (file == null) {
+            logger.warn("Can't load 'inf' file, file is null.");
+            return null;
+        }
+        try {
+            Ini inf = new Ini(file);
+            String typename = inf.get("Unit", "type");
+            if (typename == null) {
+                return ScriptingManager.UNIT_SCRIPT;
+            }
+            return typename;
+        } catch (Exception e) {
+            logger.warn("Can't load 'inf' file '" + file.getAbsolutePath() + "'.", e);
+            return null;
+        }
+
+    }
+
+    @Override
+    public Unit getUnit(File afile) {
+        Unit unit = null;
+
+        File file;
+        if (afile.isAbsolute()) {
+            file = afile.getAbsoluteFile();
+        } else {
+            file = new File(this.getFile(), afile.getPath());
+        }
+
+        String id = FilenameUtils.getBaseName(afile.getAbsolutePath());
+        ScriptingFolder parent;
+        if (FilenameUtils.equalsNormalizedOnSystem(this.getFile().getAbsolutePath(), file.getParentFile().getAbsolutePath())) {
+            parent = this;
+        } else {
+            parent = new DefaultScriptingFolder(null, manager, file.getParentFile());
+        }
+
+        if (file.isDirectory()) {
+            unit = (Unit) this.manager.createUnit(ScriptingManager.UNIT_FOLDER, parent, id);
+
+        } else if (file.isFile()) {
+            if (!file.getName().endsWith(".inf")) {
+                file = new File(file.getParentFile(),
+                        FilenameUtils.getBaseName(file.getName()) + ".inf");
+            }
+            if (!file.exists()) {
+                logger.warn("Can't get Unit, file '" + file.getAbsolutePath() + "' not exists.");
+                return null;
+            }
+            unit = (Unit) this.manager.createUnit(getTypenameFromInf(file), parent, id);
+        }
+        return unit;
+    }
+
+    @Override
     public List<ScriptingUnit> getUnits() {
-		// Listar los ficheros del directorio y pasarlo a un vector para ordenarlo
-		List<ScriptingUnit> ol = new ArrayList<ScriptingUnit>();
-		File[] files = this.folder.listFiles(new FilenameFilter() {
-			public boolean accept(File arg0, String arg1) {
-				File f = new File(arg0,arg1);
-				if( !f.canRead() ) {
-					return false;
-				}
-				if( f.isHidden() ) {
-					return false;
-				}
-				if( f.isDirectory() ) {
-					return true;
-				}
-				String ext = FilenameUtils.getExtension(f.getAbsolutePath());
-				return ext.equalsIgnoreCase("inf");
-			}
-		});
-		if (files != null){
-			Arrays.sort( files, new Comparator<File>() {
-				public int compare(File f1, File f2) {
-					if (f1.isDirectory() && !f2.isDirectory()) {
-					    return -1;
-					} else if (!f1.isDirectory() && f2.isDirectory()) {
-					    return 1;
-					} else {
-					    return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());				
-					}
-				}
-			});
-			for (int i = 0; i < files.length; i++){
-				File f = files[i];
-				ScriptingUnit unit = null;
-				try {
-					unit = this.getUnit(f);
-				} catch(Exception ex) {
-					logger.warn("Can't create unit from file '"+f.getAbsolutePath()+"'.");
-				}
-				if (unit!=null){
-					ol.add(unit);
-				}
-			}
-		}
-		return ol;
-	}
-	
-	public void add(ScriptingUnit unit) {
-		unit.move(this);
-	}
+        List<ScriptingUnit> ol = new ArrayList<>();
+        File[] files = this.folder.listFiles(new FilenameFilter() {
+            @Override
+            public boolean accept(File arg0, String arg1) {
+                File f = new File(arg0, arg1);
+                if (!f.canRead() || f.isHidden()) {
+                    return false;
+                }
+                if (f.isDirectory()) {
+                    return true;
+                }
+                String ext = FilenameUtils.getExtension(f.getName());
+                return "inf".equalsIgnoreCase(ext);
+            }
+        });
+        if (files != null) {
+            Arrays.sort(files, new Comparator<File>() {
+                @Override
+                public int compare(File f1, File f2) {
+                    if (f1.isDirectory() && !f2.isDirectory()) {
+                        return -1;
+                    } else if (!f1.isDirectory() && f2.isDirectory()) {
+                        return 1;
+                    } else {
+                        return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());
+                    }
+                }
+            });
+            for (File f : files) {
+                try {
+                    ScriptingUnit unit = this.getUnit(f);
+                    ol.add(unit);
+                } catch (Exception ex) {
+                    logger.warn("Can't create unit from file '" + f.getAbsolutePath() + "'.");
+                }
+            }
+        }
+        return ol;
+    }
 
-	public void remove(ScriptingUnit unit) {
-		unit.remove();
-	}
+    public List<ScriptingFolder> getUnitFolders() {
+        List<ScriptingFolder> ol = new ArrayList<>();
+        File[] files = this.folder.listFiles(new FilenameFilter() {
+            @Override
+            public boolean accept(File arg0, String arg1) {
+                File f = new File(arg0, arg1);
+                return f.isDirectory();
+            }
+        });
+        if (files != null) {
+            Arrays.sort(files, new Comparator<File>() {
+                @Override
+                public int compare(File f1, File f2) {
+                    return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());
+                }
+            });
+            for (File f : files) {
+                try {
+                    ScriptingFolder unit = (ScriptingFolder) this.getUnit(f);
+                    ol.add(unit);
+                } catch (Exception ex) {
+                    logger.warn("Can't create folder from '" + f.getAbsolutePath() + "'.");
+                }
+            }
+        }
+        return ol;
+    }
 
-	@Override
+    @Override
+    public void add(ScriptingUnit unit) {
+        unit.move(this);
+    }
+
+    @Override
+    public void remove(ScriptingUnit unit) {
+        unit.remove();
+    }
+
+    @Override
     public void load(ScriptingFolder folder, String id) {
-		DefaultScriptingFolder parent = (DefaultScriptingFolder) folder;
-		this.setParent(folder);
-		this.setId(id);	
-		this.folder = new File(parent.getFile(),id);
-	}
-	
-	public String[] getIconNames() {
-		return new String[]{"folder", "folder-drag-accept"};
-	}
+        DefaultScriptingFolder parent = (DefaultScriptingFolder) folder;
+        this.setParent(folder);
+        this.setId(id);
+        this.folder = new File(parent.getFile(), id);
+    }
 
-	public boolean remove() {
-		boolean r = true;
-		File folder = this.getParent().getFile();
-		File f = null;
-		try {
-			f = new File(folder,this.getId());
-			FileUtils.forceDelete(f);
-		} catch (IOException e) {
-			logger.warn("Can't remove project '"+f.getAbsolutePath()+"'.",e);
-			r = false;
-		}
-		return r;
-	}
-	
-	public void create(ScriptingFolder folder, String id, String language) {
-		File f = new File(folder.getFile(),id);
-		f.mkdir();
-		this.load(folder, id);
-	}
+    @Override
+    public String[] getIconNames() {
+        return new String[]{"folder", "folder-drag-accept"};
+    }
+
+    @Override
+    public boolean remove() {
+        File folder = this.getParent().getFile();
+        File f = new File(folder, this.getId());
+        try {
+            FileUtils.forceDelete(f);
+            return true;
+        } catch (IOException e) {
+            logger.warn("Can't remove folder '" + f.getAbsolutePath() + "'.", e);
+            return false;
+        }
+    }
+
+    @Override
+    public void create(ScriptingFolder folder, String id, String language) {
+        File f = new File(folder.getFile(), id);
+        f.mkdir();
+        this.load(folder, id);
+    }
 }
