use of org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration in project nebula.widgets.nattable by eclipse.
the class _305_FormulaDataExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
// TODO add combo box and text field for editing formulas
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, false).applyTo(buttonPanel);
ConfigRegistry configRegistry = new ConfigRegistry();
final FormulaGridLayer gridLayer = new FormulaGridLayer();
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
final FormulaBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
natTable.addConfiguration(new FillHandleConfiguration(bodyLayer.getSelectionLayer()));
// This is the formula specific configuration
natTable.addConfiguration(new DefaultFormulaConfiguration(bodyLayer.getFormulaDataProvider(), bodyLayer.getSelectionLayer(), natTable.getInternalCellClipboard()));
bodyLayer.getFormulaDataProvider().setErrorReporter(new FormulaTooltipErrorReporter(natTable, bodyLayer.getDataLayer()));
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
PoiExcelExporter exporter = new HSSFExcelExporter();
exporter.setApplyBackgroundColor(false);
exporter.setFormulaParser(bodyLayer.getFormulaDataProvider().getFormulaParser());
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, exporter);
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
final Button toggleFormulaButton = new Button(panel, SWT.PUSH);
toggleFormulaButton.setText("Disable Formula Evaluation");
toggleFormulaButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_305_FormulaDataExample.this.evaluationEnabled = !_305_FormulaDataExample.this.evaluationEnabled;
if (_305_FormulaDataExample.this.evaluationEnabled) {
natTable.doCommand(new EnableFormulaEvaluationCommand());
toggleFormulaButton.setText("Disable Formula Evaluation");
} else {
natTable.doCommand(new DisableFormulaEvaluationCommand());
toggleFormulaButton.setText("Enable Formula Evaluation");
}
}
});
return panel;
}
use of org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration in project nebula.widgets.nattable by eclipse.
the class FillHandlePasteTest method setup.
@Before
public void setup() {
this.natTable.addConfiguration(new FillHandleConfiguration(this.selectionLayer));
this.natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE);
}
});
this.natTable.configure();
}
use of org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration in project nebula.widgets.nattable by eclipse.
the class FillHandleSeriesTest method setup.
@Before
public void setup() {
this.natTable.addConfiguration(new FillHandleConfiguration(this.selectionLayer));
this.natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE);
}
});
this.natTable.configure();
}
use of org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration in project nebula.widgets.nattable by eclipse.
the class CSSExample method postConstruct.
@PostConstruct
public void postConstruct(Composite parent, Shell shell) {
parent.setLayout(new GridLayout());
// property names of the Person class
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "password", "description", "age", "money", "married", "gender", "address.street", "address.city", "favouriteFood", "favouriteDrinks" };
// 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("password", "Password");
propertyToLabelMap.put("description", "Description");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("address.street", "Street");
propertyToLabelMap.put("address.city", "City");
propertyToLabelMap.put("favouriteFood", "Food");
propertyToLabelMap.put("favouriteDrinks", "Drinks");
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), new ExtendedReflectiveColumnPropertyAccessor<ExtendedPersonWithAddress>(propertyNames));
DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap));
// unregister the default registered commandhandler to make the fill
// handle work here for the age column
gridLayer.unregisterCommandHandler(CopyDataToClipboardCommand.class);
gridLayer.getBodyLayer().unregisterCommandHandler(CopyDataToClipboardCommand.class);
final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
// create the ColumnLabelAccumulator with IDataProvider to be able to
// tell the CSS engine about the added labels
accumulator.add(new ColumnLabelAccumulator(bodyDataProvider));
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
columnLabelAccumulator.registerColumnOverrides(5, CustomLineBorderDecorator.RIGHT_LINE_BORDER_LABEL);
accumulator.add(columnLabelAccumulator);
bodyDataLayer.setConfigLabelAccumulator(accumulator);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new FillHandleConfiguration(gridLayer.getBodyLayer().getSelectionLayer()));
gridLayer.addConfiguration(new DefaultEditConfiguration());
gridLayer.addConfiguration(new DefaultEditBindings());
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, "COLUMN_4");
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DataValidator() {
@Override
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
if (newValue instanceof Integer && ((Integer) newValue).intValue() > 100) {
return false;
}
return true;
}
}, DisplayMode.NORMAL, "COLUMN_4");
}
});
natTable.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "basic");
// application model menu configuration
menuService.registerContextMenu(natTable, "org.eclipse.nebula.widgets.nattable.examples.e4.popupmenu.0");
// get the menu registered by EMenuService
final Menu e4Menu = natTable.getMenu();
// remove the menu reference from NatTable instance
natTable.setMenu(null);
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
// add NatTable menu items
// and register the DisposeListener
new PopupMenuBuilder(natTable, e4Menu).withInspectLabelsMenuItem().build();
// register the UI binding
uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(e4Menu));
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// add a custom painter for key errortext
int[] yErrorOffsets = { 0, 1, 2, 1 };
CellPainterFactory.getInstance().registerContentPainter("errortext", (properties, underlying) -> {
return new TextPainter(true, true, false) {
@Override
protected void paintDecoration(IStyle cellStyle, GC gc, int x, int y, int length, int fontHeight) {
int underlineY = y + fontHeight - (gc.getFontMetrics().getDescent() / 2);
Color previousColor = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_RED);
int startX = x;
underlineY--;
int index = 0;
while (startX <= (x + length)) {
gc.drawPoint(startX, underlineY + yErrorOffsets[(index % 4)]);
index++;
startX++;
}
gc.setForeground(previousColor);
}
};
});
showSourceLinks(parent, getClass().getName());
}
Aggregations