blob: da8d268e16b8caad48c8ce761acbb8e91490a778 (
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
|
/*******************************************************************************
* 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.common.internal.provider;
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.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.jst.j2ee.internal.common.CommonEditResourceHandler;
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
/**
* 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 CommonItemProviderAdapter extends ItemProviderAdapter {
/**
* This creates and instance from an adapter factory and a domain notifier.
*/
protected CommonItemProviderAdapter(AdapterFactory adapterFactory) {
super(adapterFactory);
}
/**
* This implements the default behavior for {@link 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 image for {@link com.ibm.etools.common.command.CreateChildCommand}.
*/
public Object getCreateChildImage(Object object) {
EObject refObject = (EObject) object;
Collection localChildrenReferences = getChildrenReferences(object);
if (localChildrenReferences.size() != 1) {
return J2EEPlugin.getPlugin().getImage("create_child");//$NON-NLS-1$
}
return J2EEPlugin.getPlugin().getImage(refObject.eClass().getName() + "Create" + //$NON-NLS-1$
((EReference) localChildrenReferences.iterator().next()).getEType().getName());
}
/**
* This returns the default create children label.
*/
public String getCreateChildrenText(Object object) {
//EObject refObject = (EObject)object;
Collection localChildrenReferences = getChildrenReferences(object);
if (localChildrenReferences.size() != 1) {
return CommonEditResourceHandler.getString("Create_Two_Children_UI_"); //$NON-NLS-1$
}
return CommonEditResourceHandler.getString("21concat", (new Object[]{((EReference) localChildrenReferences.iterator().next()).getEType().getName()})); //$NON-NLS-1$
}
/**
* This returns the default create children help text.
*/
public String getCreateChildrenToolTipText(Object object) {
EObject refObject = (EObject) object;
Collection localChildrenReferences = getChildrenReferences(object);
if (localChildrenReferences.size() != 1) {
return CommonEditResourceHandler.getString("19concat_UI_", (new Object[]{refObject.eClass().getName()})); //$NON-NLS-1$
}
return CommonEditResourceHandler.getString("20concat_UI_", (new Object[]{((EReference) localChildrenReferences.iterator().next()).getEType().getName(), refObject.eClass().getName()})); //$NON-NLS-1$ = "Create two new children of type {0} for the selected {1}."
}
/**
* This returns the default label for {@link com.ibm.etools.common.command.CreateChildCommand}.
*/
public String getCreateChildText(Object object) {
//EObject refObject = (EObject)object;
Collection localChildrenReferences = getChildrenReferences(object);
if (localChildrenReferences.size() != 1) {
return CommonEditResourceHandler.getString("Create_Child_UI_"); //$NON-NLS-1$
}
return CommonEditResourceHandler.getString("18concat_UI_", (new Object[]{((EReference) localChildrenReferences.iterator().next()).getEType().getName()})); //$NON-NLS-1$ = "Create {0}"
}
/**
* This returns the default help text for
* {@link com.ibm.etools.common.command.CreateChildCommand}.
*/
public String getCreateChildToolTipText(Object object) {
EObject refObject = (EObject) object;
Collection localChildrenReferences = getChildrenReferences(object);
if (localChildrenReferences.size() != 1) {
return CommonEditResourceHandler.getString("29concat", (new Object[]{refObject.eClass().getName()})); //$NON-NLS-1$ = "Create a new child for the selected {0}."
}
return CommonEditResourceHandler.getString("16concat_UI_", (new Object[]{((EReference) localChildrenReferences.iterator().next()).getEType().getName(), refObject.eClass().getName()})); //$NON-NLS-1$ = "Create a child of type {0} for the selected {1}."
}
}
|