upload tizen1.0 source
[sdk/ide/product.git] / org.eclipse.cdt.ui / src / org / eclipse / cdt / internal / ui / CWorkbenchAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2005, 2008 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  *     QNX Software System
11  *     Sergey Prigogin (Google)
12  *******************************************************************************/
13 package org.eclipse.cdt.internal.ui;
14
15 import org.eclipse.cdt.core.model.CModelException;
16 import org.eclipse.cdt.core.model.ICElement;
17 import org.eclipse.cdt.core.model.IParent;
18 import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
19 import org.eclipse.cdt.ui.CElementLabelProvider;
20 import org.eclipse.cdt.ui.CUIPlugin;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.ui.model.IWorkbenchAdapter;
23
24 /**
25  * An implementation of the IWorkbenchAdapter for CElements.
26  */
27 public class CWorkbenchAdapter implements IWorkbenchAdapter {
28
29         private static final Object[] fgEmptyArray = new Object[0];
30         private CElementImageProvider fImageProvider;
31         private CElementLabelProvider fLabelProvider;
32
33         public CWorkbenchAdapter() {
34                 fImageProvider = new CElementImageProvider();
35                 fLabelProvider = new CElementLabelProvider();
36         }
37
38         /**
39          * @see IWorkbenchAdapter#getChildren
40          */
41         public Object[] getChildren(Object o) {
42                 if (o instanceof IParent) {
43                         try {
44                                 Object[] members = ((IParent) o).getChildren();
45                                 if (members != null) {
46                                         return members;
47                                 }
48                         } catch (CModelException e) {
49                                 CUIPlugin.log(e);
50                         }
51                 }
52                 return fgEmptyArray;
53         }
54
55         /**
56          * @see IWorkbenchAdapter#getImageDescriptor
57          */
58         public ImageDescriptor getImageDescriptor(Object element) {
59                 if (element instanceof ICElement) {
60                         return fImageProvider.getCImageDescriptor(
61                                 (ICElement) element,
62                                 CElementImageProvider.OVERLAY_ICONS | CElementImageProvider.SMALL_ICONS);
63                 }
64                 return null;
65         }
66
67         /**
68          * @see IWorkbenchAdapter#getLabel
69          */
70         public String getLabel(Object o) {
71                 if (o instanceof ICElement) {
72                         return fLabelProvider.getText(o);
73                 }
74                 return null;
75         }
76
77         /**
78          * @see IWorkbenchAdapter#getParent
79          */
80         public Object getParent(Object o) {
81                 if (o instanceof ICElement) {
82                         return ((ICElement) o).getParent();
83                 }
84                 return null;
85         }
86 }