代码之家  ›  专栏  ›  技术社区  ›  Farhan stands with Palestine

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

  •  0
  • Farhan stands with Palestine  · 技术社区  · 4 年前

    createControl(parent) 调查方法 Wizard 第页,代码如下-

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

    我想补充一点 row 上面的复合表示为 top .

    它不允许我。如果我加上它 composite 记为 顶部 迷路了。

    下面是对顶部合成的渲染-

    enter image description here

    当我把下面的代码放在 顶部 复合材料 顶部 复合材料迷路了-

        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;
    
        }
    
    0 回复  |  直到 4 年前
        1
  •  1
  •   greg-449    4 年前

    一个向导页面只能有一个顶级组合。可以向该组合添加多个控件(包括嵌套组合)。

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

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