Search in sources :

Example 1 with FillHandleConfiguration

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) EnableFormulaEvaluationCommand(org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand) DisableFormulaEvaluationCommand(org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillHandleConfiguration(org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FormulaTooltipErrorReporter(org.eclipse.nebula.widgets.nattable.formula.FormulaTooltipErrorReporter) GridLayout(org.eclipse.swt.layout.GridLayout) DefaultFormulaConfiguration(org.eclipse.nebula.widgets.nattable.formula.config.DefaultFormulaConfiguration) PoiExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.PoiExcelExporter) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) HSSFExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter)

Example 2 with FillHandleConfiguration

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();
}
Also used : AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FillHandleConfiguration(org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration) Before(org.junit.Before)

Example 3 with FillHandleConfiguration

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();
}
Also used : AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FillHandleConfiguration(org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration) Before(org.junit.Before)

Example 4 with FillHandleConfiguration

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());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) HashMap(java.util.HashMap) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) FillHandleConfiguration(org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) PopupMenuAction(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) GC(org.eclipse.swt.graphics.GC) UiBindingRegistry(org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry) MouseEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher) Color(org.eclipse.swt.graphics.Color) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) AbstractUiBindingConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) DataValidator(org.eclipse.nebula.widgets.nattable.data.validate.DataValidator) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) PostConstruct(javax.annotation.PostConstruct)

Aggregations

AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)4 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)4 FillHandleConfiguration (org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Before (org.junit.Before)2 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 AbstractUiBindingConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)1 DataValidator (org.eclipse.nebula.widgets.nattable.data.validate.DataValidator)1 ExtendedPersonWithAddress (org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress)1 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)1 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)1 HSSFExcelExporter (org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter)1 PoiExcelExporter (org.eclipse.nebula.widgets.nattable.extension.poi.PoiExcelExporter)1 FormulaTooltipErrorReporter (org.eclipse.nebula.widgets.nattable.formula.FormulaTooltipErrorReporter)1