use of org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand in project nebula.widgets.nattable by eclipse.
the class FormulaFillHandlePasteTest method testFullFunctionCellDragDown.
@Test
public void testFullFunctionCellDragDown() {
this.dataProvider.setDataValue(4, 4, "2");
this.dataProvider.setDataValue(5, 4, "21");
this.dataProvider.setDataValue(6, 4, "=E5*F5");
assertEquals(new BigDecimal("42"), this.formulaDataProvider.getDataValue(6, 4));
this.selectionLayer.selectCell(4, 4, false, true);
this.selectionLayer.selectCell(5, 4, false, true);
this.selectionLayer.selectCell(6, 4, false, true);
testCellStates(new Point(4, 4), new Point(5, 4), new Point(6, 4));
this.natTable.doCommand(new CopyDataToClipboardCommand(// $NON-NLS-1$
"\t", // $NON-NLS-1$
System.getProperty("line.separator"), this.natTable.getConfigRegistry()));
this.selectionLayer.setFillHandleRegion(new Rectangle(4, 4, 3, 3));
this.natTable.doCommand(new FillHandlePasteCommand(FillHandleOperation.SERIES, MoveDirectionEnum.DOWN, this.natTable.getConfigRegistry()));
assertEquals("2", this.selectionLayer.getDataValueByPosition(4, 4));
assertEquals("21", this.selectionLayer.getDataValueByPosition(5, 4));
assertEquals(new BigDecimal("42"), this.selectionLayer.getDataValueByPosition(6, 4));
assertEquals("3", this.selectionLayer.getDataValueByPosition(4, 5));
assertEquals("22", this.selectionLayer.getDataValueByPosition(5, 5));
assertEquals(new BigDecimal("66"), this.selectionLayer.getDataValueByPosition(6, 5));
assertEquals("4", this.selectionLayer.getDataValueByPosition(4, 6));
assertEquals("23", this.selectionLayer.getDataValueByPosition(5, 6));
assertEquals(new BigDecimal("92"), this.selectionLayer.getDataValueByPosition(6, 6));
testCellStates(new Point(4, 4), new Point(5, 4), new Point(6, 4), new Point(4, 5), new Point(5, 5), new Point(6, 5), new Point(4, 6), new Point(5, 6), new Point(6, 6));
}
use of org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand in project nebula.widgets.nattable by eclipse.
the class FormulaFillHandlePasteTest method testSingleCellDragOneDown.
@Test
public void testSingleCellDragOneDown() {
this.dataProvider.setDataValue(4, 4, "Simpson");
this.selectionLayer.setSelectedCell(4, 4);
testCellStates(new Point(4, 4));
this.natTable.doCommand(new CopyDataToClipboardCommand(// $NON-NLS-1$
"\t", // $NON-NLS-1$
System.getProperty("line.separator"), this.natTable.getConfigRegistry()));
this.selectionLayer.setFillHandleRegion(new Rectangle(4, 4, 1, 2));
this.natTable.doCommand(new FillHandlePasteCommand(FillHandleOperation.COPY, MoveDirectionEnum.DOWN, this.natTable.getConfigRegistry()));
assertEquals("Simpson", this.selectionLayer.getDataValueByPosition(4, 5));
testCellStates(new Point(4, 4), new Point(4, 5));
}
use of org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand in project nebula.widgets.nattable by eclipse.
the class FillHandleDragMode method mouseUp.
@Override
public void mouseUp(final NatTable natTable, MouseEvent event) {
// Cancel any active viewport drag
super.mouseUp(natTable, event);
if (natTable.doCommand(new CopyDataToClipboardCommand(// $NON-NLS-1$
"\t", // $NON-NLS-1$
System.getProperty("line.separator"), natTable.getConfigRegistry()))) {
if (this.clipboard != null) {
if (showMenu(natTable)) {
openMenu(natTable);
} else {
natTable.doCommand(new FillHandlePasteCommand(FillHandleOperation.COPY, this.direction, natTable.getConfigRegistry()));
reset(natTable);
}
} else {
natTable.doCommand(new FillHandlePasteCommand(FillHandleOperation.COPY, this.direction, natTable.getConfigRegistry()));
reset(natTable);
}
} else {
reset(natTable);
}
}
use of org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand in project nebula.widgets.nattable by eclipse.
the class _751_CopyExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
panel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
// build the body layer stack
// Usually you would create a new layer stack by extending
// AbstractIndexLayerTransform and setting the ViewportLayer as
// underlying layer. But in this case using the ViewportLayer directly
// as body layer is also working.
IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(100), propertyNames);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
// register a CopyDataCommandHandler that also copies the headers and
// uses the configured IDisplayConverters
CopyDataCommandHandler copyHandler = new CopyDataCommandHandler(selectionLayer, columnHeaderDataLayer, rowHeaderDataLayer);
copyHandler.setCopyFormattedText(true);
gridLayer.registerCommandHandler(copyHandler);
final NatTable natTable = new NatTable(gridPanel, gridLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
addColumnButton.setText("Copy");
addColumnButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new // $NON-NLS-1$
CopyDataToClipboardCommand(// $NON-NLS-1$
"\t", // $NON-NLS-1$
System.getProperty("line.separator"), natTable.getConfigRegistry()));
}
});
return panel;
}
use of org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand in project nebula.widgets.nattable by eclipse.
the class FillHandlePasteTest method testMultiCellDragOneDown.
@Test
public void testMultiCellDragOneDown() {
this.dataProvider.setDataValue(3, 4, "Homer");
this.dataProvider.setDataValue(4, 4, "Simpson");
this.dataProvider.setDataValue(3, 5, "Ned");
this.dataProvider.setDataValue(4, 5, "Flanders");
this.selectionLayer.selectCell(3, 4, false, true);
this.selectionLayer.selectCell(4, 4, false, true);
this.selectionLayer.selectCell(3, 5, false, true);
this.selectionLayer.selectCell(4, 5, false, true);
testCellStates(new Point(3, 4), new Point(4, 4), new Point(3, 5), new Point(4, 5));
this.natTable.doCommand(new CopyDataToClipboardCommand(// $NON-NLS-1$
"\t", // $NON-NLS-1$
System.getProperty("line.separator"), this.natTable.getConfigRegistry()));
this.selectionLayer.setFillHandleRegion(new Rectangle(3, 4, 2, 3));
this.natTable.doCommand(new FillHandlePasteCommand(FillHandleOperation.COPY, MoveDirectionEnum.DOWN, this.natTable.getConfigRegistry()));
assertEquals("Homer", this.selectionLayer.getDataValueByPosition(3, 4));
assertEquals("Simpson", this.selectionLayer.getDataValueByPosition(4, 4));
assertEquals("Ned", this.selectionLayer.getDataValueByPosition(3, 5));
assertEquals("Flanders", this.selectionLayer.getDataValueByPosition(4, 5));
assertEquals("Homer", this.selectionLayer.getDataValueByPosition(3, 6));
assertEquals("Simpson", this.selectionLayer.getDataValueByPosition(4, 6));
testCellStates(new Point(3, 4), new Point(4, 4), new Point(3, 5), new Point(4, 5), new Point(3, 6), new Point(4, 6));
}
Aggregations