... | @@ -308,7 +308,46 @@ This class follows strictly the previously introduced concept of having a method |
... | @@ -308,7 +308,46 @@ This class follows strictly the previously introduced concept of having a method |
|
|
|
|
|
On all those buttons, a selectionlistener is added. Thanks to Java8 this can be done in a very clean fashion. And all those handler should do, is to call a method in the controller! The controller takes care of the rest.
|
|
On all those buttons, a selectionlistener is added. Thanks to Java8 this can be done in a very clean fashion. And all those handler should do, is to call a method in the controller! The controller takes care of the rest.
|
|
|
|
|
|
Following this paradigm, the model will never appear in the UI composites, and the UI only delegates everything that needs some thinking right to the controller. I encourage you to make use of
|
|
Following this paradigm, the model will never appear in the UI composites, and the UI only delegates everything that needs some thinking right to the controller. I encourage you to make use of Java8 to register your Listener.
|
|
|
|
This does not only save code, but also keeps the code clean. Another use-case where you can see its advantage is when you create a table and add its columns. The code is usually extremely long. But thanks to java8 (and its possibility ot pass methods as parameters) you can create table columsn like this:
|
|
|
|
|
|
|
|
```java
|
|
|
|
private void createColumns(TableViewer viewer) {
|
|
|
|
|
|
|
|
createTableViewerColumn("Name", 100, 0, part::determineName);
|
|
|
|
createTableViewerColumn("Freq.", 30, 1, part::determineFrequency);
|
|
|
|
createTableViewerColumn("ID", 30, 2, part::determineID);
|
|
|
|
createTableViewerColumn("Synonyme", 90, 3, part::getCoveredText);
|
|
|
|
createTableViewerColumn("Type", 60, 4, part::determineNEType);
|
|
|
|
createTableViewerColumn("Uncertain?", 30, 5, part::determineUncertainFeature);
|
|
|
|
createTableViewerColumn("Numerus", 30, 6, part::determineNumber);
|
|
|
|
createTableViewerColumn("Gender", 30, 7, part::determineGender);
|
|
|
|
createTableViewerColumn("Pseudo", 30, 8, part::determinePseudoFeature);
|
|
|
|
}
|
|
|
|
|
|
|
|
private TableViewerColumn createTableViewerColumn(String viewer2, int bound, final int colNumber,
|
|
|
|
Function<AnnotationFS, String> function) {
|
|
|
|
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
|
|
|
|
final TableColumn column = viewerColumn.getColumn();
|
|
|
|
column.setText(viewer2);
|
|
|
|
column.setWidth(bound);
|
|
|
|
column.setResizable(true);
|
|
|
|
column.setMoveable(true);
|
|
|
|
// the sorter
|
|
|
|
column.addSelectionListener(getSelectionAdapter(column, colNumber));
|
|
|
|
|
|
|
|
// also add the labelprovider
|
|
|
|
viewerColumn.setLabelProvider(new ColumnLabelProvider() {
|
|
|
|
@Override
|
|
|
|
public String getText(Object element) {
|
|
|
|
AnnotationFS p = (AnnotationFS) element;
|
|
|
|
return function.apply(p);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return viewerColumn;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|