英文:
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
的组合框上方添加一行。
但是它不允许我这样做。如果我这样做,被标记为top
的composite
会丢失。
下面是用于顶部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("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;
}
<hr/>
// 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
巫师页面必须只有一个顶级复合控件。您可以向该复合控件添加多个控件(包括嵌套的复合控件)。
因此,对于位于表格上方的标签:
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("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));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论