Author: rwhitcomb Date: Fri Aug 30 21:50:02 2013 New Revision: 1519096 URL: http://svn.apache.org/r1519096 Log: PIVOT-864: Further fixes to support a pluggable file system browser. These changes resulting from actual use with a custom provider. However, all of these are compatible with the default provider(s) also.
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSheetSkin.java pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSkin.java pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowser.java pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowserSheet.java Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSheetSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSheetSkin.java?rev=1519096&r1=1519095&r2=1519096&view=diff ============================================================================== --- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSheetSkin.java (original) +++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSheetSkin.java Fri Aug 30 21:50:02 2013 @@ -318,7 +318,7 @@ public class TerraVFSBrowserSheetSkin ex try { FileObject selectedFile = manager.resolveFile(fileName); //if (!selectedFile.isAbsolute() && !fileName.startsWith(File.separator)) { - if (!baseFileName.isDescendent(selectedFile.getName())) { + if (baseFileName == null || !baseFileName.isAncestor(selectedFile.getName())) { selectedFile = manager.resolveFile(fileBrowser.getRootDirectory(), fileName); } else { // TODO: is there really anything to do here? @@ -343,7 +343,7 @@ public class TerraVFSBrowserSheetSkin ex // TODO: canonical file again //fileBrowserSheet.setRootDirectory(root.getCanonicalFile()); fileBrowserSheet.setRootDirectory(root); - selectedFile = manager.resolveFile(selectedFile.getName().getPath()); + selectedFile = manager.resolveFile(selectedFile.getName().getURI()); } catch (IOException ioe) { Form.setFlag(saveAsBoxPane, new Form.Flag()); Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSkin.java?rev=1519096&r1=1519095&r2=1519096&view=diff ============================================================================== --- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSkin.java (original) +++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSkin.java Fri Aug 30 21:50:02 2013 @@ -143,6 +143,8 @@ public class TerraVFSBrowserSkin extends public static Image getIcon(FileObject file) { Image icon; if (file.getName().getType() == FileType.FOLDER) { + // TODO: should this check be the full URI? What about remote file systems? + // seems like it should be the original home directory, and not the local file system home icon = file.getName().getPath().equals(HOME_DIRECTORY) ? HOME_FOLDER_IMAGE : FOLDER_IMAGE; } else { icon = FILE_IMAGE; @@ -232,7 +234,7 @@ public class TerraVFSBrowserSkin extends // Update the label // TODO: should this be the full path or the base name? - String text = file.getName().getPath(); + String text = file.getName().getBaseName(); if (text.length() == 0) { text = FileName.ROOT_PATH; } @@ -245,7 +247,7 @@ public class TerraVFSBrowserSkin extends public String toString(Object item) { FileObject file = (FileObject)item; // TODO: should this be the full path or the base name? - String text = file.getName().getPath(); + String text = file.getName().getBaseName(); if (text.length() == 0) { text = FileName.ROOT_PATH; } @@ -279,12 +281,13 @@ public class TerraVFSBrowserSkin extends Image icon = null; try { + FileType type = file.getType(); if (columnName.equals(NAME_KEY)) { text = file.getName().getBaseName(); icon = getIcon(file); getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT); } else if (columnName.equals(SIZE_KEY)) { - if (file.getType() == FileType.FOLDER) { + if (type == FileType.FOLDER || type == FileType.IMAGINARY) { text = ""; } else { long length = file.getContent().getSize(); @@ -292,10 +295,14 @@ public class TerraVFSBrowserSkin extends } getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT); } else if (columnName.equals(LAST_MODIFIED_KEY)) { - long lastModified = file.getContent().getLastModifiedTime(); - Date lastModifiedDate = new Date(lastModified); - text = DATE_FORMAT.format(lastModifiedDate); - getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT); + if (type == FileType.FOLDER || type == FileType.IMAGINARY) { + text = ""; + } else { + long lastModified = file.getContent().getLastModifiedTime(); + Date lastModifiedDate = new Date(lastModified); + text = DATE_FORMAT.format(lastModifiedDate); + getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT); + } } else { System.err.println("Unexpected column name in " + getClass().getName() + ": " + columnName); @@ -336,19 +343,24 @@ public class TerraVFSBrowserSkin extends FileObject file = (FileObject)row; try { + FileType type = file.getType(); if (columnName.equals(NAME_KEY)) { string = file.getName().getBaseName(); } else if (columnName.equals(SIZE_KEY)) { - if (file.getType() == FileType.FOLDER) { + if (type == FileType.FOLDER || type == FileType.IMAGINARY) { string = ""; } else { long length = file.getContent().getSize(); string = FileSizeFormat.getInstance().format(length); } } else if (columnName.equals(LAST_MODIFIED_KEY)) { - long lastModified = file.getContent().getLastModifiedTime(); - Date lastModifiedDate = new Date(lastModified); - string = DATE_FORMAT.format(lastModifiedDate); + if (type == FileType.FOLDER || type == FileType.IMAGINARY) { + string = ""; + } else { + long lastModified = file.getContent().getLastModifiedTime(); + Date lastModifiedDate = new Date(lastModified); + string = DATE_FORMAT.format(lastModifiedDate); + } } else { System.err.println("Unexpected column name in " + getClass().getName() + ": " + columnName); @@ -493,13 +505,15 @@ public class TerraVFSBrowserSkin extends private static final long serialVersionUID = 1L; @Override public int compare(FileObject f1, FileObject f2) { - boolean file1IsDirectory = f1.getName().getType() == FileType.FOLDER; - boolean file2IsDirectory = f2.getName().getType() == FileType.FOLDER; + FileType f1Type = f1.getName().getType(); + FileType f2Type = f2.getName().getType(); + boolean file1IsFile = f1Type == FileType.FILE || f1Type == FileType.FILE_OR_FOLDER; + boolean file2IsFile = f2Type == FileType.FILE || f2Type == FileType.FILE_OR_FOLDER; int result; - if (file1IsDirectory && !file2IsDirectory) { + if (!file1IsFile && file2IsFile) { result = -1; - } else if (!file1IsDirectory && file2IsDirectory) { + } else if (file1IsFile && !file2IsFile) { result = 1; } else { // Do the compare according to the rules of the file system @@ -513,13 +527,15 @@ public class TerraVFSBrowserSkin extends private static final long serialVersionUID = 1L; @Override public int compare(FileObject f1, FileObject f2) { - boolean file1IsDirectory = f1.getName().getType() == FileType.FOLDER; - boolean file2IsDirectory = f2.getName().getType() == FileType.FOLDER; + FileType f1Type = f1.getName().getType(); + FileType f2Type = f2.getName().getType(); + boolean file1IsFile = f1Type == FileType.FILE || f1Type == FileType.FILE_OR_FOLDER; + boolean file2IsFile = f2Type == FileType.FILE || f2Type == FileType.FILE_OR_FOLDER; int result; - if (file1IsDirectory && !file2IsDirectory) { + if (!file1IsFile && file2IsFile) { result = -1; - } else if (!file1IsDirectory && file2IsDirectory) { + } else if (file1IsFile && !file2IsFile) { result = 1; } else { // Do the compare according to the rules of the file system @@ -534,10 +550,12 @@ public class TerraVFSBrowserSkin extends @Override public int compare(FileObject f1, FileObject f2) { try { - boolean file1IsDirectory = f1.getType() == FileType.FOLDER; - boolean file2IsDirectory = f2.getType() == FileType.FOLDER; - long size1 = file1IsDirectory ? 0L : f1.getContent().getSize(); - long size2 = file2IsDirectory ? 0L : f2.getContent().getSize(); + FileType f1Type = f1.getName().getType(); + FileType f2Type = f2.getName().getType(); + boolean file1IsFile = f1Type == FileType.FILE || f1Type == FileType.FILE_OR_FOLDER; + boolean file2IsFile = f2Type == FileType.FILE || f2Type == FileType.FILE_OR_FOLDER; + long size1 = file1IsFile ? f1.getContent().getSize() : 0L; + long size2 = file2IsFile ? f2.getContent().getSize() : 0L; return Long.signum(size1 - size2); } catch (FileSystemException fse) { throw new RuntimeException(fse); @@ -550,10 +568,12 @@ public class TerraVFSBrowserSkin extends @Override public int compare(FileObject f1, FileObject f2) { try { - boolean file1IsDirectory = f1.getType() == FileType.FOLDER; - boolean file2IsDirectory = f2.getType() == FileType.FOLDER; - long size1 = file1IsDirectory ? 0L : f1.getContent().getSize(); - long size2 = file2IsDirectory ? 0L : f2.getContent().getSize(); + FileType f1Type = f1.getName().getType(); + FileType f2Type = f2.getName().getType(); + boolean file1IsFile = f1Type == FileType.FILE || f1Type == FileType.FILE_OR_FOLDER; + boolean file2IsFile = f2Type == FileType.FILE || f2Type == FileType.FILE_OR_FOLDER; + long size1 = file1IsFile ? f1.getContent().getSize() : 0L; + long size2 = file2IsFile ? f2.getContent().getSize() : 0L; return Long.signum(size2 - size1); } catch (FileSystemException fse) { throw new RuntimeException(fse); @@ -566,7 +586,13 @@ public class TerraVFSBrowserSkin extends @Override public int compare(FileObject f1, FileObject f2) { try { - return Long.signum(f1.getContent().getLastModifiedTime() - f2.getContent().getLastModifiedTime()); + FileType f1Type = f1.getName().getType(); + FileType f2Type = f2.getName().getType(); + boolean file1IsFile = f1Type == FileType.FILE || f1Type == FileType.FILE_OR_FOLDER; + boolean file2IsFile = f2Type == FileType.FILE || f2Type == FileType.FILE_OR_FOLDER; + long time1 = file1IsFile ? f1.getContent().getLastModifiedTime() : 0L; + long time2 = file2IsFile ? f2.getContent().getLastModifiedTime() : 0L; + return Long.signum(time1 - time2); } catch (FileSystemException fse) { throw new RuntimeException(fse); } @@ -578,7 +604,13 @@ public class TerraVFSBrowserSkin extends @Override public int compare(FileObject f1, FileObject f2) { try { - return Long.signum(f2.getContent().getLastModifiedTime() - f1.getContent().getLastModifiedTime()); + FileType f1Type = f1.getName().getType(); + FileType f2Type = f2.getName().getType(); + boolean file1IsFile = f1Type == FileType.FILE || f1Type == FileType.FILE_OR_FOLDER; + boolean file2IsFile = f2Type == FileType.FILE || f2Type == FileType.FILE_OR_FOLDER; + long time1 = file1IsFile ? f1.getContent().getLastModifiedTime() : 0L; + long time2 = file2IsFile ? f2.getContent().getLastModifiedTime() : 0L; + return Long.signum(time2 - time1); } catch (FileSystemException fse) { throw new RuntimeException(fse); } @@ -833,6 +865,7 @@ public class TerraVFSBrowserSkin extends @Override public void buttonPressed(Button button) { try { + // TODO: should this be the remote file system's home and not the local home? fileBrowser.setRootDirectory(HOME_DIRECTORY); } catch (FileSystemException fse) { throw new RuntimeException(fse); @@ -1157,7 +1190,7 @@ public class TerraVFSBrowserSkin extends // There is an open question on the Dev list about adding "getFileRoots()" to the VFS API. /* try { FileObject[] roots = new FileObject[1]; - roots[0] = manager.resolveFile(manager.getBaseFile().getName().getRoot().getPath()); + roots[0] = manager.resolveFile(manager.getBaseFile().getName().getRoot().getURI()); drives = new ArrayList<>(); for (int i = 0; i < roots.length; i++) { FileObject root = roots[i]; Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowser.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowser.java?rev=1519096&r1=1519095&r2=1519096&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowser.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowser.java Fri Aug 30 21:50:02 2013 @@ -265,12 +265,12 @@ public class VFSBrowser extends Containe // TODO: is this a good way to do this? //if (file.isAbsolute()) { - if (baseFileName != null && baseFileName.isDescendent(file.getName())) { + if (baseFileName != null && baseFileName.isAncestor(file.getName())) { if (!file.getParent().equals(rootDirectory)) { throw new IllegalArgumentException(); } } else { - file = manager.resolveFile(rootDirectory, file.getName().getPath()); + file = manager.resolveFile(rootDirectory, file.getName().getBaseName()); } int index = selectedFiles.add(file); @@ -330,7 +330,7 @@ public class VFSBrowser extends Containe } else { // TODO: adequate replacement for "isAbsolute"? //if (file.isAbsolute()) { - if (baseFileName != null && baseFileName.isDescendent(file.getName())) { + if (baseFileName != null && baseFileName.isAncestor(file.getName())) { setRootDirectory(file.getParent()); } @@ -384,8 +384,8 @@ public class VFSBrowser extends Containe // TODO: is this correct? //if (!file.isAbsolute()) { - if (baseFileName == null || !baseFileName.isDescendent(file.getName())) { - file = manager.resolveFile(rootDirectory, file.getName().getPath()); + if (baseFileName == null || !baseFileName.isAncestor(file.getName())) { + file = manager.resolveFile(rootDirectory, file.getName().getBaseName()); } // TODO: don't do this for now -- revisit later Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowserSheet.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowserSheet.java?rev=1519096&r1=1519095&r2=1519096&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowserSheet.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/VFSBrowserSheet.java Fri Aug 30 21:50:02 2013 @@ -165,11 +165,11 @@ public class VFSBrowserSheet extends She throws FileSystemException { if (mode == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Mode is null."); } if (rootFolder == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Root folder is null."); } setManager(manager); @@ -215,7 +215,7 @@ public class VFSBrowserSheet extends She public void setMode(Mode mode) { if (mode == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Mode is null."); } Mode previousMode = this.mode; @@ -235,12 +235,12 @@ public class VFSBrowserSheet extends She throws FileSystemException { if (rootFolder == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Root folder is null."); } rootDirectory = manager.resolveFile(rootFolder); if (rootDirectory.getType() != FileType.FOLDER) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Root file is not a directory."); } } @@ -256,7 +256,7 @@ public class VFSBrowserSheet extends She { if (rootDirectory == null || rootDirectory.getType() != FileType.FOLDER) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Root file is not a directory."); } if (rootDirectory.exists()) { @@ -299,7 +299,7 @@ public class VFSBrowserSheet extends She } else { // TODO: will this work right? //if (file.isAbsolute()) { - if (baseFileName != null && baseFileName.isDescendent(file.getName())) { + if (baseFileName != null && baseFileName.isAncestor(file.getName())) { setRootDirectory(file.getParent()); } @@ -348,17 +348,17 @@ public class VFSBrowserSheet extends She FileObject file = selectedFiles.get(i); if (file == null) { - throw new IllegalArgumentException("file is null."); + throw new IllegalArgumentException("Selected file is null."); } // TODO: is this correct? //if (!file.isAbsolute()) { - if (baseFileName == null || !baseFileName.isDescendent(file.getName())) { - file = manager.resolveFile(rootDirectory, file.getName().getPath()); + if (baseFileName == null || !baseFileName.isAncestor(file.getName())) { + file = manager.resolveFile(rootDirectory, file.getName().getBaseName()); } if (!file.getParent().equals(rootDirectory)) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Selected file doesn't appear to belong to the current directory."); } fileList.add(file);