Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Confused about layer configuration
Confused about layer configuration [message #1689155] Sun, 22 March 2015 22:10 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 225
Registered: July 2009
Senior Member
Hi all,
I'm a little confused about the layer configuration with GlazedLists & Co.

Here's my current stack:
// Column header data provider includes derived properties
String[] propertyNames = ...
final IColumnPropertyAccessor<Item> derivedColumnPropertyAccessor = ...
EventList<Item> itemsListData = ...

IDataProvider columnHeaderDataProvider = new
ListViewHeaderDataProvider<Item>(propertyNames,
derivedColumnPropertyAccessor);

//create the body layer stack
final IRowDataProvider<Item> bodyDataProvider =
  new GlazedListsDataProvider<Item>(itemsListData,
derivedColumnPropertyAccessor);

//build the grid layer
gridLayer = new ListViewGridLayer<Item>(itemsListData,
derivedColumnPropertyAccessor, columnHeaderDataProvider, configRegistry,
true);
DataLayer tableDataLayer = gridLayer.getBodyDataLayer();
GlazedListsEventLayer<Item> listEventLayer = new
GlazedListsEventLayer<Item>(tableDataLayer, itemsListData);

final RowReorderLayer rowReorderLayer = new RowReorderLayer(tableDataLayer);
selectionLayer = new SelectionLayer(rowReorderLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
//build the row header layer
IDataProvider rowHeaderDataProvider = new
DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new
DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
viewportLayer, selectionLayer);
gridLayer.setRowHeaderLayer(rowHeaderLayer);

IRowIdAccessor<DocumentItem> rowIdAccessor = ...
RowSelectionModel<Item> selectionModel = new
RowSelectionModel<Item>(selectionLayer, bodyDataProvider, rowIdAccessor,
false);
selectionLayer.setSelectionModel(selectionModel);

final NatTable natTable = new NatTable(tableComposite, gridLayer, false);



The result of this configuration is an empty table (with correct column
headers). But there are no row headers (and therefore no possibility to
move the rows) and no data. I assume that I misconfigured something... I
broke my mind but I couldn't get a solution... Any help would be
appreciated...

Regards,
Ralf.

[Updated on: Mon, 23 March 2015 12:37]

Report message to a moderator

Re: Confused about layer configuration [message #1689159 is a reply to message #1689155] Sun, 22 March 2015 22:27 Go to previous messageGo to next message
Arye Shemesh is currently offline Arye ShemeshFriend
Messages: 37
Registered: November 2012
Member
Hi Ralf,

Below is a simple example (taken from NatTabe example "Getting Started"), use it as a guide to ,well, get started (especially how to configure the layers):



/*******************************************************************************
 * Copyright (c) 2012 Original authors and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Original authors and others - initial API and implementation
 ******************************************************************************/
package org.eclipse.nebula.widgets.nattable.examples.examples;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
import org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor;
import org.eclipse.nebula.widgets.nattable.examples.AbstractNatExample;
import org.eclipse.nebula.widgets.nattable.examples.fixtures.Person;
import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleRunner;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class _001_Getting_Started extends AbstractNatExample {

    private IDataProvider bodyDataProvider;
    private String[] propertyNames;
    private BodyLayerStack bodyLayer;
    private Map propertyToLabels;

    public static void main(String[] args) {
        StandaloneNatExampleRunner.run(600, 400, new _001_Getting_Started());
    }

    @Override
    public Control createExampleControl(Composite parent) {
        this.bodyDataProvider = setupBodyDataProvider();
        DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(
                this.propertyNames, this.propertyToLabels);
        DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
                this.bodyDataProvider);

        this.bodyLayer = new BodyLayerStack(this.bodyDataProvider);
        ColumnHeaderLayerStack columnHeaderLayer = new ColumnHeaderLayerStack(
                colHeaderDataProvider);
        RowHeaderLayerStack rowHeaderLayer = new RowHeaderLayerStack(
                rowHeaderDataProvider);
        DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(
                colHeaderDataProvider, rowHeaderDataProvider);
        CornerLayer cornerLayer = new CornerLayer(new DataLayer(
                cornerDataProvider), rowHeaderLayer, columnHeaderLayer);

        GridLayer gridLayer = new GridLayer(this.bodyLayer, columnHeaderLayer,
                rowHeaderLayer, cornerLayer);
        NatTable natTable = new NatTable(parent, gridLayer);

        return natTable;
    }

    private IDataProvider setupBodyDataProvider() {
        final List people = Arrays.asList(new Person(100,
                "Mickey Mouse", new Date(1000000)), new Person(110, "Batman",
                new Date(2000000)),
                new Person(120, "Bender", new Date(3000000)), new Person(130,
                        "Cartman", new Date(4000000)), new Person(140,
                        "Dogbert", new Date(5000000)));

        this.propertyToLabels = new HashMap();
        this.propertyToLabels.put("id", "ID");
        this.propertyToLabels.put("name", "First Name");
        this.propertyToLabels.put("birthDate", "DOB");

        this.propertyNames = new String[] { "id", "name", "birthDate" };
        return new ListDataProvider(people,
                new ReflectiveColumnPropertyAccessor(this.propertyNames));

    }

    public class BodyLayerStack extends AbstractLayerTransform {

        private SelectionLayer selectionLayer;

        public BodyLayerStack(IDataProvider dataProvider) {
            DataLayer bodyDataLayer = new DataLayer(dataProvider);
            ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(
                    bodyDataLayer);
            ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(
                    columnReorderLayer);
            this.selectionLayer = new SelectionLayer(columnHideShowLayer);
            ViewportLayer viewportLayer = new ViewportLayer(this.selectionLayer);
            setUnderlyingLayer(viewportLayer);
        }

        public SelectionLayer getSelectionLayer() {
            return this.selectionLayer;
        }
    }

    public class ColumnHeaderLayerStack extends AbstractLayerTransform {

        public ColumnHeaderLayerStack(IDataProvider dataProvider) {
            DataLayer dataLayer = new DataLayer(dataProvider);
            ColumnHeaderLayer colHeaderLayer = new ColumnHeaderLayer(dataLayer,
                    _001_Getting_Started.this.bodyLayer, _001_Getting_Started.this.bodyLayer.getSelectionLayer());
            setUnderlyingLayer(colHeaderLayer);
        }
    }

    public class RowHeaderLayerStack extends AbstractLayerTransform {

        public RowHeaderLayerStack(IDataProvider dataProvider) {
            DataLayer dataLayer = new DataLayer(dataProvider, 50, 20);
            RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(dataLayer,
                    _001_Getting_Started.this.bodyLayer, _001_Getting_Started.this.bodyLayer.getSelectionLayer());
            setUnderlyingLayer(rowHeaderLayer);
        }
    }
}



Re: Confused about layer configuration [message #1689279 is a reply to message #1689159] Mon, 23 March 2015 07:39 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2803
Registered: July 2012
Senior Member
Does your itemList contain elements at startup or do you add elements afterwards.

The issue with your composition is that you are trying to add the GlazedListsEventLayer to an existing layer stack. And you are trying to do this in between. That doesn't work, because you are not including it into the existing body layer stack, you are creating a new "branch". In short, your GlazedListsEventLayer as no connection to the layers that should be on top.

I don't remember a ListViewGridLayer, so I assume this is your custom layer. If that is the case, change the way you create the body layer stack to include the GlazedListsEventLayer at creation time, so the stack is build up correctly.
Previous Topic:Re-ordering of rows doesn't update row header position
Next Topic:Nattable Combobox Memory leak
Goto Forum:
  


Current Time: Mon Mar 08 16:16:19 GMT 2021

Powered by FUDForum. Page generated in 0.02292 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top