Search in sources :

Example 26 with ITreeContentProvider

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;
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) IViewPart(org.eclipse.ui.IViewPart) IContentProvider(org.eclipse.jface.viewers.IContentProvider) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 27 with ITreeContentProvider

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);
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ITreePathContentProvider(org.eclipse.jface.viewers.ITreePathContentProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 28 with ITreeContentProvider

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);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) NavigatorContentExtension(org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension) SaveablesProvider(org.eclipse.ui.navigator.SaveablesProvider)

Example 29 with ITreeContentProvider

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)));
}
Also used : Disposable(org.springsource.ide.eclipse.commons.livexp.ui.Disposable) Disposable(org.springsource.ide.eclipse.commons.livexp.ui.Disposable) Text(org.eclipse.swt.widgets.Text) StyledString(org.eclipse.jface.viewers.StyledString) Stylers(org.springsource.ide.eclipse.commons.livexp.ui.Stylers) Assert(org.eclipse.core.runtime.Assert) Filter(org.springsource.ide.eclipse.commons.livexp.util.Filter) UIValueListener(org.springsource.ide.eclipse.commons.livexp.core.UIValueListener) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Styler(org.eclipse.jface.viewers.StyledString.Styler) LiveExpression(org.springsource.ide.eclipse.commons.livexp.core.LiveExpression) ViewerCell(org.eclipse.jface.viewers.ViewerCell) ModifyListener(org.eclipse.swt.events.ModifyListener) Duration(java.time.Duration) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Filters(org.springsource.ide.eclipse.commons.livexp.util.Filters) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ValueListener(org.springsource.ide.eclipse.commons.livexp.core.ValueListener) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) LiveVariable(org.springsource.ide.eclipse.commons.livexp.core.LiveVariable) IRegion(org.eclipse.jface.text.IRegion) Stylers(org.springsource.ide.eclipse.commons.livexp.ui.Stylers) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Example 30 with ITreeContentProvider

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;
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)68 Viewer (org.eclipse.jface.viewers.Viewer)32 LabelProvider (org.eclipse.jface.viewers.LabelProvider)19 GridData (org.eclipse.swt.layout.GridData)19 Composite (org.eclipse.swt.widgets.Composite)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 GridLayout (org.eclipse.swt.layout.GridLayout)15 Label (org.eclipse.swt.widgets.Label)13 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)12 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)11 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)11 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)11 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)11 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)11 ArrayList (java.util.ArrayList)10 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)9 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)9 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)8 SourceViewer (org.eclipse.jface.text.source.SourceViewer)7