Search in sources :

Example 6 with FileBrowserSheet

use of org.apache.pivot.wtk.FileBrowserSheet in project pivot by apache.

the class Pivot862 method startup.

@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();
            // to
            fileBrowserSheet.setMode(FileBrowserSheet.Mode.SAVE_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 = // selectedFolder); // use this as a workaround ...
            new FileBrowserSheet(// test to see
            FileBrowserSheet.Mode.OPEN);
            // the wrong
            // behavior
            // new FileBrowserSheet(); // test to see the wrong behavior
            // ok, but
            fileBrowserSheet.setRootFolder(selectedFolder);
            // 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);
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) IOException(java.io.IOException) Sheet(org.apache.pivot.wtk.Sheet) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) File(java.io.File) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 7 with FileBrowserSheet

use of org.apache.pivot.wtk.FileBrowserSheet in project pivot by apache.

the class Pivot800 method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    Window window = new Window();
    window.setMaximized(true);
    sheet = new FileBrowserSheet(FileBrowserSheet.Mode.SAVE_TO);
    sheet.getWindowStateListeners().add(new SelectFileListener());
    window.open(display);
    sheet.open(window);
}
Also used : Window(org.apache.pivot.wtk.Window) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet)

Example 8 with FileBrowserSheet

use of org.apache.pivot.wtk.FileBrowserSheet in project pivot by apache.

the class FileBrowserWithCharsetTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BoxPane windowContent = new BoxPane();
    windowContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    final Checkbox showHiddenCheckbox = new Checkbox("Show hidden files");
    windowContent.add(showHiddenCheckbox);
    PushButton button = new PushButton("Open File Browser");
    button.getStyles().put(Style.padding, "[2, 4, 2, 4]");
    button.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button buttonArgument) {
            final Window window = Window.getActiveWindow();
            final FileBrowserWithCharsetTest fileBrowserSheet = new FileBrowserWithCharsetTest(FileBrowserSheet.Mode.OPEN);
            fileBrowserSheet.getStyles().put(Style.showHiddenFiles, showHiddenCheckbox.isSelected());
            fileBrowserSheet.open(window, new SheetCloseListener() {

                @Override
                public void sheetClosed(Sheet sheet) {
                    if (sheet.getResult()) {
                        Sequence<File> selectedFiles = fileBrowserSheet.getSelectedFiles();
                        ListView listView = new ListView();
                        listView.setListData(new ArrayList<>(selectedFiles));
                        listView.setSelectMode(ListView.SelectMode.NONE);
                        listView.getStyles().put(Style.backgroundColor, null);
                        Alert.alert(MessageType.INFO, "You selected (charset " + fileBrowserSheet.getCharsetName() + "):", listView, window);
                    } else {
                        Alert.alert(MessageType.INFO, "You didn't select anything.", window);
                    }
                }
            });
        }
    });
    windowContent.add(button);
    frame = new Frame(windowContent);
    frame.setMaximized(true);
    frame.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Frame(org.apache.pivot.wtk.Frame) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ListView(org.apache.pivot.wtk.ListView) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) Checkbox(org.apache.pivot.wtk.Checkbox) PushButton(org.apache.pivot.wtk.PushButton) Sheet(org.apache.pivot.wtk.Sheet) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) File(java.io.File)

Example 9 with FileBrowserSheet

use of org.apache.pivot.wtk.FileBrowserSheet in project pivot by apache.

the class TerraFileBrowserSheetSkin method previewSheetClose.

@Override
public Vote previewSheetClose(final Sheet sheet, final boolean result) {
    Vote vote = null;
    if (result && !okButton.isEnabled()) {
        vote = Vote.DENY;
    } else {
        if (result) {
            updatingSelection = true;
            FileBrowserSheet fileBrowserSheet = (FileBrowserSheet) sheet;
            FileBrowserSheet.Mode mode = fileBrowserSheet.getMode();
            switch(mode) {
                case OPEN:
                case OPEN_MULTIPLE:
                case SAVE_TO:
                    {
                        fileBrowserSheet.setSelectedFiles(fileBrowser.getSelectedFiles());
                        break;
                    }
                case SAVE_AS:
                    {
                        String fileName = saveAsTextInput.getText();
                        // Contents of the entry field could be:
                        // 1. Just a new file name in the current root directory
                        // 2. A relative or absolute path that is an existing directory
                        // to navigate to
                        // 3. A relative or absolute path including the new file name
                        // in an existing directory
                        // So, first make it an absolute path
                        File selectedFile = new File(fileName);
                        if (!selectedFile.isAbsolute() && !fileName.startsWith(File.separator)) {
                            selectedFile = new File(fileBrowser.getRootDirectory(), fileName);
                        } else {
                            selectedFile = selectedFile.getAbsoluteFile();
                        }
                        if (selectedFile.exists() && selectedFile.isDirectory()) {
                            try {
                                File root = selectedFile.getCanonicalFile();
                                fileBrowserSheet.setRootDirectory(root);
                                fileBrowser.setRootDirectory(root);
                                saveAsTextInput.setText("");
                            } catch (IOException ioe) {
                                Form.setFlag(saveAsBoxPane, new Form.Flag());
                            }
                            selectedFile = null;
                            vote = Vote.DENY;
                        } else {
                            File root = selectedFile.getParentFile();
                            if (root != null && root.exists() && root.isDirectory()) {
                                try {
                                    fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
                                    selectedFile = new File(selectedFile.getName());
                                } catch (IOException ioe) {
                                    Form.setFlag(saveAsBoxPane, new Form.Flag());
                                    selectedFile = null;
                                    vote = Vote.DENY;
                                }
                            } else {
                                // Could be an error message here
                                // ("Directory does not exist")
                                Form.setFlag(saveAsBoxPane, new Form.Flag());
                                selectedFile = null;
                                vote = Vote.DENY;
                            }
                        }
                        if (selectedFile != null) {
                            fileBrowserSheet.setSelectedFiles(new ArrayList<>(selectedFile));
                        }
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
            updatingSelection = false;
        }
        if (vote == null) {
            vote = super.previewSheetClose(sheet, result);
        }
    }
    return vote;
}
Also used : Vote(org.apache.pivot.util.Vote) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) Form(org.apache.pivot.wtk.Form) ArrayList(org.apache.pivot.collections.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 10 with FileBrowserSheet

use of org.apache.pivot.wtk.FileBrowserSheet in project pivot by apache.

the class TerraFileBrowserSheetSkin method updateOKButtonState.

private void updateOKButtonState() {
    FileBrowserSheet fileBrowserSheet = (FileBrowserSheet) getComponent();
    FileBrowserSheet.Mode mode = fileBrowserSheet.getMode();
    Sequence<File> selectedFiles = fileBrowser.getSelectedFiles();
    switch(mode) {
        case OPEN:
        case OPEN_MULTIPLE:
            {
                okButton.setEnabled(selectedFiles.getLength() > 0 && selectedDirectoryCount == 0);
                break;
            }
        case SAVE_AS:
            {
                okButton.setEnabled(saveAsTextInput.getCharacterCount() > 0);
                break;
            }
        case SAVE_TO:
            {
                okButton.setEnabled(selectedDirectoryCount > 0);
                break;
            }
        default:
            {
                break;
            }
    }
}
Also used : FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) File(java.io.File)

Aggregations

FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)10 File (java.io.File)9 Button (org.apache.pivot.wtk.Button)6 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)6 PushButton (org.apache.pivot.wtk.PushButton)6 IOException (java.io.IOException)5 Sheet (org.apache.pivot.wtk.Sheet)5 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)5 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)4 ListView (org.apache.pivot.wtk.ListView)3 ListButton (org.apache.pivot.wtk.ListButton)2 Window (org.apache.pivot.wtk.Window)2 Color (java.awt.Color)1 Font (java.awt.Font)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 ArrayList (org.apache.pivot.collections.ArrayList)1 Sequence (org.apache.pivot.collections.Sequence)1 SerializationException (org.apache.pivot.serialization.SerializationException)1