Skip to content

Package: SpreadsheetImportResultImpl

SpreadsheetImportResultImpl

nameinstructionbranchcomplexitylinemethod
SpreadsheetImportResultImpl()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
eGet(int, boolean, boolean)
M: 17 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
eInverseRemove(InternalEObject, int, NotificationChain)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
eIsSet(int)
M: 39 C: 0
0%
M: 16 C: 0
0%
M: 10 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
eSet(int, Object)
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
eStaticClass()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
eUnset(int)
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getErrorReports()
M: 0 C: 14
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getFeatureName(EStructuralFeature)
M: 40 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
getImportedEObjects()
M: 0 C: 14
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getSettingToSheetMap()
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%
getSheetLocation(EObject, EStructuralFeature)
M: 6 C: 50
89%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 1 C: 14
93%
M: 0 C: 1
100%
reportError(Severity, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
reportError(Severity, String, EMFLocation)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
reportError(Severity, String, EMFLocation, SheetLocation)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
reportError(Severity, String, SheetLocation)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (c) 2011-2015 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: * Johannes Faltermeier - initial API and implementation
13: */
14: package org.eclipse.emfforms.spi.spreadsheet.core.error.model.impl;
15:
16: import java.util.Collection;
17:
18: import org.eclipse.emf.common.notify.NotificationChain;
19: import org.eclipse.emf.common.util.EList;
20: import org.eclipse.emf.ecore.EClass;
21: import org.eclipse.emf.ecore.EObject;
22: import org.eclipse.emf.ecore.EStructuralFeature;
23: import org.eclipse.emf.ecore.InternalEObject;
24: import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
25: import org.eclipse.emf.ecore.util.EObjectContainmentEList;
26: import org.eclipse.emf.ecore.util.EObjectResolvingEList;
27: import org.eclipse.emf.ecore.util.EcoreUtil;
28: import org.eclipse.emf.ecore.util.InternalEList;
29: import org.eclipse.emfforms.internal.core.services.label.EMFFormsLabelProviderImpl;
30: import org.eclipse.emfforms.spi.spreadsheet.core.error.model.EMFLocation;
31: import org.eclipse.emfforms.spi.spreadsheet.core.error.model.ErrorFactory;
32: import org.eclipse.emfforms.spi.spreadsheet.core.error.model.ErrorPackage;
33: import org.eclipse.emfforms.spi.spreadsheet.core.error.model.ErrorReport;
34: import org.eclipse.emfforms.spi.spreadsheet.core.error.model.SettingToSheetMapping;
35: import org.eclipse.emfforms.spi.spreadsheet.core.error.model.Severity;
36: import org.eclipse.emfforms.spi.spreadsheet.core.error.model.SheetLocation;
37: import org.eclipse.emfforms.spi.spreadsheet.core.error.model.SpreadsheetImportResult;
38: import org.osgi.framework.Bundle;
39: import org.osgi.framework.BundleContext;
40: import org.osgi.framework.FrameworkUtil;
41: import org.osgi.framework.ServiceReference;
42:
43: /**
44: * <!-- begin-user-doc -->
45: * An implementation of the model object '<em><b>Reports</b></em>'.
46: * <!-- end-user-doc -->
47: * <p>
48: * The following features are implemented:
49: * </p>
50: * <ul>
51: * <li>{@link org.eclipse.emfforms.spi.spreadsheet.core.error.model.impl.SpreadsheetImportResultImpl#getErrorReports
52: * <em>Error Reports</em>}</li>
53: * <li>{@link org.eclipse.emfforms.spi.spreadsheet.core.error.model.impl.SpreadsheetImportResultImpl#getImportedEObjects
54: * <em>Imported EObjects</em>}</li>
55: * <li>
56: * {@link org.eclipse.emfforms.spi.spreadsheet.core.error.model.impl.SpreadsheetImportResultImpl#getSettingToSheetMap
57: * <em>Setting To Sheet Map</em>}</li>
58: * </ul>
59: *
60: * @generated
61: */
62: @SuppressWarnings("restriction")
63: public class SpreadsheetImportResultImpl extends MinimalEObjectImpl.Container implements SpreadsheetImportResult {
64:         /**
65:          * The cached value of the '{@link #getErrorReports() <em>Error Reports</em>}' containment reference list.
66:          * <!-- begin-user-doc -->
67:          * <!-- end-user-doc -->
68:          *
69:          * @see #getErrorReports()
70:          * @generated
71:          * @ordered
72:          */
73:         protected EList<ErrorReport> errorReports;
74:         /**
75:          * The cached value of the '{@link #getImportedEObjects() <em>Imported EObjects</em>}' reference list.
76:          * <!-- begin-user-doc -->
77:          * <!-- end-user-doc -->
78:          *
79:          * @see #getImportedEObjects()
80:          * @generated
81:          * @ordered
82:          */
83:         protected EList<EObject> importedEObjects;
84:
85:         /**
86:          * The cached value of the '{@link #getSettingToSheetMap() <em>Setting To Sheet Map</em>}' reference list.
87:          * <!-- begin-user-doc -->
88:          * <!-- end-user-doc -->
89:          *
90:          * @see #getSettingToSheetMap()
91:          * @generated
92:          * @ordered
93:          */
94:         protected EList<SettingToSheetMapping> settingToSheetMap;
95:
96:         /**
97:          * <!-- begin-user-doc -->
98:          * <!-- end-user-doc -->
99:          *
100:          * @generated
101:          */
102:         protected SpreadsheetImportResultImpl() {
103:                 super();
104:         }
105:
106:         /**
107:          * <!-- begin-user-doc -->
108:          * <!-- end-user-doc -->
109:          *
110:          * @generated
111:          */
112:         @Override
113:         protected EClass eStaticClass() {
114:                 return ErrorPackage.Literals.SPREADSHEET_IMPORT_RESULT;
115:         }
116:
117:         /**
118:          * <!-- begin-user-doc -->
119:          * <!-- end-user-doc -->
120:          *
121:          * @generated
122:          */
123:         @Override
124:         public EList<ErrorReport> getErrorReports() {
125:•                if (errorReports == null) {
126:                         errorReports = new EObjectContainmentEList<ErrorReport>(ErrorReport.class, this,
127:                                 ErrorPackage.SPREADSHEET_IMPORT_RESULT__ERROR_REPORTS);
128:                 }
129:                 return errorReports;
130:         }
131:
132:         /**
133:          * <!-- begin-user-doc -->
134:          * <!-- end-user-doc -->
135:          *
136:          * @generated
137:          */
138:         @Override
139:         public EList<EObject> getImportedEObjects() {
140:•                if (importedEObjects == null) {
141:                         importedEObjects = new EObjectResolvingEList<EObject>(EObject.class, this,
142:                                 ErrorPackage.SPREADSHEET_IMPORT_RESULT__IMPORTED_EOBJECTS);
143:                 }
144:                 return importedEObjects;
145:         }
146:
147:         /**
148:          * <!-- begin-user-doc -->
149:          *
150:          * @return The List of SettingToSheetMapping.
151:          * <!-- end-user-doc -->
152:          *
153:          * @generated NOT
154:          */
155:         @Override
156:         public EList<SettingToSheetMapping> getSettingToSheetMap() {
157:•                if (settingToSheetMap == null) {
158:                         settingToSheetMap = new EObjectResolvingEList<SettingToSheetMapping>(SettingToSheetMapping.class, this,
159:                                 ErrorPackage.SPREADSHEET_IMPORT_RESULT__SETTING_TO_SHEET_MAP) {
160:
161:                                 private static final long serialVersionUID = 8911738816135102554L;
162:
163:                                 /**
164:                                  * {@inheritDoc}
165:                                  *
166:                                  * @see org.eclipse.emf.ecore.util.EObjectEList#isUnique()
167:                                  */
168:                                 @Override
169:                                 protected boolean isUnique() {
170:                                         return false;
171:                                 }
172:
173:                         };
174:                 }
175:                 return settingToSheetMap;
176:         }
177:
178:         /**
179:          * <!-- begin-user-doc -->.
180:          * <!-- end-user-doc -->
181:          *
182:          * @generated
183:          */
184:         @Override
185:         public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
186:•                switch (featureID) {
187:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__ERROR_REPORTS:
188:                         return ((InternalEList<?>) getErrorReports()).basicRemove(otherEnd, msgs);
189:                 }
190:                 return super.eInverseRemove(otherEnd, featureID, msgs);
191:         }
192:
193:         /**
194:          * <!-- begin-user-doc -->
195:          * <!-- end-user-doc -->
196:          *
197:          * @generated
198:          */
199:         @Override
200:         public Object eGet(int featureID, boolean resolve, boolean coreType) {
201:•                switch (featureID) {
202:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__ERROR_REPORTS:
203:                         return getErrorReports();
204:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__IMPORTED_EOBJECTS:
205:                         return getImportedEObjects();
206:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__SETTING_TO_SHEET_MAP:
207:                         return getSettingToSheetMap();
208:                 }
209:                 return super.eGet(featureID, resolve, coreType);
210:         }
211:
212:         /**
213:          * <!-- begin-user-doc -->
214:          * <!-- end-user-doc -->
215:          *
216:          * @generated
217:          */
218:         @SuppressWarnings("unchecked")
219:         @Override
220:         public void eSet(int featureID, Object newValue) {
221:•                switch (featureID) {
222:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__ERROR_REPORTS:
223:                         getErrorReports().clear();
224:                         getErrorReports().addAll((Collection<? extends ErrorReport>) newValue);
225:                         return;
226:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__IMPORTED_EOBJECTS:
227:                         getImportedEObjects().clear();
228:                         getImportedEObjects().addAll((Collection<? extends EObject>) newValue);
229:                         return;
230:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__SETTING_TO_SHEET_MAP:
231:                         getSettingToSheetMap().clear();
232:                         getSettingToSheetMap().addAll((Collection<? extends SettingToSheetMapping>) newValue);
233:                         return;
234:                 }
235:                 super.eSet(featureID, newValue);
236:         }
237:
238:         /**
239:          * <!-- begin-user-doc -->
240:          * <!-- end-user-doc -->
241:          *
242:          * @generated
243:          */
244:         @Override
245:         public void eUnset(int featureID) {
246:•                switch (featureID) {
247:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__ERROR_REPORTS:
248:                         getErrorReports().clear();
249:                         return;
250:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__IMPORTED_EOBJECTS:
251:                         getImportedEObjects().clear();
252:                         return;
253:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__SETTING_TO_SHEET_MAP:
254:                         getSettingToSheetMap().clear();
255:                         return;
256:                 }
257:                 super.eUnset(featureID);
258:         }
259:
260:         /**
261:          * <!-- begin-user-doc -->
262:          * <!-- end-user-doc -->
263:          *
264:          * @generated
265:          */
266:         @Override
267:         public boolean eIsSet(int featureID) {
268:•                switch (featureID) {
269:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__ERROR_REPORTS:
270:•                        return errorReports != null && !errorReports.isEmpty();
271:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__IMPORTED_EOBJECTS:
272:•                        return importedEObjects != null && !importedEObjects.isEmpty();
273:                 case ErrorPackage.SPREADSHEET_IMPORT_RESULT__SETTING_TO_SHEET_MAP:
274:•                        return settingToSheetMap != null && !settingToSheetMap.isEmpty();
275:                 }
276:                 return super.eIsSet(featureID);
277:         }
278:
279:         @Override
280:         public void reportError(Severity severity, String message) {
281:                 reportError(severity, message, null, null);
282:         }
283:
284:         @Override
285:         public void reportError(Severity severity, String message, EMFLocation emfLocation) {
286:                 reportError(severity, message, emfLocation, null);
287:         }
288:
289:         @Override
290:         public void reportError(Severity severity, String message, SheetLocation sheetLocation) {
291:                 reportError(severity, message, null, sheetLocation);
292:         }
293:
294:         @Override
295:         public void reportError(Severity severity, String message, EMFLocation emfLocation, SheetLocation sheetLocation) {
296:                 final ErrorReport report = ErrorFactory.eINSTANCE.createErrorReport();
297:                 report.setSeverity(severity);
298:                 report.setMessage(message);
299:                 report.setEmfLocation(emfLocation);
300:                 report.setSheetLocation(sheetLocation);
301:                 getErrorReports().add(report);
302:         }
303:
304:         /**
305:          * {@inheritDoc}
306:          *
307:          * @see org.eclipse.emfforms.spi.spreadsheet.core.error.model.SpreadsheetImportResult#getSheetLocation(org.eclipse.emf.ecore.EObject,
308:          * org.eclipse.emf.ecore.EStructuralFeature)
309:          */
310:         @Override
311:         public SheetLocation getSheetLocation(EObject eObject, EStructuralFeature structuralFeature) {
312:                 SheetLocation possibleResult = null;
313:•                for (final SettingToSheetMapping settingToSheetMapping : getSettingToSheetMap()) {
314:•                        if (structuralFeature != settingToSheetMapping.getSettingLocation().getFeature()) {
315:                                 continue;
316:                         }
317:•                        if (possibleResult == null) {
318:                                 possibleResult = settingToSheetMapping.getSheetLocation();
319:                         }
320:•                        if (eObject != settingToSheetMapping.getSettingLocation().getEObject()) {
321:                                 continue;
322:                         }
323:                         return EcoreUtil.copy(settingToSheetMapping.getSheetLocation());
324:                 }
325:•                if (possibleResult != null) {
326:                         final SheetLocation result = EcoreUtil.copy(possibleResult);
327:                         result.setRow(SheetLocation.INVALID_ROW);
328:                         result.setValid(false);
329:                         return result;
330:                 }
331:
332:                 return ErrorFactory.eINSTANCE.createInvalidSheetLocation(getFeatureName(structuralFeature));
333:         }
334:
335:         private String getFeatureName(EStructuralFeature structuralFeature) {
336:                 final Bundle bundle = FrameworkUtil.getBundle(getClass());
337:•                if (bundle == null) {
338:                         return structuralFeature.getName();
339:                 }
340:                 final BundleContext bundleContext = bundle.getBundleContext();
341:•                if (bundleContext == null) {
342:                         return structuralFeature.getName();
343:                 }
344:
345:                 final ServiceReference<EMFFormsLabelProviderImpl> serviceReference = bundleContext
346:                         .getServiceReference(EMFFormsLabelProviderImpl.class);
347:•                if (serviceReference == null) {
348:                         return structuralFeature.getName();
349:                 }
350:                 final EMFFormsLabelProviderImpl labelProvider = bundleContext.getService(serviceReference);
351:•                if (labelProvider == null) {
352:                         return structuralFeature.getName();
353:                 }
354:
355:                 return labelProvider.getDisplayName(structuralFeature);
356:         }
357:
358: } // ErrorReportsImpl