Search in sources :

Example 1 with LabelProviderChangedEvent

use of org.eclipse.jface.viewers.LabelProviderChangedEvent in project eclipse.platform.text by eclipse.

the class SearchResultViewer method handleLabelProviderChanged.

@Override
protected void handleLabelProviderChanged(LabelProviderChangedEvent event) {
    Object[] changed = event.getElements();
    if (changed != null && !fResourceToItemsMapper.isEmpty()) {
        ArrayList<Object> others = new ArrayList<>(changed.length);
        for (Object curr : changed) {
            if (curr instanceof IResource)
                fResourceToItemsMapper.resourceChanged((IResource) curr);
            else if (curr instanceof IAdaptable) {
                IResource resource = ((IAdaptable) curr).getAdapter(IResource.class);
                if (resource != null)
                    fResourceToItemsMapper.resourceChanged(resource);
            } else
                others.add(curr);
        }
        if (others.isEmpty()) {
            return;
        }
        event = new LabelProviderChangedEvent((IBaseLabelProvider) event.getSource(), others.toArray());
    }
    super.handleLabelProviderChanged(event);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ArrayList(java.util.ArrayList) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) LabelProviderChangedEvent(org.eclipse.jface.viewers.LabelProviderChangedEvent) IResource(org.eclipse.core.resources.IResource)

Example 2 with LabelProviderChangedEvent

use of org.eclipse.jface.viewers.LabelProviderChangedEvent in project eclipse.platform.text by eclipse.

the class AbstractControlContentAssistSubjectAdapter method setContentAssistCueProvider.

/**
 * Sets the visual feedback provider for content assist.
 * The given {@link ILabelProvider} methods are called with
 * {@link #getControl()} as argument.
 *
 * <ul>
 *   <li><code>getImage(Object)</code> provides the visual cue image.
 *     The image can maximally be 5 pixels wide and 8 pixels high.
 *     If <code>getImage(Object)</code> returns <code>null</code>, a default image is used.
 *   </li>
 *   <li><code>getText(Object)</code> provides the hover info text.
 *     It is shown when hovering over the cue image or the adapted {@link Control}.
 *     No info text is shown if <code>getText(Object)</code> returns <code>null</code>.
 *   </li>
 * </ul>
 * <p>
 * The given {@link ILabelProvider} becomes owned by the {@link AbstractControlContentAssistSubjectAdapter},
 * i.e. it gets disposed when the adapted {@link Control} is disposed
 * or when another {@link ILabelProvider} is set.
 * </p>
 *
 * @param labelProvider a {@link ILabelProvider}, or <code>null</code>
 * 	if no visual feedback should be shown
 */
public void setContentAssistCueProvider(final ILabelProvider labelProvider) {
    if (fCueLabelProvider != null) {
        fCueLabelProvider.dispose();
    }
    fCueLabelProvider = labelProvider;
    if (labelProvider == null) {
        if (fControlDecoration != null) {
            fControlDecoration.dispose();
            fControlDecoration = null;
        }
    } else {
        if (fControlDecoration == null) {
            fControlDecoration = new ControlDecoration(getControl(), (SWT.TOP | SWT.LEFT));
            getControl().addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent e) {
                    if (fCueLabelProvider != null) {
                        fCueLabelProvider.dispose();
                        fCueLabelProvider = null;
                    }
                    if (fControlDecoration != null) {
                        fControlDecoration.dispose();
                        fControlDecoration = null;
                    }
                    if (fCachedDefaultCueImage != null) {
                        fCachedDefaultCueImage.dispose();
                        fCachedDefaultCueImage = null;
                    }
                }
            });
            fControlDecoration.setShowHover(true);
            fControlDecoration.setShowOnlyOnFocus(true);
        }
        ILabelProviderListener listener = new ILabelProviderListener() {

            @Override
            public void labelProviderChanged(LabelProviderChangedEvent event) {
                fControlDecoration.setDescriptionText(labelProvider.getText(getControl()));
                Image image = labelProvider.getImage(getControl());
                if (image == null)
                    image = getDefaultCueImage();
                fControlDecoration.setImage(image);
            }
        };
        labelProvider.addListener(listener);
        // initialize control decoration:
        listener.labelProviderChanged(new LabelProviderChangedEvent(labelProvider));
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) LabelProviderChangedEvent(org.eclipse.jface.viewers.LabelProviderChangedEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Image(org.eclipse.swt.graphics.Image)

Aggregations

LabelProviderChangedEvent (org.eclipse.jface.viewers.LabelProviderChangedEvent)2 ArrayList (java.util.ArrayList)1 IResource (org.eclipse.core.resources.IResource)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)1 IBaseLabelProvider (org.eclipse.jface.viewers.IBaseLabelProvider)1 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 Image (org.eclipse.swt.graphics.Image)1