You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2012/07/19 16:00:29 UTC

svn commit: r1363337 - in /pivot/branches/2.0.x: tests/src/org/apache/pivot/tests/issues/Pivot862.java tests/src/org/apache/pivot/tests/issues/pivot_862.bxml wtk/src/org/apache/pivot/wtk/FileBrowser.java wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java

Author: smartini
Date: Thu Jul 19 14:00:29 2012
New Revision: 1363337

URL: http://svn.apache.org/viewvc?rev=1363337&view=rev
Log:
PIVOT-862, test case and some comment inside classes to better show how to use constructors, depending on the use case

Added:
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/Pivot862.java
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot_862.bxml
Modified:
    pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowser.java
    pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java

Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/Pivot862.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/Pivot862.java?rev=1363337&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/Pivot862.java (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/Pivot862.java Thu Jul 19 14:00:29 2012
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.tests.issues;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.pivot.beans.BXML;
+import org.apache.pivot.beans.BXMLSerializer;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.FileBrowserSheet;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.Sheet;
+import org.apache.pivot.wtk.SheetCloseListener;
+import org.apache.pivot.wtk.Window;
+
+public class Pivot862 extends Application.Adapter
+{
+    private Window window = null;
+    private String selectedFolder = null;
+
+    @BXML
+    private PushButton selectFolderButton = null;
+
+    @BXML
+    private PushButton openFileButton = null;
+
+
+    @Override
+    public void startup(Display display, Map<String, String> properties) throws Exception {
+        BXMLSerializer bxmlSerializer = new BXMLSerializer();
+        window = (Window) bxmlSerializer.readObject(getClass().getResource("pivot_862.bxml"));
+        bxmlSerializer.bind(this, Pivot862.class);
+
+        selectFolderButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
+
+                fileBrowserSheet.setMode(FileBrowserSheet.Mode.SAVE_TO);  // to be able to select a folder
+                fileBrowserSheet.open(window, new SheetCloseListener() {
+                    @Override
+                    public void sheetClosed(Sheet sheet) {
+                        if (sheet.getResult()) {
+                            File loadedFile = fileBrowserSheet.getSelectedFile();
+                            try {
+                                selectedFolder = loadedFile.getCanonicalPath();
+                                System.out.println("Selected folder '" + selectedFolder + "'");
+
+                                // multiple tests ...
+                                System.out.println("Verify: Root folder (display from getName) was set to '"
+                                    + fileBrowserSheet.getRootDirectory().getName() + "'");
+                                System.out.println("Verify: Root folder (display from getCanonicalPath) was set to '"
+                                    + fileBrowserSheet.getRootDirectory().getCanonicalPath() + "'");
+                                System.out.println("Verify: Root folder (display from getCanonicalFile) was set to '"
+                                    + fileBrowserSheet.getRootDirectory().getCanonicalFile() + "'");
+
+                                openFileButton.setEnabled(true);
+                            } catch (IOException e) {
+                                e.printStackTrace();
+                                openFileButton.setEnabled(false);
+                            }
+                            window.setTitle("Selected folder: " + selectedFolder);
+                        }
+                    }
+                });
+            }
+        });
+
+        openFileButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                System.out.println("Now opening a BrowserSheet starting from the previous selected folder: \""
+                    + selectedFolder + "\"");
+                FileBrowserSheet fileBrowserSheet =
+                        // new FileBrowserSheet(FileBrowserSheet.Mode.OPEN, selectedFolder);  // use this as a workaround ...
+                        new FileBrowserSheet(FileBrowserSheet.Mode.OPEN);  // test to see the wrong behavior
+                        // new FileBrowserSheet();  // test to see the wrong behavior
+                fileBrowserSheet.setRootFolder(selectedFolder);  // ok, but doesn't solve this issue ...
+                System.out.println("\nNote: the behavior here is right only when using the constructor with two parameters ..."
+                    + " but in this source it's used one of other constructors.\n");
+
+                try {
+                    // multiple tests ...
+                    System.out.println("Verify: Root folder (display from getName) was set to '"
+                        + fileBrowserSheet.getRootDirectory().getName() + "'");
+                    System.out.println("Verify: Root folder (display from getCanonicalPath) was set to '"
+                        + fileBrowserSheet.getRootDirectory().getCanonicalPath() + "'");
+                    System.out.println("Verify: Root folder (display from getCanonicalFile) was set to '"
+                        + fileBrowserSheet.getRootDirectory().getCanonicalFile() + "'");
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+
+                fileBrowserSheet.open(window, new SheetCloseListener() {
+                    @Override
+                    public void sheetClosed(Sheet sheet) {
+                        // empty block
+                    }
+                });
+            }
+        });
+
+        window.open(display);
+    }
+
+    @Override
+    public boolean shutdown(boolean b) throws Exception {
+        return false;
+    }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(Pivot862.class, args);
+    }
+
+}

Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot_862.bxml
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot_862.bxml?rev=1363337&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot_862.bxml (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot_862.bxml Thu Jul 19 14:00:29 2012
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window title="Pivot-862" maximized="true"
+    xmlns:bxml="http://pivot.apache.org/bxml"
+    xmlns="org.apache.pivot.wtk"
+>
+    <Border styles="{padding:6}">
+        <TablePane>
+            <columns>
+                <TablePane.Column width="1*"/>
+            </columns>
+            <TablePane.Row height="-1">
+                <FlowPane styles="{padding:2, alignToBaseline:true}">
+                    <Label text="1 - "/>
+                    <Label text="Select a folder:"/>
+                    <Label text="  "/>
+                    <PushButton bxml:id="selectFolderButton" buttonData="Open Folder"/>
+                    <Label text="  "/>
+                    <TextArea editable="false" preferredWidth="400" styles="{}"
+                        text="Note: for this test you have to select a folder, and in a different disk than C: (in a Windows environment)"
+                    />
+                </FlowPane>
+            </TablePane.Row>
+            <TablePane.Row height="-1">
+                <Label text="  "/> <!-- spacer -->
+            </TablePane.Row>
+            <TablePane.Row height="-1">
+                <FlowPane styles="{padding:2, alignToBaseline:true}">
+                    <Label text="2 - "/>
+                    <Label text="Open the File Browser:"/>
+                    <Label text="  "/>
+                    <PushButton bxml:id="openFileButton" buttonData="Open File" enabled="false"/>
+                    <Label text="  "/>
+                    <TextArea editable="false" preferredWidth="400" styles="{}"
+                        text="Note: this File Browser has as root folder the previous selected folder"
+                    />
+                </FlowPane>
+            </TablePane.Row>
+            <TablePane.Row height="-1">
+                <Label text="  "/> <!-- spacer -->
+            </TablePane.Row>
+            <TablePane.Row height="-1">
+                <FlowPane styles="{padding:2, alignToBaseline:true}">
+                    <Label text="3 - "/>
+                    <TextArea editable="false" preferredWidth="500" styles="{}"
+                        text="For this Test to be successful, the File Browser (in row 2) should start from the selected folder (in point 1)"
+                    />
+                </FlowPane>
+            </TablePane.Row>
+            <TablePane.Row height="-1">
+                <Label text="  "/> <!-- spacer -->
+            </TablePane.Row>
+        </TablePane>
+    </Border>
+</Window>

Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowser.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowser.java?rev=1363337&r1=1363336&r2=1363337&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowser.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowser.java Thu Jul 19 14:00:29 2012
@@ -92,10 +92,23 @@ public class FileBrowser extends Contain
 
     private FileBrowserListenerList fileBrowserListeners = new FileBrowserListenerList();
 
+    /**
+     * Creates a new FileBrowser
+     * <p>
+     * Note that this version set by default mode to open.
+     */
     public FileBrowser() {
         this(USER_HOME);
     }
 
+    /**
+     * Creates a new FileBrowser
+     * <p>
+     * Note that this version of the constructor must be used when a custom root folder has to be set.
+     *
+     * @param rootFolder
+     * The root folder full name.
+     */
     public FileBrowser(String rootFolder) {
         if (rootFolder == null) {
             throw new IllegalArgumentException();

Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java?rev=1363337&r1=1363336&r2=1363337&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java Thu Jul 19 14:00:29 2012
@@ -85,14 +85,40 @@ public class FileBrowserSheet extends Sh
 
     private FileBrowserSheetListenerList fileBrowserSheetListeners = new FileBrowserSheetListenerList();
 
+    /**
+     * Creates a new FileBrowserSheet
+     * <p>
+     * Note that this version set by default mode to open and user home as root folder.
+     */
     public FileBrowserSheet() {
         this(Mode.OPEN);
     }
 
+    /**
+     * Creates a new FileBrowserSheet
+     * <p>
+     * Note that this version set by default the user home as root folder.
+     *
+     * @param mode
+     * The mode for opening the sheet.
+     * @see Mode
+     */
     public FileBrowserSheet(Mode mode) {
         this(mode, USER_HOME);
     }
 
+    /**
+     * Creates a new FileBrowserSheet
+     * <p>
+     * Note that this version of the constructor must be used when a custom root folder has to be set.
+     *
+     * @param mode
+     * The mode for opening the sheet.
+     * @see Mode
+     *
+     * @param rootFolder
+     * The root folder full name.
+     */
     public FileBrowserSheet(Mode mode, String rootFolder) {
         if (mode == null) {
             throw new IllegalArgumentException();
@@ -104,10 +130,7 @@ public class FileBrowserSheet extends Sh
 
         this.mode = mode;
 
-        rootDirectory = new File(rootFolder);
-        if (!rootDirectory.isDirectory()) {
-            throw new IllegalArgumentException();
-        }
+        setRootFolder(rootFolder);
 
         installSkin(FileBrowserSheet.class);
     }
@@ -133,6 +156,19 @@ public class FileBrowserSheet extends Sh
         return rootDirectory;
     }
 
+    // set the root folder but without firing events
+    public void setRootFolder(String rootFolder) {
+        if (rootFolder == null) {
+            throw new IllegalArgumentException();
+        }
+
+        rootDirectory = new File(rootFolder);
+        if (!rootDirectory.isDirectory()) {
+            throw new IllegalArgumentException();
+        }
+
+    }
+
     public void setRootDirectory(File rootDirectory) {
         if (rootDirectory == null
             || !rootDirectory.isDirectory()) {