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