Debian Codegraph @

plugins/org.eclipse.xsd.edit/src/org/eclipse/xsd/provider/XSDImportItemProvider.java

raw
1 /**
2 * Copyright (c) 2002-2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 */
11 package org.eclipse.xsd.provider;
12
13
14 import java.util.Collection;
15 import java.util.List;
16
17 import org.eclipse.emf.common.notify.AdapterFactory;
18 import org.eclipse.emf.common.notify.Notification;
19 import org.eclipse.emf.ecore.EStructuralFeature;
20 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
21 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
22 import org.eclipse.emf.edit.provider.IItemLabelProvider;
23 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
24 import org.eclipse.emf.edit.provider.IItemPropertySource;
25 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
26 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
27 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
28
29 import org.eclipse.xsd.XSDImport;
30
31
32 /**
33 * This is the item provider adpater for a {@link org.eclipse.xsd.XSDImport} object.
34 */
35 public class XSDImportItemProvider
36 extends XSDSchemaDirectiveItemProvider
37 implements
38 IEditingDomainItemProvider,
39 IStructuredItemContentProvider,
40 ITreeItemContentProvider,
41 IItemLabelProvider,
42 IItemPropertySource
43 {
44 /**
45 * This constructs an instance from a factory and a notifier.
46 */
47 public XSDImportItemProvider(AdapterFactory adapterFactory)
48 {
49 super(adapterFactory);
50 }
51
52 /**
53 * This returns the property descriptors for the adapted class.
54 */
55 @Override
56 public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object)
57 {
58 if (itemPropertyDescriptors == null)
59 {
60 super.getPropertyDescriptors(object);
61
62 // This is for the namespace feature.
63 //
64 itemPropertyDescriptors.add
65 (new ItemPropertyDescriptor
66 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
67 XSDEditPlugin.INSTANCE.getString("_UI_Namespace_label"),
68 XSDEditPlugin.INSTANCE.getString("_UI_Namespace_description"),
69 xsdPackage.getXSDImport_Namespace(),
70 true,
71 ItemPropertyDescriptor.TEXT_VALUE_IMAGE));
72
73 // This is for the annotation feature.
74 //
75 itemPropertyDescriptors.add
76 (new ItemPropertyDescriptor
77 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
78 XSDEditPlugin.INSTANCE.getString("_UI_Annotation_label"),
79 XSDEditPlugin.INSTANCE.getString("_UI_AnnotationOfImport_description"),
80 xsdPackage.getXSDImport_Annotation(),
81 false));
82
83 }
84 return itemPropertyDescriptors;
85 }
86
87 /**
88 * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
89 * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
90 * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
91 */
92 @Override
93 public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object)
94 {
95 if (childrenFeatures == null)
96 {
97 super.getChildrenFeatures(object);
98 childrenFeatures.add(xsdPackage.getXSDImport_Annotation());
99 }
100 return childrenFeatures;
101 }
102
103 /**
104 * This returns XSDImport.gif.
105 */
106 @Override
107 public Object getImage(Object object)
108 {
109 return XSDEditPlugin.INSTANCE.getImage("full/obj16/XSDImport");
110 }
111
112 @Override
113 public String getText(Object object)
114 {
115 XSDImport xsdImport = ((XSDImport)object);
116 String result = xsdImport.getSchemaLocation();
117 return result == null ? "" : result;
118 }
119
120 /**
121 * This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}.
122 */
123 @Override
124 public void notifyChanged(Notification msg)
125 {
126 if (
127 msg.getFeature() == xsdPackage.getXSDImport_Namespace() ||
128 msg.getFeature() == xsdPackage.getXSDImport_Annotation()
129 )
130 {
131 fireNotifyChanged(msg);
132 return;
133 }
134 super.notifyChanged(msg);
135 }
136
137 /**
138 * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
139 * that can be created under this object.
140 */
141 @Override
142 protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object)
143 {
144 super.collectNewChildDescriptors(newChildDescriptors, object);
145 // annotation
146 newChildDescriptors.add(createChildParameter(xsdPackage.getXSDImport_Annotation(), xsdFactory.createXSDAnnotation()));
147 }
148 }