Say I have a ItemListPart
class in my RCP project, and there is a table to be displayed in it as following:
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();
}
}
Here the ItemList<Item>
is a List which I wish could be changed from outside the ItemListPart
class, and whenever the data in ItemList<Item>
changed, the table view could be auto refreshed according to the updated data. What is the right way to achieve this goal? Thanks.