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