Fixed a bug in the String regex
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / externaltools / internal / ui / MessageLine.java
1 package net.sourceforge.phpdt.externaltools.internal.ui;
2
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp.  All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
8 **********************************************************************/
9
10 import org.eclipse.core.runtime.IStatus;
11
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.custom.CLabel;
14 import org.eclipse.swt.graphics.Color;
15 import org.eclipse.swt.graphics.Image;
16 import org.eclipse.swt.graphics.RGB;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.ui.ISharedImages;
19 import org.eclipse.ui.PlatformUI;
20
21 /**
22  * A message line displaying a status.
23  */
24 public class MessageLine extends CLabel {
25
26         private static final RGB ERROR_BACKGROUND_RGB = new RGB(230, 226, 221);
27
28         private Color fNormalMsgAreaBackground;
29         private Color fErrorMsgAreaBackground;
30
31         /**
32          * Creates a new message line as a child of the given parent.
33          */
34         public MessageLine(Composite parent) {
35                 this(parent, SWT.LEFT);
36         }
37
38         /**
39          * Creates a new message line as a child of the parent and with the given SWT stylebits.
40          */
41         public MessageLine(Composite parent, int style) {
42                 super(parent, style);
43                 fNormalMsgAreaBackground= getBackground();
44                 fErrorMsgAreaBackground= null;
45         }
46
47
48         private Image findImage(IStatus status) {
49                 if (status.isOK()) {
50                         return null;
51                 } else if (status.matches(IStatus.ERROR)) {
52                         return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
53                 } else if (status.matches(IStatus.WARNING)) {
54                         return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
55                 } else if (status.matches(IStatus.INFO)) {
56                         return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK);
57                 }
58                 return null;
59         }
60
61         /**
62          * Sets the message and image to the given status.
63          * <code>null</code> is a valid argument and will set the empty text and no image
64          */
65         public void setErrorStatus(IStatus status) {
66                 if (status != null) {
67                         String message= status.getMessage();
68                         if (message != null && message.length() > 0) {
69                                 setText(message);
70                                 setImage(findImage(status));
71                                 if (fErrorMsgAreaBackground == null) {
72                                         fErrorMsgAreaBackground= new Color(getDisplay(), ERROR_BACKGROUND_RGB);
73                                 }
74                                 setBackground(fErrorMsgAreaBackground);
75                                 return;
76                         }
77                 }
78                 setText(""); //$NON-NLS-1$
79                 setImage(null);
80                 setBackground(fNormalMsgAreaBackground);
81         }
82
83         /*
84          * @see Widget#dispose()
85          */
86         public void dispose() {
87                 if (fErrorMsgAreaBackground != null) {
88                         fErrorMsgAreaBackground.dispose();
89                         fErrorMsgAreaBackground= null;
90                 }
91                 super.dispose();
92         }
93 }