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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations