KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.jdt.internal.ui.dialogs;
12
13 import org.eclipse.core.runtime.IStatus;
14
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
21 import org.eclipse.jface.resource.JFaceColors;
22
23 import org.eclipse.jdt.internal.ui.JavaPluginImages;
24
25 /**
26  * A message line displaying a status.
27  */

28 public class MessageLine extends CLabel {
29     
30     private Color fNormalMsgAreaBackground;
31
32     /**
33      * Creates a new message line as a child of the given parent.
34      */

35     public MessageLine(Composite parent) {
36         this(parent, SWT.LEFT);
37     }
38
39     /**
40      * Creates a new message line as a child of the parent and with the given SWT stylebits.
41      */

42     public MessageLine(Composite parent, int style) {
43         super(parent, style);
44         fNormalMsgAreaBackground= getBackground();
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 JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_ERROR);
53         } else if (status.matches(IStatus.WARNING)) {
54             return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_WARNING);
55         } else if (status.matches(IStatus.INFO)) {
56             return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_INFO);
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 && !status.isOK()) {
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
Popular Tags