Search in sources :

Example 26 with TableView

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;
}
Also used : ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) TableView(org.apache.pivot.wtk.TableView)

Example 27 with TableView

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;
}
Also used : Modifier(org.apache.pivot.wtk.Keyboard.Modifier) SelectMode(org.apache.pivot.wtk.TableView.SelectMode) Keyboard(org.apache.pivot.wtk.Keyboard) ArrayList(org.apache.pivot.collections.ArrayList) Span(org.apache.pivot.wtk.Span) TableView(org.apache.pivot.wtk.TableView)

Example 28 with TableView

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;
}
Also used : ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) TableView(org.apache.pivot.wtk.TableView)

Example 29 with TableView

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;
}
Also used : TableView(org.apache.pivot.wtk.TableView)

Example 30 with TableView

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();
}
Also used : TableView(org.apache.pivot.wtk.TableView)

Aggregations

TableView (org.apache.pivot.wtk.TableView)36 ArrayList (org.apache.pivot.collections.ArrayList)12 List (org.apache.pivot.collections.List)11 TableViewHeader (org.apache.pivot.wtk.TableViewHeader)11 GradientPaint (java.awt.GradientPaint)9 Bounds (org.apache.pivot.wtk.Bounds)7 Span (org.apache.pivot.wtk.Span)6 TableViewSelectionListener (org.apache.pivot.wtk.TableViewSelectionListener)5 TableViewSortListener (org.apache.pivot.wtk.TableViewSortListener)5 IOException (java.io.IOException)4 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)4 Component (org.apache.pivot.wtk.Component)4 Keyboard (org.apache.pivot.wtk.Keyboard)4 SerializationException (org.apache.pivot.serialization.SerializationException)3 Button (org.apache.pivot.wtk.Button)3 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)3 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)3 Container (org.apache.pivot.wtk.Container)3 ListButton (org.apache.pivot.wtk.ListButton)3 ListButtonSelectionListener (org.apache.pivot.wtk.ListButtonSelectionListener)3