Search in sources :

Example 11 with SelectionLayer

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);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ArrayList(java.util.ArrayList) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) Shell(org.eclipse.swt.widgets.Shell) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) Test(org.junit.Test)

Example 12 with SelectionLayer

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);
}
Also used : SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) CopyDataCommandHandler(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)

Example 13 with SelectionLayer

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();
}
Also used : SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Example 14 with SelectionLayer

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);
}
Also used : SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 15 with SelectionLayer

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());
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Comparator(java.util.Comparator) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Aggregations

SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)107 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)75 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)73 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)71 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)63 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)58 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)54 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)47 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)46 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)44 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)43 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)43 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)42 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)41 HashMap (java.util.HashMap)38 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)37 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)34 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)27 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)25 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)25