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