Search in sources :

Example 1 with PricingDataBean

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

the class DataGeneratorTest method testGenerate.

@Test
public void testGenerate() {
    try {
        PricingDataBean pricingDataBean = new DataGenerator<PricingDataBean>().generate(PricingDataBean.class);
        Assert.assertNotNull(pricingDataBean);
        Assert.assertTrue(pricingDataBean.getBid() >= 0.0d);
        Assert.assertTrue(pricingDataBean.getBid() < 10000.0d);
        Assert.assertTrue(pricingDataBean.getAsk() >= 0.0d);
        Assert.assertTrue(pricingDataBean.getAsk() < 10000.0d);
        Assert.assertTrue(pricingDataBean.getClosingPrice() >= 0.0d);
        Assert.assertTrue(pricingDataBean.getClosingPrice() < 10000.0d);
        Assert.assertNotNull(pricingDataBean.getPricingSource());
    } catch (GeneratorException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage() + " : " + e.getCause().getMessage());
    }
}
Also used : GeneratorException(org.eclipse.nebula.widgets.nattable.dataset.generator.GeneratorException) PricingDataBean(org.eclipse.nebula.widgets.nattable.dataset.pricing.PricingDataBean) Test(org.junit.Test)

Example 2 with PricingDataBean

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

the class DataValueGeneratorTest method testClassAnnotationIsAccessible.

@Test
public void testClassAnnotationIsAccessible() {
    PricingDataBean bean = new PricingDataBean();
    boolean foundAnnotation = false;
    for (Field field : bean.getClass().getDeclaredFields()) {
        foundAnnotation |= field.isAnnotationPresent(DataValueGenerator.class);
    }
    assertTrue(foundAnnotation);
}
Also used : Field(java.lang.reflect.Field) DataValueGenerator(org.eclipse.nebula.widgets.nattable.dataset.generator.DataValueGenerator) PricingDataBean(org.eclipse.nebula.widgets.nattable.dataset.pricing.PricingDataBean) Test(org.junit.Test)

Example 3 with PricingDataBean

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

the class DataValueGeneratorTest method testClassAnnotationDataCanBeAccessed.

// TODO The following test probably has a race condition - test
// non-deterministic
@Test
public void testClassAnnotationDataCanBeAccessed() throws Exception {
    final Random random = new Random();
    final PricingDataBean bean = new PricingDataBean();
    for (Field field : bean.getClass().getDeclaredFields()) {
        if (field.isAnnotationPresent(DataValueGenerator.class)) {
            field.setAccessible(true);
            try {
                Class<? extends IValueGenerator> generatorClass = field.getAnnotation(DataValueGenerator.class).value();
                IValueGenerator generator = generatorClass.newInstance();
                Object newValue = generator.newValue(random);
                // System.out.println("newValue: "+newValue + "\t" +
                // generator.getClass().getName());
                assertNotNull(newValue);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) DataValueGenerator(org.eclipse.nebula.widgets.nattable.dataset.generator.DataValueGenerator) Random(java.util.Random) IValueGenerator(org.eclipse.nebula.widgets.nattable.dataset.generator.IValueGenerator) PricingDataBean(org.eclipse.nebula.widgets.nattable.dataset.pricing.PricingDataBean) Test(org.junit.Test)

Example 4 with PricingDataBean

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

the class ColumnStructureUpdatesGridExample method createExampleControl.

/**
 * NOTE - Glazed {@link EventList} class is thread ready but not thread
 * safe.
 */
@Override
public Control createExampleControl(Composite parent) {
    EventList<PricingDataBean> eventList = GlazedLists.eventList(PricingDataBeanGenerator.getData(10));
    this.rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
    Map<String, String> propertyToLabelMap = populateColHeaderPropertiesToLabelsMap();
    String[] propertyNames = propertyToLabelMap.keySet().toArray(ArrayUtil.STRING_TYPE_ARRAY);
    ConfigRegistry configRegistry = new ConfigRegistry();
    final ColumnStructureUpdatesExampleGridLayer<PricingDataBean> glazedListsGridLayer = new ColumnStructureUpdatesExampleGridLayer<>(this.rowObjectsGlazedList, propertyNames, propertyToLabelMap, configRegistry, true);
    final NatTable natTable = new NatTable(parent, glazedListsGridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.setConfigRegistry(configRegistry);
    natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, "ODD_BODY");
    natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, "EVEN_BODY");
    natTable.configure();
    glazedListsGridLayer.bodyDataProvider.setColumnCount(2);
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Clear list, add 6 items, Change column count");
    button.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.getReadWriteLock().writeLock().lock();
            try {
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.clear();
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                glazedListsGridLayer.bodyDataProvider.setColumnCount(8);
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
            } finally {
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.getReadWriteLock().writeLock().unlock();
            }
        }
    });
    return natTable;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) ColumnStructureUpdatesExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.ColumnStructureUpdatesExampleGridLayer) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PricingDataBean(org.eclipse.nebula.widgets.nattable.dataset.pricing.PricingDataBean) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

PricingDataBean (org.eclipse.nebula.widgets.nattable.dataset.pricing.PricingDataBean)4 Test (org.junit.Test)3 Field (java.lang.reflect.Field)2 DataValueGenerator (org.eclipse.nebula.widgets.nattable.dataset.generator.DataValueGenerator)2 Random (java.util.Random)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)1 GeneratorException (org.eclipse.nebula.widgets.nattable.dataset.generator.GeneratorException)1 IValueGenerator (org.eclipse.nebula.widgets.nattable.dataset.generator.IValueGenerator)1 ColumnStructureUpdatesExampleGridLayer (org.eclipse.nebula.widgets.nattable.examples.fixtures.ColumnStructureUpdatesExampleGridLayer)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1