Search in sources :

Example 1 with TableViewRowComparator

use of org.apache.pivot.wtk.content.TableViewRowComparator in project pivot by apache.

the class FixedColumnTableDemo method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    primaryTableView = (TableView) namespace.get("primaryTableView");
    fixedTableView = (TableView) namespace.get("fixedTableView");
    // Keep selection state in sync
    primaryTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {

        @Override
        public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
            if (!synchronizingSelection) {
                synchronizingSelection = true;
                fixedTableView.addSelectedRange(rangeStart, rangeEnd);
                synchronizingSelection = false;
            }
        }

        @Override
        public void selectedRangeRemoved(TableView tableView, int rangeStart, int rangeEnd) {
            if (!synchronizingSelection) {
                synchronizingSelection = true;
                fixedTableView.removeSelectedRange(rangeStart, rangeEnd);
                synchronizingSelection = false;
            }
        }

        @Override
        public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
            if (previousSelectedRanges != null && !synchronizingSelection) {
                synchronizingSelection = true;
                fixedTableView.setSelectedRanges(tableView.getSelectedRanges());
                synchronizingSelection = false;
            }
        }

        @Override
        public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
        // No-op
        }
    });
    fixedTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {

        @Override
        public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
            if (!synchronizingSelection) {
                synchronizingSelection = true;
                primaryTableView.addSelectedRange(rangeStart, rangeEnd);
                synchronizingSelection = false;
            }
        }

        @Override
        public void selectedRangeRemoved(TableView tableView, int rangeStart, int rangeEnd) {
            if (!synchronizingSelection) {
                synchronizingSelection = true;
                primaryTableView.removeSelectedRange(rangeStart, rangeEnd);
                synchronizingSelection = false;
            }
        }

        @Override
        public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
            if (previousSelectedRanges != null && !synchronizingSelection) {
                synchronizingSelection = true;
                primaryTableView.setSelectedRanges(tableView.getSelectedRanges());
                synchronizingSelection = false;
            }
        }

        @Override
        public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
        // No-op
        }
    });
    // Keep header state in sync
    primaryTableView.getTableViewSortListeners().add(new TableViewSortListener() {

        @Override
        public void sortChanged(TableView tableView) {
            if (!tableView.getSort().isEmpty()) {
                fixedTableView.clearSort();
            }
            @SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
            tableData.setComparator(new TableViewRowComparator(tableView));
        }
    });
    fixedTableView.getTableViewSortListeners().add(new TableViewSortListener() {

        @Override
        public void sortChanged(TableView tableView) {
            if (!tableView.getSort().isEmpty()) {
                primaryTableView.clearSort();
            }
            @SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
            tableData.setComparator(new TableViewRowComparator(tableView));
        }
    });
}
Also used : TableViewRowComparator(org.apache.pivot.wtk.content.TableViewRowComparator) TableViewSortListener(org.apache.pivot.wtk.TableViewSortListener) List(org.apache.pivot.collections.List) TableViewSelectionListener(org.apache.pivot.wtk.TableViewSelectionListener) Span(org.apache.pivot.wtk.Span) TableView(org.apache.pivot.wtk.TableView)

Example 2 with TableViewRowComparator

use of org.apache.pivot.wtk.content.TableViewRowComparator in project pivot by apache.

the class LargeData method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    basePath = properties.get(BASE_PATH_KEY);
    if (basePath == null) {
        throw new IllegalArgumentException(BASE_PATH_KEY + " is required.");
    }
    origin = ApplicationContext.getOrigin();
    if (origin == null) {
        System.out.println("Running as a Standalone Java Application, with user home: \"" + USER_HOME + "\"");
        if (USER_HOME != null) {
            System.out.println("Set as origin the user home");
            origin = (new File(USER_HOME).toURI()).toURL();
        }
    }
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(LargeData.class, "large_data.bxml");
    fileListButton = (ListButton) bxmlSerializer.getNamespace().get("fileListButton");
    loadDataButton = (PushButton) bxmlSerializer.getNamespace().get("loadDataButton");
    cancelButton = (PushButton) bxmlSerializer.getNamespace().get("cancelButton");
    clearButton = (PushButton) bxmlSerializer.getNamespace().get("clearButton");
    statusLabel = (Label) bxmlSerializer.getNamespace().get("statusLabel");
    tableView = (TableView) bxmlSerializer.getNamespace().get("tableView");
    fileListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {

        @Override
        public void selectedItemChanged(ListButton listButtonArgument, Object previousSelectedItem) {
            Object selectedItem = listButtonArgument.getSelectedItem();
            System.out.println("Selected: " + selectedItem.toString() + ", now clear table data ...");
            // empty the table
            tableView.getTableData().clear();
        }
    });
    loadDataButton.getButtonPressListeners().add((button) -> {
        loadDataButton.setEnabled(false);
        cancelButton.setEnabled(true);
        loadData();
    });
    cancelButton.getButtonPressListeners().add((button) -> {
        if (loadDataTask != null) {
            loadDataTask.abort();
        }
        loadDataButton.setEnabled(true);
        cancelButton.setEnabled(false);
    });
    clearButton.getButtonPressListeners().add((button) -> {
        if (loadDataTask != null) {
            loadDataTask.abort();
        }
        // empty the table
        tableView.getTableData().clear();
        statusLabel.setText("");
    });
    tableView.getTableViewSortListeners().add(new TableViewSortListener() {

        @Override
        public void sortChanged(TableView tableViewArgument) {
            @SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableViewArgument.getTableData();
            long startTime = System.currentTimeMillis();
            tableData.setComparator(new TableViewRowComparator(tableViewArgument));
            long endTime = System.currentTimeMillis();
            statusLabel.setText("Data sorted in " + (endTime - startTime) + " ms.");
        }
    });
    window.open(display);
}
Also used : ListButton(org.apache.pivot.wtk.ListButton) TableViewRowComparator(org.apache.pivot.wtk.content.TableViewRowComparator) ListButtonSelectionListener(org.apache.pivot.wtk.ListButtonSelectionListener) TableViewSortListener(org.apache.pivot.wtk.TableViewSortListener) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) File(java.io.File) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) TableView(org.apache.pivot.wtk.TableView)

Example 3 with TableViewRowComparator

use of org.apache.pivot.wtk.content.TableViewRowComparator in project pivot by apache.

the class StockTrackerWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    // Add stocks table view event handlers
    stocksTableView.getTableViewRowListeners().add(new TableViewRowListener() {

        @Override
        public void rowsSorted(TableView tableView) {
            List<?> tableData = stocksTableView.getTableData();
            if (tableData.getLength() > 0) {
                stocksTableView.setSelectedIndex(0);
            }
        }
    });
    stocksTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {

        @Override
        public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
            int firstSelectedIndex = stocksTableView.getFirstSelectedIndex();
            removeSymbolsAction.setEnabled(firstSelectedIndex != -1);
            refreshDetail();
        }
    });
    stocksTableView.getTableViewSortListeners().add(new TableViewSortListener() {

        @Override
        public void sortChanged(TableView tableView) {
            @SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
            tableData.setComparator(new TableViewRowComparator(tableView));
        }
    });
    stocksTableView.getComponentKeyListeners().add(new ComponentKeyListener() {

        @Override
        public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
            if (keyCode == Keyboard.KeyCode.DELETE || keyCode == Keyboard.KeyCode.BACKSPACE) {
                removeSymbolsAction.perform(component);
            } else if (keyCode == Keyboard.KeyCode.A && Keyboard.isPressed(Platform.getCommandModifier())) {
                stocksTableView.selectAll();
            }
            return false;
        }
    });
    // Add symbol text input event handlers
    symbolTextInput.getTextInputContentListeners().add(new TextInputContentListener() {

        @Override
        public void textChanged(TextInput textInput) {
            addSymbolAction.setEnabled(textInput.getCharacterCount() > 0);
        }
    });
    symbolTextInput.getComponentKeyListeners().add(new ComponentKeyListener() {

        @Override
        public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
            if (keyCode == Keyboard.KeyCode.ENTER) {
                if (addSymbolAction.isEnabled()) {
                    addSymbolAction.perform(component);
                }
            }
            return false;
        }
    });
    // Assign actions to add and remove symbol buttons
    addSymbolButton.setAction(addSymbolAction);
    removeSymbolsButton.setAction(removeSymbolsAction);
    // Add a button press listener to open the Yahoo! Finance web page when
    // the link is clicked
    yahooFinanceButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(new URL(YAHOO_FINANCE_HOME).toURI());
            } catch (MalformedURLException exception) {
                throw new RuntimeException(exception);
            } catch (URISyntaxException exception) {
                throw new RuntimeException(exception);
            } catch (IOException exception) {
                System.out.println("Unable to open " + YAHOO_FINANCE_HOME + " in default browser.");
            }
        }
    });
}
Also used : MalformedURLException(java.net.MalformedURLException) TableViewSortListener(org.apache.pivot.wtk.TableViewSortListener) URISyntaxException(java.net.URISyntaxException) Span(org.apache.pivot.wtk.Span) URL(java.net.URL) TableViewRowListener(org.apache.pivot.wtk.TableViewRowListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TableViewRowComparator(org.apache.pivot.wtk.content.TableViewRowComparator) TextInputContentListener(org.apache.pivot.wtk.TextInputContentListener) Button(org.apache.pivot.wtk.Button) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Component(org.apache.pivot.wtk.Component) TextInput(org.apache.pivot.wtk.TextInput) TableViewSelectionListener(org.apache.pivot.wtk.TableViewSelectionListener) TableView(org.apache.pivot.wtk.TableView) Keyboard(org.apache.pivot.wtk.Keyboard) IOException(java.io.IOException) ComponentKeyListener(org.apache.pivot.wtk.ComponentKeyListener) Desktop(java.awt.Desktop)

Aggregations

List (org.apache.pivot.collections.List)3 TableView (org.apache.pivot.wtk.TableView)3 TableViewSortListener (org.apache.pivot.wtk.TableViewSortListener)3 TableViewRowComparator (org.apache.pivot.wtk.content.TableViewRowComparator)3 ArrayList (org.apache.pivot.collections.ArrayList)2 Span (org.apache.pivot.wtk.Span)2 TableViewSelectionListener (org.apache.pivot.wtk.TableViewSelectionListener)2 Desktop (java.awt.Desktop)1 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Button (org.apache.pivot.wtk.Button)1 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)1 Component (org.apache.pivot.wtk.Component)1 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)1 Keyboard (org.apache.pivot.wtk.Keyboard)1 ListButton (org.apache.pivot.wtk.ListButton)1