allow more default parser include paths
[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 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.custom.CLabel;
13 import org.eclipse.swt.graphics.Color;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.graphics.RGB;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.ui.ISharedImages;
18 import org.eclipse.ui.PlatformUI;
19
20 /**
21  * A message line displaying a status.
22  */
23 public class MessageLine extends CLabel {
24
25         private static final RGB ERROR_BACKGROUND_RGB = new RGB(230, 226, 221);
26
27         private Color fNormalMsgAreaBackground;
28         private Color fErrorMsgAreaBackground;
29
30         /**
31          * Creates a new message line as a child of the given parent.
32          */
33         public MessageLine(Composite parent) {
34                 this(parent, SWT.LEFT);
35         }
36
37         /**
38          * Creates a new message line as a child of the parent and with the given SWT stylebits.
39          */
40         public MessageLine(Composite parent, int style) {
41                 super(parent, style);
42                 fNormalMsgAreaBackground= getBackground();
43                 fErrorMsgAreaBackground= null;
44         }
45
46
47         private Image findImage(IStatus status) {
48                 if (status.isOK()) {
49                         return null;
50                 } else if (status.matches(IStatus.ERROR)) {
51                         return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
52                 } else if (status.matches(IStatus.WARNING)) {
53                         return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
54                 } else if (status.matches(IStatus.INFO)) {
55                         return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK);
56                 }
57                 return null;
58         }
59
60         /**
61          * Sets the message and image to the given status.
62          * <code>null</code> is a valid argument and will set the empty text and no image
63          */
64         public void setErrorStatus(IStatus status) {
65                 if (status != null) {
66                         String message= status.getMessage();
67                         if (message != null && message.length() > 0) {
68                                 setText(message);
69                                 setImage(findImage(status));
70                                 if (fErrorMsgAreaBackground == null) {
71                                         fErrorMsgAreaBackground= new Color(getDisplay(), ERROR_BACKGROUND_RGB);
72                                 }
73                                 setBackground(fErrorMsgAreaBackground);
74                                 return;
75                         }
76                 }
77                 setText(""); //$NON-NLS-1$
78                 setImage(null);
79                 setBackground(fNormalMsgAreaBackground);
80         }
81
82         /*
83          * @see Widget#dispose()
84          */
85         public void dispose() {
86                 if (fErrorMsgAreaBackground != null) {
87                         fErrorMsgAreaBackground.dispose();
88                         fErrorMsgAreaBackground= null;
89                 }
90                 super.dispose();
91         }
92 }