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);
}
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));
}
}
Aggregations