1 11 package org.eclipse.debug.internal.ui.views; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 import org.eclipse.jface.viewers.DecoratingLabelProvider; 16 import org.eclipse.jface.viewers.IDelayedLabelDecorator; 17 import org.eclipse.jface.viewers.ILabelDecorator; 18 import org.eclipse.jface.viewers.ILabelProvider; 19 import org.eclipse.jface.viewers.StructuredViewer; 20 import org.eclipse.jface.viewers.ViewerLabel; 21 import org.eclipse.swt.graphics.Image; 22 23 27 public class DebugViewDecoratingLabelProvider extends DecoratingLabelProvider { 28 29 37 private Map computedText= new HashMap (); 38 private StructuredViewer viewer= null; 39 private boolean disposed= false; 40 41 44 public DebugViewDecoratingLabelProvider(StructuredViewer viewer, ILabelProvider provider, DebugViewLabelDecorator decorator) { 45 super(provider, decorator); 46 decorator.setLabelProvider(this); 47 this.viewer= viewer; 48 } 49 50 58 public void textComputed(Object element, String text) { 59 computedText.put(element, text); 60 } 61 62 69 public void labelsComputed(Object [] elements) { 70 if (!disposed) { 71 viewer.update(elements, null); 72 } 73 for (int i = 0; i < elements.length; i++) { 74 computedText.remove(elements[i]); 75 } 76 } 77 78 86 public String getText(Object element) { 87 String text= (String ) computedText.get(element); 88 if (text != null) { 89 return text; 90 } 91 return super.getText(element); 92 } 93 94 97 public void dispose() { 98 disposed= true; 99 super.dispose(); 100 } 101 102 106 public void updateLabel(ViewerLabel settings, Object element) { 107 108 ILabelDecorator currentDecorator = getLabelDecorator(); 109 String oldText = settings.getText(); 110 String text= getText(element); 111 boolean decorationReady = !DebugViewInterimLabelProvider.PENDING_LABEL.equals(text); 112 if (currentDecorator instanceof IDelayedLabelDecorator) { 113 IDelayedLabelDecorator delayedDecorator = (IDelayedLabelDecorator) currentDecorator; 114 if (!delayedDecorator.prepareDecoration(element, oldText)) { 115 decorationReady = false; 117 } 118 } 119 121 if (decorationReady || oldText == null 122 || settings.getText().length() == 0) 123 settings.setText(getText(element)); 124 125 Image oldImage = settings.getImage(); 126 if (decorationReady || oldImage == null) { 127 settings.setImage(getImage(element)); 128 } 129 130 if(decorationReady) 131 updateForDecorationReady(settings,element); 132 133 } 134 } 135 | Popular Tags |