From fca5e518c135176295464a9e2ab7a65729a0e32c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 24 May 2008 22:43:39 +0200 Subject: [PATCH] implement file scanning emit event when done --- src/net/pterodactylus/jsite/project/Project.java | 102 ++++++++++++----------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/src/net/pterodactylus/jsite/project/Project.java b/src/net/pterodactylus/jsite/project/Project.java index 51ec2d3..1d1de85 100644 --- a/src/net/pterodactylus/jsite/project/Project.java +++ b/src/net/pterodactylus/jsite/project/Project.java @@ -47,9 +47,12 @@ public class Project extends AbstractBean { /** Name of the “private key” property. */ public static final String PROPERTY_PRIVATE_KEY = "privateKey"; - /** Name of the “local path” property. */ + /** Name of the “base path” property. */ public static final String PROPERTY_BASE_PATH = "basePath"; + /** Name of the “base path entries” property. */ + public static final String PROPERTY_BASE_PATH_ENTRIES = "basePathEntries"; + /** Internal ID. */ private String id; @@ -68,8 +71,8 @@ public class Project extends AbstractBean { /** The base path of the project. */ private String basePath; - /** The list of files from the base path. */ - private List basePathEntries = new ArrayList(); + /** The list of files from the base path. */ + private List basePathEntries = new ArrayList(); /** * Returns the internal ID. @@ -196,52 +199,55 @@ public class Project extends AbstractBean { } /** - * Rescans the base path for new or changed files. - */ - public void rescanBasePath() { - List entries = new ArrayList(); - scanPath("", entries); - } - - /** - * Returns the list of files from the base path. - * - * @return The list of files from the base path - */ - public List getBasePathEntries() { - return basePathEntries; - } - - // - // PRIVATE METHODS - // - - /** - * Scans the given path relative to {@link #basePath} for files and adds - * them to the given list of entries. - * - * @param currentPath - * The current path, relative to the base path - * @param entries - * The list of entries - */ - private void scanPath(String currentPath, List entries) { - File currentDirectory = new File(basePath + File.separatorChar + currentPath); - if (!currentDirectory.isDirectory()) { - return; + * Rescans the base path for new or changed files. + */ + public void rescanBasePath() { + List entries = new ArrayList(); + scanPath("", entries); + basePathEntries.clear(); + basePathEntries.addAll(entries); + firePropertyChange(PROPERTY_BASE_PATH_ENTRIES, null, null); + } + + /** + * Returns the list of files from the base path. + * + * @return The list of files from the base path + */ + public List getBasePathEntries() { + return basePathEntries; + } + + // + // PRIVATE METHODS + // + + /** + * Scans the given path relative to {@link #basePath} for files and adds + * them to the given list of entries. + * + * @param currentPath + * The current path, relative to the base path + * @param entries + * The list of entries + */ + private void scanPath(String currentPath, List entries) { + File currentDirectory = new File(basePath + File.separatorChar + currentPath); + if (!currentDirectory.isDirectory()) { + return; + } + for (File file: currentDirectory.listFiles()) { + String fileName = currentPath + file.getName(); + if (file.isDirectory()) { + scanPath(fileName + File.separatorChar, entries); + continue; + } + PhysicalEntry entry = new PhysicalEntry(); + entry.setName(fileName); + entry.setPath(file.getPath()); + entry.setInsert(!file.isHidden()); + entries.add(entry); } - for (File file: currentDirectory.listFiles()) { - String fileName = currentPath + file.getName(); - if (file.isDirectory()) { - scanPath(fileName + File.separatorChar, entries); - continue; - } - PhysicalEntry entry = new PhysicalEntry(); - entry.setName(fileName); - entry.setPath(file.getPath()); - entry.setInsert(!file.isHidden()); - entries.add(entry); - } } } -- 2.7.4