1 11 package org.eclipse.debug.internal.ui.viewers.model; 12 13 import org.eclipse.debug.internal.core.commands.Request; 14 import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; 15 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.jface.viewers.TreePath; 18 import org.eclipse.swt.graphics.Color; 19 import org.eclipse.swt.graphics.Font; 20 import org.eclipse.swt.graphics.FontData; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.graphics.RGB; 23 import org.eclipse.swt.widgets.TreeItem; 24 25 28 class LabelUpdate extends Request implements ILabelUpdate { 29 30 private TreePath fElementPath; 31 private String [] fColumnIds; 32 private RGB[] fBackgrounds; 33 private RGB[] fForegrounds; 34 private ImageDescriptor[] fImageDescriptors; 35 private String [] fLabels; 36 private FontData[] fFontDatas; 37 private TreeModelLabelProvider fProvider; 38 private TreeItem fItem; 39 private int fNumColumns; 40 private IPresentationContext fContext; 41 42 46 static String PREV_LABEL_KEY = "PREV_LABEL_KEY"; static String PREV_IMAGE_KEY = "PREV_IMAGE_KEY"; static String PREV_FONT_KEY = "PREV_FONT_KEY"; static String PREV_FOREGROUND_KEY = "PREV_FOREGROUND_KEY"; static String PREV_BACKGROUND_KEY = "PREV_BACKGROUND_KEY"; 52 59 public LabelUpdate(TreePath elementPath, TreeItem item, TreeModelLabelProvider provider, String [] columnIds, IPresentationContext context) { 60 fContext = context; 61 fElementPath = elementPath; 62 fProvider = provider; 63 fColumnIds = columnIds; 64 fItem = item; 65 fNumColumns = 1; 66 if (columnIds != null) { 67 fNumColumns = columnIds.length; 68 } 69 fLabels = new String [fNumColumns]; 70 fProvider.updateStarted(this); 71 } 72 73 76 public String [] getColumnIds() { 77 return fColumnIds; 78 } 79 80 83 public TreePath getElementPath() { 84 return fElementPath; 85 } 86 87 90 public void setBackground(RGB background, int columnIndex) { 91 if (background == null) { 92 return; 93 } 94 if (fBackgrounds == null) { 95 fBackgrounds = new RGB[fNumColumns]; 96 } 97 fBackgrounds[columnIndex] = background; 98 } 99 100 103 public void setFontData(FontData fontData, int columnIndex) { 104 if (fontData == null) { 105 return; 106 } 107 if (fFontDatas == null) { 108 fFontDatas = new FontData[fNumColumns]; 109 } 110 fFontDatas[columnIndex] = fontData; 111 } 112 113 116 public void setForeground(RGB foreground, int columnIndex) { 117 if (foreground == null) { 118 return; 119 } 120 if (fForegrounds == null) { 121 fForegrounds = new RGB[fNumColumns]; 122 } 123 fForegrounds[columnIndex] = foreground; 124 } 125 126 129 public void setImageDescriptor(ImageDescriptor image, int columnIndex) { 130 if (image == null) { 131 return; 132 } 133 if (fImageDescriptors == null) { 134 fImageDescriptors = new ImageDescriptor[fNumColumns]; 135 } 136 fImageDescriptors[columnIndex] = image; 137 } 138 139 142 public void setLabel(String text, int columnIndex) { 143 fLabels[columnIndex] = text; 144 } 145 146 149 public IPresentationContext getPresentationContext() { 150 return fContext; 151 } 152 153 156 public void done() { 157 fProvider.complete(this); 158 } 159 160 163 public void update() { 164 if (!fItem.isDisposed()) { 166 167 for (int i=0; i<fNumColumns; i++){ 168 fItem.setText(i,(fLabels[i] == null ? "" : fLabels[i])); } 171 fItem.setData(PREV_LABEL_KEY, fLabels); 172 173 if (fImageDescriptors == null) { 174 for (int i=0; i<fNumColumns; i++){ 175 fItem.setImage(i,null); 176 } 177 fItem.setData(PREV_IMAGE_KEY, null); 178 } else { 179 Image[] images = new Image[fImageDescriptors.length]; 180 for (int i = 0; i < fImageDescriptors.length; i++) { 181 images[i] = fProvider.getImage(fImageDescriptors[i]); 182 } 183 if (fColumnIds == null) { 184 fItem.setImage(images[0]); 185 } else { 186 fItem.setImage(images); 187 } 188 fItem.setData(PREV_IMAGE_KEY, images); 189 } 190 191 if (fForegrounds == null) { 192 for (int i=0; i<fNumColumns; i++){ 193 fItem.setForeground(i,null); 194 } 195 fItem.setData(PREV_FOREGROUND_KEY, null); 196 } else { 197 Color[] foregrounds = new Color[fForegrounds.length]; 198 for (int i = 0; i< foregrounds.length; i++) { 199 foregrounds[i] = fProvider.getColor(fForegrounds[i]); 200 } 201 if (fColumnIds == null) { 202 fItem.setForeground(0,foregrounds[0]); 203 } else { 204 for (int i = 0; i< foregrounds.length; i++) { 205 fItem.setForeground(i, foregrounds[i]); 206 } 207 } 208 fItem.setData(PREV_FOREGROUND_KEY, foregrounds); 209 } 210 211 if (fBackgrounds == null) { 212 for (int i=0; i<fNumColumns; i++){ 213 fItem.setBackground(i,null); 214 } 215 fItem.setData(PREV_BACKGROUND_KEY, null); 216 } else { 217 Color[] backgrounds = new Color[fBackgrounds.length]; 218 for (int i = 0; i< backgrounds.length; i++) { 219 backgrounds[i] = fProvider.getColor(fBackgrounds[i]); 220 } 221 if (fColumnIds == null) { 222 fItem.setBackground(0,backgrounds[0]); 223 } else { 224 for (int i = 0; i< backgrounds.length; i++) { 225 fItem.setBackground(i, backgrounds[i]); 226 } 227 } 228 fItem.setData(PREV_BACKGROUND_KEY, backgrounds); 229 } 230 231 if (fFontDatas == null) { 232 for (int i=0; i<fNumColumns; i++){ 233 fItem.setFont(i,null); 234 } 235 fItem.setData(PREV_FONT_KEY, null); 236 } else { 237 Font[] fonts = new Font[fFontDatas.length]; 238 for (int i = 0; i < fFontDatas.length; i++) { 239 fonts[i] = fProvider.getFont(fFontDatas[i]); 240 } 241 if (fColumnIds == null) { 242 fItem.setFont(0,fonts[0]); 243 } else { 244 for (int i = 0; i < fonts.length; i++) { 245 fItem.setFont(i, fonts[i]); 246 } 247 } 248 fItem.setData(PREV_FONT_KEY, fonts); 249 } 250 } 251 fProvider.updateComplete(this); 252 } 253 254 257 public Object getElement() { 258 return getElementPath().getLastSegment(); 259 } 260 261 public String toString() { 262 StringBuffer buf = new StringBuffer (); 263 buf.append("ILabelUpdate: "); buf.append(getElement()); 265 return buf.toString(); 266 } 267 } 268 | Popular Tags |