1
说我有一个ItemListPart
类在我的RCP项目,并有显示在它下面的表格:在Eclipse RCP项目中,更新零件表格视图的正确方法是什么?
import java.util.List;
import javax.annotation.PostConstruct;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class ItemListPart {
private Table table;
@PostConstruct
public void createControls(Composite parent){
//I wish the ItemList could be changed from outside the ItemListPart class.
List<Item> ItemList = getItemList();
parent.setLayout(new GridLayout(2, false));
table = new Table(parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 200;
table.setLayoutData(data);
String[] titles = { "Item Name", "Description"};
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText(titles[i]);
table.getColumn(i).pack();
}
for(Item it:ItemList){
TableItem item = new TableItem(table, SWT.NONE);
item.setText(0, it.getName());
item.setText(1, it.getDesc());
}
for (int i=0; i<titles.length; i++) {
table.getColumn (i).pack();
}
}
@Focus
public void onFocus() {
table.setFocus();
}
}
这里ItemList<Item>
是我希望能够从ItemListPart
类外修改列表,并且每当ItemList<Item>
中的数据发生更改时,都可以根据更新的数据自动刷新表视图。什么是实现这一目标的正确途径?谢谢。
谢谢大家一些更多的信息。在你的代码示例中,传递的数据是否为'Collections.EMPTY_MAP'以便更新?如果是这样,我怎么能在方法'listUpdated(@UIEventTopic(“/ list/updated”)事件事件)中获取数据? – kenshinji
是的,我添加了一个例子,将事件中的一些数据传递给答案。 –