Skip to content

Package: DateTimeControl

DateTimeControl

nameinstructionbranchcomplexitylinemethod
DateTimeControl()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
bindValue()
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
createDateAndTimeWidget(Composite)
M: 45 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
fillControlComposite(Composite)
M: 40 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getControlsForTooltip()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getUnsetButtonTooltip()
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%
getUnsetLabelText()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setEditable(boolean)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
updateValidationColor(Color)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

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: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.edit.internal.swt.controls;
16:
17: import org.eclipse.core.databinding.Binding;
18: import org.eclipse.core.databinding.observable.value.DateAndTimeObservableValue;
19: import org.eclipse.core.databinding.observable.value.IObservableValue;
20: import org.eclipse.emfforms.spi.localization.LocalizationServiceHelper;
21: import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
22: import org.eclipse.jface.layout.GridDataFactory;
23: import org.eclipse.jface.layout.GridLayoutFactory;
24: import org.eclipse.swt.SWT;
25: import org.eclipse.swt.graphics.Color;
26: import org.eclipse.swt.layout.GridData;
27: import org.eclipse.swt.widgets.Composite;
28: import org.eclipse.swt.widgets.Control;
29: import org.eclipse.swt.widgets.DateTime;
30:
31: /**
32: * This class defines a DateTimeControl which is used for displaying {@link org.eclipse.emf.ecore.EStructuralFeature
33: * EStructuralFeature}s which have a date
34: * value.
35: *
36: * @author Eugen Neufeld
37: *
38: */
39: @Deprecated
40: public class DateTimeControl extends SingleControl {
41:
42:         private DateTime dateWidget;
43:
44:         private DateTime timeWidget;
45:
46:         @Override
47:         protected void fillControlComposite(Composite composite) {
48:                 final Composite dateTimeComposite = new Composite(composite, SWT.NONE);
49:                 dateTimeComposite.setBackground(composite.getBackground());
50:                 int numColumns = 3;
51:•                if (isEmbedded()) {
52:                         numColumns = 2;
53:                 }
54:                 GridLayoutFactory.fillDefaults().numColumns(numColumns).spacing(2, 0).equalWidth(false)
55:                         .applyTo(dateTimeComposite);
56:
57:                 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(dateTimeComposite);
58:                 createDateAndTimeWidget(dateTimeComposite);
59:
60:         }
61:
62:         /**
63:          * This method creates the date widget, the time widget and the delete button.
64:          *
65:          * @param composite the parent {@link Composite}
66:          */
67:         private void createDateAndTimeWidget(Composite composite) {
68:
69:                 dateWidget = new DateTime(composite, SWT.DATE | SWT.BORDER);
70:                 dateWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
71:                 dateWidget.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_control_dateTime_date"); //$NON-NLS-1$
72:
73:                 timeWidget = new DateTime(composite, SWT.TIME | SWT.SHORT | SWT.BORDER);
74:                 timeWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
75:                 timeWidget.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_control_dateTime_time"); //$NON-NLS-1$
76:         }
77:
78:         /**
79:          * {@inheritDoc}
80:          */
81:         @Override
82:         public void setEditable(boolean isEditable) {
83:                 dateWidget.setEnabled(isEditable);
84:                 timeWidget.setEnabled(isEditable);
85:         }
86:
87:         @Override
88:         public Binding bindValue() {
89:                 final IObservableValue dateObserver = WidgetProperties.dateTimeSelection().observe(dateWidget);
90:                 final IObservableValue timeObserver = WidgetProperties.dateTimeSelection().observe(timeWidget);
91:                 final IObservableValue target = new DateAndTimeObservableValue(dateObserver, timeObserver);
92:                 final Binding binding = getDataBindingContext().bindValue(target, getModelValue());
93:                 return binding;
94:         }
95:
96:         /*
97:          * (non-Javadoc)
98:          * @see org.eclipse.emf.ecp.edit.internal.swt.controls.SingleControl#getUnsetLabelText()
99:          */
100:         @Override
101:         protected String getUnsetLabelText() {
102:                 return LocalizationServiceHelper.getString(getClass(),
103:                         DepricatedControlMessageKeys.DateTimeControl_NoDateSetClickToSetDate);
104:         }
105:
106:         /*
107:          * (non-Javadoc)
108:          * @see org.eclipse.emf.ecp.edit.internal.swt.controls.SingleControl#getUnsetButtonTooltip()
109:          */
110:         @Override
111:         protected String getUnsetButtonTooltip() {
112:                 return LocalizationServiceHelper.getString(getClass(), DepricatedControlMessageKeys.DateTimeControl_UnsetDate);
113:         }
114:
115:         /*
116:          * (non-Javadoc)
117:          * @see org.eclipse.emf.ecp.edit.internal.swt.util.SWTControl#getControlForTooltip()
118:          */
119:         @Override
120:         protected Control[] getControlsForTooltip() {
121:                 // return new Control[] { dateWidget, timeWidget };
122:                 return new Control[0];
123:         }
124:
125:         /**
126:          * {@inheritDoc}
127:          *
128:          * @see org.eclipse.emf.ecp.edit.internal.swt.controls.SingleControl#updateValidationColor(org.eclipse.swt.graphics.Color)
129:          */
130:         @Override
131:         protected void updateValidationColor(Color color) {
132:                 dateWidget.setBackground(color);
133:                 timeWidget.setBackground(color);
134:         }
135: }