Skip to main content
summaryrefslogtreecommitdiffstats
blob: fa80205bdb56159bc14dd4ea81704ed03f534ce3 (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
/*******************************************************************************
 * Copyright (c) 2003, 2004 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.web.providers;

import java.util.Collection;
import java.util.Collections;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.jst.j2ee.internal.web.plugin.WebPlugin;


/**
 * This extended item provider supports two addition features, (@link CreateChildCommand} and
 * {@link CreateChildrenCommand}. These two actions are implemented uniformly on all our item
 * adapters using this common base class.
 */
public class WebapplicationItemProviderAdapter extends org.eclipse.emf.edit.provider.ItemProviderAdapter {

	/**
	 * This creates and instance from an adapter factory and a domain notifier.
	 */
	protected WebapplicationItemProviderAdapter(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	/**
	 * This implements the default behavior for
	 * {@link org.eclipse.jst.j2ee.internal.internal.webapplication.command.CreateChildCommand}.
	 */
	public Object createChild(Object object) {
		return null;
	}

	/**
	 * This creates the default new children for {@link CreateChildrenCommand}.
	 */
	public Collection createChildren(Object object) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * This returns the default create child image.
	 */
	public Object getCreateChildImage(Object object) {
		EObject refObject = (EObject) object;
		Collection achildrenReferences = getChildrenReferences(object);
		if (achildrenReferences.size() != 1) {
			return WebPlugin.getDefault().getImage("create_child"); //$NON-NLS-1$
		}
		return WebPlugin.getDefault().getImage(refObject.eClass().getName() + "Create" + //$NON-NLS-1$
					((EReference) achildrenReferences.iterator().next()).getEType().getName());

	}

	/**
	 * This returns the default create children label.
	 */
	public String getCreateChildrenText(Object object) {
		//EObject refObject = (EObject) object;
		Collection achildrenReferences = getChildrenReferences(object);
		if (achildrenReferences.size() != 1) {
			return WebAppEditResourceHandler.getString("Create_Two_Children_UI_"); //$NON-NLS-1$ = "Create Two Children"
		}
		return WebAppEditResourceHandler.getString("9concat_UI_", (new Object[]{((EReference) achildrenReferences.iterator().next()).getEType().getName()})); //$NON-NLS-1$ = "Create Two {0}s"

	}

	/**
	 * This returns the default create children help text.
	 */
	public String getCreateChildrenToolTipText(Object object) {
		EObject refObject = (EObject) object;
		Collection achildrenReferences = getChildrenReferences(object);
		if (achildrenReferences.size() != 1) {
			return WebAppEditResourceHandler.getString("7concat_UI_", (new Object[]{refObject.eClass().getName()})); //$NON-NLS-1$ = "Create two new children for the selected {0}."
		}
		return WebAppEditResourceHandler.getString("8concat_UI_", (new Object[]{((EReference) achildrenReferences.iterator().next()).getEType().getName(), refObject.eClass().getName()})); //$NON-NLS-1$
		//$NON-NLS-1$ = "Create two new children of type {0} for the selected {1}."

	}

	/**
	 * This returns the default create child label.
	 */
	public String getCreateChildText(Object object) {
		//EObject refObject = (EObject) object;
		Collection achildrenReferences = getChildrenReferences(object);
		if (achildrenReferences.size() != 1) {
			return WebAppEditResourceHandler.getString("Create_Child_UI_"); //$NON-NLS-1$ = "Create Child"
		}
		return WebAppEditResourceHandler.getString("6concat_UI_", (new Object[]{((EReference) achildrenReferences.iterator().next()).getEType().getName()})); //$NON-NLS-1$ = "Create {0}"

	}

	/**
	 * This returns the default create child help text.
	 */
	public String getCreateChildToolTipText(Object object) {
		EObject refObject = (EObject) object;
		Collection achildrenReferences = getChildrenReferences(object);
		if (achildrenReferences.size() != 1) {
			return WebAppEditResourceHandler.getString("2concat_UI_", (new Object[]{refObject.eClass().getName()})); //$NON-NLS-1$ = "Create a new child for the selected {0}."
		}
		return WebAppEditResourceHandler.getString("4concat_UI_", (new Object[]{((EReference) achildrenReferences.iterator().next()).getEType().getName(), refObject.eClass().getName()})); //$NON-NLS-1$
		//$NON-NLS-1$ = "Create a child of type {0} for the selected {1}."

	}
}

Back to the top