KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > templates > 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.ui.texteditor.templates;
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
24 /**
25  * A message line displaying a status.
26  *
27  * @since 3.0
28  */

29 class MessageLine extends CLabel {
30
31     private Color fNormalMsgAreaBackground;
32
33     /**
34      * Creates a new message line as a child of the given parent.
35      *
36      * @param parent the parent composite
37      */

38     public MessageLine(Composite parent) {
39         this(parent, SWT.LEFT);
40     }
41
42     /**
43      * Creates a new message line as a child of the parent and with the given SWT style bits.
44      *
45      * @param parent the parent composite
46      * @param style the style
47      */

48     public MessageLine(Composite parent, int style) {
49         super(parent, style);
50         fNormalMsgAreaBackground= getBackground();
51     }
52
53
54     private Image findImage(IStatus status) {
55         if (status.isOK()) {
56             return null;
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      * @param status the status
66      */

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