X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fproject%2FProject.java;h=51ec2d323669c7508972e8f900806f16712a5ba3;hb=06602fb38a0a5f943c967da582b7a304f5ea5d51;hp=2c6609fb2b35e322329d57d8f1144d576c1c5a75;hpb=10b165ebaa51eccec487500b32f0c7b3106923af;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/project/Project.java b/src/net/pterodactylus/jsite/project/Project.java index 2c6609f..51ec2d3 100644 --- a/src/net/pterodactylus/jsite/project/Project.java +++ b/src/net/pterodactylus/jsite/project/Project.java @@ -20,6 +20,9 @@ package net.pterodactylus.jsite.project; import java.beans.PropertyChangeListener; +import java.io.File; +import java.util.ArrayList; +import java.util.List; import net.pterodactylus.util.beans.AbstractBean; @@ -45,7 +48,10 @@ public class Project extends AbstractBean { public static final String PROPERTY_PRIVATE_KEY = "privateKey"; /** Name of the “local path” property. */ - public static final String PROPERTY_LOCAL_PATH = "localPath"; + public static final String PROPERTY_BASE_PATH = "basePath"; + + /** Internal ID. */ + private String id; /** The name of the project. */ private String name; @@ -62,9 +68,27 @@ public class Project extends AbstractBean { /** The base path of the project. */ private String basePath; - // - // EVENT MANAGEMENT - // + /** The list of files from the base path. */ + private List basePathEntries = new ArrayList(); + + /** + * Returns the internal ID. + * + * @return The internal ID + */ + String getId() { + return id; + } + + /** + * Sets the internal ID. + * + * @param id + * The internal ID + */ + void setId(String id) { + this.id = id; + } /** * Returns the name of the project. @@ -84,9 +108,7 @@ public class Project extends AbstractBean { public void setName(String name) { String oldName = this.name; this.name = name; - if (!equal(oldName, name)) { - firePropertyChange(PROPERTY_NAME, oldName, name); - } + fireIfPropertyChanged(PROPERTY_NAME, oldName, name); } /** @@ -107,9 +129,7 @@ public class Project extends AbstractBean { public void setDescription(String description) { String oldDescription = this.description; this.description = description; - if (!equal(oldDescription, description)) { - firePropertyChange(PROPERTY_DESCRIPTION, oldDescription, description); - } + fireIfPropertyChanged(PROPERTY_DESCRIPTION, oldDescription, description); } /** @@ -127,12 +147,10 @@ public class Project extends AbstractBean { * @param publicKey * The public key of the project */ - public void setPublicKey(String publicKey) { + void setPublicKey(String publicKey) { String oldPublicKey = this.publicKey; this.publicKey = publicKey; - if (!equal(oldPublicKey, publicKey)) { - firePropertyChange(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey); - } + fireIfPropertyChanged(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey); } /** @@ -150,12 +168,10 @@ public class Project extends AbstractBean { * @param privateKey * The private key of the project */ - public void setPrivateKey(String privateKey) { + void setPrivateKey(String privateKey) { String oldPrivateKey = this.privateKey; this.privateKey = privateKey; - if (!equal(oldPrivateKey, privateKey)) { - firePropertyChange(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey); - } + fireIfPropertyChanged(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey); } /** @@ -176,7 +192,56 @@ public class Project extends AbstractBean { public void setBasePath(String basePath) { String oldBasePath = this.basePath; this.basePath = basePath; - firePropertyChange(PROPERTY_LOCAL_PATH, oldBasePath, basePath); + fireIfPropertyChanged(PROPERTY_BASE_PATH, oldBasePath, basePath); + } + + /** + * 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; + } + 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); + } } }