Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2beda77b68459af6e1e7c00418f59fcf92d17409 (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
/*******************************************************************************
 * 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.Collections;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jst.j2ee.ejb.AssemblyDescriptor;
import org.eclipse.jst.j2ee.ejb.CMPAttribute;
import org.eclipse.jst.j2ee.ejb.EJBJar;
import org.eclipse.jst.j2ee.ejb.EnterpriseBean;
import org.eclipse.jst.j2ee.ejb.MethodPermission;
import org.eclipse.jst.j2ee.ejb.internal.impl.EjbFactoryImpl;


public class MethodPermissionsContentProvider extends AbstractMethodsContentProvider {
	private static final EStructuralFeature PERMISSION_MES_SF = EjbFactoryImpl.getPackage().getMethodPermission_MethodElements();
	private static final EStructuralFeature PERMISSION_MES_UNCHECKED_SF = EjbFactoryImpl.getPackage().getMethodPermission_Unchecked();
	private static final EStructuralFeature PERMISSION_MES_ROLES_SF = EjbFactoryImpl.getPackage().getMethodPermission_Roles();
	private static final EStructuralFeature AD_MP_SF = EjbFactoryImpl.getPackage().getAssemblyDescriptor_MethodPermissions();

	/**
	 * Constructor for MethodPermissionsContentProvider.
	 * 
	 * @param adapterFactory
	 * @param root
	 * @param viewer
	 */
	public MethodPermissionsContentProvider(AdapterFactory adapterFactory, boolean root) {
		super(adapterFactory, root);
	}

	/**
	 * Constructor for MethodPermissionsContentProvider.
	 * 
	 * @param adapterFactory
	 */
	public MethodPermissionsContentProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	/*
	 * @see ITreeContentProvider#getChildren(Object)
	 */
	@Override
	public Object[] getChildren(Object parentElement) {
		if (parentElement instanceof MethodPermission)
			return getEnterpriseBeans((MethodPermission) parentElement);
		return super.getChildren(parentElement);
	}

	protected Object[] getEnterpriseBeans(MethodPermission mp) {
		List mes = mp.getMethodElements();
		return getEnterpriseBeans(mp, mes);
	}

	/*
	 * @see AbstractMethodsContentProvider#getMethodElements(EObject, EnterpriseBean)
	 */
	@Override
	protected List getMethodElements(EObject aRefObject, EnterpriseBean anEJB) {
		if (aRefObject == null || !(aRefObject instanceof MethodPermission))
			return Collections.EMPTY_LIST;
		MethodPermission parentMP = (MethodPermission) aRefObject;
		return parentMP.getMethodElements(anEJB);
	}

	/*
	 * @see IStructuredContentProvider#getElements(Object)
	 */
	@Override
	public Object[] getElements(Object inputElement) {
		super.getElements(inputElement);
		if (inputElement instanceof EJBJar) {
			EJBJar jar = (EJBJar) inputElement;
			if (jar.getAssemblyDescriptor() != null)
				return jar.getAssemblyDescriptor().getMethodPermissions().toArray();
		}
		if (inputElement instanceof AssemblyDescriptor)
			return ((AssemblyDescriptor) inputElement).getMethodPermissions().toArray();
		return new Object[0];
	}

	/*
	 * @see ITreeContentProvider#hasChildren(Object)
	 */
	@Override
	public boolean hasChildren(Object element) {
		if (element instanceof MethodPermission)
			return !((MethodPermission) element).getMethodElements().isEmpty();
		return super.hasChildren(element);
	}

	/*
	 * @see AbstractMethodsContentProvider#getMethodElementsReference()
	 */
	@Override
	protected EStructuralFeature getMethodElementsReference() {
		return PERMISSION_MES_SF;
	}

	/**
	 * @see org.eclipse.jst.j2ee.internal.internal.ejb.ui.providers.AbstractMethodsContentProvider#getMethodElementsContainerReference()
	 */
	@Override
	protected EStructuralFeature getMethodElementsContainerReference() {
		return AD_MP_SF;
	}

	/**
	 * @see org.eclipse.emf.edit.provider.INotifyChangedListener#notifyChanged(Notification)
	 */
	@Override
	public void notifyChanged(Notification notification) {
		if (notification.getFeature() == PERMISSION_MES_SF || notification.getFeature() == AD_MP_SF)
			refreshTreeViewer();
		else if (notification.getOldValue() instanceof CMPAttribute && notification.getNewValue() == null)
			return;
		if (notification.getFeature() == PERMISSION_MES_UNCHECKED_SF || notification.getFeature() == PERMISSION_MES_ROLES_SF || notification.getFeature() == getMethodElementsReference() || notification.getFeature() == getMethodElementsContainerReference())
			super.notifyChanged(notification);
	}
}

Back to the top