Search in sources :

Example 16 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class TerraVFSBrowserSkin method rootDirectoryChanged.

@Override
public void rootDirectoryChanged(VFSBrowser fileBrowser, FileObject previousRootDirectory) {
    ArrayList<FileObject> path = new ArrayList<>();
    // FileSystemManager manager = fileBrowser.getManager();
    FileObject rootDirectory = fileBrowser.getRootDirectory();
    try {
        FileObject ancestorDirectory = rootDirectory.getParent();
        while (ancestorDirectory != null) {
            path.add(ancestorDirectory);
            ancestorDirectory = ancestorDirectory.getParent();
        }
    } catch (FileSystemException fse) {
        throw new RuntimeException(fse);
    }
    @SuppressWarnings("unchecked") ArrayList<FileObject> drives = (ArrayList<FileObject>) driveListButton.getListData();
    if (refreshRoots) {
        // TODO: this is ugly -- need to do much better at managing drive
        // list with VFS
        // 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().getURI()); drives =
             * new ArrayList<>(); for (int i = 0; i < roots.length; i++) {
             * FileObject root = roots[i]; if (root.exists()) {
             * drives.add(root); } } driveListButton.setListData(drives); }
             * catch (FileSystemException fse) { throw new
             * RuntimeException(fse); }
             */
        refreshRoots = false;
    }
    driveListButton.setVisible(drives.getLength() > 1);
    FileObject drive;
    if (path.getLength() == 0) {
        drive = rootDirectory;
    } else {
        drive = path.get(path.getLength() - 1);
    }
    driveListButton.setSelectedItem(drive);
    pathListButton.setListData(path);
    pathListButton.setButtonData(rootDirectory);
    pathListButton.setEnabled(rootDirectory.getName().getDepth() > 0);
    goUpButton.setEnabled(pathListButton.isEnabled());
    goHomeButton.setEnabled(!rootDirectory.equals(homeDirectory));
    fileScrollPane.setScrollTop(0);
    fileScrollPane.setScrollLeft(0);
    searchTextInput.setText("");
    fileTableView.requestFocus();
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) ArrayList(org.apache.pivot.collections.ArrayList) FileObject(org.apache.commons.vfs2.FileObject)

Example 17 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class TerraVFSBrowserSkin method updateSelectedFiles.

private void updateSelectedFiles(VFSBrowser fileBrowser) {
    if (!updatingSelection) {
        Sequence<FileObject> selectedFiles = fileBrowser.getSelectedFiles();
        ArrayList<Span> selectedRanges = new ArrayList<>();
        for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
            FileObject selectedFile = selectedFiles.get(i);
            @SuppressWarnings("unchecked") List<FileObject> files = (List<FileObject>) fileTableView.getTableData();
            int index = files.indexOf(selectedFile);
            if (index != -1) {
                selectedRanges.add(new Span(index, index));
            }
        }
        updatingSelection = true;
        fileTableView.setSelectedRanges(selectedRanges);
        updatingSelection = false;
    }
}
Also used : ArrayList(org.apache.pivot.collections.ArrayList) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) FileObject(org.apache.commons.vfs2.FileObject) Span(org.apache.pivot.wtk.Span) Point(org.apache.pivot.wtk.Point)

Example 18 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class TerraFileBrowserSkin method updateSelectedFiles.

private void updateSelectedFiles(FileBrowser fileBrowser) {
    if (!updatingSelection) {
        Sequence<File> selectedFiles = fileBrowser.getSelectedFiles();
        ArrayList<Span> selectedRanges = new ArrayList<>();
        for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
            File selectedFile = selectedFiles.get(i);
            @SuppressWarnings("unchecked") List<File> files = (List<File>) fileTableView.getTableData();
            int index = files.indexOf(selectedFile);
            if (index != -1) {
                selectedRanges.add(new Span(index, index));
            }
        }
        updatingSelection = true;
        fileTableView.setSelectedRanges(selectedRanges);
        updatingSelection = false;
    }
}
Also used : ArrayList(org.apache.pivot.collections.ArrayList) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) File(java.io.File) Span(org.apache.pivot.wtk.Span) Point(org.apache.pivot.wtk.Point)

Example 19 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class ExpensesWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    expenseTableView = (TableView) namespace.get("expenseTableView");
    activityIndicator = (ActivityIndicator) namespace.get("activityIndicator");
    activityIndicatorBoxPane = (BoxPane) namespace.get("activityIndicatorBoxPane");
    // Load the add/edit sheet
    try {
        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        expenseSheet = (ExpenseSheet) bxmlSerializer.readObject(ExpenseSheet.class, "expense_sheet.bxml", true);
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    } catch (SerializationException exception) {
        throw new RuntimeException(exception);
    }
    // Create the delete confirmation prompt
    ArrayList<String> options = new ArrayList<>((String) resources.get("ok"), (String) resources.get("cancel"));
    deleteConfirmationPrompt = new Prompt(MessageType.QUESTION, (String) resources.get("confirmDelete"), options);
    // Attach event listeners
    expenseTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {

        @Override
        public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
            int selectedIndex = expenseTableView.getSelectedIndex();
            editSelectedExpenseAction.setEnabled(selectedIndex != -1);
            deleteSelectedExpenseAction.setEnabled(selectedIndex != -1);
        }
    });
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) ArrayList(org.apache.pivot.collections.ArrayList) Prompt(org.apache.pivot.wtk.Prompt) IOException(java.io.IOException) TableViewSelectionListener(org.apache.pivot.wtk.TableViewSelectionListener) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) TableView(org.apache.pivot.wtk.TableView)

Example 20 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class SuggestionPopups method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    stateTextInput = (TextInput) namespace.get("stateTextInput");
    stateTextInput.getTextInputContentListeners().add(new TextInputContentListener() {

        @Override
        public void textInserted(TextInput textInput, int index, int count) {
            String text = textInput.getText();
            ArrayList<String> suggestions = new ArrayList<>();
            for (String state : states) {
                if (state.toUpperCase().startsWith(text.toUpperCase())) {
                    suggestions.add(state);
                }
            }
            if (suggestions.getLength() > 0) {
                suggestionPopup.setSuggestionData(suggestions);
                suggestionPopup.open(textInput);
            }
        }

        @Override
        public void textRemoved(TextInput textInput, int index, int count) {
            suggestionPopup.close();
        }
    });
    suggestionPopup.setListSize(4);
}
Also used : TextInputContentListener(org.apache.pivot.wtk.TextInputContentListener) ArrayList(org.apache.pivot.collections.ArrayList) TextInput(org.apache.pivot.wtk.TextInput)

Aggregations

ArrayList (org.apache.pivot.collections.ArrayList)41 List (org.apache.pivot.collections.List)9 Span (org.apache.pivot.wtk.Span)8 Test (org.junit.Test)6 IOException (java.io.IOException)5 ListView (org.apache.pivot.wtk.ListView)5 Point (org.apache.pivot.wtk.Point)5 TableView (org.apache.pivot.wtk.TableView)5 StringWriter (java.io.StringWriter)4 HashMap (org.apache.pivot.collections.HashMap)4 CSVSerializer (org.apache.pivot.serialization.CSVSerializer)4 SerializationException (org.apache.pivot.serialization.SerializationException)4 Vote (org.apache.pivot.util.Vote)4 Component (org.apache.pivot.wtk.Component)4 Form (org.apache.pivot.wtk.Form)4 File (java.io.File)3 FileObject (org.apache.commons.vfs2.FileObject)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 Bounds (org.apache.pivot.wtk.Bounds)3 ListButton (org.apache.pivot.wtk.ListButton)3