filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT);
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final TreeViewer typeTree = new TreeViewer(composite, SWT.SINGLE | SWT.V_SCROLL);
typeTree.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL |
GridData.FILL_VERTICAL));
filterText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP) {
typeTree.getControl().setFocus();
}
}
public void keyReleased(KeyEvent e) {
typeTree.refresh(false);
}
});
typeTree.setContentProvider(new ITreeContentProvider() {
public Object[] getChildren(Object parentElement) {
return null;
}
public Object getParent(Object element) {
return null;
}
public boolean hasChildren(Object element) {
return false;
}
public Object[] getElements(Object inputElement) {
TypeSystem typeSystem = (TypeSystem) inputElement;
List types = typeSystem.getProperlySubsumedTypes(typeSystem
.getType(CAS.TYPE_NAME_ANNOTATION));
return types.toArray();
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
typeTree.setFilters(new ViewerFilter[] { new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
// check if the string from the filterText is contained in the type name
Type type = (Type) element;
return type.getName().contains(filterText.getText());
}
} });
typeTree.getControl().addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
Tree tree = (Tree) typeTree.getControl();
TreeItem item = tree.getItem(new Point(e.x, e.y));
if (item != null) {
tree.setSelection(item);
}
}
});
typeTree.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
StructuredSelection selection = (StructuredSelection) event.getSelection();
Type annotationType = (Type) selection.getFirstElement();
if (annotationType != null) {
Point textSelection = editor.getSelection();
AnnotationFS annotation = editor.getDocument().getCAS().createAnnotation(annotationType,
textSelection.x, textSelection.y);
editor.getDocument().addFeatureStructure(annotation);
if (annotation.getType().equals(editor.getAnnotationMode())) {
editor.setAnnotationSelection(annotation);
}
}
QuickTypeSelectionDialog.this.close();
}
});
typeTree.setInput(editor.getDocument().getCAS().getTypeSystem());
ISelection modeSelection = new StructuredSelection(new Object[] { editor.getAnnotationMode() });
typeTree.setSelection(modeSelection, true);
return composite;
}