use of org.eclipse.nebula.widgets.nattable.resize.action.VerticalResizeCursorAction in project nebula.widgets.nattable by eclipse.
the class _5045_ScrollableRowHeaderExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// 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");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(10), columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
DataLayer rowDataLayer = new DataLayer(new IDataProvider() {
@Override
public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
}
@Override
public int getRowCount() {
return bodyDataProvider.getRowCount();
}
@Override
public Object getDataValue(int columnIndex, int rowIndex) {
return "Lorem ipsum dolor";
}
@Override
public int getColumnCount() {
return 1;
}
});
rowDataLayer.setDefaultColumnWidth(150);
ViewportLayer rowViewport = new ViewportLayer(rowDataLayer);
RowHeaderLayer scrollableRowHeaderLayer = new RowHeaderLayer(rowViewport, viewportLayer, selectionLayer);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
CompositeLayer compositeLayer = new CompositeLayer(2, 1);
compositeLayer.setChildLayer(GridRegion.ROW_HEADER, rowHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.ROW_HEADER, scrollableRowHeaderLayer, 1, 0);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
final DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
final AbstractLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowDataLayer.getDataProvider());
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
final ILayer cornerLayer = new CornerLayer(cornerDataLayer, compositeLayer, columnHeaderLayer);
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, compositeLayer, cornerLayer);
// MULTI-VIEWPORT-CONFIGURATION
// use a cell layer painter that is configured for left clipping
// this ensures that the rendering works correctly for split
// viewports
selectionLayer.setLayerPainter(new SelectionLayerPainter(true, false));
columnHeaderLayer.setLayerPainter(new CellLayerPainter(true, false));
// as the CompositeLayer is setting a IClientAreaProvider for the
// composition we need to set a special ClientAreaAdapter after the
// creation of the CompositeLayer to support split viewports
int leftWidth = 100;
ClientAreaAdapter leftClientAreaAdapter = new ClientAreaAdapter(rowViewport.getClientAreaProvider());
leftClientAreaAdapter.setWidth(leftWidth);
rowViewport.setClientAreaProvider(leftClientAreaAdapter);
// Wrap NatTable in composite so we can slap on the external horizontal
// sliders
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
composite.setLayout(gridLayout);
NatTable natTable = new NatTable(composite, gridLayer);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
natTable.setLayoutData(gridData);
createSplitSliders(composite, rowViewport, rowHeaderLayer.getWidth(), viewportLayer);
// add an IOverlayPainter to render the split viewport border
natTable.addOverlayPainter(new IOverlayPainter() {
@Override
public void paintOverlay(GC gc, ILayer layer) {
Color beforeColor = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_GRAY);
int viewportBorderX = compositeLayer.getWidth() - 1;
gc.drawLine(viewportBorderX, 0, viewportBorderX, layer.getHeight() - 1);
gc.setForeground(beforeColor);
}
});
// Mouse move - Show resize cursor
natTable.getUiBindingRegistry().registerFirstMouseMoveBinding(new ClientAreaResizeMatcher(compositeLayer), new VerticalResizeCursorAction());
natTable.getUiBindingRegistry().registerFirstMouseDragMode(new ClientAreaResizeMatcher(compositeLayer), new ClientAreaResizeDragMode(compositeLayer, rowDataLayer, leftClientAreaAdapter, rowViewport, viewportLayer));
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.resize.action.VerticalResizeCursorAction in project nebula.widgets.nattable by eclipse.
the class _5046_MultiScrollExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
List<PersonWithAddress> values = PersonService.getPersonsWithAddress(10);
ContentBodyLayerStack contentBodyLayer = new ContentBodyLayerStack(values);
StructureBodyLayerStack structureBodyLayer = new StructureBodyLayerStack(values, contentBodyLayer);
// build the column header layer
IDataProvider contentHeaderDataProvider = new DefaultColumnHeaderDataProvider(contentBodyLayer.propertyNames, contentBodyLayer.propertyToLabelMap);
DataLayer contentHeaderDataLayer = new DefaultColumnHeaderDataLayer(contentHeaderDataProvider);
AbstractLayer contentColumnHeaderLayer = new ColumnHeaderLayer(contentHeaderDataLayer, contentBodyLayer, contentBodyLayer.getSelectionLayer());
IDataProvider structureHeaderDataProvider = new DefaultColumnHeaderDataProvider(structureBodyLayer.propertyNames, structureBodyLayer.propertyToLabelMap);
DataLayer structureHeaderDataLayer = new DefaultColumnHeaderDataLayer(structureHeaderDataProvider);
ColumnHeaderLayer structureColumnHeaderLayer = new ColumnHeaderLayer(structureHeaderDataLayer, structureBodyLayer, structureBodyLayer.selectionLayer);
structureColumnHeaderLayer.setVerticalLayerDependency(contentColumnHeaderLayer);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(contentBodyLayer.bodyDataProvider));
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, contentBodyLayer, (SelectionLayer) null);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(contentHeaderDataProvider, rowHeaderDataLayer.getDataProvider());
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, contentColumnHeaderLayer);
ExtendedGridLayer gridLayer = new ExtendedGridLayer(contentBodyLayer, contentColumnHeaderLayer, structureBodyLayer, structureColumnHeaderLayer, rowHeaderLayer, cornerLayer);
// MULTI-VIEWPORT-CONFIGURATION
// as the CompositeLayer is setting a IClientAreaProvider for the
// composition we need to set a special ClientAreaAdapter after the
// creation of the CompositeLayer to support split viewports
int leftWidth = 80;
ClientAreaAdapter leftClientAreaAdapter = new ClientAreaAdapter(structureBodyLayer.getViewportLayer().getClientAreaProvider());
leftClientAreaAdapter.setWidth(leftWidth);
structureBodyLayer.getViewportLayer().setClientAreaProvider(leftClientAreaAdapter);
structureBodyLayer.getViewportLayer().setVerticalScrollbarEnabled(false);
// use a cell layer painter that is configured for left clipping
// this ensures that the rendering works correctly for split
// viewports
contentBodyLayer.getSelectionLayer().setLayerPainter(new SelectionLayerPainter(true, false));
contentColumnHeaderLayer.setLayerPainter(new CellLayerPainter(true, false));
ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
// Wrap NatTable in composite so we can slap on the external horizontal
// sliders
Composite composite = new Composite(sc, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
composite.setLayout(gridLayout);
NatTable natTable = new NatTable(composite, gridLayer);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
natTable.setLayoutData(gridData);
createSplitSliders(composite, gridLayer, rowHeaderLayer.getWidth());
sc.setContent(composite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
updateScrolledCompositeSize(sc, gridLayer);
// add an IOverlayPainter to render the split viewport border
natTable.addOverlayPainter(new IOverlayPainter() {
@Override
public void paintOverlay(GC gc, ILayer layer) {
Color beforeColor = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_GRAY);
int viewportBorderX = rowHeaderLayer.getWidth() + gridLayer.getStructureBody().getWidth() - 1;
gc.drawLine(viewportBorderX, 0, viewportBorderX, layer.getHeight() - 1);
gc.setForeground(beforeColor);
}
});
// Mouse move - Show resize cursor
natTable.getUiBindingRegistry().registerFirstMouseMoveBinding(new ClientAreaResizeMatcher(gridLayer), new VerticalResizeCursorAction());
natTable.getUiBindingRegistry().registerFirstMouseDragMode(new ClientAreaResizeMatcher(gridLayer), new ClientAreaResizeDragMode(gridLayer, sc));
return natTable;
}
Aggregations