Search in sources :

Example 1 with CopyDataCommandHandler

use of org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler in project nebula.widgets.nattable by eclipse.

the class DefaultGridLayer method init.

protected void init(IUniqueIndexLayer bodyDataLayer, IUniqueIndexLayer columnHeaderDataLayer, IUniqueIndexLayer rowHeaderDataLayer, IUniqueIndexLayer cornerDataLayer) {
    // Body
    this.bodyDataLayer = bodyDataLayer;
    DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(bodyDataLayer);
    SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    // Column header
    this.columnHeaderDataLayer = columnHeaderDataLayer;
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, selectionLayer);
    // Row header
    this.rowHeaderDataLayer = rowHeaderDataLayer;
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, selectionLayer);
    // Corner
    this.cornerDataLayer = cornerDataLayer;
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
    setBodyLayer(bodyLayer);
    setColumnHeaderLayer(columnHeaderLayer);
    setRowHeaderLayer(rowHeaderLayer);
    setCornerLayer(cornerLayer);
    CopyDataCommandHandler cdch = new CopyDataCommandHandler(selectionLayer, columnHeaderDataLayer, rowHeaderDataLayer);
    cdch.setCopyFormattedText(true);
    registerCommandHandler(cdch);
}
Also used : SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) CopyDataCommandHandler(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)

Example 2 with CopyDataCommandHandler

use of org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler 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 3 with CopyDataCommandHandler

use of org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler in project nebula.widgets.nattable by eclipse.

the class SelectionLayer method registerCommandHandlers.

// Command handling
@Override
protected void registerCommandHandlers() {
    registerCommandHandler(this.selectCellCommandHandler);
    registerCommandHandler(this.selectRowCommandHandler);
    registerCommandHandler(this.selectColumnCommandHandler);
    registerCommandHandler(new SelectRegionCommandHandler(this));
    registerCommandHandler(new EditSelectionCommandHandler(this));
    registerCommandHandler(new InitializeAutoResizeColumnsCommandHandler(this));
    registerCommandHandler(new InitializeAutoResizeRowsCommandHandler(this));
    registerCommandHandler(new CopyDataCommandHandler(this));
    registerCommandHandler(new SearchGridCellsCommandHandler(this));
}
Also used : EditSelectionCommandHandler(org.eclipse.nebula.widgets.nattable.edit.command.EditSelectionCommandHandler) InitializeAutoResizeColumnsCommandHandler(org.eclipse.nebula.widgets.nattable.grid.command.InitializeAutoResizeColumnsCommandHandler) InitializeAutoResizeRowsCommandHandler(org.eclipse.nebula.widgets.nattable.grid.command.InitializeAutoResizeRowsCommandHandler) CopyDataCommandHandler(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler) SearchGridCellsCommandHandler(org.eclipse.nebula.widgets.nattable.search.command.SearchGridCellsCommandHandler)

Aggregations

CopyDataCommandHandler (org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler)3 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)2 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)2 HashMap (java.util.HashMap)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 CopyDataToClipboardCommand (org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1 EditSelectionCommandHandler (org.eclipse.nebula.widgets.nattable.edit.command.EditSelectionCommandHandler)1 InitializeAutoResizeColumnsCommandHandler (org.eclipse.nebula.widgets.nattable.grid.command.InitializeAutoResizeColumnsCommandHandler)1 InitializeAutoResizeRowsCommandHandler (org.eclipse.nebula.widgets.nattable.grid.command.InitializeAutoResizeRowsCommandHandler)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 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)1