KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > MessageLine


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.jface.resource.JFaceColors;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.custom.CLabel;
17 import org.eclipse.swt.graphics.Color;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.ui.ISharedImages;
21 import org.eclipse.ui.PlatformUI;
22
23 /**
24  * A message line displaying a status.
25  */

26 public class MessageLine extends CLabel {
27     
28     private Color fNormalMsgAreaBackground;
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     }
44
45     
46     private Image findImage(IStatus status) {
47         if (status.isOK()) {
48             return null;
49         } else if (status.matches(IStatus.ERROR)) {
50             return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
51         } else if (status.matches(IStatus.WARNING)) {
52             return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
53         } else if (status.matches(IStatus.INFO)) {
54             return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK);
55         }
56         return null;
57     }
58
59     /**
60      * Sets the message and image to the given status.
61      * <code>null</code> is a valid argument and will set the empty text and no image
62      */

63     public void setErrorStatus(IStatus status) {
64         if (status != null && !status.isOK()) {
65             String JavaDoc message= status.getMessage();
66             if (message != null && message.length() > 0) {
67                 setText(message);
68                 setImage(findImage(status));
69                 setBackground(JFaceColors.getErrorBackground(getDisplay()));
70                 return;
71             }
72         }
73         setText(""); //$NON-NLS-1$
74
setImage(null);
75         setBackground(fNormalMsgAreaBackground);
76     }
77 }
78
79
Popular Tags