intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.ui / src / net / sourceforge / phpeclipse / js / ui / model / JSWorkbenchAdapter.java
1 /*
2  * Copyright (c) 2004 Christopher Lenz and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial implementation
10  * 
11  * $Id: JSWorkbenchAdapter.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.js.ui.model;
15
16 import net.sourceforge.phpeclipse.js.core.model.JSClassElement;
17 import net.sourceforge.phpeclipse.js.core.model.JSClassMethodElement;
18 import net.sourceforge.phpeclipse.js.core.model.JSClassVariableElement;
19 import net.sourceforge.phpeclipse.js.core.model.JSElement;
20 import net.sourceforge.phpeclipse.js.core.model.JSElementList;
21 import net.sourceforge.phpeclipse.js.core.model.JSFunctionElement;
22 import net.sourceforge.phpeclipse.js.core.model.JSGlobalVariableElement;
23 import net.sourceforge.phpeclipse.js.core.model.JSInstanceMethodElement;
24 import net.sourceforge.phpeclipse.js.core.model.JSInstanceVariableElement;
25 import net.sourceforge.phpeclipse.js.ui.editors.JSImages;
26
27 import org.eclipse.jface.resource.ImageDescriptor;
28 import org.eclipse.ui.model.WorkbenchAdapter;
29
30 /**
31  * Adapter that provides a visual representation of JavaScript model elements.
32  */
33 public class JSWorkbenchAdapter extends WorkbenchAdapter {
34
35         // IWorkbenchAdapter Implementation ----------------------------------------
36
37         /* 
38          * @see IWorkbenchAdapter#getChildren(Object)
39          */
40         public Object[] getChildren(Object o) {
41                 if (o instanceof JSElementList) {
42                         return ((JSElementList) o).getChildren(null);
43                 } else if (o instanceof JSElement) {
44                         return ((JSElement) o).getChildren(null);
45                 }
46                 return super.getChildren(o);
47         }
48
49         /* 
50          * @see IWorkbenchAdapter#getImageDescriptor(Object)
51          */
52         public ImageDescriptor getImageDescriptor(Object o) {
53                 if (o instanceof JSClassElement) {
54                         return JSImages.getDescriptor(JSImages.ICON_CLASS);
55                 } else if (o instanceof JSGlobalVariableElement) {
56                         return JSImages.getDescriptor(JSImages.ICON_VAR);
57                 } else if (o instanceof JSFunctionElement) {
58                         return JSImages.getDescriptor(JSImages.ICON_FUNCTION);
59                 } else if (o instanceof JSClassMethodElement) {
60                         return JSImages.getDescriptor(JSImages.ICON_CLASS_METHOD);
61                 } else if (o instanceof JSClassVariableElement) {
62                         return JSImages.getDescriptor(JSImages.ICON_CLASS_VAR);
63                 } else if (o instanceof JSInstanceMethodElement) {
64                         return JSImages.getDescriptor(JSImages.ICON_INSTANCE_METHOD);
65                 } else if (o instanceof JSInstanceVariableElement) {
66                         return JSImages.getDescriptor(JSImages.ICON_INSTANCE_VAR);
67                 }
68                 return super.getImageDescriptor(o);
69         }
70
71         /* 
72          * @see IWorkbenchAdapter#getLabel(Object)
73          */
74         public String getLabel(Object o) {
75                 if (o instanceof JSElement) {
76                         return ((JSElement) o).getName();
77                 }
78                 return super.getLabel(o);
79         }
80
81         /* 
82          * @see IWorkbenchAdapter#getParent(Object)
83          */
84         public Object getParent(Object o) {
85                 if (o instanceof JSElement) {
86                         return ((JSElement) o).getParent(null);
87                 }
88                 return super.getParent(o);
89         }
90
91 }