Search in sources :

Example 31 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SearchGridCellsCommandHandler method doCommand.

@Override
public boolean doCommand(ILayer targetLayer, SearchCommand searchCommand) throws PatternSyntaxException {
    searchCommand.convertToTargetLayer(targetLayer);
    final ILayerListener searchEventListener = searchCommand.getSearchEventListener();
    if (searchEventListener != null) {
        this.selectionLayer.addLayerListener(searchEventListener);
    }
    try {
        PositionCoordinate anchor = this.selectionLayer.getSelectionAnchor();
        if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
            anchor = new PositionCoordinate(this.selectionLayer, 0, 0);
        }
        Object dataValueToFind = null;
        if ((dataValueToFind = searchCommand.getSearchText()) == null) {
            dataValueToFind = this.selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
        }
        boolean performActionOnResult = true;
        if (searchCommand.getSearchStrategy() instanceof AbstractSearchStrategy) {
            AbstractSearchStrategy searchStrategy = (AbstractSearchStrategy) searchCommand.getSearchStrategy();
            searchStrategy.setContextLayer(targetLayer);
            searchStrategy.setCaseSensitive(searchCommand.isCaseSensitive());
            searchStrategy.setWrapSearch(searchCommand.isWrapSearch());
            searchStrategy.setWholeWord(searchCommand.isWholeWord());
            searchStrategy.setIncremental(searchCommand.isIncremental());
            searchStrategy.setRegex(searchCommand.isRegex());
            searchStrategy.setIncludeCollapsed(searchCommand.isIncludeCollapsed());
            searchStrategy.setSearchDirection(searchCommand.getSearchDirection());
            searchStrategy.setComparator(searchCommand.getComparator());
            performActionOnResult = !searchStrategy.processResultInternally();
        }
        this.searchResultCellCoordinate = searchCommand.getSearchStrategy().executeSearch(dataValueToFind);
        this.selectionLayer.fireLayerEvent(new SearchEvent(this.searchResultCellCoordinate));
        if (performActionOnResult && this.searchResultCellCoordinate != null) {
            final SelectCellCommand command = new SelectCellCommand(this.selectionLayer, this.searchResultCellCoordinate.columnPosition, this.searchResultCellCoordinate.rowPosition, false, false);
            command.setForcingEntireCellIntoViewport(true);
            this.selectionLayer.doCommand(command);
        }
    } finally {
        if (searchEventListener != null) {
            this.selectionLayer.removeLayerListener(searchEventListener);
        }
    }
    return true;
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) SearchEvent(org.eclipse.nebula.widgets.nattable.search.event.SearchEvent) AbstractSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.AbstractSearchStrategy)

Example 32 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SearchDialog method doFindInit.

private void doFindInit() {
    // $NON-NLS-1$
    this.statusLabel.setText("");
    this.statusLabel.setForeground(null);
    if (this.selectionLayer != null) {
        // If the current selection is different, the user must have
        // clicked a new selection, and we need to update to that.
        PositionCoordinate pos = getPosition();
        if (!pos.equals(this.selections.peek().pos)) {
            this.selections.clear();
            this.selections.push(new SelectionItem(getTextForSelection(pos), pos));
        }
    }
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 33 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SearchDialog method doFind0.

private void doFind0(final boolean isIncremental, final String text) {
    BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

        @Override
        public void run() {
            PositionCoordinate previous = new PositionCoordinate(SearchDialog.this.selections.peek().pos);
            try {
                final SearchCommand searchCommand = createSearchCommand(text, isIncremental);
                final SearchEventListener searchEventListener = new SearchEventListener();
                searchCommand.setSearchEventListener(searchEventListener);
                SearchDialog.this.natTable.doCommand(searchCommand);
                if (searchEventListener.pos == null) {
                    // Beep and show status if not found
                    // $NON-NLS-1$
                    SearchDialog.this.statusLabel.setText(Messages.getString("Search.textNotFound"));
                    getShell().getDisplay().beep();
                } else {
                    SelectionItem selection = new SelectionItem(text, searchEventListener.pos);
                    SearchDialog.this.selections.push(selection);
                    if (!isIncremental) {
                        resetIncrementalSelections();
                    }
                    // Beep and show status if wrapped
                    if (previous != null && previous.columnPosition > -1) {
                        int columnDelta = selection.pos.columnPosition - previous.columnPosition;
                        int rowDelta = selection.pos.rowPosition - previous.rowPosition;
                        if (!SearchDialog.this.forwardValue) {
                            columnDelta = -columnDelta;
                            rowDelta = -rowDelta;
                        }
                        int primaryDelta = SearchDialog.this.columnFirstValue ? columnDelta : rowDelta;
                        int secondaryDelta = SearchDialog.this.columnFirstValue ? rowDelta : columnDelta;
                        if (primaryDelta < 0 || !isIncremental && primaryDelta == 0 && secondaryDelta <= 0) {
                            // $NON-NLS-1$
                            SearchDialog.this.statusLabel.setText(Messages.getString("Search.wrappedSearch"));
                            getShell().getDisplay().beep();
                        }
                    }
                }
                if (!isIncremental) {
                    updateFindHistory();
                }
            } catch (PatternSyntaxException e) {
                SearchDialog.this.statusLabel.setText(e.getLocalizedMessage());
                SearchDialog.this.statusLabel.setForeground(JFaceColors.getErrorText(SearchDialog.this.statusLabel.getDisplay()));
                getShell().getDisplay().beep();
            }
        }
    });
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) SearchCommand(org.eclipse.nebula.widgets.nattable.search.command.SearchCommand) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 34 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate 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 35 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SelectionUtils method hasConsecutiveSelection.

/**
 * Checks whether the selected region tracked by the given
 * {@link SelectionLayer} is consecutive or not.
 *
 * @param selectionLayer
 *            The {@link SelectionLayer} that tracks the selection.
 * @return <code>true</code> if the current selection is consecutive,
 *         <code>false</code> if not.
 *
 * @since 1.4
 */
public static boolean hasConsecutiveSelection(SelectionLayer selectionLayer) {
    if (selectionLayer != null && SelectionUtils.isConsecutive(selectionLayer.getSelectedColumnPositions())) {
        Map<Integer, Set<Integer>> positions = new HashMap<Integer, Set<Integer>>();
        int column = -1;
        int row = -1;
        // collect the selection information
        for (PositionCoordinate coord : selectionLayer.getSelectedCellPositions()) {
            Set<Integer> rows = positions.get(coord.columnPosition);
            if (rows == null) {
                rows = new LinkedHashSet<Integer>();
                positions.put(coord.columnPosition, rows);
            }
            rows.add(coord.rowPosition);
            column = Math.max(column, coord.columnPosition);
            row = Math.max(row, coord.rowPosition);
        }
        // check if the selected region is a rectangle
        // every row collection for each column needs to have the same size
        // and the same content
        Set<Integer> previous = null;
        for (Set<Integer> rows : positions.values()) {
            if (previous != null && !previous.equals(rows)) {
                return false;
            }
            previous = rows;
        }
        // test if rows are consecutive
        if (previous != null) {
            int[] rowPositions = new int[previous.size()];
            int i = 0;
            for (Integer rowPos : previous) {
                rowPositions[i++] = rowPos;
            }
            if (SelectionUtils.isConsecutive(rowPositions)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Aggregations

PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)97 Test (org.junit.Test)55 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)10 Rectangle (org.eclipse.swt.graphics.Rectangle)9 SelectRegionCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand)7 ArrayList (java.util.ArrayList)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)5 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)5 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 ViewportSelectColumnGroupCommand (org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand)4 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)4 SelectAllCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand)4 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)3 HashSet (java.util.HashSet)2 Pattern (java.util.regex.Pattern)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 ColumnPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)2 RowPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)2 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2