1
|
/**
|
2
|
* Copyright (C) 2014 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.ui.mvc.element;
|
10
|
|
11
|
|
12
|
import java.util.Calendar;
|
13
|
import java.util.ConcurrentModificationException;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.eclipse.core.runtime.Assert;
|
17
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
18
|
import org.eclipse.swt.SWT;
|
19
|
import org.eclipse.swt.events.DisposeEvent;
|
20
|
import org.eclipse.swt.events.DisposeListener;
|
21
|
import org.eclipse.swt.events.SelectionAdapter;
|
22
|
import org.eclipse.swt.events.SelectionEvent;
|
23
|
import org.eclipse.swt.graphics.Image;
|
24
|
import org.eclipse.swt.layout.GridData;
|
25
|
import org.eclipse.swt.layout.GridLayout;
|
26
|
import org.eclipse.swt.widgets.Button;
|
27
|
import org.eclipse.swt.widgets.Composite;
|
28
|
import org.eclipse.swt.widgets.DateTime;
|
29
|
import org.eclipse.swt.widgets.Display;
|
30
|
import org.eclipse.swt.widgets.Label;
|
31
|
import org.eclipse.swt.widgets.Shell;
|
32
|
import org.eclipse.swt.widgets.Text;
|
33
|
import org.eclipse.ui.forms.widgets.FormToolkit;
|
34
|
import org.eclipse.ui.forms.widgets.TableWrapData;
|
35
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
36
|
//import org.joda.time.DateTime;
|
37
|
|
38
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
39
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
40
|
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
41
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
42
|
import eu.etaxonomy.taxeditor.ui.element.IPropertyChangeEmitter;
|
43
|
import eu.etaxonomy.taxeditor.ui.mvc.AbstractCdmComposite;
|
44
|
|
45
|
/**
|
46
|
* @author pplitzner
|
47
|
* @date 16.06.2014
|
48
|
*
|
49
|
*/
|
50
|
public class DateElement extends AbstractCdmComposite<DateElementController> {
|
51
|
|
52
|
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
|
53
|
private org.joda.time.DateTime initialDateTime;
|
54
|
private Text textDate;
|
55
|
// private final Button openDateDialog;
|
56
|
|
57
|
|
58
|
/**
|
59
|
* Create the composite.
|
60
|
* @param parent
|
61
|
* @param style
|
62
|
*/
|
63
|
public DateElement(Composite parent, org.joda.time.DateTime initialDateTime, int style) {
|
64
|
super(parent, style);
|
65
|
this.initialDateTime = initialDateTime;
|
66
|
addDisposeListener(new DisposeListener() {
|
67
|
@Override
|
68
|
public void widgetDisposed(DisposeEvent e) {
|
69
|
toolkit.dispose();
|
70
|
}
|
71
|
});
|
72
|
toolkit.adapt(this);
|
73
|
toolkit.paintBordersFor(this);
|
74
|
{
|
75
|
TableWrapLayout tableWrapLayout = new TableWrapLayout();
|
76
|
tableWrapLayout.verticalSpacing = 0;
|
77
|
tableWrapLayout.topMargin = 0;
|
78
|
tableWrapLayout.rightMargin = 0;
|
79
|
tableWrapLayout.leftMargin = 0;
|
80
|
tableWrapLayout.horizontalSpacing = 0;
|
81
|
tableWrapLayout.bottomMargin = 0;
|
82
|
setLayout(tableWrapLayout);
|
83
|
}
|
84
|
|
85
|
textDate = new Text(this, SWT.BORDER | SWT.WRAP);
|
86
|
textDate.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));
|
87
|
|
88
|
// openDateDialog = new Button (this, SWT.PUSH);
|
89
|
// Image image = getDisplay().getSystemImage(SWT.DATE);
|
90
|
// openDateDialog.setText ("Open Date Dialog");
|
91
|
// openDateDialog.addSelectionListener (new SelectionAdapter() {
|
92
|
// @Override
|
93
|
// public void widgetSelected(SelectionEvent e){
|
94
|
// final Shell dialog = new Shell (parent.getShell(), SWT.DIALOG_TRIM);
|
95
|
//
|
96
|
// dialog.setLayout (new GridLayout (3, false));
|
97
|
//
|
98
|
// final DateTime calendar = new DateTime (dialog, SWT.CALENDAR | SWT.BORDER);
|
99
|
// //final DateTime time = new DateTime (dialog, SWT.TIME | SWT.SHORT);
|
100
|
//
|
101
|
// new Label (dialog, SWT.NONE);
|
102
|
// new Label (dialog, SWT.NONE);
|
103
|
// Button ok = new Button (dialog, SWT.PUSH);
|
104
|
// ok.setText ("OK");
|
105
|
// ok.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, false, false));
|
106
|
// ok.addSelectionListener (new SelectionAdapter() {
|
107
|
// @Override
|
108
|
// public void widgetSelected(SelectionEvent e){
|
109
|
// setData(makeJodaFromSWT(calendar));
|
110
|
// setTextDate((calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ());
|
111
|
// System.out.println ("Calendar date selected (MM/DD/YYYY) = " + (calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ());
|
112
|
// // System.out.println ("Time selected (HH:MM) = " + time.getHours () + ":" + (time.getMinutes () < 10 ? "0" : "") + time.getMinutes ());
|
113
|
// dialog.close ();
|
114
|
// }
|
115
|
// });
|
116
|
// dialog.setDefaultButton (ok);
|
117
|
// dialog.pack ();
|
118
|
// dialog.open ();
|
119
|
// }
|
120
|
// });
|
121
|
|
122
|
toolkit.adapt(textDate, true, true);
|
123
|
}
|
124
|
|
125
|
/* (non-Javadoc)
|
126
|
* @see eu.etaxonomy.taxeditor.ui.mvc.AbstractCdmComposite#initInternalController(eu.etaxonomy.taxeditor.ui.element.CdmFormFactory, eu.etaxonomy.taxeditor.ui.element.ICdmFormElement)
|
127
|
*/
|
128
|
@Override
|
129
|
protected void initInternalController(CdmFormFactory formFactory, ICdmFormElement parentElement) {
|
130
|
controller = new DateElementController(this, formFactory, parentElement, initialDateTime);
|
131
|
formFactory.adapt(controller);
|
132
|
}
|
133
|
public Text getTextDate() {
|
134
|
return textDate;
|
135
|
}
|
136
|
|
137
|
// public void setTextDate(String text){
|
138
|
// textDate.setText(text);
|
139
|
// }
|
140
|
// /**
|
141
|
// * <p>
|
142
|
// * Setter for the field <code>entity</code>.
|
143
|
// * </p>
|
144
|
// *
|
145
|
// * @param selection
|
146
|
// * a T object.
|
147
|
// */
|
148
|
// public void setEntity(org.joda.time.DateTime time) {
|
149
|
// this.initialDateTime = time;
|
150
|
//
|
151
|
// }
|
152
|
//
|
153
|
//
|
154
|
// public static org.joda.time.DateTime makeJodaFromSWT(
|
155
|
// org.eclipse.swt.widgets.DateTime widget) {
|
156
|
// return new org.joda.time.DateTime(widget.getYear(),
|
157
|
// widget.getMonth(),
|
158
|
// widget.getDay(),
|
159
|
// widget.getHours(),
|
160
|
// widget.getMinutes(),
|
161
|
// widget.getSeconds());
|
162
|
// }
|
163
|
//
|
164
|
// public static void updateSWTwithJoda(
|
165
|
// org.eclipse.swt.widgets.DateTime widget,
|
166
|
// org.joda.time.DateTime dateTime) {
|
167
|
// widget.setYear(dateTime.getYear());
|
168
|
// widget.setMonth(dateTime.getMonthOfYear());
|
169
|
// widget.setDay(dateTime.getDayOfMonth());
|
170
|
// widget.setHours(dateTime.getHourOfDay());
|
171
|
// widget.setMinutes(dateTime.getMinuteOfHour());
|
172
|
// widget.setSeconds(dateTime.getSecondOfMinute());
|
173
|
// }
|
174
|
//
|
175
|
// public void setData (org.joda.time.DateTime data) {
|
176
|
// this.initialDateTime = data;
|
177
|
//
|
178
|
// }
|
179
|
|
180
|
|
181
|
|
182
|
|
183
|
|
184
|
|
185
|
}
|