Search in sources :

Example 96 with NatTable

use of org.eclipse.nebula.widgets.nattable.NatTable in project nebula.widgets.nattable by eclipse.

the class ZoomedViewportSelectionDataLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    ZoomLayer zoomLayer = new ZoomLayer(new DummyGridLayerStack());
    zoomLayer.setZoomFactor(3.0f);
    return new NatTable(parent, zoomLayer);
}
Also used : DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ZoomLayer(org.eclipse.nebula.widgets.nattable.layer.ZoomLayer)

Example 97 with NatTable

use of org.eclipse.nebula.widgets.nattable.NatTable in project nebula.widgets.nattable by eclipse.

the class Derived_or_computed_column_data method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    List<Person> myList = new ArrayList<>();
    myList.add(new Person("Homer", "Simpson", "Sargeant", 1234567890L));
    myList.add(new Person("Waylon", "Smithers", "Admiral", 6666666666L));
    myList.add(new Person("Bart", "Smithers", "General", 9125798342L));
    myList.add(new Person("Nelson", "Muntz", "Private", 0000000001L));
    myList.add(new Person("John", "Frink", "Lieutenant", 3141592654L));
    String[] propertyNames = { "firstName", "lastName", "rank", "serialNumber" };
    final IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    // Add derived 'fullName' column
    final IColumnPropertyAccessor<Person> derivedColumnPropertyAccessor = new IColumnPropertyAccessor<Person>() {

        @Override
        public Object getDataValue(Person rowObject, int columnIndex) {
            if (columnIndex < columnPropertyAccessor.getColumnCount()) {
                return columnPropertyAccessor.getDataValue(rowObject, columnIndex);
            } else if (columnIndex == columnPropertyAccessor.getColumnCount()) {
                return columnPropertyAccessor.getDataValue(rowObject, 0) + " " + columnPropertyAccessor.getDataValue(rowObject, 1);
            } else {
                return null;
            }
        }

        @Override
        public void setDataValue(Person rowObject, int columnIndex, Object newValue) {
            columnPropertyAccessor.setDataValue(rowObject, columnIndex, newValue);
        }

        @Override
        public int getColumnCount() {
            return columnPropertyAccessor.getColumnCount() + 1;
        }

        @Override
        public String getColumnProperty(int columnIndex) {
            if (columnIndex < columnPropertyAccessor.getColumnCount()) {
                return columnPropertyAccessor.getColumnProperty(columnIndex);
            } else if (columnIndex == columnPropertyAccessor.getColumnCount()) {
                return "fullName";
            } else {
                return null;
            }
        }

        @Override
        public int getColumnIndex(String propertyName) {
            if ("fullName".equals(propertyName)) {
                return columnPropertyAccessor.getColumnCount() + 1;
            } else {
                return columnPropertyAccessor.getColumnIndex(propertyName);
            }
        }
    };
    final IDataProvider listDataProvider = new ListDataProvider<>(myList, derivedColumnPropertyAccessor);
    // Column header data provider includes derived properties
    IDataProvider columnHeaderDataProvider = new IDataProvider() {

        @Override
        public Object getDataValue(int columnIndex, int rowIndex) {
            return derivedColumnPropertyAccessor.getColumnProperty(columnIndex);
        }

        @Override
        public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
        // noop
        }

        @Override
        public int getColumnCount() {
            return derivedColumnPropertyAccessor.getColumnCount();
        }

        @Override
        public int getRowCount() {
            return 1;
        }
    };
    ILayer layer = new DefaultGridLayer(listDataProvider, columnHeaderDataProvider);
    return new NatTable(parent, layer);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ArrayList(java.util.ArrayList) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) IColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 98 with NatTable

use of org.eclipse.nebula.widgets.nattable.NatTable in project nebula.widgets.nattable by eclipse.

the class AutomaticRowHeightExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    GridData layoutData = GridDataFactory.fillDefaults().grab(true, true).create();
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    panel.setLayout(layout);
    panel.setLayoutData(layoutData);
    loadMessages();
    ListDataProvider<LogRecord> dataProvider = new ListDataProvider<>(this.logMessages, // $NON-NLS-1$
    new ReflectiveColumnPropertyAccessor<LogRecord>(new String[] { "message" }));
    DataLayer dataLayer = new DataLayer(dataProvider);
    dataLayer.setColumnPercentageSizing(true);
    dataLayer.setColumnWidthPercentageByPosition(0, 100);
    dataLayer.setConfigLabelAccumulator(new ValidatorMessageLabelAccumulator());
    ViewportLayer layer = new ViewportLayer(dataLayer);
    layer.setRegionName(GridRegion.BODY);
    NatTable natTable = new NatTable(panel, NatTable.DEFAULT_STYLE_OPTIONS | SWT.BORDER, layer, false);
    natTable.addConfiguration(new ValidationMessageTableStyleConfiguration());
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    return panel;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) Composite(org.eclipse.swt.widgets.Composite) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) LogRecord(java.util.logging.LogRecord) GridData(org.eclipse.swt.layout.GridData) NatTable(org.eclipse.nebula.widgets.nattable.NatTable)

Example 99 with NatTable

use of org.eclipse.nebula.widgets.nattable.NatTable in project nebula.widgets.nattable by eclipse.

the class _001_Vertical_layer_composition method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    ViewportLayer layer = new ViewportLayer(new SelectionLayer(new DataLayer(new DummyBodyDataProvider(1000000, 1000000))));
    layer.setRegionName(GridRegion.BODY);
    return new NatTable(parent, layer);
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)

Example 100 with NatTable

use of org.eclipse.nebula.widgets.nattable.NatTable in project nebula.widgets.nattable by eclipse.

the class ColumnHeaderViewportSelectionDataLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    DummyBodyDataProvider bodyDataProvider = new DummyBodyDataProvider(500, 1000000);
    SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider));
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
    return new NatTable(parent, compositeLayer);
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider)

Aggregations

NatTable (org.eclipse.nebula.widgets.nattable.NatTable)221 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)150 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)113 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)100 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)90 HashMap (java.util.HashMap)88 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)88 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)79 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)75 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)74 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)73 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)73 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)72 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)72 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)72 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)71 SelectionEvent (org.eclipse.swt.events.SelectionEvent)67 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)66 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)66 GridLayout (org.eclipse.swt.layout.GridLayout)64