1 package net.sourceforge.phpdt.internal.ui.dialog;
3 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
4 import org.eclipse.core.runtime.IStatus;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.custom.CLabel;
7 import org.eclipse.swt.graphics.Color;
8 import org.eclipse.swt.graphics.Image;
9 import org.eclipse.swt.graphics.RGB;
10 import org.eclipse.swt.widgets.Composite;
13 * A message line displaying a status.
15 public class MessageLine extends CLabel {
17 private static final RGB ERROR_BACKGROUND_RGB = new RGB(230, 226, 221);
19 private Color fNormalMsgAreaBackground;
20 private Color fErrorMsgAreaBackground;
23 * Creates a new message line as a child of the given parent.
25 public MessageLine(Composite parent) {
26 this(parent, SWT.LEFT);
30 * Creates a new message line as a child of the parent and with the given SWT stylebits.
32 public MessageLine(Composite parent, int style) {
34 fNormalMsgAreaBackground= getBackground();
35 fErrorMsgAreaBackground= null;
39 private Image findImage(IStatus status) {
42 } else if (status.matches(IStatus.ERROR)) {
43 return PHPUiImages.get(PHPUiImages.IMG_OBJS_ERROR);
44 } else if (status.matches(IStatus.WARNING)) {
45 return PHPUiImages.get(PHPUiImages.IMG_OBJS_WARNING);
46 } else if (status.matches(IStatus.INFO)) {
47 return PHPUiImages.get(PHPUiImages.IMG_OBJS_INFO);
53 * Sets the message and image to the given status.
54 * <code>null</code> is a valid argument and will set the empty text and no image
56 public void setErrorStatus(IStatus status) {
58 String message= status.getMessage();
59 if (message != null && message.length() > 0) {
61 setImage(findImage(status));
62 if (fErrorMsgAreaBackground == null) {
63 fErrorMsgAreaBackground= new Color(getDisplay(), ERROR_BACKGROUND_RGB);
65 setBackground(fErrorMsgAreaBackground);
71 setBackground(fNormalMsgAreaBackground);
75 * @see Widget#dispose()
77 public void dispose() {
78 if (fErrorMsgAreaBackground != null) {
79 fErrorMsgAreaBackground.dispose();
80 fErrorMsgAreaBackground= null;