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));
}
});
}
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);
}
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.");
}
}
});
}
Aggregations