in uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/QuickTypeSelectionDialog.java [217:395]
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
// TODO: focus always goes to the text box, but should
// go to the Tree control, find out why, can SWT.NO_FOCUS be used
// to fix it ?
filterText = new Text(composite, SWT.NO_FOCUS);
filterText.setBackground(parent.getBackground());
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));
typeTree.getControl().setFocus();
filterText.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP) {
typeTree.getControl().setFocus();
Tree tree = (Tree) typeTree.getControl();
if (tree.getItemCount() > 0) {
tree.setSelection(tree.getItem(0));
}
}
}
@Override
public void keyReleased(KeyEvent e) {
typeTree.refresh(false);
}
});
typeTree.setContentProvider(new ITreeContentProvider() {
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object[] getElements(Object inputElement) {
return (Type[]) inputElement;
}
@Override
public void dispose() {
}
@Override
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.setLabelProvider(new ILabelProvider() {
@Override
public Image getImage(Object element) {
return null;
}
@Override
public String getText(Object element) {
Type type = (Type) element;
Character key = typeShortcutMap.get(type);
if (key != null) {
return "[" + key + "] " + type.getShortName();
} else {
return type.getShortName();
}
}
@Override
public void addListener(ILabelProviderListener listener) {
}
@Override
public void dispose() {
}
@Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
@Override
public void removeListener(ILabelProviderListener listener) {
}
});
typeTree.getControl().addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
Type type = shortcutTypeMap.get(Character.toLowerCase(e.character));
if (type != null) {
annotateAndClose(type);
}
}
@Override
public void keyReleased(KeyEvent e) {
}
});
typeTree.getControl().addMouseMoveListener(new MouseMoveListener() {
@Override
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);
}
}
});
// TODO open listener needs a double click, single click should be enough
// because there is already a selection below the mouse
typeTree.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
StructuredSelection selection = (StructuredSelection) event.getSelection();
annotateAndClose((Type) selection.getFirstElement());
}
});
Collection<Type> shownAnnotationTypes = editor.getShownAnnotationTypes();
Type[] types = shownAnnotationTypes.toArray(new Type[shownAnnotationTypes.size()]);
typeTree.setInput(types);
ISelection modeSelection = new StructuredSelection(new Object[] { editor.getAnnotationMode() });
typeTree.setSelection(modeSelection, true);
return composite;
}