001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.provisional.views.markers;
011:
012: import org.eclipse.core.resources.IMarker;
013: import org.eclipse.jface.dialogs.Dialog;
014: import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
015: import org.eclipse.jface.resource.ImageDescriptor;
016: import org.eclipse.jface.resource.JFaceResources;
017: import org.eclipse.jface.resource.LocalResourceManager;
018: import org.eclipse.jface.resource.ResourceManager;
019: import org.eclipse.jface.viewers.ColumnLabelProvider;
020: import org.eclipse.jface.viewers.DecorationOverlayIcon;
021: import org.eclipse.jface.viewers.IDecoration;
022: import org.eclipse.swt.graphics.Image;
023: import org.eclipse.ui.ide.IDE;
024: import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
025: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
026: import org.eclipse.ui.internal.provisional.views.markers.api.MarkerField;
027: import org.eclipse.ui.internal.provisional.views.markers.api.MarkerItem;
028:
029: /**
030: * The MarkerColumnLabelProvider is a label provider for an individual column.
031: *
032: * @since 3.4
033: *
034: */
035: public class MarkerColumnLabelProvider extends ColumnLabelProvider {
036:
037: MarkerField field;
038: private boolean showAnnotations;
039: private ResourceManager imageManager;
040:
041: /**
042: * Create a MarkerViewLabelProvider on a field.
043: *
044: * @param field
045: * @param decorate
046: * <code>true</code> if annotations are to be shown.
047: */
048: MarkerColumnLabelProvider(MarkerField field, boolean decorate) {
049: FieldDecorationRegistry.getDefault();
050: this .field = field;
051: this .showAnnotations = decorate;
052: imageManager = new LocalResourceManager(JFaceResources
053: .getResources());
054: }
055:
056: /*
057: * (non-Javadoc)
058: *
059: * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
060: */
061: public String getText(Object element) {
062: return field.getValue((MarkerItem) element);
063: }
064:
065: /*
066: * (non-Javadoc)
067: *
068: * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
069: */
070: public Image getImage(Object element) {
071:
072: // if (showAnnotations && element instanceof MarkerEntry) {
073: // MarkerItem item = (MarkerItem) element;
074: // IMarker marker = item.getMarker();
075: // if (marker != null) {
076: // String contextId = IDE.getMarkerHelpRegistry().getHelp(marker);
077: //
078: // if (contextId != null)
079: // return JFaceResources.getImage(Dialog.DLG_IMG_HELP);
080: // }
081: // }
082:
083: MarkerItem item = (MarkerItem) element;
084: Image image = field.getImage(item);
085: ImageDescriptor[] descriptors = new ImageDescriptor[5];
086: if (showAnnotations && item.isConcrete()) {
087: IMarker marker = item.getMarker();
088: // If there is no image get the full image rather than the decorated
089: // one
090: if (marker != null) {
091: String contextId = IDE.getMarkerHelpRegistry().getHelp(
092: marker);
093: if (contextId != null) {
094: if (image == null)
095: image = JFaceResources
096: .getImage(Dialog.DLG_IMG_HELP);
097: else
098: descriptors[IDecoration.TOP_RIGHT] = IDEWorkbenchPlugin
099: .getIDEImageDescriptor(MarkerSupportInternalUtilities.IMG_MARKERS_HELP_DECORATION_PATH);
100: }
101: if (IDE.getMarkerHelpRegistry().hasResolutions(marker)) {
102: if (image == null)
103: image = imageManager
104: .createImage(IDEInternalWorkbenchImages
105: .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ELCL_QUICK_FIX_ENABLED));
106: else
107: descriptors[IDecoration.BOTTOM_RIGHT] = IDEWorkbenchPlugin
108: .getIDEImageDescriptor(MarkerSupportInternalUtilities.IMG_MARKERS_QUICK_FIX_DECORATION_PATH);
109: }
110:
111: if (descriptors[IDecoration.TOP_RIGHT] != null
112: || descriptors[IDecoration.BOTTOM_RIGHT] != null)
113: image = imageManager
114: .createImage(new DecorationOverlayIcon(
115: image, descriptors));
116: }
117: }
118: return image;
119: }
120:
121: /*
122: * (non-Javadoc)
123: *
124: * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
125: */
126: public void dispose() {
127: super.dispose();
128: imageManager.dispose();
129: }
130: }
|