Layout which ignores controls wishing to grow?

I am creating wizard in Eclipse plugin. And one of wizard pages containing a TableView, which is very tall. This makes entire wizard window being also tall, according to the size of TableView.

Currently I am using FillLayout, like this

    @Override
    public void createControl(Composite superParent) {

        //superParent.setLayout(new FillLayout());


        // creating "main" control
        Composite control = new Composite(superParent, SWT.NONE) {
            @Override
            public String toString() {
                return super.toString() + ": control of CoreSettingsPage";
            }
        };
        control.setLayout(new FillLayout());
        //control.setLayoutData(null);


        // creating viewer
        viewer = new TreeViewer(control, SWT.BORDER);
        viewer.setContentProvider(new TreeNodeContentProvider());

So, how to make that wizard window ignore the size of TreeView, making scrollbars appear? Or may be there is some Layout in SWT, which ignores the size of containing control? Like JScrollPane in Swing?

UPDATE 1

Below is entire wizard code with some tried options

package try_eclipsewizardlayout_01;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;

public class TryWizard extends Wizard {

    abstract class TableLabelProvider extends LabelProvider implements ITableLabelProvider {
    }

    public class Page1 extends WizardPage {

        protected Page1() {
            super("Page 1");
        }

        @Override
        public void createControl(Composite parent) {

            Composite control = new Composite(parent, SWT.NONE) {
                @Override
                public String toString() {
                    return super.toString() + ": control of Page1";
                }
            };
            control.setLayout(new RowLayout(SWT.VERTICAL));

            Group group = new Group(control, SWT.NONE);
            group.setLayout(new GridLayout(1, false));
            group.setText("Options");

            Button option1 = new Button(group, SWT.RADIO);
            option1.setText("Option 1");

            Button option2 = new Button(group, SWT.RADIO);
            option2.setText("Option 2");

            Button option3 = new Button(group, SWT.RADIO);
            option3.setText("Option 3");

            setControl(control);


        }

    }

    public class Page2 extends WizardPage {

        TableViewer viewer;

        private void createViewer(Composite child) {

            viewer = new TableViewer(child, SWT.BORDER);

            viewer.setContentProvider(new IStructuredContentProvider() {

                @Override
                public void dispose() {
                }

                @Override
                public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
                }

                @Override
                public Object[] getElements(Object inputElement) {
                    Object[] ans = new Object[100];
                    for(int i=0; i<ans.length; ++i) {
                        ans[i] = new String[] {"name " + i, "value " + i};
                    }
                    return ans;
                }

            });

            viewer.setLabelProvider(
                    new TableLabelProvider() {

                        @Override
                        public String getColumnText(Object element, int columnIndex) {
                            return ((String[])element)[columnIndex];
                        }

                        @Override
                        public Image getColumnImage(Object element, int columnIndex) {
                            return null;
                        }
                    }
            );

            // dummy data which is ignored
            viewer.setInput(new Object());
        }

        protected Page2() {
            super("Page 2");
        }

        /* 
         * this version shows normal sized wizrd (not tall)
         * but no table on Page 2
         */
        @Override
        public void createControl(Composite parent) {

            ScrolledComposite control = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL) {
                @Override
                public String toString() {
                    return super.toString() + ": control of Page2";
                }
            };

            // Create a child composite to hold the controls
            Composite child = new Composite(control, SWT.NONE);
            child.setLayout(new FillLayout());

            createViewer(child);

            control.setContent(child);
            control.setMinSize(100, 100);

            setControl(control);
        }

        /*
        @Override
        public void createControl(Composite parent) {

            Composite control = new Composite(parent, SWT.BORDER) {
                @Override
                public String toString() {
                    return super.toString() + ": control of Page2";
                }
            };


            createViewer(control);


            // control.setLayout(new FillLayout()); // tall wizard, table fills it, vertical scroll present

            control.setLayout(new GridLayout(1, false));
            viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // tall wizard, table fills it, vertical scroll present
            //viewer.getTable().setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true)); // tall wizard, thin table, vertical scroll present
            //viewer.getTable().setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); // tall wizard,  thin table, no vertical scroll
            //viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); // tall wizard,  thin table, no vertical scroll          


            setControl(control);

        }
        */

    }

    Page1 page1 = new Page1();
    Page2 page2 = new Page2();

    @Override
    public void addPages() {
        addPage(page1);
        addPage(page2);
    }

    @Override
    public boolean performFinish() {
        return false;
    }

}

Entire simple eclipse project SSCCE is here: https://drive.google.com/file/d/0By8pZ9a2478Yb2l4TUp6WTh1UGs/edit?usp=sharing

Answers


You can use org.eclipse.swt.layout.GridLayout(1, false) as a layout for your tree:

GridData gd= new GridData(GridData.FILL, GridData.BEGINNING, true, true);
gd.heightHint= 200;
viewer.getTree().setLayout(new GridLayout());
viewer.getTree().setLayoutData(gd);

If you are not sure what layout has your superParent, then to be on a safe side create composite for your viewer like this:

Composite c = new Composite(shell, SWT.NONE);
c.setLayout(new GridLayout());
c.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
viewer = new TreeViewer(c, SWT.BORDER);

There are two things you can do:

  1. Wrap the TableViewer in a ScrolledComposite (here is an example).
  2. Use GridLayout and GridData and set the vertical/horizontal alignment to something else than SWT.FILL, i.e., SWT.BEGINNING or SWT.TOP in order to not make it use excessive space and then restrict the size of the parent.

Need Your Help

How to add a footer to a FlowDocument in WPF?

c# wpf flowdocument

I have a FlowDocument in my application which looks like as follows: