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;
22 private Color fErrorMsgAreaBackground;
25 * Creates a new message line as a child of the given parent.
27 public MessageLine(Composite parent) {
28 this(parent, SWT.LEFT);
32 * Creates a new message line as a child of the parent and with the given
35 public MessageLine(Composite parent, int style) {
37 fNormalMsgAreaBackground = getBackground();
38 fErrorMsgAreaBackground = null;
41 private Image findImage(IStatus status) {
44 } else if (status.matches(IStatus.ERROR)) {
45 return PHPUiImages.get(PHPUiImages.IMG_OBJS_ERROR);
46 } else if (status.matches(IStatus.WARNING)) {
47 return PHPUiImages.get(PHPUiImages.IMG_OBJS_WARNING);
48 } else if (status.matches(IStatus.INFO)) {
49 return PHPUiImages.get(PHPUiImages.IMG_OBJS_INFO);
55 * Sets the message and image to the given status. <code>null</code> is a
56 * valid argument and will set the empty text and no image
58 public void setErrorStatus(IStatus status) {
60 String message = status.getMessage();
61 if (message != null && message.length() > 0) {
63 setImage(findImage(status));
64 if (fErrorMsgAreaBackground == null) {
65 fErrorMsgAreaBackground = new Color(getDisplay(),
66 ERROR_BACKGROUND_RGB);
68 setBackground(fErrorMsgAreaBackground);
74 setBackground(fNormalMsgAreaBackground);
78 * @see Widget#dispose()
80 public void dispose() {
81 if (fErrorMsgAreaBackground != null) {
82 fErrorMsgAreaBackground.dispose();
83 fErrorMsgAreaBackground = null;