1 11 package org.eclipse.pde.internal.runtime.logview; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.jface.viewers.ITableLabelProvider; 17 import org.eclipse.jface.viewers.LabelProvider; 18 import org.eclipse.pde.internal.runtime.PDERuntimeMessages; 19 import org.eclipse.pde.internal.runtime.PDERuntimePluginImages; 20 import org.eclipse.swt.graphics.Image; 21 22 import com.ibm.icu.text.DateFormat; 23 import com.ibm.icu.text.SimpleDateFormat; 24 25 public class LogViewLabelProvider 26 extends LabelProvider 27 implements ITableLabelProvider { 28 29 private static int MAX_LABEL_LENGTH = 200; 30 31 private Image infoImage; 32 private Image okImage; 33 private Image errorImage; 34 private Image warningImage; 35 private Image errorWithStackImage; 36 ArrayList consumers = new ArrayList (); 37 38 public LogViewLabelProvider() { 39 errorImage = PDERuntimePluginImages.DESC_ERROR_ST_OBJ.createImage(); 40 warningImage = PDERuntimePluginImages.DESC_WARNING_ST_OBJ.createImage(); 41 infoImage = PDERuntimePluginImages.DESC_INFO_ST_OBJ.createImage(); 42 okImage = PDERuntimePluginImages.DESC_OK_ST_OBJ.createImage(); 43 errorWithStackImage = PDERuntimePluginImages.DESC_ERROR_STACK_OBJ.createImage(); 44 } 45 public void dispose() { 46 if (consumers.size() == 0){ 47 errorImage.dispose(); 48 infoImage.dispose(); 49 okImage.dispose(); 50 warningImage.dispose(); 51 errorWithStackImage.dispose(); 52 super.dispose(); 53 } 54 } 55 public Image getColumnImage(Object element, int columnIndex) { 56 LogEntry entry = (LogEntry) element; 57 if (columnIndex == 0) { 58 switch (entry.getSeverity()) { 59 case IStatus.INFO : 60 return infoImage; 61 case IStatus.OK : 62 return okImage; 63 case IStatus.WARNING : 64 return warningImage; 65 default : 66 return (entry.getStack() == null ? errorImage : errorWithStackImage); 67 } 68 } 69 return null; 70 } 71 72 public String getColumnText(Object element, int columnIndex) { 73 LogEntry entry = (LogEntry) element; 74 switch (columnIndex) { 75 case 0: 76 if (entry.getMessage() != null) { 77 String message = entry.getMessage(); 78 if (message.length() > MAX_LABEL_LENGTH) { 79 String warning = PDERuntimeMessages.LogViewLabelProvider_truncatedMessage; 80 StringBuffer sb = new StringBuffer (message.substring(0, MAX_LABEL_LENGTH - warning.length())); 81 sb.append(warning); 82 return sb.toString(); 83 } 84 return entry.getMessage(); 85 } 86 case 1: 87 if (entry.getPluginId() != null) 88 return entry.getPluginId(); 89 case 2: 90 if (entry.getDate() != null) { 91 DateFormat formatter = new SimpleDateFormat(LogEntry.F_DATE_FORMAT); 92 return formatter.format(entry.getDate()); 93 } 94 } 95 return ""; } 97 98 public void connect(Object consumer) { 99 if (!consumers.contains(consumer)) 100 consumers.add(consumer); 101 } 102 103 public void disconnect(Object consumer) { 104 consumers.remove(consumer); 105 if (consumers.size() == 0) { 106 dispose(); 107 } 108 } 109 } 110 | Popular Tags |