use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class EditUtils method allCellsEditable.
public static boolean allCellsEditable(SelectionLayer selectionLayer, IConfigRegistry configRegistry) {
PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
for (PositionCoordinate cell : selectedCells) {
LabelStack labelStack = selectionLayer.getConfigLabelsByPosition(cell.columnPosition, cell.rowPosition);
IEditableRule editableRule = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, labelStack.getLabels());
int columnIndex = selectionLayer.getColumnIndexByPosition(cell.columnPosition);
int rowIndex = selectionLayer.getRowIndexByPosition(cell.rowPosition);
if (!editableRule.isEditable(columnIndex, rowIndex)) {
return false;
}
}
return true;
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class MultiCellEditController method editSelectedCells.
public static boolean editSelectedCells(SelectionLayer selectionLayer, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
LayerCell lastSelectedCell = EditUtils.getLastSelectedCell(selectionLayer);
// IF cell is selected
if (lastSelectedCell != null) {
final List<String> lastSelectedCellLabelsArray = lastSelectedCell.getConfigLabels().getLabels();
PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
// AND selected cell count > 1
if (selectedCells.length > 1) {
ICellEditor lastSelectedCellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
// AND all selected cells are editable
if (EditUtils.isEditorSame(selectionLayer, configRegistry, lastSelectedCellEditor) && EditUtils.allCellsEditable(selectionLayer, configRegistry)) {
// THEN use multi commit handler and populate editor in popup
ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
IDisplayConverter dataTypeConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, lastSelectedCellLabelsArray);
IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, lastSelectedCellLabelsArray);
IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
Object originalCanonicalValue = lastSelectedCell.getDataValue();
for (PositionCoordinate selectedCell : selectedCells) {
Object cellValue = selectionLayer.getCellByPosition(selectedCell.columnPosition, selectedCell.rowPosition).getDataValue();
if (!cellValue.equals(originalCanonicalValue)) {
originalCanonicalValue = null;
break;
}
}
ITickUpdateHandler tickUpdateHandler = configRegistry.getConfigAttribute(TickUpdateConfigAttributes.UPDATE_HANDLER, DisplayMode.EDIT, lastSelectedCellLabelsArray);
boolean allowIncrementDecrement = tickUpdateHandler != null && tickUpdateHandler.isApplicableFor(originalCanonicalValue);
MultiCellEditDialog dialog = new MultiCellEditDialog(parent.getShell(), cellEditor, dataTypeConverter, cellStyle, dataValidator, originalCanonicalValue, initialEditValue, allowIncrementDecrement);
int returnValue = dialog.open();
ActiveCellEditor.close();
if (returnValue == Dialog.OK) {
Object editorValue = dialog.getEditorValue();
Object newValue = editorValue;
if (allowIncrementDecrement) {
switch(dialog.getEditType()) {
case INCREASE:
newValue = tickUpdateHandler.getIncrementedValue(originalCanonicalValue);
break;
case DECREASE:
newValue = tickUpdateHandler.getDecrementedValue(originalCanonicalValue);
break;
}
}
for (PositionCoordinate selectedCell : selectedCells) {
selectionLayer.doCommand(new UpdateDataCommand(selectionLayer, selectedCell.columnPosition, selectedCell.rowPosition, newValue));
}
}
}
} else {
// ELSE use single commit handler and populate editor inline in cell rectangle
selectionLayer.fireLayerEvent(new InlineCellEditEvent(selectionLayer, new PositionCoordinate(selectionLayer, lastSelectedCell.getColumnPosition(), lastSelectedCell.getRowPosition()), parent, configRegistry, initialEditValue));
}
return true;
}
return false;
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class FreezeEventHandler method handleLayerEvent.
public void handleLayerEvent(IStructuralChangeEvent event) {
PositionCoordinate topLeftPosition = freezeLayer.getTopLeftPosition();
PositionCoordinate bottomRightPosition = freezeLayer.getBottomRightPosition();
Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
if (columnDiffs != null) {
int leftOffset = 0;
int rightOffset = 0;
for (StructuralDiff columnDiff : columnDiffs) {
switch(columnDiff.getDiffType()) {
case ADD:
Range afterPositionRange = columnDiff.getAfterPositionRange();
if (afterPositionRange.start < topLeftPosition.columnPosition) {
leftOffset += afterPositionRange.size();
}
if (afterPositionRange.start <= bottomRightPosition.columnPosition) {
rightOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = columnDiff.getBeforePositionRange();
if (beforePositionRange.start < topLeftPosition.columnPosition) {
leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.columnPosition + 1) - beforePositionRange.start;
}
if (beforePositionRange.start <= bottomRightPosition.columnPosition) {
rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.columnPosition + 1) - beforePositionRange.start;
}
break;
}
}
topLeftPosition.columnPosition += leftOffset;
bottomRightPosition.columnPosition += rightOffset;
}
Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
if (rowDiffs != null) {
int leftOffset = 0;
int rightOffset = 0;
for (StructuralDiff rowDiff : rowDiffs) {
switch(rowDiff.getDiffType()) {
case ADD:
Range afterPositionRange = rowDiff.getAfterPositionRange();
if (afterPositionRange.start < topLeftPosition.rowPosition) {
leftOffset += afterPositionRange.size();
}
if (afterPositionRange.start <= bottomRightPosition.rowPosition) {
rightOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = rowDiff.getBeforePositionRange();
if (beforePositionRange.start < topLeftPosition.rowPosition) {
leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.rowPosition + 1) - beforePositionRange.start;
}
if (beforePositionRange.start <= bottomRightPosition.rowPosition) {
rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.rowPosition + 1) - beforePositionRange.start;
}
break;
}
}
topLeftPosition.rowPosition += leftOffset;
bottomRightPosition.rowPosition += rightOffset;
}
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class FreezeCommandHandler method handleFreezeCommand.
protected void handleFreezeCommand(IFreezeCoordinatesProvider coordinatesProvider) {
// if not already frozen
if (freezeLayer.getColumnCount() == 0 && freezeLayer.getRowCount() == 0) {
final PositionCoordinate topLeftPosition = coordinatesProvider.getTopLeftPosition();
final PositionCoordinate bottomRightPosition = coordinatesProvider.getBottomRightPosition();
freezeLayer.setTopLeftPosition(topLeftPosition.columnPosition, topLeftPosition.rowPosition);
freezeLayer.setBottomRightPosition(bottomRightPosition.columnPosition, bottomRightPosition.rowPosition);
viewportLayer.setMinimumOriginPosition(bottomRightPosition.columnPosition + 1, bottomRightPosition.rowPosition + 1);
viewportLayer.fireLayerEvent(new FreezeEvent(viewportLayer));
}
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class FreezeSelectionStrategy method getTopLeftPosition.
public PositionCoordinate getTopLeftPosition() {
PositionCoordinate lastSelectedCellPosition = selectionLayer.getLastSelectedCellPosition();
int columnPosition = viewportLayer.getOriginColumnPosition();
if (columnPosition >= lastSelectedCellPosition.columnPosition) {
columnPosition = lastSelectedCellPosition.columnPosition - 1;
}
int rowPosition = viewportLayer.getOriginRowPosition();
if (rowPosition >= lastSelectedCellPosition.rowPosition) {
rowPosition = lastSelectedCellPosition.rowPosition - 1;
}
return new PositionCoordinate(freezeLayer, columnPosition, rowPosition);
}
Aggregations