1 11 package org.eclipse.ui.internal.decorators; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IConfigurationElement; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.jface.util.SafeRunnable; 17 import org.eclipse.jface.viewers.IBaseLabelProvider; 18 import org.eclipse.jface.viewers.ILabelDecorator; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.swt.graphics.Image; 21 import org.eclipse.ui.internal.WorkbenchMessages; 22 import org.eclipse.ui.internal.WorkbenchPlugin; 23 24 28 29 class FullDecoratorDefinition extends DecoratorDefinition { 30 31 ILabelDecorator decorator; 32 33 37 38 FullDecoratorDefinition(String identifier, IConfigurationElement element) { 39 super(identifier, element); 40 } 41 42 50 protected ILabelDecorator internalGetDecorator() throws CoreException { 51 if (labelProviderCreationFailed) { 52 return null; 53 } 54 55 final CoreException[] exceptions = new CoreException[1]; 56 57 if (decorator == null) { 58 Platform 59 .run(new SafeRunnable( 60 NLS.bind(WorkbenchMessages.DecoratorManager_ErrorActivatingDecorator, getName() )) { 61 public void run() { 62 try { 63 decorator = (ILabelDecorator) WorkbenchPlugin 64 .createExtension( 65 definingElement, 66 DecoratorDefinition.ATT_CLASS); 67 decorator.addListener(WorkbenchPlugin 68 .getDefault().getDecoratorManager()); 69 } catch (CoreException exception) { 70 exceptions[0] = exception; 71 } 72 } 73 }); 74 } else { 75 return decorator; 76 } 77 78 if (decorator == null) { 79 this.labelProviderCreationFailed = true; 80 setEnabled(false); 81 } 82 83 if (exceptions[0] != null) { 84 throw exceptions[0]; 85 } 86 87 return decorator; 88 } 89 90 93 protected void refreshDecorator() { 94 if (!this.enabled && decorator != null) { 97 IBaseLabelProvider cached = decorator; 98 decorator = null; 99 disposeCachedDecorator(cached); 100 } 101 } 102 103 109 Image decorateImage(Image image, Object element) { 110 try { 111 ILabelDecorator currentDecorator = internalGetDecorator(); 113 if (currentDecorator != null) { 114 return currentDecorator.decorateImage(image, element); 115 } 116 117 } catch (CoreException exception) { 118 handleCoreException(exception); 119 } 120 return null; 121 } 122 123 129 String decorateText(String text, Object element) { 130 try { 131 ILabelDecorator currentDecorator = internalGetDecorator(); 133 if (currentDecorator != null) { 134 return currentDecorator.decorateText(text, element); 135 } 136 } catch (CoreException exception) { 137 handleCoreException(exception); 138 } 139 return null; 140 } 141 142 147 public ILabelDecorator getDecorator() { 148 return decorator; 149 } 150 151 154 protected IBaseLabelProvider internalGetLabelProvider() 155 throws CoreException { 156 return internalGetDecorator(); 157 } 158 159 162 public boolean isFull() { 163 return true; 164 } 165 166 } 167 | Popular Tags |