Skip to content

Package: CategoryItemProvider

CategoryItemProvider

nameinstructionbranchcomplexitylinemethod
CategoryItemProvider(AdapterFactory)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
collectContainerChildDecriptors(Collection, Object)
M: 0 C: 64
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
collectNewChildDescriptors(Collection, Object)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getChildFeature(Object, Object)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getChildrenDescriptorCollector()
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getChildrenFeatures(Object)
M: 0 C: 15
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getImage(Object)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getPropertyDescriptors(Object)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getText(Object)
M: 0 C: 23
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
notifyChanged(Notification)
M: 0 C: 22
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * EclipseSource Munich - initial API and implementation
13: */
14: package org.eclipse.emf.ecp.view.spi.categorization.model.provider;
15:
16: import java.util.Collection;
17: import java.util.List;
18:
19: import org.eclipse.emf.common.notify.AdapterFactory;
20: import org.eclipse.emf.common.notify.Notification;
21: import org.eclipse.emf.common.util.URI;
22: import org.eclipse.emf.ecore.EStructuralFeature;
23: import org.eclipse.emf.ecore.resource.Resource;
24: import org.eclipse.emf.ecore.resource.ResourceSet;
25: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
26: import org.eclipse.emf.ecp.common.spi.ChildrenDescriptorCollector;
27: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationPackage;
28: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategory;
29: import org.eclipse.emf.ecp.view.spi.model.VContainer;
30: import org.eclipse.emf.ecp.view.spi.model.VElement;
31: import org.eclipse.emf.ecp.view.spi.model.VElementUtil;
32: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
33: import org.eclipse.emf.ecp.view.spi.vertical.model.VVerticalFactory;
34: import org.eclipse.emf.ecp.view.spi.vertical.model.VVerticalLayout;
35: import org.eclipse.emf.edit.command.CommandParameter;
36: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
37: import org.eclipse.emf.edit.domain.EditingDomain;
38: import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
39: import org.eclipse.emf.edit.provider.ViewerNotification;
40:
41: /**
42: * This is the item provider adapter for a {@link org.eclipse.emf.ecp.view.spi.categorization.model.VCategory} object.
43: * <!-- begin-user-doc -->
44: * <!-- end-user-doc -->
45: *
46: * @generated
47: */
48: public class CategoryItemProvider
49:         extends AbstractCategorizationItemProvider {
50:         /** Do not access directly! Use {@link #getChildrenDescriptorCollector()}. */
51:         private ChildrenDescriptorCollector childrenDescriptorCollector;
52:
53:         /**
54:          * This constructs an instance from a factory and a notifier.
55:          * <!-- begin-user-doc -->
56:          * <!-- end-user-doc -->
57:          *
58:          * @generated
59:          */
60:         public CategoryItemProvider(AdapterFactory adapterFactory) {
61:                 super(adapterFactory);
62:         }
63:
64:         /**
65:          * This returns the property descriptors for the adapted class.
66:          * <!-- begin-user-doc -->
67:          * <!-- end-user-doc -->
68:          *
69:          * @generated
70:          */
71:         @Override
72:         public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
73:•                if (itemPropertyDescriptors == null) {
74:                         super.getPropertyDescriptors(object);
75:
76:                 }
77:                 return itemPropertyDescriptors;
78:         }
79:
80:         /**
81:          * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
82:          * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
83:          * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
84:          * <!-- begin-user-doc -->
85:          * <!-- end-user-doc -->
86:          *
87:          * @generated
88:          */
89:         @Override
90:         public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) {
91:•                if (childrenFeatures == null) {
92:                         super.getChildrenFeatures(object);
93:                         childrenFeatures.add(VCategorizationPackage.Literals.CATEGORY__COMPOSITE);
94:                 }
95:                 return childrenFeatures;
96:         }
97:
98:         /**
99:          * <!-- begin-user-doc -->
100:          * <!-- end-user-doc -->
101:          *
102:          * @generated
103:          */
104:         @Override
105:         protected EStructuralFeature getChildFeature(Object object, Object child) {
106:                 // Check the type of the specified child object and return the proper feature to use for
107:                 // adding (see {@link AddCommand}) it as a child.
108:
109:                 return super.getChildFeature(object, child);
110:         }
111:
112:         /**
113:          * This returns Category.gif.
114:          * <!-- begin-user-doc -->
115:          * <!-- end-user-doc -->
116:          *
117:          * @generated
118:          */
119:         @Override
120:         public Object getImage(Object object) {
121:                 return overlayImage(object, getResourceLocator().getImage("full/obj16/Category")); //$NON-NLS-1$
122:         }
123:
124:         /**
125:          * This returns the label text for the adapted class.
126:          * <!-- begin-user-doc -->
127:          * <!-- end-user-doc -->
128:          *
129:          * @generated NOT
130:          */
131:         @Override
132:         public String getText(Object object) {
133:                 String label = ((VCategory) object).getLabel();
134:•                if (label == null) {
135:                         label = VElementUtil.getCleanName(VElement.class.cast(object));
136:                 }
137:•                return label == null || label.length() == 0 ? getString("_UI_Category_type") : label; //$NON-NLS-1$
138:         }
139:
140:         /**
141:          * This handles model notifications by calling {@link #updateChildren} to update any cached
142:          * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
143:          * <!-- begin-user-doc -->
144:          * <!-- end-user-doc -->
145:          *
146:          * @generated
147:          */
148:         @Override
149:         public void notifyChanged(Notification notification) {
150:                 updateChildren(notification);
151:
152:•                switch (notification.getFeatureID(VCategory.class)) {
153:                 case VCategorizationPackage.CATEGORY__COMPOSITE:
154:                         fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
155:                         return;
156:                 }
157:                 super.notifyChanged(notification);
158:         }
159:
160:         /**
161:          * Returns the cached {@link ChildrenDescriptorCollector}.
162:          *
163:          * @return The {@link ChildrenDescriptorCollector}.
164:          * @since 1.17
165:          */
166:         protected ChildrenDescriptorCollector getChildrenDescriptorCollector() {
167:•                if (childrenDescriptorCollector == null) {
168:                         childrenDescriptorCollector = new ChildrenDescriptorCollector();
169:                 }
170:                 return childrenDescriptorCollector;
171:         }
172:
173:         /**
174:          * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
175:          * that can be created under this object.
176:          * <!-- begin-user-doc -->
177:          * <!-- end-user-doc -->
178:          *
179:          * @generated NOT
180:          */
181:         @Override
182:         protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
183:                 super.collectNewChildDescriptors(newChildDescriptors, object);
184:
185:                 collectContainerChildDecriptors(newChildDescriptors, object);
186:         }
187:
188:         /**
189:          * Adds child descriptors for the {@link VContainer}'s children reference. This is necessary as long as
190:          * {@link VCategory} does not extend {@link VCategory}.
191:          *
192:          * @param newChildDescriptors The collection of child descriptors that the collected descriptors will be added to.
193:          * @param object The object for which the child descriptors are collected
194:          * @since 1.17
195:          */
196:         protected void collectContainerChildDecriptors(Collection<Object> newChildDescriptors, Object object) {
197:                 // Get children descriptors for a vertical layout
198:                 final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(object);
199:                 final VVerticalLayout verticalLayout = VVerticalFactory.eINSTANCE.createVerticalLayout();
200:                 final ResourceSet resourceSet = new ResourceSetImpl();
201:                 resourceSet.eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(editingDomain));
202:                 final Resource resource = resourceSet.createResource(URI.createURI("VIRTUAL_URI")); //$NON-NLS-1$
203:•                if (resource != null) {
204:                         resource.getContents().add(verticalLayout);
205:                 }
206:                 final Collection<?> verticalDescriptors = getChildrenDescriptorCollector()
207:                         .getDescriptors(verticalLayout);
208:
209:                 // TODO needed?
210:                 resourceSet.eAdapters().clear();
211:
212:                 // Iterate over the gathered descriptors and transform relevant ones to fit for the VCategory
213:•                for (final Object descriptor : verticalDescriptors) {
214:                         final CommandParameter parameter = (CommandParameter) descriptor;
215:                         // We only need the descriptors for the VContainer's children reference
216:•                        if (parameter.getEStructuralFeature() == VViewPackage.Literals.CONTAINER__CHILDREN) {
217:                                 newChildDescriptors
218:                                         .add(createChildParameter(VCategorizationPackage.Literals.CATEGORY__COMPOSITE,
219:                                                 parameter.getValue()));
220:                         }
221:                 }
222:         }
223: }