use of org.apache.pivot.wtk.TableView 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.TableView 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.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin method mouseDown.
@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
if (button == Mouse.Button.LEFT) {
TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
int headerIndex = getHeaderAt(x);
if (headerIndex != -1) {
Bounds headerBounds = getHeaderBounds(headerIndex);
TableView.Column column = tableView.getColumns().get(headerIndex);
if (columnsResizable && !column.isRelative() && column.getWidth() != -1 && x > headerBounds.x + headerBounds.width - RESIZE_HANDLE_SIZE) {
resizeHeaderIndex = headerIndex;
} else if (headersPressable) {
pressedHeaderIndex = headerIndex;
repaintComponent(headerBounds);
}
}
}
}
return consumed;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin method install.
@Override
public void install(Component component) {
super.install(component);
TableViewHeader tableViewHeader = (TableViewHeader) component;
tableViewHeader.getTableViewHeaderListeners().add(this);
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
tableView.getTableViewColumnListeners().add(this);
tableView.getTableViewSortListeners().add(this);
}
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin method tableViewChanged.
// Table view header events
@Override
public void tableViewChanged(TableViewHeader tableViewHeader, TableView previousTableView) {
if (previousTableView != null) {
previousTableView.getTableViewColumnListeners().remove(this);
previousTableView.getTableViewSortListeners().remove(this);
}
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
tableView.getTableViewColumnListeners().add(this);
tableView.getTableViewSortListeners().add(this);
}
invalidateComponent();
}
Aggregations