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
9 * Christopher Lenz - initial implementation
11 * $Id: JSWorkbenchAdapter.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $
14 package net.sourceforge.phpeclipse.js.ui.model;
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;
27 import org.eclipse.jface.resource.ImageDescriptor;
28 import org.eclipse.ui.model.WorkbenchAdapter;
31 * Adapter that provides a visual representation of JavaScript model elements.
33 public class JSWorkbenchAdapter extends WorkbenchAdapter {
35 // IWorkbenchAdapter Implementation ----------------------------------------
38 * @see IWorkbenchAdapter#getChildren(Object)
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);
46 return super.getChildren(o);
50 * @see IWorkbenchAdapter#getImageDescriptor(Object)
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);
68 return super.getImageDescriptor(o);
72 * @see IWorkbenchAdapter#getLabel(Object)
74 public String getLabel(Object o) {
75 if (o instanceof JSElement) {
76 return ((JSElement) o).getName();
78 return super.getLabel(o);
82 * @see IWorkbenchAdapter#getParent(Object)
84 public Object getParent(Object o) {
85 if (o instanceof JSElement) {
86 return ((JSElement) o).getParent(null);
88 return super.getParent(o);