use of org.eclipse.jface.viewers.ITreeContentProvider in project jbosstools-openshift by jbosstools.
the class OpenShiftUIUtils method getConnectionForExplorerSelection.
/**
* Returns the connection for the given type and current selection in the OpenShift explorer.
*
* @param klass connection type
* @return
*/
public static <T extends IConnection> T getConnectionForExplorerSelection(Class<T> klass) {
ISelection selection = getOpenShiftExplorerSelection();
if (selection != null && !selection.isEmpty()) {
T result = UIUtils.getFirstElement(selection, klass);
IViewPart part = getOpenShiftExplorer();
if (result == null && selection instanceof IStructuredSelection && part instanceof CommonNavigator) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
IContentProvider provider = ((CommonNavigator) part).getCommonViewer().getContentProvider();
if (provider instanceof ITreeContentProvider) {
ITreeContentProvider tree = (ITreeContentProvider) provider;
while (selected != null && result == null) {
result = UIUtils.adapt(selected, klass);
selected = tree.getParent(selected);
}
}
}
return result;
}
return null;
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method getActiveSaveables.
public synchronized Saveable[] getActiveSaveables() {
ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection instanceof ITreeSelection) {
return getActiveSaveablesFromTreeSelection((ITreeSelection) selection);
} else if (contentProvider instanceof ITreePathContentProvider) {
return getActiveSaveablesFromTreePathProvider(selection, (ITreePathContentProvider) contentProvider);
} else {
return getActiveSaveablesFromTreeProvider(selection, contentProvider);
}
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method createSaveablesProvider.
/**
* @param descriptor
* @return the SaveablesProvider, or null
*/
private SaveablesProvider createSaveablesProvider(NavigatorContentDescriptor descriptor) {
NavigatorContentExtension extension = contentService.getExtension(descriptor, true);
// Use getContentProvider to get the client objects, this is important
// for the adaptation below. See bug 306545
ITreeContentProvider contentProvider = extension.getContentProvider();
return (SaveablesProvider) AdaptabilityUtility.getAdapter(contentProvider, SaveablesProvider.class);
}
use of org.eclipse.jface.viewers.ITreeContentProvider 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.eclipse.jface.viewers.ITreeContentProvider in project webtools.sourceediting by eclipse.
the class HTMLSyntaxColoringPage method createStylesViewer.
/**
* Creates the List viewer where we see the various syntax element display
* names--would it ever be a Tree like JDT's?
*
* @param parent
* @return
*/
private StructuredViewer createStylesViewer(Composite parent) {
StructuredViewer stylesViewer = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
stylesViewer.setComparator(new ViewerComparator(Collator.getInstance()));
stylesViewer.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
Object description = fStyleToDescriptionMap.get(element);
if (description != null)
return description.toString();
return super.getText(element);
}
});
stylesViewer.setContentProvider(new ITreeContentProvider() {
public void dispose() {
}
public Object[] getChildren(Object parentElement) {
return getStylePreferenceKeys().toArray();
}
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
public Object getParent(Object element) {
return getStylePreferenceKeys();
}
public boolean hasChildren(Object element) {
return false;
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
return stylesViewer;
}
Aggregations