001: /*******************************************************************************
002: * Copyright (c) 2000, 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.pde.internal.runtime.logview;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.jface.viewers.ITableLabelProvider;
016: import org.eclipse.jface.viewers.LabelProvider;
017: import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
018: import org.eclipse.pde.internal.runtime.PDERuntimePluginImages;
019: import org.eclipse.swt.graphics.Image;
020:
021: import com.ibm.icu.text.DateFormat;
022: import com.ibm.icu.text.SimpleDateFormat;
023:
024: public class LogViewLabelProvider extends LabelProvider implements
025: ITableLabelProvider {
026:
027: private static int MAX_LABEL_LENGTH = 200;
028:
029: private Image infoImage;
030: private Image okImage;
031: private Image errorImage;
032: private Image warningImage;
033: private Image errorWithStackImage;
034: ArrayList consumers = new ArrayList();
035:
036: public LogViewLabelProvider() {
037: errorImage = PDERuntimePluginImages.DESC_ERROR_ST_OBJ
038: .createImage();
039: warningImage = PDERuntimePluginImages.DESC_WARNING_ST_OBJ
040: .createImage();
041: infoImage = PDERuntimePluginImages.DESC_INFO_ST_OBJ
042: .createImage();
043: okImage = PDERuntimePluginImages.DESC_OK_ST_OBJ.createImage();
044: errorWithStackImage = PDERuntimePluginImages.DESC_ERROR_STACK_OBJ
045: .createImage();
046: }
047:
048: public void dispose() {
049: if (consumers.size() == 0) {
050: errorImage.dispose();
051: infoImage.dispose();
052: okImage.dispose();
053: warningImage.dispose();
054: errorWithStackImage.dispose();
055: super .dispose();
056: }
057: }
058:
059: public Image getColumnImage(Object element, int columnIndex) {
060: LogEntry entry = (LogEntry) element;
061: if (columnIndex == 0) {
062: switch (entry.getSeverity()) {
063: case IStatus.INFO:
064: return infoImage;
065: case IStatus.OK:
066: return okImage;
067: case IStatus.WARNING:
068: return warningImage;
069: default:
070: return (entry.getStack() == null ? errorImage
071: : errorWithStackImage);
072: }
073: }
074: return null;
075: }
076:
077: public String getColumnText(Object element, int columnIndex) {
078: LogEntry entry = (LogEntry) element;
079: switch (columnIndex) {
080: case 0:
081: if (entry.getMessage() != null) {
082: String message = entry.getMessage();
083: if (message.length() > MAX_LABEL_LENGTH) {
084: String warning = PDERuntimeMessages.LogViewLabelProvider_truncatedMessage;
085: StringBuffer sb = new StringBuffer(message
086: .substring(0, MAX_LABEL_LENGTH
087: - warning.length()));
088: sb.append(warning);
089: return sb.toString();
090: }
091: return entry.getMessage();
092: }
093: case 1:
094: if (entry.getPluginId() != null)
095: return entry.getPluginId();
096: case 2:
097: if (entry.getDate() != null) {
098: DateFormat formatter = new SimpleDateFormat(
099: LogEntry.F_DATE_FORMAT);
100: return formatter.format(entry.getDate());
101: }
102: }
103: return ""; //$NON-NLS-1$
104: }
105:
106: public void connect(Object consumer) {
107: if (!consumers.contains(consumer))
108: consumers.add(consumer);
109: }
110:
111: public void disconnect(Object consumer) {
112: consumers.remove(consumer);
113: if (consumers.size() == 0) {
114: dispose();
115: }
116: }
117: }
|