01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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.internal;
11:
12: import org.eclipse.core.runtime.IStatus;
13: import org.eclipse.jface.resource.JFaceColors;
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: import org.eclipse.ui.ISharedImages;
20: import org.eclipse.ui.PlatformUI;
21:
22: /**
23: * A message line displaying a status.
24: */
25: public class MessageLine extends CLabel {
26:
27: private Color fNormalMsgAreaBackground;
28:
29: /**
30: * Creates a new message line as a child of the given parent.
31: */
32: public MessageLine(Composite parent) {
33: this (parent, SWT.LEFT);
34: }
35:
36: /**
37: * Creates a new message line as a child of the parent and with the given SWT stylebits.
38: */
39: public MessageLine(Composite parent, int style) {
40: super (parent, style);
41: fNormalMsgAreaBackground = null;
42: }
43:
44: private Image findImage(IStatus status) {
45: if (status.isOK()) {
46: return null;
47: } else if (status.matches(IStatus.ERROR)) {
48: return PlatformUI.getWorkbench().getSharedImages()
49: .getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
50: } else if (status.matches(IStatus.WARNING)) {
51: return PlatformUI.getWorkbench().getSharedImages()
52: .getImage(ISharedImages.IMG_OBJS_WARN_TSK);
53: } else if (status.matches(IStatus.INFO)) {
54: return PlatformUI.getWorkbench().getSharedImages()
55: .getImage(ISharedImages.IMG_OBJS_INFO_TSK);
56: }
57: return null;
58: }
59:
60: /**
61: * Sets the message and image to the given status.
62: * <code>null</code> is a valid argument and will set the empty text and no image
63: */
64: public void setErrorStatus(IStatus status) {
65: if (status != null) {
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:
80: }
|