KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.internal;
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 = null;
43     }
44
45     private Image findImage(IStatus status) {
46         if (status.isOK()) {
47             return null;
48         } else if (status.matches(IStatus.ERROR)) {
49             return PlatformUI.getWorkbench().getSharedImages().getImage(
50                     ISharedImages.IMG_OBJS_ERROR_TSK);
51         } else if (status.matches(IStatus.WARNING)) {
52             return PlatformUI.getWorkbench().getSharedImages().getImage(
53                     ISharedImages.IMG_OBJS_WARN_TSK);
54         } else if (status.matches(IStatus.INFO)) {
55             return PlatformUI.getWorkbench().getSharedImages().getImage(
56                     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 JavaDoc message = status.getMessage();
68             if (message != null && message.length() > 0) {
69                 setText(message);
70                 setImage(findImage(status));
71                 setBackground(JFaceColors.getErrorBackground(getDisplay()));
72                 return;
73             }
74         }
75         setText(""); //$NON-NLS-1$
76
setImage(null);
77         setBackground(fNormalMsgAreaBackground);
78     }
79
80 }
81
82
Popular Tags