开发者社区> 问答> 正文

如何在包含表格查看器的另一个组合的顶部显示组合?

在Page 的createControl(parent)方法中Wizard,代码如下

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

我想row在表示的复合材料上方添加top。

它不允许我。如果添加它,composite表示的top会丢失。

下面是最上面的复合材料的渲染 当我将以下代码放置在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; }

// 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;

}


问题来源:Stack Overflow

展开
收起
montos 2020-03-23 16:20:05 430 0
1 条回答
写回答
取消 提交回答
  • 向导页面必须只有一个顶层组合。您可以向该组合添加多个控件(包括嵌套的组合)。

    因此,对于表上方的标签:

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

    回答来源:Stack Overflow

    2020-03-23 16:20:30
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
继承与功能组合 立即下载
数据展现:可视化报表及嵌入应用 立即下载
重新定义计算的边界 立即下载