blob: 814e1710ac801d0e4ccf09747044f77b288bffee (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*******************************************************************************
* Copyright (c) 2004 - 2006 University Of British Columbia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* University Of British Columbia - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.ui.planner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.mylyn.tasks.ui.DatePicker;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* @author Ken Sueda
* @author Mik Kersten
* @author Rob Elves
*/
public class ReminderCellEditor extends DialogCellEditor {
private Date reminderDate;
private DateSelectionDialog dialog;
private String formatString = "dd-MMM-yyyy";
private SimpleDateFormat format = new SimpleDateFormat(formatString, Locale.ENGLISH);
public ReminderCellEditor(Composite parent) {
super(parent, SWT.NONE);
}
@Override
protected Object openDialogBox(Control cellEditorWindow) {
Calendar initialCalendar = null;
String value = (String) super.getValue();
if (value != null) {
try {
Date tempDate = format.parse(value);
if (tempDate != null) {
initialCalendar = GregorianCalendar.getInstance();
initialCalendar.setTime(tempDate);
}
} catch (ParseException e) {
// ignore
}
}
Calendar newCalendar = GregorianCalendar.getInstance();
if (initialCalendar != null) {
newCalendar.setTime(initialCalendar.getTime());
}
dialog = new DateSelectionDialog(cellEditorWindow.getShell(), newCalendar, DatePicker.TITLE_DIALOG);
int dialogResponse = dialog.open();
if (dialogResponse == DateSelectionDialog.CANCEL) {
if (initialCalendar != null) {
reminderDate = initialCalendar.getTime();
} else {
reminderDate = null;
}
} else {
reminderDate = dialog.getDate();
}
String result = null;
if (reminderDate != null) {
result = format.format(reminderDate);
}
return result;
}
public Date getReminderDate() {
return reminderDate;
}
@Override
protected void doSetFocus() {
reminderDate = null;
super.doSetFocus();
}
}
|