01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.texteditor.templates;
11:
12: import org.eclipse.core.runtime.IStatus;
13:
14: import org.eclipse.swt.SWT;
15: import org.eclipse.swt.custom.CLabel;
16: import org.eclipse.swt.graphics.Color;
17: import org.eclipse.swt.graphics.Image;
18: import org.eclipse.swt.widgets.Composite;
19:
20: import org.eclipse.jface.resource.JFaceColors;
21:
22: /**
23: * A message line displaying a status.
24: *
25: * @since 3.0
26: */
27: class MessageLine extends CLabel {
28:
29: private Color fNormalMsgAreaBackground;
30:
31: /**
32: * Creates a new message line as a child of the given parent.
33: *
34: * @param parent the parent composite
35: */
36: public MessageLine(Composite parent) {
37: this (parent, SWT.LEFT);
38: }
39:
40: /**
41: * Creates a new message line as a child of the parent and with the given SWT style bits.
42: *
43: * @param parent the parent composite
44: * @param style the style
45: */
46: public MessageLine(Composite parent, int style) {
47: super (parent, style);
48: fNormalMsgAreaBackground = getBackground();
49: }
50:
51: private Image findImage(IStatus status) {
52: if (status.isOK()) {
53: return null;
54: }
55: return null;
56: }
57:
58: /**
59: * Sets the message and image to the given status.
60: * <code>null</code> is a valid argument and will set the empty text and no image
61: *
62: * @param status the status
63: */
64: public void setErrorStatus(IStatus status) {
65: if (status != null && !status.isOK()) {
66: String message = status.getMessage();
67: if (message != null && message.length() > 0) {
68: setText(message);
69: setImage(findImage(status));
70: setBackground(JFaceColors
71: .getErrorBackground(getDisplay()));
72: return;
73: }
74: }
75: setText(""); //$NON-NLS-1$
76: setImage(null);
77: setBackground(fNormalMsgAreaBackground);
78: }
79: }
|