listPanel.setLayout(new FillLayout());
subscriptionsList = new Table(listPanel,SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.VIRTUAL);
subscriptionsList.setHeaderVisible(true);
TableColumn name = new TableColumn(subscriptionsList,SWT.NONE);
name.setText(MessageText.getString("subscriptions.listwindow.name"));
name.setWidth(310);
name.setResizable(false);
TableColumn popularity = new TableColumn(subscriptionsList,SWT.NONE);
popularity.setText(MessageText.getString("subscriptions.listwindow.popularity"));
popularity.setWidth(70);
popularity.setResizable(false);
subscriptionsList.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event e) {
TableItem item = (TableItem) e.item;
int index = subscriptionsList.indexOf(item);
if(index >= 0 && index < subscriptionItems.length) {
SubscriptionItemModel subscriptionItem = subscriptionItems[index];
item.setText(0,subscriptionItem.name);
item.setText(1,subscriptionItem.popularityDisplay);
}
}
});
subscriptionsList.setSortColumn(popularity);
subscriptionsList.setSortDirection(SWT.DOWN);
subscriptionsList.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event arg0) {
action.setEnabled(subscriptionsList.getSelectionIndex() != -1);
}
});
Listener sortListener = new Listener() {
public void handleEvent(Event e) {
// determine new sort column and direction
TableColumn sortColumn = subscriptionsList.getSortColumn();
TableColumn currentColumn = (TableColumn) e.widget;
int dir = subscriptionsList.getSortDirection();
if (sortColumn == currentColumn) {
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
} else {
subscriptionsList.setSortColumn(currentColumn);