Author: rwhitcomb Date: Thu Nov 14 22:36:48 2013 New Revision: 1542110 URL: http://svn.apache.org/r1542110 Log: PIVOT-864: Fix a NullPointerException trying to check a file against the home directory. Basically the VFSBrowser component is not in the component hierarchy of the skin, so we need another way to get to it. Set an explicit pointer in the renderers themselves after loading the bxml file.
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraVFSBrowserSkin.java 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=1542110&r1=1542109&r2=1542110&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 Thu Nov 14 22:36:48 2013 @@ -96,6 +96,7 @@ public class TerraVFSBrowserSkin extends public static abstract class FileRenderer extends BoxPane { protected ImageView imageView = new ImageView(); protected Label label = new Label(); + protected VFSBrowser fileBrowser = null; public static final int ICON_WIDTH = 16; public static final int ICON_HEIGHT = 16; @@ -133,12 +134,8 @@ public class TerraVFSBrowserSkin extends validate(); } - private static VFSBrowser getBrowser(Component component) { - Component parent = component; - while (!(parent instanceof VFSBrowser)) { - parent = parent.getParent(); - } - return (VFSBrowser)parent; + protected void setFileBrowser(VFSBrowser fileBrowser) { + this.fileBrowser = fileBrowser; } /** @@ -146,10 +143,10 @@ public class TerraVFSBrowserSkin extends * * @param file */ - public static Image getIcon(FileObject file, Component component) { + public Image getIcon(FileObject file) { Image icon; if (file.getName().getType() == FileType.FOLDER) { - icon = file.equals(getBrowser(component).getHomeDirectory()) ? HOME_FOLDER_IMAGE + icon = file.equals(fileBrowser.getHomeDirectory()) ? HOME_FOLDER_IMAGE : FOLDER_IMAGE; } else { icon = FILE_IMAGE; @@ -173,7 +170,7 @@ public class TerraVFSBrowserSkin extends FileObject file = (FileObject) data; // Update the image view - imageView.setImage(getIcon(file, button)); + imageView.setImage(getIcon(file)); imageView.getStyles().put("opacity", button.isEnabled() ? 1.0f : 0.5f); // Update the label @@ -233,7 +230,7 @@ public class TerraVFSBrowserSkin extends FileObject file = (FileObject) item; // Update the image view - imageView.setImage(getIcon(file, listView)); + imageView.setImage(getIcon(file)); imageView.getStyles().put("opacity", (listView.isEnabled() && !disabled) ? 1.0f : 0.5f); @@ -287,7 +284,7 @@ public class TerraVFSBrowserSkin extends FileType type = file.getType(); if (columnName.equals(NAME_KEY)) { text = file.getName().getBaseName(); - icon = getIcon(file, tableView); + icon = getIcon(file); getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT); } else if (columnName.equals(SIZE_KEY)) { if (type == FileType.FOLDER || type == FileType.IMAGINARY) { @@ -391,7 +388,7 @@ public class TerraVFSBrowserSkin extends static { try { - DRIVE_IMAGE = Image.load(FileRenderer.class.getResource("drive.png")); + DRIVE_IMAGE = Image.load(DriveRenderer.class.getResource("drive.png")); } catch (TaskExecutionException exception) { throw new RuntimeException(exception); } @@ -818,6 +815,13 @@ public class TerraVFSBrowserSkin extends bxmlSerializer.bind(this, TerraVFSBrowserSkin.class); + // Notify all the renderers of which component they are dealing with + ((FileRenderer)pathListButton.getDataRenderer()).setFileBrowser(fileBrowser); + ((FileRenderer)pathListButton.getItemRenderer()).setFileBrowser(fileBrowser); + for (TableView.Column col : fileTableView.getColumns()) { + ((FileRenderer)col.getCellRenderer()).setFileBrowser(fileBrowser); + } + homeDirectory = fileBrowser.getHomeDirectory(); driveListButton.getListButtonSelectionListeners().add(