KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > elements > adapters > AsynchronousDebugLabelAdapter


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.debug.internal.ui.elements.adapters;
13
14 import java.util.Arrays JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.Map JavaDoc;
17 import java.util.Map.Entry;
18
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.debug.core.model.IDebugElement;
21 import org.eclipse.debug.internal.ui.DelegatingModelPresentation;
22 import org.eclipse.debug.internal.ui.LazyModelPresentation;
23 import org.eclipse.debug.internal.ui.viewers.PartPresentationContext;
24 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
25 import org.eclipse.debug.internal.ui.viewers.provisional.AsynchronousLabelAdapter;
26 import org.eclipse.debug.internal.ui.viewers.provisional.ILabelRequestMonitor;
27 import org.eclipse.debug.internal.ui.views.launch.DebugElementHelper;
28 import org.eclipse.debug.ui.IDebugModelPresentation;
29 import org.eclipse.debug.ui.IDebugView;
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.swt.graphics.FontData;
32 import org.eclipse.swt.graphics.RGB;
33 import org.eclipse.ui.IWorkbenchPart;
34
35 /**
36  * Asynchronous label adapter for debug elements.
37  *
38  * @since 3.2
39  */

40 public class AsynchronousDebugLabelAdapter extends AsynchronousLabelAdapter {
41           
42     /* (non-Javadoc)
43      * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#computeLabels(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext, org.eclipse.debug.ui.viewers.ILabelRequestMonitor)
44      */

45     protected void computeLabels(Object JavaDoc element, IPresentationContext context, ILabelRequestMonitor monitor) {
46         DelegatingModelPresentation presentation = DebugElementHelper.getPresentation();
47         // Honor view specific settings in a debug view by copying model presentation settings
48
// into the debug element helper's presentation before we get the label. This allows
49
// for qualified name and type name settings to remain in tact.
50
if (context instanceof PartPresentationContext) {
51             PartPresentationContext ppc = (PartPresentationContext) context;
52             if (element instanceof IDebugElement && ppc.getPart() instanceof IDebugView) {
53                 IWorkbenchPart part = ppc.getPart();
54                 if (part instanceof IDebugView) {
55                     IDebugModelPresentation pres = ((IDebugView)part).getPresentation(((IDebugElement)element).getModelIdentifier());
56                     Map JavaDoc settings = null;
57                     synchronized (presentation) {
58                         if (pres instanceof DelegatingModelPresentation) {
59                             settings = ((DelegatingModelPresentation)pres).getAttributes();
60                         } else if (pres instanceof LazyModelPresentation) {
61                             settings = ((LazyModelPresentation)pres).getAttributes();
62                         }
63                         if (settings != null) {
64                             Iterator JavaDoc iterator = settings.entrySet().iterator();
65                             while (iterator.hasNext()) {
66                                 Map.Entry JavaDoc entry = (Entry) iterator.next();
67                                 presentation.setAttribute((String JavaDoc) entry.getKey(), entry.getValue());
68                             }
69                             super.computeLabels(element, context, monitor);
70                             return;
71                         }
72                     }
73                 }
74             }
75         }
76         super.computeLabels(element, context, monitor);
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getLabels(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext)
81      */

82     protected String JavaDoc[] getLabels(Object JavaDoc element, IPresentationContext context) throws CoreException {
83         return new String JavaDoc[] {DebugElementHelper.getLabel(element)};
84     }
85
86     /* (non-Javadoc)
87      * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getImageDescriptors(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext)
88      */

89     protected ImageDescriptor[] getImageDescriptors(Object JavaDoc element, IPresentationContext context) throws CoreException {
90         return new ImageDescriptor[] {DebugElementHelper.getImageDescriptor(element)};
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getFontDatas(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext)
95      */

96     protected FontData[] getFontDatas(Object JavaDoc element, IPresentationContext context) throws CoreException {
97         FontData[] datas = new FontData[getNumElements(context)];
98         Arrays.fill(datas, DebugElementHelper.getFont(element));
99         return datas;
100     }
101
102     /* (non-Javadoc)
103      * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getForegrounds(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext)
104      */

105     protected RGB[] getForegrounds(Object JavaDoc element, IPresentationContext context) throws CoreException {
106         RGB[] rgbs = new RGB[getNumElements(context)];
107         Arrays.fill(rgbs, DebugElementHelper.getForeground(element));
108         return rgbs;
109     }
110
111     /* (non-Javadoc)
112      * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getBackgrounds(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext)
113      */

114     protected RGB[] getBackgrounds(Object JavaDoc element, IPresentationContext context) throws CoreException {
115         RGB[] rgbs = new RGB[getNumElements(context)];
116         Arrays.fill(rgbs, DebugElementHelper.getBackground(element));
117         return rgbs;
118     }
119     
120     /**
121      * Returns the number of columns in the given presentation context, or 1
122      * if there are no columns.
123      *
124      * @param context presentation context
125      * @return number of columns or 1 if none
126      */

127     protected int getNumElements(IPresentationContext context) {
128         String JavaDoc[] columns = context.getColumns();
129         if (columns == null) {
130             return 1;
131         }
132         return columns.length;
133     }
134
135 }
136
Popular Tags