A common framework for display of lists and tables
Introduction
The purpose of this package is to provide an easy-to-use interface for displaying lists of data, like analysis results, profile and monitor lists etc. using the Eclipse SWT framework. The main class inside the package is MATTableViewer. This is an extension of Eclipse TableViewer. When used in place of a normal TableViewer, it takes care of setting up the surrounding helper classes, and uses its internal metadata to add additional properties to table columns, implementing sorting according to column data type, columns whose fields trigger a callback function, and more.
Using the package in 3 steps:
Step 1
Include the MATTableViewer in your view, editor or dialog, by calling its constructor in your control initialization code (eg. in the createPartControl() method)
Sample:
public void createPartControl(Composite parent) {
viewer = new MATTableViewer(parent);
}
Step 2
Define the columns you want to use in the table, using the addColumn() methods of the MATTableViewer.
Sample:
viewer.addColumn("Name", MATTableViewer.COLUMN_SIZE_8CHAR, "Name of the dog", MATTableViewer.COLUMN_TYPE_STRING);
viewer.addColumn("Breed", MATTableViewer.COLUMN_SIZE_8CHAR, "Breed of the dog", MATTableViewer.COLUMN_TYPE_STRING, true, false);
Step 3
Get the MATTableModel and insert the data you wish to display in the table. Note that any changes to the contents of the model will reflect in the table, no need to refresh your view. Also note that you can use a single MATTableDataset with multiple MATTableViewers.
Samples:
public void init(Dog[] dogs) {
MATTableModel model = viewer.getMATTableModel();
Dog[] dogs = new Dog[]{ new Dog(model, "dog1", "bulldog"),
new Dog(model, "dog2", "bulldog"),
new Dog(model, "dog3", "bulldog"),
};
for (Dog dog : dogs)
{
model.addRow(dog);
}
}
}
public void addDog(Dog dog) {
viewer.getMATTableModel().addRow(dog})
}
public void removeDog(Dog dog) {
viewer.getMATTableModel().removeRow(dog);
}
public class Dog extends MATTableRow
{
private String name;
private String breed;
public Dog(MATTableModel model, String name, String breed)
{
super(model);
this.name=name;
this.name=breed;
}
@Override
protected Object[] getArray()
{
return new Object[]{name,breed}; //same order as columns in the table definition
}
}