Search in sources :

Example 1 with EventData

use of org.eclipse.nebula.widgets.nattable.dataset.EventData in project nebula.widgets.nattable by eclipse.

the class CrossValidationDialogErrorHandling method createEventData.

private List<EventData> createEventData() {
    List<EventData> result = new ArrayList<>();
    EventData ed = new EventData();
    ed.setTitle("My correct event");
    ed.setDescription("My event that validates correctly");
    ed.setWhere("Somewhere");
    ed.setFromDate(new GregorianCalendar(2013, 2, 1).getTime());
    ed.setToDate(new GregorianCalendar(2013, 2, 3).getTime());
    result.add(ed);
    ed = new EventData();
    ed.setTitle("My wrong event");
    ed.setDescription("My event where validation fails");
    ed.setWhere("Somewhere else");
    ed.setFromDate(new GregorianCalendar(2013, 2, 3).getTime());
    ed.setToDate(new GregorianCalendar(2013, 2, 1).getTime());
    result.add(ed);
    return result;
}
Also used : ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) EventData(org.eclipse.nebula.widgets.nattable.dataset.EventData)

Example 2 with EventData

use of org.eclipse.nebula.widgets.nattable.dataset.EventData in project nebula.widgets.nattable by eclipse.

the class CrossValidationDialogErrorHandling method createExampleControl.

@Override
@SuppressWarnings("unchecked")
public Control createExampleControl(Composite parent) {
    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);
    // property names of the EventData class
    String[] propertyNames = { "title", "description", "where", "fromDate", "toDate" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("title", "Title");
    propertyToLabelMap.put("description", "Description");
    propertyToLabelMap.put("where", "Where");
    propertyToLabelMap.put("fromDate", "From");
    propertyToLabelMap.put("toDate", "To");
    this.valuesToShow.addAll(createEventData());
    ConfigRegistry configRegistry = new ConfigRegistry();
    DefaultGridLayer gridLayer = new DefaultGridLayer(this.valuesToShow, propertyNames, propertyToLabelMap);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    IRowDataProvider<EventData> bodyDataProvider = (IRowDataProvider<EventData>) bodyDataLayer.getDataProvider();
    bodyDataLayer.setConfigLabelAccumulator(new CrossValidationLabelAccumulator(bodyDataProvider));
    final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new CrossValidationEditConfiguration(bodyDataProvider));
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    return panel;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) EventData(org.eclipse.nebula.widgets.nattable.dataset.EventData) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) IRowDataProvider(org.eclipse.nebula.widgets.nattable.data.IRowDataProvider) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 3 with EventData

use of org.eclipse.nebula.widgets.nattable.dataset.EventData in project nebula.widgets.nattable by eclipse.

the class CrossValidationDialogErrorHandling method validate.

@Override
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
    // get the row object out of the dataprovider
    EventData rowObject = this.bodyDataProvider.getRowObject(rowIndex);
    // as the object itself is not yet updated, we need to validate against
    // the given new value
    Date fromDate = rowObject.getFromDate();
    Date toDate = rowObject.getToDate();
    if (columnIndex == 3) {
        fromDate = (Date) newValue;
    } else if (columnIndex == 4) {
        toDate = (Date) newValue;
    }
    if (!CrossValidationGridExample.isEventDataValid(fromDate, toDate)) {
        throw new ValidationFailedException("fromDate is not before toDate");
    }
    return true;
}
Also used : ValidationFailedException(org.eclipse.nebula.widgets.nattable.data.validate.ValidationFailedException) EventData(org.eclipse.nebula.widgets.nattable.dataset.EventData) Date(java.util.Date)

Example 4 with EventData

use of org.eclipse.nebula.widgets.nattable.dataset.EventData in project nebula.widgets.nattable by eclipse.

the class CrossValidationDialogErrorHandling method createExampleControl.

@Override
@SuppressWarnings("unchecked")
public Control createExampleControl(Composite parent) {
    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);
    // property names of the EventData class
    String[] propertyNames = { "title", "description", "where", "fromDate", "toDate" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("title", "Title");
    propertyToLabelMap.put("description", "Description");
    propertyToLabelMap.put("where", "Where");
    propertyToLabelMap.put("fromDate", "From");
    propertyToLabelMap.put("toDate", "To");
    this.valuesToShow.addAll(createEventData());
    ConfigRegistry configRegistry = new ConfigRegistry();
    DefaultGridLayer gridLayer = new DefaultGridLayer(this.valuesToShow, propertyNames, propertyToLabelMap);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    IRowDataProvider<EventData> bodyDataProvider = (IRowDataProvider<EventData>) bodyDataLayer.getDataProvider();
    bodyDataLayer.setConfigLabelAccumulator(new CrossValidationLabelAccumulator(bodyDataProvider));
    final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new CrossValidationEditConfiguration(bodyDataProvider));
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    return panel;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) EventData(org.eclipse.nebula.widgets.nattable.dataset.EventData) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) IRowDataProvider(org.eclipse.nebula.widgets.nattable.data.IRowDataProvider) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 5 with EventData

use of org.eclipse.nebula.widgets.nattable.dataset.EventData in project nebula.widgets.nattable by eclipse.

the class CrossValidationDialogErrorHandling method validate.

@Override
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
    // get the row object out of the dataprovider
    EventData rowObject = this.bodyDataProvider.getRowObject(rowIndex);
    // as the object itself is not yet updated, we need to validate against
    // the given new value
    Date fromDate = rowObject.getFromDate();
    Date toDate = rowObject.getToDate();
    if (columnIndex == 3) {
        fromDate = (Date) newValue;
    } else if (columnIndex == 4) {
        toDate = (Date) newValue;
    }
    if (!_4451_CrossValidationGridExample.isEventDataValid(fromDate, toDate)) {
        throw new ValidationFailedException("fromDate is not before toDate");
    }
    return true;
}
Also used : ValidationFailedException(org.eclipse.nebula.widgets.nattable.data.validate.ValidationFailedException) EventData(org.eclipse.nebula.widgets.nattable.dataset.EventData) Date(java.util.Date)

Aggregations

EventData (org.eclipse.nebula.widgets.nattable.dataset.EventData)6 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 HashMap (java.util.HashMap)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 IRowDataProvider (org.eclipse.nebula.widgets.nattable.data.IRowDataProvider)2 ValidationFailedException (org.eclipse.nebula.widgets.nattable.data.validate.ValidationFailedException)2 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2