use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class ViewportIntegrationTest method shouldInitWithNoScroll.
@Test
public void shouldInitWithNoScroll() {
List<String> contents = new ArrayList<>(Arrays.asList("one", "two", "three", "four", "five"));
IDataProvider bodyDataProvider = new ListDataProvider<>(contents, new IColumnAccessor<String>() {
@Override
public Object getDataValue(String rowObject, int columnIndex) {
return rowObject;
}
@Override
public void setDataValue(String rowObject, int columnIndex, Object newValue) {
// ignore
}
@Override
public int getColumnCount() {
return 1;
}
});
SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider));
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
IDataProvider colDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
ColumnHeaderLayer colHeader = new ColumnHeaderLayer(new DataLayer(colDataProvider), viewportLayer, selectionLayer);
IDataProvider rowDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowDataProvider), viewportLayer, selectionLayer);
CornerLayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(colDataProvider, rowDataProvider)), rowHeaderLayer, colHeader);
GridLayer grid = new GridLayer(viewportLayer, colHeader, rowHeaderLayer, cornerLayer);
// create the table with no scrollbars
NatTable natTable = new NatTable(new Shell(), SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, grid);
// this caused a NPE for scrollbar initialization
natTable.setSize(600, 600);
}
use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class DefaultGridLayer method init.
protected void init(IUniqueIndexLayer bodyDataLayer, IUniqueIndexLayer columnHeaderDataLayer, IUniqueIndexLayer rowHeaderDataLayer, IUniqueIndexLayer cornerDataLayer) {
// Body
this.bodyDataLayer = bodyDataLayer;
DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(bodyDataLayer);
SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
// Column header
this.columnHeaderDataLayer = columnHeaderDataLayer;
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, selectionLayer);
// Row header
this.rowHeaderDataLayer = rowHeaderDataLayer;
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, selectionLayer);
// Corner
this.cornerDataLayer = cornerDataLayer;
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
setBodyLayer(bodyLayer);
setColumnHeaderLayer(columnHeaderLayer);
setRowHeaderLayer(rowHeaderLayer);
setCornerLayer(cornerLayer);
CopyDataCommandHandler cdch = new CopyDataCommandHandler(selectionLayer, columnHeaderDataLayer, rowHeaderDataLayer);
cdch.setCopyFormattedText(true);
registerCommandHandler(cdch);
}
use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class SearchDialog method setInput.
public void setInput(NatTable natTable, IDialogSettings settings) {
if (natTable != null && natTable.equals(this.natTable)) {
return;
}
this.natTable = natTable;
if (natTable != null) {
ILayer result = findSelectionLayer(this.natTable.getLayer());
if (result != null && result instanceof SelectionLayer) {
this.selectionLayer = (SelectionLayer) result;
if (this.findButton != null && !this.findButton.isDisposed()) {
this.findButton.setEnabled(true);
}
}
} else {
this.selectionLayer = null;
if (this.findButton != null && !this.findButton.isDisposed()) {
this.findButton.setEnabled(false);
}
}
this.originalSettings = settings;
if (settings == null) {
this.dialogSettings = null;
this.dialogBounds = null;
} else {
this.dialogSettings = settings.getSection(getClass().getName());
if (this.dialogSettings == null) {
this.dialogSettings = settings.addNewSection(getClass().getName());
}
// $NON-NLS-1$
String boundsName = getClass().getName() + "_dialogBounds";
this.dialogBounds = settings.getSection(boundsName);
if (this.dialogBounds == null) {
this.dialogBounds = settings.addNewSection(boundsName);
}
}
readConfiguration();
}
use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class SearchDialog method create.
@Override
public void create() {
super.create();
// $NON-NLS-1$
getShell().setText(Messages.getString("Search.find"));
// set dialog position
if (this.dialogPositionValue != null) {
getShell().setBounds(this.dialogPositionValue);
}
this.findCombo.removeModifyListener(this.findComboModifyListener);
updateCombo(this.findCombo, this.findHistory);
this.findCombo.addModifyListener(this.findComboModifyListener);
// search SelectionLayer in layer stack
ILayer result = findSelectionLayer(this.natTable.getLayer());
if (result != null && result instanceof SelectionLayer) {
this.selectionLayer = (SelectionLayer) result;
}
// Pick the user's selection, if possible
PositionCoordinate pos = getPosition();
final String text = getTextForSelection(pos);
this.selections.push(new SelectionItem(text, pos));
this.findCombo.setText(text);
}
use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer 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());
}
Aggregations