View | Details | Raw Unified | Return to bug 22118 | Differences between
and this patch

Collapse All | Expand All

(-)DecoratorManager.java (-9 / +87 lines)
Lines 10-17 Link Here
10
import org.eclipse.core.runtime.IAdaptable;
10
import org.eclipse.core.runtime.IAdaptable;
11
import org.eclipse.core.runtime.Platform;
11
import org.eclipse.core.runtime.Platform;
12
import org.eclipse.jface.viewers.*;
12
import org.eclipse.jface.viewers.*;
13
import org.eclipse.jface.viewers.ILabelDecorator;
14
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
15
import org.eclipse.swt.graphics.Image;
13
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.ui.IContributorResourceAdapter;
14
import org.eclipse.ui.IContributorResourceAdapter;
17
import org.eclipse.ui.IDecoratorManager;
15
import org.eclipse.ui.IDecoratorManager;
Lines 126-133 Link Here
126
		if (checkAdapted) {
124
		if (checkAdapted) {
127
			//Get any adaptions to IResource
125
			//Get any adaptions to IResource
128
			Object adapted = getResourceAdapter(element);
126
			Object adapted = getResourceAdapter(element);
129
			if (adapted != null)
127
			if (adapted != null) {
130
				result = decorateText(result, adapted, false);
128
                
129
                // http://bugs.eclipse.org/bugs/show_bug.cgi?id=22118
130
                //
131
                // don't do it recursive, will decorate twice sometimes
132
                //result = decorateText(result, adapted, false);
133
                
134
                List alreadyAppliedDecorators = Arrays.asList(decorators);
135
                DecoratorDefinition[] resourceDecorators = getDecoratorsFor(adapted);
136
                for (int i = 0; i < resourceDecorators.length; i++) {
137
                    if( !alreadyAppliedDecorators.contains(resourceDecorators[i]) ) {
138
                        String newResult = resourceDecorators[i].decorateText(result, adapted);
139
                        if (newResult != null)
140
                            result = newResult;
141
                    }
142
                }
143
            }
131
		}
144
		}
132
145
133
		return result;
146
		return result;
Lines 162-169 Link Here
162
		if (checkAdapted) {
175
		if (checkAdapted) {
163
			//Get any adaptions to IResource
176
			//Get any adaptions to IResource
164
			Object adapted = getResourceAdapter(element);
177
			Object adapted = getResourceAdapter(element);
165
			if (adapted != null)
178
			if (adapted != null) {
166
				result = decorateImage(result, adapted, false);
179
                
180
                // http://bugs.eclipse.org/bugs/show_bug.cgi?id=22118
181
                //
182
                // don't do it recursive, will decorate twice sometimes
183
                //result = decorateImage(result, adapted, false);
184
                
185
                List alreadyAppliedDecorators = Arrays.asList(decorators);
186
                DecoratorDefinition[] resourceDecorators = getDecoratorsFor(adapted);
187
                for (int i = 0; i < resourceDecorators.length; i++) {
188
                    if( !alreadyAppliedDecorators.contains(resourceDecorators[i]) ) {
189
                        Image newResult = resourceDecorators[i].decorateImage(result, adapted);
190
                        if (newResult != null)
191
                            result = newResult;
192
                    }
193
                }
194
            }
167
		}
195
		}
168
196
169
		return result;
197
		return result;
Lines 205-218 Link Here
205
233
206
		Class elementClass = element.getClass();
234
		Class elementClass = element.getClass();
207
		String className = elementClass.getName();
235
		String className = elementClass.getName();
208
		DecoratorDefinition[] decoratorArray =
236
        
237
		DecoratorDefinition[] decoratorArray = 
209
			(DecoratorDefinition[]) cachedDecorators.get(className);
238
			(DecoratorDefinition[]) cachedDecorators.get(className);
210
		if (decoratorArray != null) {
239
		if (decoratorArray != null) {
240
            // http://bugs.eclipse.org/bugs/show_bug.cgi?id=22118
241
            //
242
            // adaptable decorators are element dependend
243
            Set adaptableDecorators = new HashSet();
244
            findDecorators((IAdaptable)element, enabledDefinitions(), adaptableDecorators);
245
            if( !adaptableDecorators.isEmpty() )
246
            {
247
                adaptableDecorators.addAll(Arrays.asList(decoratorArray));
248
                decoratorArray = new DecoratorDefinition[adaptableDecorators.size()];
249
                adaptableDecorators.toArray(decoratorArray);
250
            }
211
			return decoratorArray;
251
			return decoratorArray;
212
		}
252
		}
213
253
214
		List allClasses = computeClassOrder(elementClass);
254
		List allClasses = computeClassOrder(elementClass);
215
		ArrayList decorators = new ArrayList();
255
		Set decorators = new HashSet();
216
		DecoratorDefinition[] enabledDefinitions = enabledDefinitions();
256
		DecoratorDefinition[] enabledDefinitions = enabledDefinitions();
217
257
218
		findDecorators(allClasses, enabledDefinitions, decorators);
258
		findDecorators(allClasses, enabledDefinitions, decorators);
Lines 221-226 Link Here
221
			computeInterfaceOrder(allClasses),
261
			computeInterfaceOrder(allClasses),
222
			enabledDefinitions,
262
			enabledDefinitions,
223
			decorators);
263
			decorators);
264
            
265
        // http://bugs.eclipse.org/bugs/show_bug.cgi?id=22118
266
        //
267
        // dont forget to check for decorators also decorating adaptables
268
        if( element instanceof IAdaptable )
269
            findDecorators((IAdaptable)element, enabledDefinitions, decorators);
224
270
225
		decoratorArray = new DecoratorDefinition[decorators.size()];
271
		decoratorArray = new DecoratorDefinition[decorators.size()];
226
		decorators.toArray(decoratorArray);
272
		decorators.toArray(decoratorArray);
Lines 235-241 Link Here
235
	private void findDecorators(
281
	private void findDecorators(
236
		Collection classList,
282
		Collection classList,
237
		DecoratorDefinition[] enabledDefinitions,
283
		DecoratorDefinition[] enabledDefinitions,
238
		ArrayList result) {
284
		Collection result) {
239
285
240
		Iterator classes = classList.iterator();
286
		Iterator classes = classList.iterator();
241
		while (classes.hasNext()) {
287
		while (classes.hasNext()) {
Lines 247-252 Link Here
247
		}
293
		}
248
294
249
	}
295
	}
296
297
    /** 
298
     * Find defined decorators that have a type that the specified adaptable object
299
     * has an adapter for.
300
     * <b>NOTE:</b> The result can't becached with this implementation. See source for details.
301
     */
302
    private void findDecorators(
303
        IAdaptable adaptableObject,
304
        DecoratorDefinition[] enabledDefinitions,
305
        Collection result) {
306
    
307
        // http://bugs.eclipse.org/bugs/show_bug.cgi?id=22118
308
        
309
        for (int i = 0; i < enabledDefinitions.length; i++) {
310
            if( enabledDefinitions[i].isAdaptable() ) {
311
				try
312
				{
313
					Class objectClass = getClass().forName(enabledDefinitions[i].getObjectClass());
314
					if (null != adaptableObject.getAdapter(objectClass) ) {
315
                        
316
                        // NOTE: we are checking the object for an adapter
317
                        // it may be possible that not all objects of the same type have an adapter
318
                        // for the same type
319
                        // --> DO NOT cache result for types!!! 
320
					    result.add(enabledDefinitions[i]);
321
					}
322
				}
323
				catch (ClassNotFoundException e)
324
				{ /** @todo implement error handling */ }
325
            }
326
        }
327
    }
250
328
251
	/**
329
	/**
252
	* Return whether or not the decorator registered for element
330
	* Return whether or not the decorator registered for element

Return to bug 22118