Search in sources :

Example 1 with TableViewRowListener

use of org.apache.pivot.wtk.TableViewRowListener 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

Desktop (java.awt.Desktop)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (org.apache.pivot.collections.ArrayList)1 List (org.apache.pivot.collections.List)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 Span (org.apache.pivot.wtk.Span)1 TableView (org.apache.pivot.wtk.TableView)1 TableViewRowListener (org.apache.pivot.wtk.TableViewRowListener)1 TableViewSelectionListener (org.apache.pivot.wtk.TableViewSelectionListener)1 TableViewSortListener (org.apache.pivot.wtk.TableViewSortListener)1 TextInput (org.apache.pivot.wtk.TextInput)1 TextInputContentListener (org.apache.pivot.wtk.TextInputContentListener)1 TableViewRowComparator (org.apache.pivot.wtk.content.TableViewRowComparator)1