Search in sources :

Example 1 with ColumnGroupModel

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel in project nebula.widgets.nattable by eclipse.

the class ColumnGroupExpandCollapseLayerTest method setup.

@Before
public void setup() {
    this.model = new ColumnGroupModel();
    // 10 Columns in total - column 10 hidden
    this.underlyingLayer = new ColumnHideShowLayerFixture(9);
    this.expandCollapseLayer = new ColumnGroupExpandCollapseLayer(this.underlyingLayer, this.model);
    this.model.addColumnsIndexesToGroup(TEST_GROUP_NAME, 2, 3, 4, 5);
}
Also used : ColumnHideShowLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.ColumnHideShowLayerFixture) ColumnGroupExpandCollapseLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupExpandCollapseLayer) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) Before(org.junit.Before)

Example 2 with ColumnGroupModel

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel in project nebula.widgets.nattable by eclipse.

the class _5112_TwoLevelColumnGroupingExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "address.street", "address.housenumber", "address.postalCode", "address.city", "age", "birthday", "money", "description", "favouriteFood", "favouriteDrinks" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("address.street", "Street");
    propertyToLabelMap.put("address.housenumber", "Housenumber");
    propertyToLabelMap.put("address.postalCode", "Postalcode");
    propertyToLabelMap.put("address.city", "City");
    propertyToLabelMap.put("age", "Age");
    propertyToLabelMap.put("birthday", "Birthday");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("description", "Description");
    propertyToLabelMap.put("favouriteFood", "Food");
    propertyToLabelMap.put("favouriteDrinks", "Drinks");
    IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    ColumnGroupModel columnGroupModel = new ColumnGroupModel();
    ColumnGroupModel sndColumnGroupModel = new ColumnGroupModel();
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer as
    // underlying layer. But in this case using the ViewportLayer directly
    // as body layer is also working.
    IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), columnPropertyAccessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
    ColumnGroupReorderLayer columnGroupReorderLayer = new ColumnGroupReorderLayer(columnReorderLayer, columnGroupModel);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnGroupReorderLayer);
    ColumnGroupExpandCollapseLayer columnGroupExpandCollapseLayer = new ColumnGroupExpandCollapseLayer(columnHideShowLayer, sndColumnGroupModel, columnGroupModel);
    SelectionLayer selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer, selectionLayer, columnGroupModel);
    // configure the column groups
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Person", 0, 1, 2, 3);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Address", 4, 5, 6, 7);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Facts", 8, 9, 10);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Personal", 11, 12, 13);
    columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Person", 0, 1);
    columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Address", 4, 5, 6);
    columnGroupHeaderLayer.setGroupUnbreakable(1);
    ColumnGroupGroupHeaderLayer sndGroup = new ColumnGroupGroupHeaderLayer(columnGroupHeaderLayer, selectionLayer, sndColumnGroupModel);
    sndGroup.addColumnsIndexesToGroup("PersonWithAddress", 0, 1, 2, 3, 4, 5, 6, 7);
    sndGroup.addColumnsIndexesToGroup("Additional Information", 8, 9, 10, 11, 12, 13);
    sndGroup.setStaticColumnIndexesByGroup("PersonWithAddress", 0, 1);
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, sndGroup);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, sndGroup, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    NatTable natTable = new NatTable(parent, gridLayer);
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnGroupGroupHeaderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupGroupHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ColumnGroupReorderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupReorderLayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) ColumnGroupHeaderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupHeaderLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnGroupExpandCollapseLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupExpandCollapseLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 3 with ColumnGroupModel

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel in project nebula.widgets.nattable by eclipse.

the class ColumnGroupModelAssembler method setupColumnGroups.

public static ColumnGroupModel setupColumnGroups(TableColumn[] columnProps) {
    ColumnGroupModel columnGroupModel;
    columnGroupModel = new ColumnGroupModel();
    Map<String, Set<Integer>> columnGroupToColumnIndexesMap = new HashMap<String, Set<Integer>>();
    for (int columnIndex = 0; columnIndex < columnProps.length; columnIndex++) {
        String columnGroupName = columnProps[columnIndex].groupName;
        // Column if part of a group
        if (columnGroupName != null) {
            Set<Integer> columnGroupIndexes = columnGroupToColumnIndexesMap.get(columnGroupName);
            // Create an entry in the map for the group
            if (columnGroupIndexes == null) {
                columnGroupIndexes = new HashSet<Integer>();
                columnGroupToColumnIndexesMap.put(columnGroupName, columnGroupIndexes);
            }
            // Add to map
            columnGroupIndexes.add(columnIndex);
        }
    }
    // Transfer the map created to the model
    for (String columnGroupName : columnGroupToColumnIndexesMap.keySet()) {
        Set<Integer> columnIndexes = columnGroupToColumnIndexesMap.get(columnGroupName);
        int[] intColumnIndexes = new int[columnIndexes.size()];
        int i = 0;
        for (Integer columnIndex : columnIndexes) {
            intColumnIndexes[i] = columnIndex;
            i++;
        }
        columnGroupModel.addColumnsIndexesToGroup(columnGroupName, intColumnIndexes);
    }
    return columnGroupModel;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)

Example 4 with ColumnGroupModel

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel in project nebula.widgets.nattable by eclipse.

the class ColumnChooserDialogTest method createColumnChooserDialogTestHelper.

/**
 * item string format: position:index{,position:index}* --> e.g. 0:0,1:1,2:2<br>
 * column group string format: (index{,index}*) --> e.g. (0,1)<br>
 *
 * @param availableItems
 *            the column entries in the list of available columns.
 * @param selectedItems
 *            the column entries in the list of selected columns.
 * @param columnGroups
 *            the column groups.
 * @return a helper class giving access to an instance of a
 *         {@link ColumnChooserDialog} parameterized as defined.
 */
private ColumnChooserDialogTestHelper createColumnChooserDialogTestHelper(String availableItems, String selectedItems, String... columnGroups) {
    Shell shell = new Shell();
    ColumnChooserDialog dialog = new ColumnChooserDialog(shell, "", "");
    dialog.createDialogArea(shell);
    List<ColumnEntry> availableEntries = parseEntryString(availableItems);
    List<ColumnEntry> visibleEntries = parseEntryString(selectedItems);
    ColumnGroupModel columnGroupModel = parseColumnGroups(columnGroups);
    dialog.populateAvailableTree(availableEntries, columnGroupModel);
    dialog.populateSelectedTree(visibleEntries, columnGroupModel);
    TestTreeListener listener = new TestTreeListener();
    dialog.addListener(listener);
    return new ColumnChooserDialogTestHelper(dialog, listener);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)

Example 5 with ColumnGroupModel

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel in project nebula.widgets.nattable by eclipse.

the class ColumnChooserDialogTest method parseColumnGroups.

private static ColumnGroupModel parseColumnGroups(String[] columnGroups) {
    ColumnGroupModel columnGroupModel = new ColumnGroupModel();
    if (columnGroups != null) {
        for (int i = 0; i < columnGroups.length; i++) {
            String columnGroup = columnGroups[i];
            String[] indexes = columnGroup.substring(1, columnGroup.length() - 1).split(",");
            int[] columnIndexes = new int[indexes.length];
            for (int j = 0; j < indexes.length; j++) {
                columnIndexes[j] = Integer.valueOf(indexes[j]);
            }
            columnGroupModel.addColumnsIndexesToGroup("Column Group " + i, columnIndexes);
        }
    }
    return columnGroupModel;
}
Also used : ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)

Aggregations

ColumnGroupModel (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)12 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)5 ColumnGroupHeaderLayer (org.eclipse.nebula.widgets.nattable.group.ColumnGroupHeaderLayer)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)5 HashMap (java.util.HashMap)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)4 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)4 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)4 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)4 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)4 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)4 ColumnGroupExpandCollapseLayer (org.eclipse.nebula.widgets.nattable.group.ColumnGroupExpandCollapseLayer)4 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)3 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)3 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)3 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)3