如何将一个复合组件显示在另一个包含表格查看器的复合组件之上?

huangapple go评论95阅读模式
英文:

How to display a composite on the top of another composite which contains a table viewer?

问题

Wizard页面的createControl(parent)方法中,代码如下所示-

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

我想在被标记为top的组合框上方添加一行。

但是它不允许我这样做。如果我这样做,被标记为topcomposite会丢失。

下面是用于顶部composite的呈现效果-

如何将一个复合组件显示在另一个包含表格查看器的复合组件之上?

在我将以下代码放置在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 display");

请建议如何实现相同的效果。


以下是我这种情况下的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 display");
		label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
		
		
		createViewer(top);
	}

以下是创建表格查看器列的代码:

    // This will create the columns for the table
    private void createColumns(final Composite parent, final TableViewer viewer) {
        // ...
    }

请注意,由于您请求仅返回翻译好的部分,我已经省略了您提供的图片链接。如果您有任何关于这段翻译的问题,请随时询问。

英文:

In the createControl(parent) method of the Wizard Page, the code is as below-

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

I want to add a row above the composite denoted by top.

It doesn't allows me. If I add it, the composite denoted by top gets lost.

The below is rendered for the top composite -

如何将一个复合组件显示在另一个包含表格查看器的复合组件之上?

The moment I place the below code before the top composite, the top composite gets lost -

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

Please suggest on how to achieve the same.
<hr/>

The below is the createControl snippet in my case. It breaks the scrolling and size of the table viewer if add a row.

@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(&quot;Some text to disply&quot;);
	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;
}

如何将一个复合组件显示在另一个包含表格查看器的复合组件之上?

<hr/>

// This will create the columns for the table
    private void createColumns(final Composite parent, final TableViewer viewer) {
        String[] titles = { &quot;Node Status&quot;, &quot;Node Type&quot;, &quot;Node Name&quot; };
        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 (&quot;ns_flow&quot;.equals(model.getIcon())) {
                    return CommonUtility.FLOW_SERVICE;
                } 
                if (&quot;ns_open_interface&quot;.equals(model.getIcon())) {
                    return CommonUtility.FOLDER;
                } 
                if (&quot;ns_record&quot;.equals(model.getIcon())) {
                    return CommonUtility.DOCUMENT_TYPE;
                } 
                if (&quot;ns_package&quot;.equals(model.getIcon())) {
                    return CommonUtility.PACKAGE;
                } 
                if(&quot;RestResource&quot;.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

巫师页面必须只有一个顶级复合控件。您可以向该复合控件添加多个控件(包括嵌套的复合控件)。

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

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

    Label label = new Label(top, SWT.NONE);
    label.setText("要显示的一些文本");
    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

    TableViewer viewer = new TableViewer(top, .... 标志
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
英文:

A wizard page must only have one top level composite. You can add multiple controls (including nested composites) to that composite.

So for a label above to table:

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

Label label = new Label(top, SWT.NONE);
label.setText(&quot;Some text to disply&quot;);
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));

huangapple
  • 本文由 发表于 2020年3月16日 05:57:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/60698069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定