changed isPHPIdentifierStart, isPHPIdentifierPart
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / dialog / MessageLine.java
1 package net.sourceforge.phpdt.internal.ui.dialog;
2
3 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
4
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;
12
13 /**
14  * A message line displaying a status.
15  */
16 public class MessageLine extends CLabel {
17         
18         private static final RGB ERROR_BACKGROUND_RGB = new RGB(230, 226, 221);
19         
20         private Color fNormalMsgAreaBackground;
21         private Color fErrorMsgAreaBackground;
22
23         /**
24          * Creates a new message line as a child of the given parent.
25          */
26         public MessageLine(Composite parent) {
27                 this(parent, SWT.LEFT);
28         }
29
30         /**
31          * Creates a new message line as a child of the parent and with the given SWT stylebits.
32          */
33         public MessageLine(Composite parent, int style) {
34                 super(parent, style);
35                 fNormalMsgAreaBackground= getBackground();
36                 fErrorMsgAreaBackground= null;
37         }
38
39         
40         private Image findImage(IStatus status) {
41                 if (status.isOK()) {
42                         return null;
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);
49                 }
50                 return null;
51         }
52
53         /**
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
56          */
57         public void setErrorStatus(IStatus status) {
58                 if (status != null) {
59                         String message= status.getMessage();
60                         if (message != null && message.length() > 0) {
61                                 setText(message);
62                                 setImage(findImage(status));
63                                 if (fErrorMsgAreaBackground == null) {
64                                         fErrorMsgAreaBackground= new Color(getDisplay(), ERROR_BACKGROUND_RGB);
65                                 }
66                                 setBackground(fErrorMsgAreaBackground);
67                                 return;
68                         }
69                 }               
70                 setText("");
71                 setImage(null);
72                 setBackground(fNormalMsgAreaBackground);        
73         }
74         
75         /*
76          * @see Widget#dispose()
77          */
78         public void dispose() {
79                 if (fErrorMsgAreaBackground != null) {
80                         fErrorMsgAreaBackground.dispose();
81                         fErrorMsgAreaBackground= null;
82                 }
83                 super.dispose();
84         }
85 }