fNewsColumnViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
fNewsColumnViewer.setContentProvider(new ArrayContentProvider());
fNewsColumnViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
NewsColumn column = (NewsColumn) element;
return column.getName();
}
});
fNewsColumnViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateMoveEnablement();
updateRemoveEnablement();
}
});
/* Right: Buttons to manage Columns */
Composite buttonContainer = new Composite(this, SWT.None);
buttonContainer.setLayout(LayoutUtils.createGridLayout(1, 0, 0));
buttonContainer.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
/* Add */
final Menu menu = new Menu(getShell(), SWT.POP_UP);
menu.addMenuListener(new MenuListener() {
public void menuShown(MenuEvent e) {
MenuItem[] items = menu.getItems();
for (MenuItem item : items) {
item.dispose();
}
NewsColumn[] newsColumns = NewsColumn.values();
for (final NewsColumn column : newsColumns) {
if (column.isSelectable() && !fModel.contains(column)) {
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(column.getName());
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fModel.addColumn(column);
fNewsColumnViewer.add(column);
updateRemoveEnablement();
fNewsColumnViewer.setSelection(new StructuredSelection(column));
}
});
}
}
}
public void menuHidden(MenuEvent e) {}
});
final Button addButton = new Button(buttonContainer, SWT.DOWN);
setButtonLayoutData(addButton);
addButton.setText(Messages.NewsColumnSelectionControl_ADD);
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Rectangle rect = addButton.getBounds();
Point pt = new Point(rect.x, rect.y + rect.height);
pt = addButton.toDisplay(pt);
menu.setLocation(pt.x, pt.y);
menu.setVisible(true);
}
});
addButton.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
menu.dispose();
}
});
/* Remove */
fRemoveButton = new Button(buttonContainer, SWT.PUSH);
setButtonLayoutData(fRemoveButton);
fRemoveButton.setText(Messages.NewsColumnSelectionControl_REMOVE);
fRemoveButton.setEnabled(false);
fRemoveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onDelete();
}
});
/* Move Up */
fMoveUpButton = new Button(buttonContainer, SWT.PUSH);
setButtonLayoutData(fMoveUpButton);
fMoveUpButton.setText(Messages.NewsColumnSelectionControl_MOVE_UP);
fMoveUpButton.setEnabled(false);
fMoveUpButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onMove(true);
}
});
/* Move Down */
fMoveDownButton = new Button(buttonContainer, SWT.PUSH);
setButtonLayoutData(fMoveDownButton);
fMoveDownButton.setText(Messages.NewsColumnSelectionControl_MOVE_DOWN);
fMoveDownButton.setEnabled(false);
fMoveDownButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onMove(false);
}
});
/* Bottom: Sort Column */
Composite sortByContainer = new Composite(this, SWT.None);
sortByContainer.setLayout(LayoutUtils.createGridLayout(3, 0, 0));
sortByContainer.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
Label sortByLabel = new Label(sortByContainer, SWT.NONE);
sortByLabel.setText(Messages.NewsColumnSelectionControl_SORT_BY);
fSortByViewer = new ComboViewer(sortByContainer, SWT.READ_ONLY | SWT.BORDER);
fSortByViewer.getCombo().setVisibleItemCount(20);
fSortByViewer.setContentProvider(new ArrayContentProvider());
fSortByViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
NewsColumn column = (NewsColumn) element;
return column.getName();
}
});
fSortByViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element == NewsColumn.RELEVANCE)
return false;
return true;
}
});
fSortByViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
NewsColumn column = (NewsColumn) selection.getFirstElement();
fModel.setSortColumn(column);
}
});
fSortAscendingViewer = new ComboViewer(sortByContainer, SWT.READ_ONLY | SWT.BORDER);