1 11 package org.eclipse.jface.dialogs; 12 13 import org.eclipse.jface.resource.JFaceResources; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.custom.CLabel; 16 import org.eclipse.swt.graphics.Image; 17 import org.eclipse.swt.layout.GridData; 18 import org.eclipse.swt.layout.GridLayout; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Label; 21 import org.eclipse.swt.widgets.Text; 22 23 33 public class DialogMessageArea extends Object { 34 private Text messageText; 35 36 private Label messageImageLabel; 37 38 private Composite messageComposite; 39 40 private String lastMessageText; 41 42 private int lastMessageType; 43 44 private CLabel titleLabel; 45 46 49 public DialogMessageArea() { 50 } 52 53 59 public void createContents(Composite parent) { 60 61 titleLabel = new CLabel(parent, SWT.NONE); 63 titleLabel.setFont(JFaceResources.getBannerFont()); 64 messageComposite = new Composite(parent, SWT.NONE); 65 GridLayout messageLayout = new GridLayout(); 66 messageLayout.numColumns = 2; 67 messageLayout.marginWidth = 0; 68 messageLayout.marginHeight = 0; 69 messageLayout.makeColumnsEqualWidth = false; 70 messageComposite.setLayout(messageLayout); 71 messageImageLabel = new Label(messageComposite, SWT.NONE); 72 messageImageLabel.setImage(JFaceResources 73 .getImage(Dialog.DLG_IMG_MESSAGE_INFO)); 74 messageImageLabel.setLayoutData(new GridData( 75 GridData.VERTICAL_ALIGN_CENTER)); 76 77 messageText = new Text(messageComposite, SWT.NONE); 78 messageText.setEditable(false); 79 80 GridData textData = new GridData(GridData.GRAB_HORIZONTAL 81 | GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER); 82 messageText.setLayoutData(textData); 83 84 } 85 86 94 public void setTitleLayoutData(Object layoutData) { 95 titleLabel.setLayoutData(layoutData); 96 } 97 98 106 public void setMessageLayoutData(Object layoutData) { 107 messageComposite.setLayoutData(layoutData); 108 } 109 110 118 public void showTitle(String titleMessage, Image titleImage) { 119 titleLabel.setImage(titleImage); 120 titleLabel.setText(titleMessage); 121 restoreTitle(); 122 return; 123 } 124 125 128 public void restoreTitle() { 129 titleLabel.setVisible(true); 130 messageComposite.setVisible(false); 131 lastMessageText = null; 132 lastMessageType = IMessageProvider.NONE; 133 } 134 135 146 public void updateText(String newMessage, int newType) { 147 Image newImage = null; 148 switch (newType) { 149 case IMessageProvider.NONE: 150 if (newMessage == null) { 151 restoreTitle(); 152 } else { 153 showTitle(newMessage, null); 154 } 155 return; 156 case IMessageProvider.INFORMATION: 157 newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO); 158 break; 159 case IMessageProvider.WARNING: 160 newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING); 161 break; 162 case IMessageProvider.ERROR: 163 newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR); 164 165 break; 166 } 167 messageComposite.setVisible(true); 168 titleLabel.setVisible(false); 169 String shortText = Dialog.shortenText(newMessage,messageText); 174 if (newMessage.equals(messageText.getToolTipText()) 175 && newImage == messageImageLabel.getImage() 176 && shortText.equals(messageText.getText())) { 177 return; 178 } 179 messageImageLabel.setImage(newImage); 180 messageText.setText(Dialog.shortenText(newMessage,messageText)); 181 messageText.setToolTipText(newMessage); 182 lastMessageText = newMessage; 183 184 } 185 186 187 192 public void clearErrorMessage() { 193 if (lastMessageText == null) { 194 restoreTitle(); 195 } else { 196 updateText(lastMessageText, lastMessageType); 197 } 198 } 199 } 200 | Popular Tags |