我急需一些有指导的帮助。我已经能够完成并开始使用 Tables 和 TableViewers 的代码示例。但是我没有找到任何示例来帮助我进行粒子设置。
请指导我正确的方向。
我的课程:
AHandler.java - 这允许用户从鼠标右键单击中选择数据。在执行期间,我正在调用一个单例类来将用户选择的数据添加到数组列表中。
ASelectedData.getInstance().add(tcRevision, selectedDataset);
ASelectedData.java - 是将用户选择添加到 ArrayList 的单例类。
ABase.java - 通过单击菜单打开此对话框。该对话框应显示一个包含 ArrayList 值的表。执行其他操作的一些按钮。
我现在拥有的方式是在 ABase.java 类中创建表和表查看器。我正在从中提取表格的信息。
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(AplotSelectedDataTable.getInstance().getArrayData());
这将使用正确的数据填充表。
但是 ABase.java 类是 MODELESS。那么为什么打开该对话框,用户可以继续使用鼠标右键选择数据并添加到数组列表中。但是我对表格进行编码的方式是我必须重新打开窗口来更新数据。
* 编辑 * *** 在我的主 GUI 中,我创建了一个 TableViewer。TableViewer 创建一个表,该表在单独的类中显示来自 arraylist 的数据。问题是用户仍然能够转到主应用程序 GUI(不是我的应用程序 GUI)并在我的 GUI 仍然打开时选择更多数据。他们希望在选择表格时看到添加到表格中的新数据。
问题是我无法告诉表格新数据已经到达所以刷新表格。获取数据并将其添加到 ArrayList 的 Add 方法位于 ASelectedData 类中。不是创建 tableviewer 的类。
执行 Add Method 时,我需要一种方法来告诉表刷新。问题是表和方法在两个单独的类中。
希望这更有意义
编辑*
我使用 TableViewer 的主要 GUI
public AplotBaseDialog(Shell shell, TCSession theSession) Constructor
//////////////////////////////////////////////////////////////////////////
// createTableViewer() //
//////////////////////////////////////////////////////////////////////////
private TableViewer createTableViewer(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
createColumns(parent, viewer);
Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(AplotSelectedDataTable.getInstance().getArrayData());
// 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);
return viewer;
}
//////////////////////////////////////////////////////////////////////////
// updateTableViewer() //
//////////////////////////////////////////////////////////////////////////
public void updateTableViewer() {
viewer.refresh();
}
添加到其他类的代码
AplotBaseDialog abd = new AplotBaseDialog(null, null);
public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset) {
AplotDatasetData pp = new AplotDatasetData(tcRevision, selectedDataset);
if (!dataArrayList.contains(pp)) {
dataArrayList.add(pp);
}
abd.updateTableViewer();
}// end add()