use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class MoveCellSelectionCommandHandler method moveLastSelectedUp.
@Override
protected void moveLastSelectedUp(ITraversalStrategy traversalStrategy, boolean withShiftMask, boolean withControlMask) {
if (this.selectionLayer.hasRowSelection()) {
this.lastSelectedCellPosition = this.selectionLayer.getCellPositionToMoveFrom(withShiftMask, withControlMask);
ILayerCell lastSelectedCell = this.selectionLayer.getCellByPosition(this.lastSelectedCellPosition.columnPosition, this.lastSelectedCellPosition.rowPosition);
if (lastSelectedCell != null) {
int stepSize = traversalStrategy.getStepCount();
this.newSelectedColumnPosition = this.lastSelectedCellPosition.columnPosition;
this.newSelectedRowPosition = (stepSize >= 0) ? lastSelectedCell.getOriginRowPosition() - stepSize : 0;
ILayerCell newSelected = this.selectionLayer.getCellByPosition(this.newSelectedColumnPosition, this.newSelectedRowPosition);
if (newSelected != null) {
this.newSelectedRowPosition = newSelected.getOriginRowPosition();
}
// boolean flag to stop traversal if calculated target is
// invalid needed to avoid endless loop if there are no further
// valid traversal targets
boolean stopTraversalOnInvalid = false;
if (this.newSelectedRowPosition < 0) {
if (traversalStrategy.getTraversalScope().equals(TraversalScope.AXIS)) {
if (!traversalStrategy.isCycle()) {
// on axis scope with no cycle, stop moving
this.newSelectedRowPosition = 0;
stopTraversalOnInvalid = true;
} else {
// on axis scope with cycle, move to bottom
while (this.newSelectedRowPosition < 0) {
this.newSelectedRowPosition = this.newSelectedRowPosition + this.selectionLayer.getRowCount();
}
}
} else if (traversalStrategy.getTraversalScope().equals(TraversalScope.TABLE)) {
// on table scope, move to bottom
int columnMove = 0;
while (this.newSelectedRowPosition < 0) {
this.newSelectedRowPosition = this.newSelectedRowPosition + this.selectionLayer.getRowCount();
columnMove++;
}
this.newSelectedColumnPosition = this.newSelectedColumnPosition - columnMove;
if (this.newSelectedColumnPosition < 0) {
if (traversalStrategy.isCycle()) {
// at the beginning and cycle so go to end
this.newSelectedColumnPosition = this.newSelectedColumnPosition + this.selectionLayer.getColumnCount();
} else {
// at the top and no cycle so stop moving
this.newSelectedColumnPosition = 0;
this.newSelectedRowPosition = 0;
stopTraversalOnInvalid = true;
}
}
}
}
if (positionMoved()) {
// adjacent
if (!traversalStrategy.isValidTarget(lastSelectedCell, this.selectionLayer.getCellByPosition(this.newSelectedColumnPosition, this.newSelectedRowPosition))) {
if (!stopTraversalOnInvalid) {
moveLastSelectedUp(createIncrementalStrategy(traversalStrategy), withShiftMask, withControlMask);
} else {
// since the calculated target is invalid and
// invalid traversal movement should stop, the new
// selected position is the last valid one
this.newSelectedColumnPosition = this.lastSelectedCellPosition.columnPosition;
this.newSelectedRowPosition = this.lastSelectedCellPosition.rowPosition;
}
} else {
this.selectionLayer.selectCell(this.newSelectedColumnPosition, this.newSelectedRowPosition, withShiftMask, withControlMask);
this.selectionLayer.fireCellSelectionEvent(this.newSelectedColumnPosition, this.newSelectedRowPosition, true, withShiftMask, withControlMask);
}
}
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class CellDisplayValueSearchUtil method findCell.
/**
* Finds the first matching cell in a table slice.
*
* @param layer
* @param configRegistry
* @param firstDimIndex
* @param secondDimStart
* @param secondDimEnd
* @param direction
* @param pattern
* @param stringValue
* @param comparator
* @param caseSensitive
* @param wholeWord
* @param regex
* @param columnFirst
* @param includeCollapsed
* @return
* @throws PatternSyntaxException
*/
private static PositionCoordinate findCell(ILayer layer, IConfigRegistry configRegistry, int firstDimIndex, int secondDimStart, int secondDimEnd, int direction, Pattern pattern, String stringValue, Comparator<String> comparator, boolean caseSensitive, boolean wholeWord, boolean regex, final boolean columnFirst, boolean includeCollapsed) throws PatternSyntaxException {
int columnPosition;
int rowPosition;
if (columnFirst) {
columnPosition = firstDimIndex;
rowPosition = secondDimStart;
} else {
columnPosition = secondDimStart;
rowPosition = firstDimIndex;
}
for (int i = secondDimStart; direction * (secondDimEnd - i) > 0; i += direction) {
ILayerCell cellByPosition = layer.getCellByPosition(columnPosition, rowPosition);
PositionCoordinate searchAnchor = getSearchAnchor(cellByPosition, direction);
// Thus we skip the compare and proceed to the next position.
if (searchAnchor.columnPosition == columnPosition && searchAnchor.rowPosition == rowPosition) {
if (compare(layer, configRegistry, pattern, stringValue, comparator, caseSensitive, wholeWord, regex, columnPosition, rowPosition)) {
return new PositionCoordinate(layer, columnPosition, rowPosition);
}
}
if (columnFirst) {
rowPosition += direction;
} else {
columnPosition += direction;
}
}
return null;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class CellDisplayValueSearchUtil method compare.
private static boolean compare(ILayer layer, IConfigRegistry configRegistry, Pattern pattern, String stringValue, Comparator<String> comparator, boolean caseSensitive, boolean wholeWord, boolean regex, int columnPosition, int rowPosition) {
// Convert cell's data
LabelStack labels = layer.getConfigLabelsByPosition(columnPosition, rowPosition);
if (!labels.hasLabel(ISearchStrategy.SKIP_SEARCH_RESULT_LABEL)) {
final IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, labels.getLabels());
Object dataValue = null;
if (displayConverter != null) {
ILayerCell cell = layer.getCellByPosition(columnPosition, rowPosition);
if (cell != null) {
dataValue = displayConverter.canonicalToDisplayValue(cell, configRegistry, cell.getDataValue());
}
}
// Compare with valueToMatch
if (dataValue instanceof Comparable<?>) {
String dataValueString = caseSensitive ? dataValue.toString() : dataValue.toString().toLowerCase();
if (regex) {
if (pattern.matcher(dataValueString).matches()) {
return true;
}
} else if (comparator.compare(stringValue, dataValueString) == 0) {
return true;
} else if (!wholeWord && dataValueString.contains(stringValue)) {
return true;
} else if (wholeWord) {
// we also need to check single words in a multi word value
// $NON-NLS-1$
String[] split = dataValueString.split("\\b");
for (String word : split) {
if (comparator.compare(stringValue, word) == 0) {
return true;
}
}
}
}
}
return false;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class GridSearchStrategy method executeSearch.
@Override
public PositionCoordinate executeSearch(Object valueToMatch) throws PatternSyntaxException {
ILayer contextLayer = getContextLayer();
if (!(contextLayer instanceof SelectionLayer)) {
// $NON-NLS-1$
throw new RuntimeException("For the GridSearchStrategy to work it needs the selectionLayer to be passed as the contextLayer.");
}
SelectionLayer selectionLayer = (SelectionLayer) contextLayer;
PositionCoordinate selectionAnchor = selectionLayer.getSelectionAnchor();
// Pick start and end values depending on the direction of the search.
int direction = this.searchDirection.equals(ISearchDirection.SEARCH_FORWARD) ? 1 : -1;
boolean hadSelectionAnchor = selectionAnchor.columnPosition >= 0 && selectionAnchor.rowPosition >= 0;
if (!hadSelectionAnchor) {
selectionAnchor.columnPosition = 0;
selectionAnchor.rowPosition = 0;
}
// Pick a first and second dimension based on whether it's a column or
// row-first search.
int firstDimPosition;
int firstDimCount;
int secondDimPosition;
int secondDimCount;
if (this.columnFirst) {
firstDimPosition = selectionAnchor.columnPosition;
firstDimCount = selectionLayer.getColumnCount();
secondDimPosition = selectionAnchor.rowPosition;
secondDimCount = selectionLayer.getRowCount();
if (direction < 0) {
// If we are searching backwards we must accommodate spanned
// cells by starting the search from the right of the cell.
ILayerCell cellByPosition = selectionLayer.getCellByPosition(selectionAnchor.columnPosition, selectionAnchor.rowPosition);
firstDimPosition = selectionAnchor.columnPosition + cellByPosition.getColumnSpan() - 1;
}
} else {
firstDimPosition = selectionAnchor.rowPosition;
firstDimCount = selectionLayer.getRowCount();
secondDimPosition = selectionAnchor.columnPosition;
secondDimCount = selectionLayer.getColumnCount();
if (direction < 0) {
// If we are searching backwards we must accommodate spanned
// cells by starting the search from the bottom of the cell.
ILayerCell cellByPosition = selectionLayer.getCellByPosition(selectionAnchor.columnPosition, selectionAnchor.rowPosition);
firstDimPosition = selectionAnchor.rowPosition + cellByPosition.getRowSpan() - 1;
}
}
int firstDimStart;
int firstDimEnd;
int secondDimStart;
int secondDimEnd;
if (direction == 1) {
firstDimStart = 0;
firstDimEnd = firstDimCount;
secondDimStart = 0;
secondDimEnd = secondDimCount;
} else {
firstDimStart = firstDimCount - 1;
firstDimEnd = -1;
secondDimStart = secondDimCount - 1;
secondDimEnd = -1;
}
// Move to the next cell if a selection was active and it's not
// an incremental search.
final boolean startWithNextCell = hadSelectionAnchor && !isIncremental();
if (startWithNextCell) {
if (secondDimPosition + direction != secondDimEnd) {
// Increment the second dimension
secondDimPosition += direction;
} else {
// Wrap the second dimension
secondDimPosition = secondDimStart;
if (firstDimPosition + direction != firstDimEnd) {
// Increment the first dimension
firstDimPosition += direction;
} else if (this.wrapSearch) {
// Wrap the first dimension
firstDimPosition = firstDimStart;
} else {
// Fail outright because there's nothing to search
return null;
}
}
}
// Get a sequence of ranges for searching.
List<GridRectangle> gridRanges = getRanges(firstDimPosition, secondDimPosition, direction, firstDimStart, firstDimEnd, secondDimStart, secondDimEnd);
// Perform the search.
@SuppressWarnings("unchecked") Comparator<String> comparator = (Comparator<String>) getComparator();
return CellDisplayValueSearchUtil.findCell(getContextLayer(), this.configRegistry, gridRanges, valueToMatch, comparator, isCaseSensitive(), isWholeWord(), isRegex(), isColumnFirst(), isIncludeCollapsed());
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class TreeLayer method getConfigLabelsByPosition.
@Override
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) {
LabelStack configLabels = super.getConfigLabelsByPosition(columnPosition, rowPosition);
if (isTreeColumn(columnPosition)) {
configLabels.addLabelOnTop(TREE_COLUMN_CELL);
ILayerCell cell = getCellByPosition(columnPosition, rowPosition);
if (cell != null) {
int rowIndex = cell.getOriginRowPosition();
configLabels.addLabelOnTop(DefaultTreeLayerConfiguration.TREE_DEPTH_CONFIG_TYPE + this.treeRowModel.depth(rowIndex));
if (!this.treeRowModel.hasChildren(rowIndex)) {
configLabels.addLabelOnTop(DefaultTreeLayerConfiguration.TREE_LEAF_CONFIG_TYPE);
} else {
if (this.treeRowModel.isCollapsed(rowIndex)) {
configLabels.addLabelOnTop(DefaultTreeLayerConfiguration.TREE_COLLAPSED_CONFIG_TYPE);
} else {
configLabels.addLabelOnTop(DefaultTreeLayerConfiguration.TREE_EXPANDED_CONFIG_TYPE);
}
}
}
}
return configLabels;
}
Aggregations