Grid Eclipse Nebula Widget

The Eclipse Nebula sub-project present the Grid widget, an alpha version which works great, i use it in my application to administrate reservation of swimming course. The JFace layer is not implemented yet but it’s on rails. But I don’t know if a GridViewer will be very useful because the needs of a spreadsheet are very large.

This is an example of Grid with header of columns and rows, column grouping, expand/collapse event of group column. The objective is to show the schedules in columns and the week days in rows, each column is composed of 3 sub-columns showing the total capacity, the availability and the sold place. The total capacity column can be desactivated :

public Grid createGrid(List in_schedules, Composite in_composite) {
        // Grid creation
        Grid l_grid = new Grid(in_composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
        // show column header
        l_grid.setHeaderVisible(true);
        // show row header
        l_grid.setRowHeaderVisible(true);
        // enable cell selection
        l_grid.setCellSelectionEnabled(true);
        GC l_gc = new GC(l_grid);
        // list of swimming course schedules
        for (ScheduleType l_scheduleType : in_schedules) {
            // create column group with dynamic column (TOGGLE)
            GridColumnGroup l_scheduleColumn = new GridColumnGroup(l_grid, SWT.TOGGLE);
            // column group header name
            l_scheduleColumn.setText(l_scheduleType.getLabel());
            final int l_colWidth = l_gc.stringExtent(l_scheduleType.getLabel() + " <<").x + 6;
            // initialize state (collapse)
            l_scheduleColumn.setExpanded(false);
            // listen expand event
            l_scheduleColumn.addListener(SWT.Expand, new Listener() {
                public void handleEvent(Event event) {
                    int l_width = l_colWidth / 3;
                    if (l_width < 20) {
                        l_width = 20;
                    }
                    for (GridColumn l_column : ((GridColumnGroup) event.widget).getColumns()) {
                        l_column.setWidth(l_width);
                    }
                }
            });
            // listen collapse event
            l_scheduleColumn.addListener(SWT.Collapse, new Listener() {
                public void handleEvent(Event event) {
                    int l_width = l_colWidth / 2;
                    if (l_width < 20) {
                        l_width = 20;
                    }
                    for (GridColumn l_column : ((GridColumnGroup) event.widget).getColumns()) {
                        if (l_column.isSummary()) {
                            l_column.setWidth(l_width);
                        }
                    }
                }
            });
            int l_width = l_colWidth / 2;
            if (l_width < 20) {
                l_width = 20;
            }
            // create columns group
            GridColumn l_capacity = new GridColumn(l_scheduleColumn, SWT.CENTER);
            l_capacity.setText("C");
            l_capacity.setWidth(20);
            l_capacity.setCellSelectionEnabled(false);
            // collapsed ? no
            l_capacity.setSummary(false);
            l_capacity = new GridColumn(l_scheduleColumn, SWT.CENTER);
            l_capacity.setText("V");
            l_capacity.setWidth(l_width);
            l_capacity.setCellSelectionEnabled(false);
            // collapsed ? yes
            l_capacity.setSummary(true);
            l_capacity = new GridColumn(l_scheduleColumn, SWT.CENTER);
            l_capacity.setText("L");
            l_capacity.setWidth(l_width);
            l_capacity.setSummary(true);
            l_capacity.setData(l_scheduleType);
        }
        l_gc.dispose();
        //l_grid.pack(true);
        return l_grid;
    }

The Grid binding is realise via the GridItem object

// GridItem creation
l_gridItem = new GridItem(l_grid, SWT.CENTER);
// row header name
l_gridItem.setHeaderText(l_headerText);
// set value by index column
l_gridItem.setText(, );

It possible to merge cell of a same line e.g.:
e.g.:

l_gridItem.setColumnSpan(0, in_grid.getColumnCount());

And to get the selection :

Point[] l_selections = l_grid.getCellSelection();
for (Point l_selection : l_selections) {
	// get GridItem
	l_grid.getItem(l_selection.y);
	// get GridColumn
	l_grid.getColumn(l_selection.x)
}

2 réflexions sur « Grid Eclipse Nebula Widget »

  1. Hi.

    I’m desperately looking for an example project of how to use the Nebula Grid. I tried to get it work, but i failed. I think I have to several project setups and plug-in imports or sth like that. It would be great if you could send me a project, may one of you existing ones. Or just a small one where I can run the basics. I think i can figure out the rest by myself then, its just the basic setup where I have big trouble.

    Thanks alot and regards,

    Hannes

  2. My project is too big and not open source, the principal elements of codes to use the grid is in this example. Ask me the problems you have via this comment feed and i try to help you if i can.

Les commentaires sont fermés.