001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.views.markers.internal;
011:
012: import org.eclipse.jface.resource.DeviceResourceException;
013: import org.eclipse.jface.resource.JFaceResources;
014: import org.eclipse.swt.graphics.Image;
015: import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
016:
017: /**
018: * The FieldSeverityAndMessage is the field that
019: * displays severities and messages.
020: *
021: */
022: public class FieldSeverityAndMessage extends FieldMessage {
023:
024: private String description;
025:
026: /**
027: * Create a new instance of the receiver.
028: */
029: public FieldSeverityAndMessage() {
030: description = MarkerMessages.problemSeverity_description;
031: }
032:
033: /*
034: * (non-Javadoc)
035: *
036: * @see org.eclipse.ui.views.markers.internal.IField#getDescription()
037: */
038: public String getDescription() {
039: return description;
040: }
041:
042: /*
043: * (non-Javadoc)
044: *
045: * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
046: */
047: public Image getImage(Object obj) {
048: if (obj == null || !(obj instanceof MarkerNode)) {
049: return null;
050: }
051:
052: MarkerNode node = (MarkerNode) obj;
053: if (node.isConcrete()) {
054: if (node instanceof ProblemMarker) {
055: return Util.getImage(((ProblemMarker) obj)
056: .getSeverity());
057: }
058: return null;
059: }
060:
061: try {
062: return JFaceResources
063: .getResources()
064: .createImageWithDefault(
065: IDEInternalWorkbenchImages
066: .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_PROBLEM_CATEGORY));
067: } catch (DeviceResourceException e) {
068: return null;
069: }
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object,
076: * java.lang.Object)
077: */
078: public int compare(Object obj1, Object obj2) {
079: if (obj1 == null || obj2 == null
080: || !(obj1 instanceof ProblemMarker)
081: || !(obj2 instanceof ProblemMarker)) {
082: return 0;
083: }
084:
085: ProblemMarker marker1 = (ProblemMarker) obj1;
086: ProblemMarker marker2 = (ProblemMarker) obj2;
087:
088: int severity1 = marker1.getSeverity();
089: int severity2 = marker2.getSeverity();
090: if (severity1 == severity2)
091: return marker1.getDescriptionKey().compareTo(
092: marker2.getDescriptionKey());
093: return severity2 - severity1;
094: }
095:
096: /*
097: * (non-Javadoc)
098: *
099: * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderImage()
100: */
101: public Image getColumnHeaderImage() {
102: return getImage(FieldDone.DESCRIPTION_IMAGE_PATH);
103: }
104:
105: }
|