label.setText(Messages.LocationControl_CHOOSE_BINS_MSG);
break;
}
/* Filter for Filtered Tree */
final PatternFilter filter = new PatternFilter() {
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
if (fMode == Mode.SELECT_BIN && !(element instanceof INewsBin))
return false;
String labelText = ((IFolderChild) element).getName();
if (labelText == null)
return false;
return wordMatches(labelText);
}
};
/* Filtered Tree to make it easier to chose an element */
fFilteredTree = new FilteredTree(composite, SWT.BORDER, filter) {
@Override
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
fViewer = new CheckboxTreeViewer(parent, SWT.BORDER) {
@Override
public void refresh(boolean updateLabels) {
super.refresh(updateLabels);
/* Avoid collapsed Tree */
expandToLevel(fMode == Mode.SELECT_BIN ? AbstractTreeViewer.ALL_LEVELS : 2);
/* Restore Checked Elements */
for (IFolderChild child : fCheckedElementsCache) {
setParentsExpanded(child);
fViewer.setChecked(child, true);
setChildsChecked(child, true, true, false);
}
}
};
fViewer.setAutoExpandLevel(fMode == Mode.SELECT_BIN ? AbstractTreeViewer.ALL_LEVELS : 2);
fViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
fViewer.getTree().setData(ApplicationWorkbenchWindowAdvisor.FOCUSLESS_SCROLL_HOOK, new Object());
return fViewer;
}
@Override
protected void updateToolbar(boolean visible) {
if (filterToolBar != null)
filterToolBar.getControl().setEnabled(visible);
}
@Override
protected Composite createFilterControls(Composite parent) {
Composite filterControls = super.createFilterControls(parent);
if (filterToolBar != null) {
filterToolBar.getControl().setVisible(true);
filterToolBar.getControl().setEnabled(false);
}
return filterControls;
}
};
fFilteredTree.setInitialText(""); //$NON-NLS-1$
if (fMode == Mode.SEARCH_LOCATION) {
fFilteredTree.getFilterControl().setMessage(Messages.LocationControl_FILTER_LOCATIONS);
OwlUI.makeAccessible(fFilteredTree.getFilterControl(), Messages.LocationControl_FILTER_LOCATIONS);
} else {
fFilteredTree.getFilterControl().setMessage(Messages.LocationControl_FILTER_BINS);
OwlUI.makeAccessible(fFilteredTree.getFilterControl(), Messages.LocationControl_FILTER_BINS);
}
fFilteredTree.getViewer().getControl().setFocus();
/* Filter when Typing into Tree */
fFilteredTree.getViewer().getControl().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.character > 0x20) {
String character = String.valueOf(e.character);
Text text = fFilteredTree.getFilterControl();
text.setFocus();
text.setText(character);
text.setSelection(1);
filter.setPattern(character);
/* Consume the Event */
e.doit = false;
}
}