Почему горизонтальная прокрутка средства просмотра таблиц исчезает, когда страница мастера возвращается к своему обычному размеру после расширения? - PullRequest
1 голос
/ 24 марта 2020

У меня есть средство просмотра таблиц, отображаемое на странице мастера. При первом отображении страницы, как видно, полосы прокрутки horizontal и vertical отображаются желтым цветом, как показано на изображении ниже -

enter image description here

Горизонтальная полоса прокрутки исчезает, когда страница мастера раскрывается в обоих направлениях, а затем возвращается к своему обычному размеру. Как видно ниже, есть только вертикальная полоса прокрутки, но горизонтальная полоса прокрутки потеряна.

enter image description here

Как вернуть горизонтальную полосу прокрутки?

Фрагмент кода, имитирующий приведенный выше пример, показан ниже-

package somepkg;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;


public class MakeNodesSuccessWizardPage extends WizardPage {

    private Composite top;
    private TableViewer viewer;
    private TableColumnLayout tableLayout;

    public MakeNodesSuccessWizardPage() {
        super("MyPage");
        setTitle("Some Title");
        setMessage("Some Message");
    }

    @Override
    public void createControl(Composite parent) {
        top = new Composite(parent, SWT.NONE);
        top.setLayout(new GridLayout());
        setControl(top);
        createViewer(top);
        createHelp();
        setPageComplete(false);
    }

    private void createHelp() {
        Composite wrapper = new Composite(top, SWT.NONE);
        wrapper.setLayout(new GridLayout(2, false));
        wrapper.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        createFirstRow(wrapper);
        createSecondRow(wrapper);
        createThirdRow(wrapper);

    }

    private void createFirstRow(Composite wrapper) {
        //column 1 
        Label greenMark = new Label(wrapper, SWT.NONE);
        greenMark.setText("Cheched ");

        //column 2 
        Label help = new Label(wrapper, SWT.NONE);
        help.setText("indicates that a node is newly created");
    }

    private void createSecondRow(Composite wrapper) {
        //column 1 
        Label crossMark = new Label(wrapper, SWT.NONE);
        crossMark.setText("Unchecked ");

        //column 2 
        Label help = new Label(wrapper, SWT.NONE);
        help.setText("indicates that a node is an existing one, and so left untouched");
    }

    private void createThirdRow(Composite wrapper) {
        //column 1 
        Label refresh = new Label(wrapper, SWT.NONE);
        refresh.setText("Refresh");

        Label help = new Label(wrapper, SWT.NONE);
        help.setText("The Selected Server Node in the Package Navigator will Auto Refresh if there is/are any node(s) created");
    }

    private void createViewer(Composite parent) {

        tableLayout = new TableColumnLayout();

        // A separate composite containing just the table viewer is required
        Composite tableComp = new Composite(parent, SWT.NONE);

        tableComp.setLayout(tableLayout);
        tableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        viewer = new TableViewer(tableComp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        createColumns(parent, viewer);
        final Table table = viewer.getTable();
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        viewer.setContentProvider(new ArrayContentProvider());

        // Layout the viewer
        GridData gridData = new GridData();
        gridData.verticalAlignment = GridData.FILL;
        gridData.horizontalSpan = 2;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalAlignment = GridData.FILL;
        viewer.getControl().setLayoutData(gridData);
    }

    public TableViewer getViewer() {
        return viewer;
    }

    // This will create the columns for the table
    private void createColumns(final Composite parent, final TableViewer viewer) {
        TableViewerColumn col = createTableViewerColumn("Name", 100, 0);
        col.setLabelProvider(new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
                return (String)element;
            }
        });
        tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(100));

    }

    private TableViewerColumn createTableViewerColumn(String title, int bound, final int colNumber) {
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.LEAD);
        final TableColumn column = viewerColumn.getColumn();
        column.setText(title);
        column.setWidth(bound);
        column.setResizable(true);
        column.setMoveable(true);
        column.setAlignment(SWT.CENTER);
        return viewerColumn;

    }

    @Override
    public void setVisible(boolean visible) {
        if (visible) {
            Set<String> components = new HashSet<>();
            components.add("In the midst of chaos, there is also opportunity");
            components.add("Remote work is/will be the new TREND");
            components.add("All these years, all these memories, there was you. You pull me through time.");
            components.add("I will not die, not here, not now, never...");
            components.add("Death is the road to awe.");
            components.add("There's been progress at work.");
            components.add("Death is a disease, it's like any other. And there's a cure. A cure - and I will find it.");
            components.add("Our bodies are prisons for our souls. Our skin and blood, the iron bars of confinement. ");
            components.add("But fear not. All flesh decays. Death turns all to ash. And thus, death frees every soul.");
            components.add("our destiny is life!");
            components.add("I'm not afraid anymore, Tommy");

            viewer.setInput(components);
            top.layout();
            setPageComplete(false);
        }
        super.setVisible(visible);
    }
}
...