use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method getVariableRowHeight.
protected int getVariableRowHeight(int rowIndex, ArrayList<Integer> columnWidthsArgument) {
TableView tableView = (TableView) getComponent();
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
TableView.ColumnSequence columns = tableView.getColumns();
Object rowData = tableData.get(rowIndex);
int rowHeight = 0;
for (int i = 0, n = columns.getLength(); i < n; i++) {
TableView.Column column = columns.get(i);
TableView.CellRenderer cellRenderer = column.getCellRenderer();
cellRenderer.render(rowData, rowIndex, i, tableView, column.getName(), false, false, false);
rowHeight = Math.max(rowHeight, cellRenderer.getPreferredHeight(columnWidthsArgument.get(i).intValue()));
}
return rowHeight;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method mouseDown.
@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
TableView tableView = (TableView) getComponent();
int rowIndex = getRowAt(y);
if (rowIndex >= 0 && !tableView.isRowDisabled(rowIndex)) {
TableView.SelectMode selectMode = tableView.getSelectMode();
if (button == Mouse.Button.LEFT) {
Keyboard.Modifier commandModifier = Platform.getCommandModifier();
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT) && selectMode == TableView.SelectMode.MULTI) {
Filter<?> disabledRowFilter = tableView.getDisabledRowFilter();
if (disabledRowFilter == null) {
// Select the range
int startIndex = tableView.getFirstSelectedIndex();
int endIndex = tableView.getLastSelectedIndex();
// indicated row
if (startIndex == -1) {
tableView.addSelectedIndex(rowIndex);
} else {
// otherwise select the range of rows
Span selectedRange = (rowIndex > startIndex) ? new Span(startIndex, rowIndex) : new Span(rowIndex, endIndex);
ArrayList<Span> selectedRanges = new ArrayList<>();
selectedRanges.add(selectedRange);
tableView.setSelectedRanges(selectedRanges);
}
}
} else if (Keyboard.isPressed(commandModifier) && selectMode == TableView.SelectMode.MULTI) {
// Toggle the item's selection state
if (tableView.isRowSelected(rowIndex)) {
tableView.removeSelectedIndex(rowIndex);
} else {
tableView.addSelectedIndex(rowIndex);
}
} else if (Keyboard.isPressed(commandModifier) && selectMode == TableView.SelectMode.SINGLE) {
// Toggle the item's selection state
if (tableView.isRowSelected(rowIndex)) {
tableView.setSelectedIndex(-1);
} else {
tableView.setSelectedIndex(rowIndex);
}
} else {
if (selectMode != TableView.SelectMode.NONE) {
if (!tableView.isRowSelected(rowIndex)) {
tableView.setSelectedIndex(rowIndex);
}
selectIndex = rowIndex;
}
}
}
}
tableView.requestFocus();
if (editOnMouseDown) {
if (selectIndex != -1 && button == Mouse.Button.LEFT) {
TableView.RowEditor rowEditor = tableView.getRowEditor();
if (rowEditor != null) {
if (rowEditor.isEditing()) {
rowEditor.endEdit(true);
}
rowEditor.beginEdit(tableView, selectIndex, getColumnAt(x));
}
}
}
return consumed;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method getRowAt.
// Table view skin methods
@Override
public int getRowAt(int y) {
Utils.checkNonNegative(y, "y");
TableView tableView = (TableView) getComponent();
int rowIndex;
if (variableRowHeight) {
if (y == 0) {
rowIndex = 0;
} else {
rowIndex = ArrayList.binarySearch(rowBoundaries, Integer.valueOf(y));
if (rowIndex < 0) {
rowIndex = -(rowIndex + 1);
}
}
} else {
rowIndex = (y / (fixedRowHeight + 1));
}
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
if (rowIndex >= tableData.getLength()) {
rowIndex = -1;
}
return rowIndex;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method mouseClick.
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
boolean consumed = super.mouseClick(component, button, x, y, count);
if (!editOnMouseDown) {
TableView tableView = (TableView) getComponent();
if (selectIndex != -1 && count == 2 && button == Mouse.Button.LEFT) {
TableView.RowEditor rowEditor = tableView.getRowEditor();
if (rowEditor != null) {
if (rowEditor.isEditing()) {
rowEditor.endEdit(true);
}
rowEditor.beginEdit(tableView, selectIndex, getColumnAt(x));
}
}
}
selectIndex = -1;
return consumed;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method columnSourceChanged.
@Override
public void columnSourceChanged(TableView tableView, TableView previousColumnSource) {
if (previousColumnSource != null) {
previousColumnSource.getTableViewColumnListeners().remove(this);
}
TableView columnSource = tableView.getColumnSource();
if (columnSource != null) {
columnSource.getTableViewColumnListeners().add(this);
}
invalidateComponent();
}
Aggregations