eclipse / nebula

Nebula Project
https://eclipse.org/nebula
Eclipse Public License 2.0
84 stars 98 forks source link

Grid: Align GridItem text and images. Border column separator is not visible #547

Closed IvanGarSer closed 7 months ago

IvanGarSer commented 7 months ago

Hello everyone!

We are using nebula v3.0.0 for building a table based on a Grid. Checking this snippet code we create an example where we experienced some strange behaviours (https://github.com/eclipse/nebula/blob/master/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/GridSnippet9.java):

We customized it a bit for having more columns and introduce some images beside the text. This is our code: //CODE SNIPPET EXAMPLE final Grid grid = new Grid(composite, SWT.BORDER); grid.setLinesVisible(true); for (int i = 0; i < 5; i++) { GridColumn column = new GridColumn(grid, SWT.NONE); column.setText("COLUMN" + i); column.setWidth(150); grid.setHeaderVisible(true); }

    for (int i = 1; i < 4; i++) {
        GridItem item0 = new GridItem(grid, SWT.NONE|SWT.BORDER);
        item0.setText("Item " + i);
        GridItem item1= new GridItem(grid, SWT.NONE|SWT.BORDER);
        item1.setHeight(48);
        item1.setText(0, "Some text...");
        item1.setImage(0, ImageHelper.INSTANCE.getImage(this.getClass(), Icons.PARAM_MAN));
    }
    GridItem[] items = grid.getItems();

    for (int j = 0; j < items.length; j++) {

        GridEditor editor = new GridEditor(grid);
        CCombo combo = new CCombo(grid, SWT.NONE);
        combo.setText("CCombo Widget " + j);
        combo.add("item 1");
        combo.add("item 2");
        combo.add("item 3");
        editor.minimumWidth = 150;
        editor.setEditor(combo, items[j], 1);

        editor = new GridEditor(grid);
        Button button = new Button(grid, SWT.CHECK);
        button.setText("Check me");
        button.pack();
        editor.grabHorizontal = true;
        editor.setEditor(button, items[j], 2);

        editor = new GridEditor(grid);
        Text text = new Text(grid, SWT.NONE);
        text.setText("Text " + j);
        editor.grabHorizontal = true;
        editor.setEditor(text, items[j], 3);

        GridEditor commentGridEditable = new GridEditor(grid);
        Text commentControl = new Text(grid, SWT.NONE);
        commentControl.setText("Comment text" + j);
        commentControl.pack();
        commentGridEditable.grabHorizontal = true;
                    commentGridEditable.setEditor(commentControl, items[j], 4);

    }

This is the look of our table: image

Two questions are raised from here:

  1. How to align the text and image into the first column?
  2. The border separator between column3 and column 4 is hidden or gone (they both are editable cells). How can we paint it again?

It should be very appreaciated your answers Thanks in advanced and Best regards!!

lcaron commented 7 months ago

Hi

Thank you for using Nebula :)

For your first question : you can align the text by calling the method setAligment() on a column object, for example

column.setAlignment(SWT.RIGHT);

Unfortunately, an image is always aligned on the left. You can create a custom GridCellRenderer or create an issue to add a new feature.

For the border separator, this is a bug. I'm working on it. Good news : a new release of Nebula is planned for the end of this month.

IvanGarSer commented 7 months ago

Hi!

Thank you very much for your answer! We'll wait for the new nebula's version and try to align the image as you adviced us, since we need it align to the left.

Thanks again and have a great day! :)

lcaron commented 7 months ago

@IvanGarSer I've fixed the bug for the border separator (cf. https://github.com/eclipse/nebula/issues/551)