1 package net.sourceforge.phpdt.internal.ui.dialogs;
3 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
5 import org.eclipse.core.runtime.IStatus;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.custom.CLabel;
8 import org.eclipse.swt.graphics.Color;
9 import org.eclipse.swt.graphics.Image;
10 import org.eclipse.swt.graphics.RGB;
11 import org.eclipse.swt.widgets.Composite;
14 * A message line displaying a status.
16 public class MessageLine extends CLabel {
18 private static final RGB ERROR_BACKGROUND_RGB = new RGB(230, 226, 221);
20 private Color fNormalMsgAreaBackground;
21 private Color fErrorMsgAreaBackground;
24 * Creates a new message line as a child of the given parent.
26 public MessageLine(Composite parent) {
27 this(parent, SWT.LEFT);
31 * Creates a new message line as a child of the parent and with the given SWT stylebits.
33 public MessageLine(Composite parent, int style) {
35 fNormalMsgAreaBackground= getBackground();
36 fErrorMsgAreaBackground= null;
40 private Image findImage(IStatus status) {
43 } else if (status.matches(IStatus.ERROR)) {
44 return PHPUiImages.get(PHPUiImages.IMG_OBJS_ERROR);
45 } else if (status.matches(IStatus.WARNING)) {
46 return PHPUiImages.get(PHPUiImages.IMG_OBJS_WARNING);
47 } else if (status.matches(IStatus.INFO)) {
48 return PHPUiImages.get(PHPUiImages.IMG_OBJS_INFO);
54 * Sets the message and image to the given status.
55 * <code>null</code> is a valid argument and will set the empty text and no image
57 public void setErrorStatus(IStatus status) {
59 String message= status.getMessage();
60 if (message != null && message.length() > 0) {
62 setImage(findImage(status));
63 if (fErrorMsgAreaBackground == null) {
64 fErrorMsgAreaBackground= new Color(getDisplay(), ERROR_BACKGROUND_RGB);
66 setBackground(fErrorMsgAreaBackground);
72 setBackground(fNormalMsgAreaBackground);
76 * @see Widget#dispose()
78 public void dispose() {
79 if (fErrorMsgAreaBackground != null) {
80 fErrorMsgAreaBackground.dispose();
81 fErrorMsgAreaBackground= null;