use of org.eclipse.ui.dialogs.FilteredTree in project translationstudio8 by heartsome.
the class LanguageCodesPreferencePage method createFilterControls.
/**
* 创建包含过滤文本的 TreeViewer
* @param parent
* 顶层容器 ;
*/
private void createFilterControls(Composite parent) {
fFilteredTree = new FilteredTree(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION, new PatternFilter(), true);
GridData gridData;
final GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 0;
fFilteredTree.setLayout(layout);
gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = SWT.FILL;
fFilteredTree.setLayoutData(gridData);
final TreeViewer viewer = fFilteredTree.getViewer();
// 确保 filtered tree 有显示 ITEMS_TO_SHOW 的高度
final Tree tree = viewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
final Object layoutData = tree.getLayoutData();
if (layoutData instanceof GridData) {
gridData = (GridData) layoutData;
// 适应大小
gridData.heightHint = parent.getSize().y;
}
LanguageCodeComparator comparator = new LanguageCodeComparator();
final TreeColumn codeColumn = new TreeColumn(tree, SWT.LEFT, LANGUAGE_CODE_COLUMN);
codeColumn.setText(Messages.getString("languagecode.LanguageCodesPreferencePage.codeColumn"));
tree.setSortColumn(codeColumn);
tree.setSortColumn(codeColumn);
tree.setSortDirection(SWT.UP);
codeColumn.addSelectionListener(new ResortColumn(comparator, codeColumn, viewer, LANGUAGE_CODE_COLUMN));
final TreeColumn nameColumn = new TreeColumn(tree, SWT.LEFT, LANGUAGE_NAME_COLUMN);
nameColumn.setText(Messages.getString("languagecode.LanguageCodesPreferencePage.nameColumn"));
nameColumn.addSelectionListener(new ResortColumn(comparator, nameColumn, viewer, LANGUAGE_NAME_COLUMN));
final TreeColumn bidiColumn = new TreeColumn(tree, SWT.LEFT, LANGUAGE_BIDI_COLUMN);
bidiColumn.setText(Messages.getString("languagecode.LanguageCodesPreferencePage.bidiColumn"));
bidiColumn.addSelectionListener(new ResortColumn(comparator, bidiColumn, viewer, LANGUAGE_BIDI_COLUMN));
viewer.setContentProvider(new LanguageCodeContentProvider());
viewer.setLabelProvider(new LanguageCodeLabelProvider());
viewer.setComparator(comparator);
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
verifyCurrentSelected(EDIT);
}
});
fFilteredTree.getPatternFilter().setIncludeLeadingWildcard(true);
final TreeColumn[] columns = viewer.getTree().getColumns();
columns[LANGUAGE_CODE_COLUMN].setWidth(100);
columns[LANGUAGE_NAME_COLUMN].setWidth(240);
columns[LANGUAGE_BIDI_COLUMN].setWidth(100);
}
Aggregations