Search in sources :

Example 1 with FilteredTree

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);
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree)

Aggregations

DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Tree (org.eclipse.swt.widgets.Tree)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1 FilteredTree (org.eclipse.ui.dialogs.FilteredTree)1 PatternFilter (org.eclipse.ui.dialogs.PatternFilter)1