1 11 package org.eclipse.pde.internal.ui.parts; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.pde.internal.ui.PDELabelProvider; 15 import org.eclipse.pde.internal.ui.PDEPlugin; 16 import org.eclipse.pde.internal.ui.PDEPluginImages; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.custom.CLabel; 19 import org.eclipse.swt.graphics.Color; 20 import org.eclipse.swt.graphics.Image; 21 import org.eclipse.swt.graphics.RGB; 22 import org.eclipse.swt.widgets.Composite; 23 24 27 public class MessageLine extends CLabel { 28 29 private static final RGB ERROR_BACKGROUND_RGB = new RGB(230, 226, 221); 30 31 private Color fNormalMsgAreaBackground; 32 private Color fErrorMsgAreaBackground; 33 34 37 public MessageLine(Composite parent) { 38 this(parent, SWT.LEFT); 39 } 40 41 44 public MessageLine(Composite parent, int style) { 45 super(parent, style); 46 fNormalMsgAreaBackground= getBackground(); 47 fErrorMsgAreaBackground= null; 48 } 49 50 51 private Image findImage(IStatus status) { 52 PDELabelProvider provider = PDEPlugin.getDefault().getLabelProvider(); 53 if (status.isOK()) { 54 return null; 55 } else if (status.matches(IStatus.ERROR)) { 56 return provider.get(PDEPluginImages.DESC_ERROR_ST_OBJ); 57 } else if (status.matches(IStatus.WARNING)) { 58 return provider.get(PDEPluginImages.DESC_WARNING_ST_OBJ); 59 } else if (status.matches(IStatus.INFO)) { 60 return provider.get(PDEPluginImages.DESC_INFO_ST_OBJ); 61 } 62 return null; 63 } 64 65 69 public void setErrorStatus(IStatus status) { 70 if (status != null) { 71 String message= status.getMessage(); 72 if (message != null && message.length() > 0) { 73 setText(message); 74 setImage(findImage(status)); 75 if (fErrorMsgAreaBackground == null) { 76 fErrorMsgAreaBackground= new Color(getDisplay(), ERROR_BACKGROUND_RGB); 77 } 78 setBackground(fErrorMsgAreaBackground); 79 return; 80 } 81 } 82 setText(""); setImage(null); 84 setBackground(fNormalMsgAreaBackground); 85 } 86 87 90 public void dispose() { 91 if (fErrorMsgAreaBackground != null) { 92 fErrorMsgAreaBackground.dispose(); 93 fErrorMsgAreaBackground= null; 94 } 95 super.dispose(); 96 } 97 } 98 99 | Popular Tags |