use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
preferredWidth = TerraTableViewSkin.getPreferredWidth(tableView, includeTrailingVerticalGridLine);
}
return preferredWidth;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin 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 (button == Mouse.Button.LEFT) {
TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
TableView tableView = tableViewHeader.getTableView();
if (resizeHeaderIndex != -1) {
TableView.Column column = tableView.getColumns().get(resizeHeaderIndex);
if (count == 2 && !column.isRelative() && column.getWidth() != -1) {
// Size the column to fit its contents
int columnWidth = 0;
TableView.CellRenderer cellRenderer = column.getCellRenderer();
List<?> tableData = tableView.getTableData();
int rowIndex = 0;
for (Object rowData : tableData) {
cellRenderer.render(rowData, rowIndex++, resizeHeaderIndex, tableView, column.getName(), false, false, false);
columnWidth = Math.max(cellRenderer.getPreferredWidth(-1), columnWidth);
}
column.setWidth(columnWidth);
}
} else if (pressedHeaderIndex != -1) {
// Press the header
tableViewHeader.pressHeader(pressedHeaderIndex);
// Update the sort
TableViewHeader.SortMode sortMode = tableViewHeader.getSortMode();
if (sortMode != TableViewHeader.SortMode.NONE) {
TableView.Column column = tableView.getColumns().get(pressedHeaderIndex);
String columnName = column.getName();
SortDirection sortDirection = tableView.getSort().get(columnName);
if (sortDirection == null) {
sortDirection = SortDirection.ASCENDING;
} else if (sortDirection == SortDirection.ASCENDING) {
sortDirection = SortDirection.DESCENDING;
} else {
sortDirection = SortDirection.ASCENDING;
}
if (sortMode == TableViewHeader.SortMode.MULTI_COLUMN && Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
tableView.getSort().put(columnName, sortDirection);
} else {
tableView.setSort(columnName, sortDirection);
}
consumed = true;
}
}
resizeHeaderIndex = -1;
pressedHeaderIndex = -1;
}
return consumed;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method mouseUp.
@Override
public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseUp(component, button, x, y);
TableView tableView = (TableView) getComponent();
if (selectIndex != -1 && tableView.getFirstSelectedIndex() != tableView.getLastSelectedIndex()) {
tableView.setSelectedIndex(selectIndex);
selectIndex = -1;
}
return consumed;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method mouseOut.
@Override
public void mouseOut(Component component) {
super.mouseOut(component);
TableView tableView = (TableView) getComponent();
if (highlightIndex != -1 && tableView.getSelectMode() != TableView.SelectMode.NONE && showHighlight) {
repaintComponent(getRowBounds(highlightIndex));
}
highlightIndex = -1;
selectIndex = -1;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method install.
@Override
public void install(Component component) {
super.install(component);
TableView tableView = (TableView) component;
tableView.getTableViewListeners().add(this);
tableView.getTableViewColumnListeners().add(this);
tableView.getTableViewRowListeners().add(this);
tableView.getTableViewSelectionListeners().add(this);
}
Aggregations