Как отобразить составной элемент поверх другого составного элемента, который содержит средство просмотра таблиц? - PullRequest
0 голосов
/ 16 марта 2020

В методе createControl(parent) на странице Wizard код выглядит следующим образом:

    top = new Composite(parent, SWT.NONE);
    top.setLayout(new FillLayout());
    setControl(top);
    setPageComplete(false);
    createViewer(top);

Я хочу добавить row над составным, обозначенным top.

Это не позволяет мне. Если я добавлю его, composite, обозначенный top, будет потерян.

Для верхнего композита приведено ниже -

enter image description here

В тот момент, когда я помещаю приведенный ниже код перед композитом top, top композит теряется -

    upper = new Composite(parent, SWT.NONE);
    upper.setLayout(new FillLayout());
    setControl(upper);
    Label label = new Label(page, SWT.NONE);
    label.setText("Some text to disply");

Пожалуйста, предложите, как этого добиться.

Ниже приведен фрагмент createControl в моем случае. Если добавить строку, он нарушает прокрутку и размер средства просмотра таблицы.

@Override
public void createControl(Composite parent) {

    /*top = new Composite(parent, SWT.NONE);
    top.setLayout(new FillLayout());
    setControl(top);*/
    setPageComplete(false);

    top = new Composite(parent, SWT.NONE);
    top.setLayout(new GridLayout());
    setControl(top);

    Label label = new Label(top, SWT.NONE);
    label.setText("Some text to disply");
    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));


    createViewer(top);
}

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);
    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;
}

enter image description here

// This will create the columns for the table
    private void createColumns(final Composite parent, final TableViewer viewer) {
        String[] titles = { "Node Status", "Node Type", "Node Name" };
        int[] bounds = { 100, 100, 100 };
        Image HEADER = CommonUtility.HEADER;

        TableViewerColumn col = null;

        // First column is for type
        col = createTableViewerColumn(HEADER, titles[0], bounds[0], 0);
        col.setLabelProvider(new CentredImageCellLabelProvider() {

            @Override
            public Image getImage(Object element) {
                GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
                if (model.isNew()) {
                    return CommonUtility.CHECKED;
                } else {
                    return CommonUtility.UNCHECKED;
                } 
            }
        });
        // Weight for column
        tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(50));

        // now the newly created
        col = createTableViewerColumn(HEADER, titles[1], bounds[1], 1);
        col.setLabelProvider(new CentredImageCellLabelProvider() {

            @Override
            public Image getImage(Object element) {
                GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
                if ("ns_flow".equals(model.getIcon())) {
                    return CommonUtility.FLOW_SERVICE;
                } 
                if ("ns_open_interface".equals(model.getIcon())) {
                    return CommonUtility.FOLDER;
                } 
                if ("ns_record".equals(model.getIcon())) {
                    return CommonUtility.DOCUMENT_TYPE;
                } 
                if ("ns_package".equals(model.getIcon())) {
                    return CommonUtility.PACKAGE;
                } 
                if("RestResource".equals(model.getIcon())){
                    return CommonUtility.RESTFUL_FOLDER;
                }
                return null;
            }

        });
        // Weight for column
        tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(50));


        // First column is for the component name
        col = createTableViewerColumn(HEADER, titles[2], bounds[2], 2);
        col.setLabelProvider(new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
                GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
                return model.getComponentName();
            }
        });
        // Weight for column
        tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(100));

    }

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

    }

1 Ответ

1 голос
/ 16 марта 2020

На странице мастера должна быть только одна составная часть верхнего уровня. Вы можете добавить несколько элементов управления (включая вложенные композиты) к этому композиту.

Таким образом, для метки выше таблицы:

top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
setControl(top);

Label label = new Label(top, SWT.NONE);
label.setText("Some text to disply");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

TableViewer viewer = new TableViewer(top, .... flags
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
...