Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5660abfb7cd6d8175693f7b7cdbbc8f98332f3ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.j2ee.internal.ejb.provider;


import java.util.Collection;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jem.java.JavaClass;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jst.j2ee.ejb.EnterpriseBean;
import org.eclipse.jst.j2ee.ejb.Entity;
import org.eclipse.jst.j2ee.internal.plugin.J2EEEditorUtility;
import org.eclipse.jst.j2ee.internal.plugin.J2EEUIPlugin;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.common.frameworks.internal.ui.OverlayIcon;

public abstract class J2EEJavaClassProviderHelper implements IAdaptable {
	private EnterpriseBean ejb;
	public static final Class IRESOURCE_CLASS = IResource.class;

	/**
	 * J2EEJavaClassProviderHelper constructor comment.
	 */
	public J2EEJavaClassProviderHelper(EnterpriseBean anEJB) {
		super();
		setEjb(anEJB);
	}

	public static void addChildren(Entity ejb, Collection children) {
		addChildren((EnterpriseBean) ejb, children);
		if (ejb.getPrimaryKey() != null)
			children.add(new PrimaryKeyClassProviderHelper(ejb));
	}

	public static void addChildren(EnterpriseBean ejb, Collection children) {

		if (ejb.getHomeInterface() != null)
			children.add(new HomeInterfaceProviderHelper(ejb));
		if (ejb.getRemoteInterface() != null)
			children.add(new RemoteInterfaceProviderHelper(ejb));
		if (ejb.getLocalHomeInterface() != null)
			children.add(new LocalHomeInterfaceProviderHelper(ejb));
		if (ejb.getLocalInterface() != null)
			children.add(new LocalInterfaceProviderHelper(ejb));
		if (ejb.getEjbClass() != null)
			children.add(new BeanClassProviderHelper(ejb));
	}

	protected Image createImage() {
		ImageDescriptor base = J2EEUIPlugin.getDefault().getImageDescriptor("jcu_obj");//$NON-NLS-1$
		if (base == null)
			return null;
		ImageDescriptor overlay = getOverlayDescriptor();
		if (overlay == null)
			return base.createImage();
		return new OverlayIcon(base, new ImageDescriptor[][]{{overlay}}).createImage();
	}

	/**
	 * Insert the method's description here. Creation date: (7/11/2001 1:47:24 PM)
	 * 
	 * @return org.eclipse.jst.j2ee.internal.internal.ejb.EnterpriseBean
	 */
	public org.eclipse.jst.j2ee.ejb.EnterpriseBean getEjb() {
		return ejb;
	}

	public Image getImage() {
		return null;
	}

	/**
	 * Insert the method's description here. Creation date: (6/20/2001 10:30:54 PM)
	 * 
	 * @return JavaClass
	 */
	public abstract JavaClass getJavaClass();

	protected ImageDescriptor getOverlayDescriptor() {
		return J2EEUIPlugin.getDefault().getImageDescriptor(getOverlayKey());
	}

	protected abstract String getOverlayKey();

	protected IProject getProject() {
		return ProjectUtilities.getProject(getJavaClass());
	}

	public String getStatusLineMessage() {
		if (getJavaClass() != null)
			return getTypeString(getJavaClass().getQualifiedName());
		return ""; //$NON-NLS-1$
	}

	public String getText() {
		if (getJavaClass() != null)
			return getJavaClass().getName();
		return ""; //$NON-NLS-1$
	}

	public abstract String getTypeString(String className);

	public void openInEditor() {
		IProject project = ProjectUtilities.getProject(getJavaClass());
		try {
			J2EEEditorUtility.openInEditor(getJavaClass(), project);
		} catch (Exception cantOpen) {
			//Ignore
		}
	}

	/**
	 * Insert the method's description here. Creation date: (7/11/2001 1:47:24 PM)
	 * 
	 * @param newEjb
	 *            org.eclipse.jst.j2ee.internal.internal.ejb.EnterpriseBean
	 */
	public void setEjb(org.eclipse.jst.j2ee.ejb.EnterpriseBean newEjb) {
		ejb = newEjb;
	}

	/**
	 * @see IAdaptable#EcoreUtil.getAdapter(eAdapters(),Class)
	 */
	public Object getAdapter(Class adapter) {
		if (adapter == IRESOURCE_CLASS)
			return J2EEEditorUtility.getFile(getJavaClass());
		return null;
	}

}

Back to the top