use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionTest method shouldExtendFromAnchorWithShiftKeyPressed.
@Test
public void shouldExtendFromAnchorWithShiftKeyPressed() {
// start from a clear selection state
this.selectionLayer.clear();
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 4, true, false));
// select rows to the top
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 2, true, false));
for (int row = 2; row <= 4; row++) {
assertTrue("row " + row + " not fully selected", this.selectionLayer.isRowPositionFullySelected(row));
}
assertFalse("row 5 fully selected", this.selectionLayer.isRowPositionFullySelected(5));
// select rows to the bottom
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 6, true, false));
assertFalse("row 2 fully selected", this.selectionLayer.isRowPositionFullySelected(2));
assertFalse("row 3 fully selected", this.selectionLayer.isRowPositionFullySelected(3));
for (int row = 4; row <= 6; row++) {
assertTrue("row " + row + " not fully selected", this.selectionLayer.isRowPositionFullySelected(row));
}
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionTest method testMultiSelectionRestore.
@Test
public void testMultiSelectionRestore() {
this.selectionLayer.clear();
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 0, false, false));
assertEquals(1, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(1, this.selectionLayer.getSelectedRowCount());
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 2, true, false));
assertEquals(1, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(3, this.selectionLayer.getSelectedRowCount());
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 2, false, true));
assertEquals(1, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(2, this.selectionLayer.getSelectedRowCount());
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 1, false, true));
assertEquals(1, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(1, this.selectionLayer.getSelectedRowCount());
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 0, false, true));
assertEquals(0, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 0, false, true));
assertEquals(1, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(1, this.selectionLayer.getSelectedRowCount());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionProvider method setSelection.
@SuppressWarnings("unchecked")
@Override
public void setSelection(ISelection selection) {
if (this.selectionLayer != null && selection instanceof IStructuredSelection) {
if (!this.addSelectionOnSet || selection.isEmpty()) {
this.selectionLayer.clear(false);
}
if (!selection.isEmpty()) {
List<T> rowObjects = ((IStructuredSelection) selection).toList();
Set<Integer> rowPositions = new HashSet<Integer>();
for (T rowObject : rowObjects) {
int rowIndex = this.rowDataProvider.indexOfRowObject(rowObject);
int rowPosition = this.selectionLayer.getRowPositionByIndex(rowIndex);
rowPositions.add(Integer.valueOf(rowPosition));
}
int intValue = -1;
if (!rowPositions.isEmpty()) {
Integer max = Collections.max(rowPositions);
intValue = max.intValue();
}
if (intValue >= 0) {
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 0, ObjectUtils.asIntArray(rowPositions), false, true, intValue));
}
} else {
this.selectionLayer.fireCellSelectionEvent(this.selectionLayer.getLastSelectedCell().columnPosition, this.selectionLayer.getLastSelectedCell().rowPosition, false, false, false);
}
}
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class SelectRowAction method run.
@Override
public void run(NatTable natTable, MouseEvent event) {
super.run(natTable, event);
natTable.doCommand(new SelectRowsCommand(natTable, getGridColumnPosition(), getGridRowPosition(), isWithShiftMask(), isWithControlMask()));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class _308_DataModificationExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// set the GridLayout because the FillLayout seems to introduce a
// scrollbar rendering issue on changing the content
parent.setLayout(new GridLayout());
// property names of the Person class
String[] personPropertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> personPropertyToLabelMap = new HashMap<>();
personPropertyToLabelMap.put("firstName", "Firstname");
personPropertyToLabelMap.put("lastName", "Lastname");
personPropertyToLabelMap.put("gender", "Gender");
personPropertyToLabelMap.put("married", "Married");
personPropertyToLabelMap.put("birthday", "Birthday");
ListDataProvider<Person> bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(10), new ReflectiveColumnPropertyAccessor<Person>(personPropertyNames));
IDataProvider personColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(personPropertyNames, personPropertyToLabelMap);
IDataProvider personRowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
// mapping from property to label, needed for column header labels
Map<String, String> addressPropertyToLabelMap = new HashMap<>();
addressPropertyToLabelMap.put("street", "Street");
addressPropertyToLabelMap.put("housenumber", "Housenumber");
addressPropertyToLabelMap.put("postalCode", "Postal Code");
addressPropertyToLabelMap.put("city", "City");
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(buttonPanel);
ConfigRegistry configRegistry = new ConfigRegistry();
// create the body layer stack
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
bodyDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
switch(columnPosition) {
case 3:
configLabels.addLabel("MARRIED");
break;
case 4:
configLabels.addLabel("DATE");
break;
}
}
});
DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(bodyDataLayer);
bodyDataLayer.registerCommandHandler(new DeleteRowCommandHandler<>(bodyDataProvider.getList()));
bodyDataLayer.registerCommandHandler(new InsertRowCommandHandler<>(bodyDataProvider.getList()));
// create the column header layer stack
DataLayer columnHeaderDataLayer = new DataLayer(personColumnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
// create the row header layer stack
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(personRowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(personColumnHeaderDataProvider, personRowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, "MARRIED");
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDateDisplayConverter("yyyy-MM-dd"), DisplayMode.NORMAL, "DATE");
}
});
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
private final Menu bodyMenu = new PopupMenuBuilder(natTable).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem deleteRow = new MenuItem(popupMenu, SWT.PUSH);
deleteRow.setText("Insert below");
deleteRow.setEnabled(true);
deleteRow.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
natTable.doCommand(new InsertRowCommand<>(bodyDataLayer, rowPosition, PersonService.getPersons(1).get(0)));
}
});
}
}).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem deleteRow = new MenuItem(popupMenu, SWT.PUSH);
deleteRow.setText("Delete");
deleteRow.setEnabled(true);
deleteRow.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
natTable.doCommand(new DeleteRowCommand(natTable, rowPosition));
}
});
}
}).build();
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(this.bodyMenu) {
@Override
public void run(NatTable natTable, MouseEvent event) {
int columnPosition = natTable.getColumnPositionByX(event.x);
int rowPosition = natTable.getRowPositionByY(event.y);
if (!bodyLayerStack.getSelectionLayer().isRowPositionFullySelected(rowPosition)) {
natTable.doCommand(new SelectRowsCommand(natTable, columnPosition, rowPosition, false, false));
}
super.run(natTable, event);
}
});
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
return panel;
}
Aggregations