Search in sources :

Example 11 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer 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 12 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer 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 13 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer 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)

Example 14 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class SelectionSearchStrategy 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 SelectionSearchStrategy to work it needs the selectionLayer to be passed as the contextLayer.");
    }
    SelectionLayer selectionLayer = (SelectionLayer) contextLayer;
    @SuppressWarnings("unchecked") PositionCoordinate coordinate = CellDisplayValueSearchUtil.findCell(selectionLayer, this.configRegistry, getSelectedCells(selectionLayer), valueToMatch, (Comparator<String>) getComparator(), isCaseSensitive(), isWholeWord(), isRegex(), isIncludeCollapsed());
    if (coordinate != null) {
        selectionLayer.moveSelectionAnchor(coordinate.columnPosition, coordinate.rowPosition);
        selectionLayer.doCommand(new VisualRefreshCommand());
    }
    return coordinate;
}
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) VisualRefreshCommand(org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand)

Example 15 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class ViewportLayer method moveColumnPositionIntoViewport.

/**
 * Scrolls the viewport (if required) so that the specified column is
 * visible.
 *
 * @param scrollableColumnPosition
 *            column position in terms of the Scrollable Layer
 */
public void moveColumnPositionIntoViewport(int scrollableColumnPosition) {
    ILayer underlyingLayer = getUnderlyingLayer();
    int maxWidth = getMaxWidth();
    if (underlyingLayer.getColumnIndexByPosition(scrollableColumnPosition) >= 0 && (maxWidth < 0 || (maxWidth >= 0 && underlyingLayer.getStartXOfColumnPosition(scrollableColumnPosition) < maxWidth))) {
        if (scrollableColumnPosition >= getMinimumOriginColumnPosition()) {
            int originColumnPosition = getOriginColumnPosition();
            if (scrollableColumnPosition <= originColumnPosition) {
                // Move left
                setOriginX(this.scrollableLayer.getStartXOfColumnPosition(scrollableColumnPosition));
            } else {
                int scrollableColumnStartX = underlyingLayer.getStartXOfColumnPosition(scrollableColumnPosition);
                int scrollableColumnEndX = scrollableColumnStartX + underlyingLayer.getColumnWidthByPosition(scrollableColumnPosition);
                int clientAreaWidth = getClientAreaWidth();
                int viewportEndX = getOrigin().getX() + clientAreaWidth;
                int maxX = maxWidth >= 0 ? Math.min(maxWidth, scrollableColumnEndX) : scrollableColumnEndX;
                if (viewportEndX < maxX) {
                    // Move right
                    setOriginX(Math.min(maxX - clientAreaWidth, maxX));
                }
            }
        }
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Aggregations

ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)127 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)91 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)90 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)82 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)73 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)71 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)68 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)68 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)67 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)67 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)64 HashMap (java.util.HashMap)62 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)60 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)58 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)58 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)53 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)48 GridLayout (org.eclipse.swt.layout.GridLayout)35 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)34 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)33