use of org.eclipse.nebula.widgets.nattable.hover.action.ClearHoverStylingAction in project nebula.widgets.nattable by eclipse.
the class _5064_GridHeaderHoverStylingExample 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");
// 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(10), 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);
HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHoverLayer, viewportLayer, selectionLayer, false);
// add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
// and resizing is working together
columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHoverLayer));
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
HoverLayer rowHoverLayer = new HoverLayer(rowHeaderDataLayer, false);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHoverLayer, viewportLayer, selectionLayer, false);
// add RowHeaderHoverLayerConfiguration to ensure that hover styling and
// resizing is working together
rowHeaderLayer.addConfiguration(new RowHeaderHoverLayerConfiguration(rowHoverLayer));
// 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);
// turn the auto configuration off as we want to add our header menu
// configuration
NatTable natTable = new NatTable(parent, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration manually
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerMouseMoveBinding(new MouseEventMatcher(GridRegion.BODY), new ClearHoverStylingAction());
}
});
// add the style configuration for hover
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_RED);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.HOVER, GridRegion.ROW_HEADER);
Image bgImage = GUIHelper.getImageByURL("columnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/column_header_bg.png"));
Image hoverBgImage = GUIHelper.getImageByURL("hoverColumnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/hovered_column_header_bg.png"));
Image selectedBgImage = GUIHelper.getImageByURL("selectedColumnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/selected_column_header_bg.png"));
TextPainter txtPainter = new TextPainter(false, false);
ICellPainter bgImagePainter = new BackgroundImagePainter(txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.CORNER);
ICellPainter hoveredHeaderPainter = new BackgroundImagePainter(txtPainter, hoverBgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, hoveredHeaderPainter, DisplayMode.HOVER, GridRegion.COLUMN_HEADER);
ICellPainter selectedHeaderPainter = new BackgroundImagePainter(txtPainter, selectedBgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, selectedHeaderPainter, DisplayMode.SELECT, GridRegion.COLUMN_HEADER);
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.hover.action.ClearHoverStylingAction in project nebula.widgets.nattable by eclipse.
the class BodyHoverStylingBindings method configureUiBindings.
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
// apply a hover styling on moving the mouse over a NatTable
uiBindingRegistry.registerFirstMouseMoveBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
return BodyHoverStylingBindings.this.layer.getClientAreaProvider().getClientArea().contains(event.x, event.y);
}
}, new HoverStylingAction(this.layer));
// clear any hover styling if the mouse is moved out of the region area
// uiBindingRegistry.registerMouseMoveBinding(
// new IMouseEventMatcher() {
// @Override
// public boolean matches(NatTable natTable, MouseEvent event,
// LabelStack regionLabels) {
// return
// (!layer.getClientAreaProvider().getClientArea().contains(event.x,
// event.y));
// }
//
// }, new ClearHoverStylingAction());
// clear any hover styling if the mouse is moved out of a NatTable
// region
uiBindingRegistry.registerMouseMoveBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
return (natTable != null && regionLabels == null);
}
}, new ClearHoverStylingAction());
// clear any hover styling if the mouse is moved out of the NatTable
// area
uiBindingRegistry.registerMouseExitBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
// not necessary
return true;
}
}, new ClearHoverStylingAction());
}
use of org.eclipse.nebula.widgets.nattable.hover.action.ClearHoverStylingAction in project nebula.widgets.nattable by eclipse.
the class ColumnHeaderResizeHoverBindings method configureUiBindings.
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
// Mouse move - Show resize cursor
uiBindingRegistry.registerFirstMouseMoveBinding(new ColumnResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 0), new ColumnResizeCursorAction());
// apply a hover styling on moving the mouse over a NatTable and clear
// the cursor
uiBindingRegistry.registerMouseMoveBinding(new MouseEventMatcher(GridRegion.COLUMN_HEADER), new HoverStylingAction(this.layer));
// clear any hover styling if the mouse is moved out of a NatTable
// region
uiBindingRegistry.registerMouseMoveBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
return ((natTable != null && regionLabels == null) || regionLabels != null && regionLabels.hasLabel(GridRegion.CORNER));
}
}, new ClearHoverStylingAction());
// clear any hover styling if the mouse is moved out of the NatTable
// area
uiBindingRegistry.registerMouseExitBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
// not necessary
return true;
}
}, new ClearHoverStylingAction());
// Column resize
uiBindingRegistry.registerFirstMouseDragMode(new ColumnResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 1), new ColumnResizeDragMode());
uiBindingRegistry.registerDoubleClickBinding(new ColumnResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 1), new AutoResizeColumnAction());
uiBindingRegistry.registerSingleClickBinding(new ColumnResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 1), new NoOpMouseAction());
}
use of org.eclipse.nebula.widgets.nattable.hover.action.ClearHoverStylingAction in project nebula.widgets.nattable by eclipse.
the class RowHeaderResizeHoverBindings method configureUiBindings.
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
// Mouse move - Show resize cursor
uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, 0), new RowResizeCursorAction());
// apply a hover styling on moving the mouse over a NatTable and clear
// the cursor
uiBindingRegistry.registerMouseMoveBinding(new MouseEventMatcher(GridRegion.ROW_HEADER), new HoverStylingAction(this.layer));
// clear any hover styling if the mouse is moved out of the region area
// uiBindingRegistry.registerMouseMoveBinding(
// new IMouseEventMatcher() {
// @Override
// public boolean matches(NatTable natTable, MouseEvent event,
// LabelStack regionLabels) {
// return (regionLabels != null &&
// !regionLabels.hasLabel(GridRegion.ROW_HEADER));
// }
//
// }, new ClearHoverStylingAction(layer));
// clear any hover styling if the mouse is moved out of a NatTable
// region
uiBindingRegistry.registerMouseMoveBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
return (natTable != null && regionLabels == null);
}
}, new ClearHoverStylingAction());
// clear any hover styling if the mouse is moved out of the NatTable
// area
uiBindingRegistry.registerMouseExitBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
// not necessary
return true;
}
}, new ClearHoverStylingAction());
// Row resize
uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, 1), new RowResizeDragMode());
uiBindingRegistry.registerDoubleClickBinding(new RowResizeEventMatcher(SWT.NONE, 1), new AutoResizeRowAction());
uiBindingRegistry.registerSingleClickBinding(new RowResizeEventMatcher(SWT.NONE, 1), new NoOpMouseAction());
}
use of org.eclipse.nebula.widgets.nattable.hover.action.ClearHoverStylingAction in project nebula.widgets.nattable by eclipse.
the class SimpleHoverStylingBindings method configureUiBindings.
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
// apply a hover styling on moving the mouse over a NatTable
uiBindingRegistry.registerFirstMouseMoveBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
int width = SimpleHoverStylingBindings.this.layer.getPreferredWidth();
int height = SimpleHoverStylingBindings.this.layer.getPreferredHeight();
return ((event.x > 0 && event.x < width) && (event.y > 0 && event.y < height));
}
}, new HoverStylingAction(this.layer));
// clear any hover styling if the mouse is moved out of the region area
uiBindingRegistry.registerMouseMoveBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
int width = SimpleHoverStylingBindings.this.layer.getPreferredWidth();
int height = SimpleHoverStylingBindings.this.layer.getPreferredHeight();
return ((event.x < 0 || event.x > width) || (event.y < 0 || event.y > height));
}
}, new ClearHoverStylingAction());
// clear any hover styling if the mouse is moved out of a NatTable
// region
uiBindingRegistry.registerMouseMoveBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
return (natTable != null && regionLabels == null);
}
}, new ClearHoverStylingAction());
// clear any hover styling if the mouse is moved out of the NatTable
// area
uiBindingRegistry.registerMouseExitBinding(new IMouseEventMatcher() {
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
// not necessary
return true;
}
}, new ClearHoverStylingAction());
}
Aggregations