1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.jface.resource.JFaceColors; 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.custom.CLabel; 17 import org.eclipse.swt.graphics.Color; 18 import org.eclipse.swt.graphics.Image; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.ui.ISharedImages; 21 import org.eclipse.ui.PlatformUI; 22 23 26 public class MessageLine extends CLabel { 27 28 private Color fNormalMsgAreaBackground; 29 30 33 public MessageLine(Composite parent) { 34 this(parent, SWT.LEFT); 35 } 36 37 40 public MessageLine(Composite parent, int style) { 41 super(parent, style); 42 fNormalMsgAreaBackground = null; 43 } 44 45 private Image findImage(IStatus status) { 46 if (status.isOK()) { 47 return null; 48 } else if (status.matches(IStatus.ERROR)) { 49 return PlatformUI.getWorkbench().getSharedImages().getImage( 50 ISharedImages.IMG_OBJS_ERROR_TSK); 51 } else if (status.matches(IStatus.WARNING)) { 52 return PlatformUI.getWorkbench().getSharedImages().getImage( 53 ISharedImages.IMG_OBJS_WARN_TSK); 54 } else if (status.matches(IStatus.INFO)) { 55 return PlatformUI.getWorkbench().getSharedImages().getImage( 56 ISharedImages.IMG_OBJS_INFO_TSK); 57 } 58 return null; 59 } 60 61 65 public void setErrorStatus(IStatus status) { 66 if (status != null) { 67 String message = status.getMessage(); 68 if (message != null && message.length() > 0) { 69 setText(message); 70 setImage(findImage(status)); 71 setBackground(JFaceColors.getErrorBackground(getDisplay())); 72 return; 73 } 74 } 75 setText(""); setImage(null); 77 setBackground(fNormalMsgAreaBackground); 78 } 79 80 } 81 82 | Popular Tags |