Search in sources :

Example 11 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class SelectionSearchStrategy method executeSearch.

public PositionCoordinate executeSearch(Object valueToMatch) {
    ILayer contextLayer = getContextLayer();
    if (!(contextLayer instanceof SelectionLayer)) {
        throw new RuntimeException("For the GridSearchStrategy to work it needs the selectionLayer to be passed as the contextLayer.");
    }
    SelectionLayer selectionLayer = (SelectionLayer) contextLayer;
    PositionCoordinate coordinate = CellDisplayValueSearchUtil.findCell(selectionLayer, configRegistry, getSelectedCells(selectionLayer), valueToMatch, getComparator(), isCaseSensitive());
    return coordinate;
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) ILayer(net.sourceforge.nattable.layer.ILayer) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 12 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class SelectionLayerPainter method paintLayer.

@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
    Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
    columnPositionOffset = positionRectangle.x;
    rowPositionOffset = positionRectangle.y;
    cells = new HashMap<PositionCoordinate, LayerCell>();
    super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
    // Save gc settings
    int originalLineStyle = gc.getLineStyle();
    Color originalForeground = gc.getForeground();
    // Apply border settings
    gc.setLineStyle(SWT.LINE_CUSTOM);
    gc.setLineDash(new int[] { 1, 1 });
    gc.setForeground(GUIHelper.COLOR_BLACK);
    // Draw horizontal borders
    boolean selectedMode = false;
    for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++) {
        LayerCell cell = null;
        for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++) {
            cell = cells.get(new PositionCoordinate(natLayer, columnPosition, rowPosition));
            if (cell != null) {
                if (selectedMode != isSelected(cell)) {
                    selectedMode = !selectedMode;
                    Rectangle cellBounds = cell.getBounds();
                    // Draw top edge
                    gc.drawLine(cellBounds.x - 1, cellBounds.y - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y - 1);
                }
            }
        }
        if (selectedMode && cell != null) {
            // If last cell is selected, draw its bottom edge
            Rectangle cellBounds = cell.getBounds();
            gc.drawLine(cellBounds.x - 1, cellBounds.y + cellBounds.height - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y + cellBounds.height - 1);
        }
        selectedMode = false;
    }
    // Draw vertical borders
    for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++) {
        LayerCell cell = null;
        for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++) {
            cell = cells.get(new PositionCoordinate(natLayer, columnPosition, rowPosition));
            if (cell != null) {
                if (selectedMode != isSelected(cell)) {
                    selectedMode = !selectedMode;
                    Rectangle cellBounds = cell.getBounds();
                    // Draw left edge
                    gc.drawLine(cellBounds.x - 1, cellBounds.y - 1, cellBounds.x - 1, cellBounds.y + cellBounds.height - 1);
                }
            }
        }
        if (selectedMode && cell != null) {
            // If last cell is selected, draw its right edge
            Rectangle cellBounds = cell.getBounds();
            gc.drawLine(cellBounds.x + cellBounds.width - 1, cellBounds.y - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y + cellBounds.height - 1);
        }
        selectedMode = false;
    }
    // Restore original gc settings
    gc.setLineStyle(originalLineStyle);
    gc.setForeground(originalForeground);
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 13 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class SearchGridCellsCommandHandler method doCommand.

public boolean doCommand(ILayer targetLayer, SearchCommand searchCommand) {
    searchCommand.convertToTargetLayer(targetLayer);
    AbstractSearchStrategy searchStrategy = (AbstractSearchStrategy) searchCommand.getSearchStrategy();
    if (searchCommand.getSearchEventListener() != null) {
        selectionLayer.addLayerListener(searchCommand.getSearchEventListener());
    }
    PositionCoordinate anchor = selectionLayer.getSelectionAnchor();
    if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
        anchor = new PositionCoordinate(selectionLayer, 0, 0);
    }
    searchStrategy.setContextLayer(targetLayer);
    Object dataValueToFind = null;
    if ((dataValueToFind = searchCommand.getSearchText()) == null) {
        dataValueToFind = selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
    }
    searchStrategy.setCaseSensitive(searchCommand.isCaseSensitive());
    searchStrategy.setWrapSearch(searchCommand.isWrapSearch());
    searchStrategy.setSearchDirection(searchCommand.getSearchDirection());
    searchStrategy.setComparator(searchCommand.getComparator());
    searchResultCellCoordinate = searchStrategy.executeSearch(dataValueToFind);
    selectionLayer.fireLayerEvent(new SearchEvent(searchResultCellCoordinate));
    if (searchResultCellCoordinate != null) {
        final SelectCellCommand command = new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, searchResultCellCoordinate.rowPosition, false, false);
        command.setForcingEntireCellIntoViewport(true);
        selectionLayer.doCommand(command);
    }
    return true;
}
Also used : SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) SearchEvent(net.sourceforge.nattable.search.event.SearchEvent) AbstractSearchStrategy(net.sourceforge.nattable.search.strategy.AbstractSearchStrategy)

Example 14 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class CellDisplayValueSearchUtil method getDescendingCellCoordinates.

static List<PositionCoordinate> getDescendingCellCoordinates(ILayer contextLayer, int startingColumnPosition, int startingRowPosition, int width, int height) {
    List<PositionCoordinate> coordinates = new ArrayList<PositionCoordinate>();
    for (int columnPosition = width; columnPosition >= 0 && startingColumnPosition >= 0; columnPosition--) {
        for (int rowPosition = height; rowPosition >= 0 && startingRowPosition >= 0; rowPosition--) {
            PositionCoordinate coordinate = new PositionCoordinate(contextLayer, startingColumnPosition, startingRowPosition--);
            coordinates.add(coordinate);
        }
        startingColumnPosition--;
    }
    return coordinates;
}
Also used : ArrayList(java.util.ArrayList) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 15 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class GridSearchStrategy method searchGrid.

private PositionCoordinate searchGrid(Object valueToMatch, ILayer contextLayer, SelectionLayer selectionLayer, final int anchorColumnPosition, int startingRowPosition, int[] columnsToSearch) {
    // Search for value across columns		
    ColumnSearchStrategy columnSearcher = new ColumnSearchStrategy(columnsToSearch, startingRowPosition, configRegistry, searchDirection);
    columnSearcher.setCaseSensitive(caseSensitive);
    columnSearcher.setWrapSearch(wrapSearch);
    columnSearcher.setContextLayer(contextLayer);
    columnSearcher.setComparator(getComparator());
    PositionCoordinate executeSearch = columnSearcher.executeSearch(valueToMatch);
    if (executeSearch == null && wrapSearch) {
        if (searchDirection.equals(ISearchDirection.SEARCH_FORWARD)) {
            columnSearcher.setColumnPositions(getColumnsToSearchArray(anchorColumnPosition + 1, 0));
        } else {
            columnSearcher.setColumnPositions(getDescendingColumnsToSearchArray(anchorColumnPosition));
        }
        columnSearcher.setStartingRowPosition(0);
        executeSearch = columnSearcher.executeSearch(valueToMatch);
    }
    return executeSearch;
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Aggregations

PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)28 SelectionLayer (net.sourceforge.nattable.selection.SelectionLayer)5 ArrayList (java.util.ArrayList)4 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)4 CellRegion (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion)3 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)3 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)3 ILayer (net.sourceforge.nattable.layer.ILayer)3 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)3 ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)3 Point (org.eclipse.swt.graphics.Point)3 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)2 ActiveCellRegion (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.ActiveCellRegion)2 Range (net.sourceforge.nattable.coordinate.Range)2 LabelStack (net.sourceforge.nattable.layer.LabelStack)2 IRegion (org.eclipse.jface.text.IRegion)2 MessageFormat (java.text.MessageFormat)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1