use of org.eclipse.ui.dialogs.PatternFilter 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);
}
use of org.eclipse.ui.dialogs.PatternFilter in project dbeaver by dbeaver.
the class ManageCRSDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
if (crsLoader == null) {
crsLoader = new CRSLoader();
try {
UIUtils.runInProgressDialog(crsLoader);
} catch (InvocationTargetException e) {
log.error("Error loading CRS list", e.getTargetException());
}
}
PatternFilter patternFilter = new PatternFilter() {
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
if (element instanceof CRSInfo) {
return wordMatches(((CRSInfo) element).name) || wordMatches(String.valueOf(((CRSInfo) element).code)) || wordMatches(((CRSInfo) element).coordSystemName) || wordMatches(((CRSInfo) element).projectionName);
}
return super.isLeafMatch(viewer, element);
}
};
TreeViewer treeViewer = DialogUtils.createFilteredTree(dialogArea, SWT.BORDER | SWT.FULL_SELECTION, patternFilter, null);
Tree crsTree = treeViewer.getTree();
crsTree.setLayoutData(new GridData(GridData.FILL_BOTH));
crsTree.setHeaderVisible(true);
UIUtils.createTreeColumn(crsTree, SWT.LEFT, GISMessages.panel_manage_crs_dialog_tree_column_text_name);
UIUtils.createTreeColumn(crsTree, SWT.LEFT, GISMessages.panel_manage_crs_dialog_tree_column_text_srid);
UIUtils.createTreeColumn(crsTree, SWT.LEFT, GISMessages.panel_manage_crs_dialog_tree_column_text_coordinate_system);
UIUtils.createTreeColumn(crsTree, SWT.LEFT, GISMessages.panel_manage_crs_dialog_tree_column_text_projection);
treeViewer.setContentProvider(new ITreeContentProvider() {
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement == crsLoader) {
return crsLoader.crsMap.keySet().toArray(new Object[0]);
} else if (parentElement instanceof String) {
List<CRSInfo> crsInfos = crsLoader.crsMap.get(parentElement);
return crsInfos == null ? null : crsInfos.toArray(new Object[0]);
} else {
return new Object[0];
}
}
@Override
public Object getParent(Object element) {
if (element instanceof String) {
return crsTree;
} else {
return null;
}
}
@Override
public boolean hasChildren(Object element) {
if (element == crsLoader) {
return !crsLoader.crsMap.isEmpty();
} else if (element instanceof String) {
List<CRSInfo> crsInfos = crsLoader.crsMap.get(element);
return crsInfos != null && !crsInfos.isEmpty();
} else {
return false;
}
}
@Override
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
});
treeViewer.setLabelProvider(new CRSLabelProvider());
treeViewer.setInput(crsLoader);
treeViewer.expandAll();
treeViewer.addSelectionChangedListener(event -> {
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
Object selElement = ((IStructuredSelection) selection).getFirstElement();
if (selElement instanceof CRSInfo) {
// List<CRSInfo> crsInfo = crsLoader.crsMap.get(selElement);
selectedSRID = ((CRSInfo) selElement).code;
}
}
});
/*
for (String regName : crsLoader.crsMap.keySet()) {
regName = regName.toUpperCase(Locale.ENGLISH);
TreeItem regItem = new TreeItem(crsTree, SWT.NONE);
regItem.setText(0, regName);
for (CRSInfo crsInfo : crsLoader.crsMap.get(regName)) {
TreeItem crsItem = new TreeItem(regItem, SWT.NONE);
crsItem.setText(0, crsInfo.name);
crsItem.setText(1, String.valueOf(crsInfo.code));
crsItem.setText(2, crsInfo.coordSystemName);
crsItem.setText(3, crsInfo.projectionName);
crsItem.setData(crsInfo);
}
regItem.setExpanded(true);
}
*/
UIUtils.packColumns(crsTree, true, null);
return dialogArea;
}
use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class PageFunctions method createContents.
/**
* @see org.eclipse.jface.dialogs.DialogTray#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(comp);
Label label = new Label(comp, SWT.NONE);
label.setText("Functions Overview");
label.setFont(JFaceResources.getHeaderFont());
// tree viwever
PatternFilter patternFilter = new TreePathPatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
final FilteredTree filteredTree = new TreePathFilteredTree(comp, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
TreeViewer tree = filteredTree.getViewer();
tree.setUseHashlookup(true);
HelperFunctionLabelProvider labelProvider = new HelperFunctionLabelProvider();
tree.setLabelProvider(labelProvider);
IContentProvider contentProvider;
HelperFunctionsService functions = HaleUI.getServiceProvider().getService(HelperFunctionsService.class);
contentProvider = new TreePathProviderAdapter(new HelperFunctionContentProvider(functions));
tree.setContentProvider(contentProvider);
GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);
tree.setComparator(new HelperFunctionComparator());
tree.setInput(Category.ROOT);
// Examples
Label example = new Label(comp, SWT.NONE);
example.setText("Function documentation");
try {
browser = new Browser(comp, SWT.WRAP | SWT.BORDER);
browser.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 250).create());
} catch (Throwable e) {
if (BROWSER_ERROR_REPORTED.compareAndSet(false, true)) {
log.error("Could not create embedded browser, using text field as fall-back", e);
}
textField = new Text(comp, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
textField.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 250).create());
}
tree.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
String eg = null;
HelperFunctionSpecification hfs = null;
if (!event.getSelection().isEmpty()) {
TreeSelection treesel = (TreeSelection) event.getSelection();
TreePath[] paths = treesel.getPaths();
if (paths != null) {
TreePath path = paths[0];
for (int i = 0; i < path.getSegmentCount(); i++) {
if (path.getSegment(i) instanceof Category) {
eg = "Select a function to see its documentation.";
if (browser != null) {
browser.setText(eg);
} else if (textField != null) {
textField.setText(eg);
}
} else if (path.getSegment(i) instanceof HelperFunctionOrCategory) {
HelperFunctionOrCategory hfoc = ((HelperFunctionOrCategory) path.getSegment(i));
try {
hfs = (HelperFunctionSpecification) hfoc.asFunction().getSpec(hfoc.getName());
} catch (Exception e) {
log.error("There is a problem in retrieving the specification for a helper function.", e);
}
// displaying the specification
if (browser != null) {
eg = getFunctionSpecHTML(hfs);
browser.setText(eg);
} else if (textField != null) {
eg = getFunctionSpecText(hfs);
textField.setText(eg);
}
}
}
}
}
}
});
return comp;
}
use of org.eclipse.ui.dialogs.PatternFilter in project egit by eclipse.
the class BranchSelectionDialog method createCustomArea.
@Override
protected Control createCustomArea(Composite parent) {
Composite area = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(area);
area.setLayout(new GridLayout(1, false));
if (multiMode) {
fTree = new FilteredCheckboxTree(area, null, SWT.NONE, new PatternFilter()) {
/*
* Overridden to check page when refreshing is done.
*/
@Override
protected WorkbenchJob doCreateRefreshJob() {
WorkbenchJob refreshJob = super.doCreateRefreshJob();
refreshJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
checkPage();
}
});
}
}
});
return refreshJob;
}
};
CachedCheckboxTreeViewer viewer = fTree.getCheckboxTreeViewer();
GridDataFactory.fillDefaults().grab(true, true).applyTo(fTree);
viewer.setContentProvider(new ITreeContentProvider() {
@Override
public void inputChanged(Viewer actViewer, Object oldInput, Object newInput) {
// nothing
}
@Override
public void dispose() {
// nothing
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public Object[] getElements(Object inputElement) {
return ((List) inputElement).toArray();
}
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
});
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
checkPage();
}
});
viewer.setLabelProvider(new GitLabelProvider());
viewer.setComparator(new ViewerComparator(CommonUtils.STRING_ASCENDING_COMPARATOR));
viewer.setInput(nodes);
preselectBranchMultiMode(nodes, fTree);
} else {
branchesList = new TableViewer(area, this.style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, true).applyTo(branchesList.getControl());
branchesList.setContentProvider(ArrayContentProvider.getInstance());
branchesList.setLabelProvider(new GitLabelProvider());
branchesList.setComparator(new ViewerComparator(CommonUtils.STRING_ASCENDING_COMPARATOR));
branchesList.setInput(nodes);
preselectBranchSingleMode(nodes, branchesList);
branchesList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
checkPage();
}
});
branchesList.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
buttonPressed(OK);
}
});
}
return area;
}
use of org.eclipse.ui.dialogs.PatternFilter in project egit by eclipse.
the class AbstractBranchSelectionDialog method createDialogArea.
@Override
protected final Composite createDialogArea(Composite base) {
Composite parent = (Composite) super.createDialogArea(base);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
int selectionModel = -1;
if ((settings & ALLOW_MULTISELECTION) != 0)
selectionModel = SWT.MULTI;
else
selectionModel = SWT.SINGLE;
FilteredTree tree = new FilteredTree(composite, selectionModel | SWT.BORDER, new PatternFilter(), true);
branchTree = tree.getViewer();
branchTree.setUseHashlookup(true);
branchTree.setLabelProvider(new RepositoriesViewStyledCellLabelProvider());
branchTree.setContentProvider(new RepositoriesViewContentProvider());
ColumnViewerToolTipSupport.enableFor(branchTree);
GridDataFactory.fillDefaults().grab(true, true).hint(500, 300).applyTo(tree);
branchTree.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
String refName = refNameFromDialog();
refNameSelected(refName);
}
});
// double-click support
branchTree.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
RepositoryTreeNode node = (RepositoryTreeNode) ((IStructuredSelection) branchTree.getSelection()).getFirstElement();
if (node == null)
return;
final RepositoryTreeNodeType type = node.getType();
if (type != RepositoryTreeNodeType.REF && type != RepositoryTreeNodeType.TAG && type != RepositoryTreeNodeType.ADDITIONALREF)
branchTree.setExpandedState(node, !branchTree.getExpandedState(node));
else if (isOkButtonEnabled())
buttonPressed(OK);
}
});
branchTree.setComparator(new ViewerComparator(STRING_ASCENDING_COMPARATOR));
createCustomArea(composite);
setTitle(getTitle());
setMessage(getMessageText());
getShell().setText(getWindowTitle());
applyDialogFont(composite);
return composite;
}
Aggregations