use of org.springsource.ide.eclipse.commons.livexp.ui.Disposable in project eclipse-integration-commons by spring-projects.
the class SwtConnect method connectTextBasedFilter.
/**
* Connect a filterbox model to a treeviewer. This assumes that the filter is text-based. The filter is applied to the labels of the elements in the tree.
* <p>
* For the viewer filter to work correctly the ITreeContentProvider must provide a proper implementation of the 'getParent' method. If getParent only
* returns null the viewer filter will not be able to check whether an element should be shown when a parent element is selected by the search filter.
* <p>
* Note: you can use {@link TreeElementWrappingContentProvider} in order to ensure that ITreeContentProvider keeps track of parent nodes properly.
*/
public static void connectTextBasedFilter(TreeViewer viewer, LiveExpression<Filter<String>> searchBoxModel, LabelProvider labels, ITreeContentProvider treeContent) {
TreeAwareViewerFilter viewerFilter = new TreeAwareViewerFilter(viewer, Filters.acceptAll(), labels, treeContent);
Disposable disposable = searchBoxModel.onChange(UIValueListener.from((e, filter) -> {
viewerFilter.setFilter(searchBoxModel.getValue());
viewer.refresh(true);
}));
// TODO: what if there are existing filters?
viewer.setFilters(viewerFilter);
viewer.getControl().addDisposeListener(de -> {
disposable.dispose();
});
Stylers stylers = new Stylers(viewer.getTree().getFont());
viewer.getControl().addDisposeListener(de -> {
disposable.dispose();
stylers.dispose();
});
ILabelProvider baseLabels = (ILabelProvider) viewer.getLabelProvider();
// Can't add bolding support without this! Ensure label provider is set before calling this method
Assert.isNotNull(baseLabels);
viewer.setLabelProvider(boldMatchedElements(stylers, baseLabels, Filters.delegatingTo(searchBoxModel)));
}
use of org.springsource.ide.eclipse.commons.livexp.ui.Disposable in project eclipse-integration-commons by spring-projects.
the class SwtConnect method connect.
public static void connect(Text text, LiveVariable<String> model) {
if (!text.isDisposed()) {
text.addDisposeListener(de -> model.dispose());
ModifyListener widgetListener = (me) -> {
if (!text.isDisposed()) {
model.setValue(text.getText());
}
};
text.addModifyListener(widgetListener);
Disposable disconnect = model.onChange(UIValueListener.from((e, v) -> {
String oldText = text.getText();
String newText = model.getValue();
if (newText == null) {
newText = "";
}
if (!oldText.equals(newText)) {
text.setText(newText);
}
}));
text.addDisposeListener(de -> disconnect.dispose());
model.onDispose(de -> text.removeModifyListener(widgetListener));
}
}
use of org.springsource.ide.eclipse.commons.livexp.ui.Disposable in project sts4 by spring-projects.
the class GotoSymbolDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite dialogArea = new Composite(parent, SWT.NONE);
dialogArea.addDisposeListener(de -> {
for (Disposable d : disposables) {
d.dispose();
}
});
if (parent.getLayout() instanceof GridLayout) {
dialogArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
}
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
dialogArea.setLayout(layout);
Text pattern = new Text(dialogArea, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
// pattern.getAccessible().addAccessibleListener(new AccessibleAdapter() {
// public void getName(AccessibleEvent e) {
// e.result = LegacyActionTools.removeMnemonics(headerLabel)
// .getText());
// }
// });
pattern.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pattern.setMessage(model.getSearchBoxHintMessage());
SwtConnect.connect(pattern, model.getSearchBox());
TreeViewer viewer = new TreeViewer(dialogArea, SWT.SINGLE);
ColumnViewerToolTipSupport.enableFor(viewer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());
viewer.setContentProvider(new SymbolsContentProvider());
viewer.setLabelProvider(new GotoSymbolsLabelProvider(viewer.getTree().getFont()));
viewer.setUseHashlookup(true);
disposables.add(model.getSymbols().onChange(UIValueListener.from((e, v) -> {
if (!viewer.getControl().isDisposed())
viewer.refresh();
})));
// TODO: somehow show selection in local file, (but not in other file ?)
// viewer.addSelectionChangedListener(event -> {
// IStructuredSelection selection = (IStructuredSelection) event.getSelection();
// if (selection.isEmpty()) {
// return;
// }
// SymbolInformation symbolInformation = (SymbolInformation) selection.getFirstElement();
// Location location = symbolInformation.getLocation();
//
// IResource targetResource = LSPEclipseUtils.findResourceFor(location.getUri());
// if (targetResource == null) {
// return;
// }
// IDocument targetDocument = FileBuffers.getTextFileBufferManager()
// .getTextFileBuffer(targetResource.getFullPath(), LocationKind.IFILE).getDocument();
// if (targetDocument != null) {
// try {
// int offset = LSPEclipseUtils.toOffset(location.getRange().getStart(), targetDocument);
// int endOffset = LSPEclipseUtils.toOffset(location.getRange().getEnd(), targetDocument);
// fTextEditor.selectAndReveal(offset, endOffset - offset);
// } catch (BadLocationException e) {
// LanguageServerPlugin.logError(e);
// }
// }
// });
installWidgetListeners(pattern, viewer);
Label statusLabel = new Label(dialogArea, SWT.NONE);
statusLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
SwtConnect.connect(statusLabel, model.getStatus(), Duration.ofMillis(500));
viewer.setInput(model);
return dialogArea;
}
Aggregations