Addition of previous bugfix. Added project based path to search-path.
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / 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
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
40          * SWT stylebits.
41          */
42         public MessageLine(Composite parent, int style) {
43                 super(parent, style);
44                 fNormalMsgAreaBackground = getBackground();
45                 fErrorMsgAreaBackground = null;
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(
53                                         ISharedImages.IMG_OBJS_ERROR_TSK);
54                 } else if (status.matches(IStatus.WARNING)) {
55                         return PlatformUI.getWorkbench().getSharedImages().getImage(
56                                         ISharedImages.IMG_OBJS_WARN_TSK);
57                 } else if (status.matches(IStatus.INFO)) {
58                         return PlatformUI.getWorkbench().getSharedImages().getImage(
59                                         ISharedImages.IMG_OBJS_INFO_TSK);
60                 }
61                 return null;
62         }
63
64         /**
65          * Sets the message and image to the given status. <code>null</code> is a
66          * valid argument and will set the empty text and no image
67          */
68         public void setErrorStatus(IStatus status) {
69                 if (status != null) {
70                         String message = status.getMessage();
71                         if (message != null && message.length() > 0) {
72                                 setText(message);
73                                 setImage(findImage(status));
74                                 if (fErrorMsgAreaBackground == null) {
75                                         fErrorMsgAreaBackground = new Color(getDisplay(),
76                                                         ERROR_BACKGROUND_RGB);
77                                 }
78                                 setBackground(fErrorMsgAreaBackground);
79                                 return;
80                         }
81                 }
82                 setText(""); //$NON-NLS-1$
83                 setImage(null);
84                 setBackground(fNormalMsgAreaBackground);
85         }
86
87         /*
88          * @see Widget#dispose()
89          */
90         public void dispose() {
91                 if (fErrorMsgAreaBackground != null) {
92                         fErrorMsgAreaBackground.dispose();
93                         fErrorMsgAreaBackground = null;
94                 }
95                 super.dispose();
96         }
97 }