Search in sources :

Example 41 with CopyDataToClipboardCommand

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));
}
Also used : FillHandlePasteCommand(org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand) CopyDataToClipboardCommand(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 42 with CopyDataToClipboardCommand

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));
}
Also used : FillHandlePasteCommand(org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand) CopyDataToClipboardCommand(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Example 43 with CopyDataToClipboardCommand

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);
    }
}
Also used : FillHandlePasteCommand(org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand) CopyDataToClipboardCommand(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand)

Example 44 with CopyDataToClipboardCommand

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;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) CopyDataToClipboardCommand(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) CopyDataCommandHandler(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 45 with CopyDataToClipboardCommand

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));
}
Also used : FillHandlePasteCommand(org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand) CopyDataToClipboardCommand(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Aggregations

CopyDataToClipboardCommand (org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand)84 FillHandlePasteCommand (org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand)83 Rectangle (org.eclipse.swt.graphics.Rectangle)82 Test (org.junit.Test)82 Point (org.eclipse.swt.graphics.Point)34 Date (java.util.Date)6 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 CopyDataCommandHandler (org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1 DefaultBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider)1 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)1 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)1 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)1 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)1 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)1 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)1 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)1 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)1