简体   繁体   中英

Dynamic content of IWizardPage not properly shown

I am working on an Eclipse product which will open a wizard which content depends on previous user selection. I created a few WizardPages which read global parameters and then show the appropriate content.

But I am struggling with the newest page which should show a table which contains an arbitrary number of columns with an arbitrary number of rows.

Because the content of the table depends on user inputs on previous pages the creation of the Page is not done in public void createControl(Composite parent) . In this function I create a global composite which will host the table which is created when the page gets visible because at that moment the needed information are available.

The number and titles of columns depend on user input just like the number of rows.

I added an example where the table should have 3 columns and ~15 rows. Every cell except the ones of the last column contain a checkbox. The cells of the last column contain text. But as you can see the most of the WizardPage is grey and on the bottom there is a small area where you can see the table. It is looking like there is some kind of overlay. Additionally the whole table looks like it is shifted to the left as u can only see two columns on the example picture.

在此处输入图片说明

If I add all the content in a ScrolledComposite not even the little area is visible. (Later I will change to ScrolledComposite because the table can get very big.) I debugged the project and I can see that the page is correctly build and the composite composite hosts only the table and no other elements. All column titles and number of rows created are correct but I am not able to display the table correctly.

I am thankful for every advice.

Code below:

public class selectionListPage extends CoevolutionDecisionPage implements SelectionListener {

    private ScrolledComposite scrolledComposite;
    private Composite composite;
    private Table table;

    private HashMap<String, String> parameters;

    public selectionListPage(String name, HashMap<String, String> parameters) {
        super(name);
        this.setTitle(name);
        this.parameters = parameters;
    }

    @Override
    public void createControl(Composite parent) {
        composite = new Composite(parent, SWT.NULL);
        composite.setLayout(new GridLayout());
        setControl(composite);
    }

    @Override
    public void setVisible(boolean visible) {
        super.setVisible(visible);
        if (visible) {
            onEnterPage();
        }
    }

    public void onEnterPage() {
        CoevolutionWizard wizard = (CoevolutionWizard)getWizard();
        // this list will contain all titles for all columns
        ArrayList<String> titles = new ArrayList<String> ();
        /* read titles from wizard */
        // create table for data
        table = new Table(composite, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
        table.setLinesVisible (true);
        table.setHeaderVisible (true);
        table.setVisible(true);
        // set layout data so that all cells are equal
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
        table.setLayoutData(data);
        for (int i = 0; i < titles.size(); i++) {
            TableColumn column = new TableColumn (table, SWT.NONE);
            column.setText (titles.get(i));
        }
        // add table column for attributes
        TableColumn column = new TableColumn (table, SWT.NONE);
        column.setText ("Attribute");
        // this list will contain all relevant elements for all inspected elements
        ArrayList<ArrayList<String>> allElements = new ArrayList<ArrayList<String>> ();
        /* read data from wizard */
        // this counter indicates which column is default value for items
        int elementCount = 0;
        // every element has an own element of nested elements
        for (ArrayList<String> list : allElements) {
            // iterate over all nested elements
            for (String element : list) {
                // each row has one tableItem which contains all cells and meta data about items
                TableItem item = new TableItem (table, SWT.NONE);
                // for every column a cell will be created
                for (int j = 0; j < titles.size()-1; j++) {
                    // create a checkbutton
                    Button checkButton = new Button(table, SWT.CHECK);
                    TableEditor editor = new TableEditor(table);
                    // pack button for correct display size and set listener
                    checkButton.pack();
                    checkButton.addSelectionListener(this);
                    // set size and alignment options for this cell
                    editor.minimumWidth = checkButton.getSize().x;
                    editor.horizontalAlignment = SWT.CENTER;
                    // add button to meta data of table item
                    item.setData("checkButton" + j, checkButton);
                    // add element to table
                    editor.setEditor(checkButton, item, j);
                }
                // add text
                item.setText (titles.size(), titles.get(titles.size()-1));
                // add additional meta data
                item.setData("name", titles.get(titles.size()-1));
                item.setData("default", titles.get(elementCount));
            }
            elementCount++;
        }
        for (int j = 0; j < titles.size(); j++) {
            table.getColumn(j).pack();
        }
        composite.pack();
        // proceeding from this page is possible at every moment
        this.setPageComplete(true);
    }

    @Override
    public void widgetSelected(SelectionEvent e) {
        System.out.println("click");
    }

Edit: Added code of CoevolutionDecisionPage

/**
 * Superclass for all decision pages of the refactoring wizard.
 */
public abstract class CoevolutionDecisionPage extends WizardPage {

    /**
     * Creates a decision page for the refactoring wizard.
     * 
     * @param refElem
     *            Refactoring element.
     * @param decision
     *            Decision to show
     */
    public CoevolutionDecisionPage(String name) {
        super(name);
        this.setPageComplete(false);
    }

    /**
     * Is called as soon as data to execute the query delivering elements to
     * decide is available. This is important because a decision can depend on
     * previous decisions.
     */
    abstract public void updateData();
}

Edit2: I did not solve the problem but I think I have some relevant information for the solution (at least I hope so).

At a moment of frustration I changed the Layout from the composite parent inside of createControl(Composite parent) to FillLayout and then the Wizard was divided into as many equal "columns" as I have WizardPages. Each column contains the correct WizardPage and displays it at the right time. So FillLayout behaves correct. But of course this is not a long term solution but allowed me to work on other tasks. And it allows me to verify the correct creation of the table.

So I added an other WizardPage after the page that is not working. This page only contains a number of labels (it is the last page and shows a summary). But this page shows the same strange behavior (if parent layout is not set to FillLayout) like my selectionListPage : It is "overlayed".

So I assume that the problem resides in one of the previous pages. In total I have four WizardPages:

  • Welcome page which shows some information (only text) which are read from "global" parameters.
  • A page where the user has to type names into an arbitrary number of textfields (which are created and deleted on the fly so that only one empty textfield is present every moment)
  • The described selectionListPage which contains a table.
  • The summary page.

The first to pages behave like expected but the other two are not displayed probably.

You need to update the composite layout, call

composite.layout(true, true);

just before the call to composite.pack() at the end of onEnterPage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM