Skip to content

Package: DateCellStringTooltipModifier

DateCellStringTooltipModifier

nameinstructionbranchcomplexitylinemethod
DateCellStringTooltipModifier()
M: 0 C: 29
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
getPriority()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
modifyString(String, EStructuralFeature.Setting)
M: 14 C: 43
75%
M: 3 C: 9
75%
M: 3 C: 4
57%
M: 4 C: 14
78%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2017 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: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.edit.internal.swt.table;
15:
16: import java.text.DateFormat;
17: import java.util.Date;
18: import java.util.Locale;
19:
20: import javax.xml.datatype.XMLGregorianCalendar;
21:
22: import org.eclipse.emf.ecore.EClassifier;
23: import org.eclipse.emf.ecore.EReference;
24: import org.eclipse.emf.ecore.EStructuralFeature;
25: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
26: import org.eclipse.emf.ecp.view.spi.provider.ECPStringModifier;
27: import org.eclipse.emfforms.spi.common.locale.EMFFormsLocaleProvider;
28: import org.osgi.framework.BundleContext;
29: import org.osgi.framework.FrameworkUtil;
30: import org.osgi.framework.ServiceReference;
31:
32: /** String modifier for date cell tooltips. */
33: public class DateCellStringTooltipModifier implements ECPStringModifier {
34:
35:         private final DateFormat dateInstance;
36:
37:         /** Default constructor. */
38:         public DateCellStringTooltipModifier() {
39:                 final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
40:                 final ServiceReference<EMFFormsLocaleProvider> serviceReference = bundleContext
41:                         .getServiceReference(EMFFormsLocaleProvider.class);
42:                 final EMFFormsLocaleProvider localeProvider = bundleContext.getService(serviceReference);
43:                 final Locale locale = localeProvider.getLocale();
44:                 bundleContext.ungetService(serviceReference);
45:                 dateInstance = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
46:         }
47:
48:         @Override
49:         public String modifyString(String text, Setting setting) {
50:•                if (setting != null) {
51:                         final Object value = setting.get(true);
52:•                        if (value == null) {
53:                                 return text;
54:                         }
55:                         final EStructuralFeature eStructuralFeature = setting.getEStructuralFeature();
56:•                        if (eStructuralFeature instanceof EReference) {
57:                                 return text;
58:                         }
59:                         final EClassifier eType = eStructuralFeature.getEType();
60:•                        if (eType == null) {
61:                                 return text;
62:                         }
63:•                        if (XMLGregorianCalendar.class.isAssignableFrom(eType.getInstanceClass())) {
64:                                 final XMLGregorianCalendar calendar = (XMLGregorianCalendar) value;
65:                                 return dateInstance.format(calendar.toGregorianCalendar().getTime());
66:                         }
67:•                        if (Date.class.isAssignableFrom(eType.getInstanceClass())) {
68:                                 final Date date = (Date) value;
69:                                 final String string = dateInstance.format(date);
70:                                 return string;
71:                         }
72:                 }
73:                 return text;
74:         }
75:
76:         @Override
77:         public double getPriority() {
78:                 return 10;
79:         }
80:
81: }