1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 14 import org.eclipse.core.runtime.IStatus; 15 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.custom.CLabel; 18 import org.eclipse.swt.graphics.Color; 19 import org.eclipse.swt.graphics.Image; 20 import org.eclipse.swt.graphics.RGB; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.ui.ISharedImages; 23 import org.eclipse.ui.PlatformUI; 24 25 28 public class MessageLine extends CLabel { 29 30 private static final RGB ERROR_BACKGROUND_RGB = new RGB(230, 226, 221); 31 32 private Color fNormalMsgAreaBackground; 33 private Color fErrorMsgAreaBackground; 34 35 38 public MessageLine(Composite parent) { 39 this(parent, SWT.LEFT); 40 } 41 42 45 public MessageLine(Composite parent, int style) { 46 super(parent, style); 47 fNormalMsgAreaBackground= getBackground(); 48 fErrorMsgAreaBackground= null; 49 } 50 51 52 private Image findImage(IStatus status) { 53 if (status.isOK()) { 54 return null; 55 } else if (status.matches(IStatus.ERROR)) { 56 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); 57 } else if (status.matches(IStatus.WARNING)) { 58 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK); 59 } else if (status.matches(IStatus.INFO)) { 60 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK); 61 } 62 return null; 63 } 64 65 69 public void setErrorStatus(IStatus status) { 70 if (status != null) { 71 String message= status.getMessage(); 72 if (message != null && message.length() > 0) { 73 setText(message); 74 setImage(findImage(status)); 75 if (fErrorMsgAreaBackground == null) { 76 fErrorMsgAreaBackground= new Color(getDisplay(), ERROR_BACKGROUND_RGB); 77 } 78 setBackground(fErrorMsgAreaBackground); 79 return; 80 } 81 } 82 setText(""); setImage(null); 84 setBackground(fNormalMsgAreaBackground); 85 } 86 87 90 public void dispose() { 91 if (fErrorMsgAreaBackground != null) { 92 fErrorMsgAreaBackground.dispose(); 93 fErrorMsgAreaBackground= null; 94 } 95 super.dispose(); 96 } 97 } 98 | Popular Tags |