-
Notifications
You must be signed in to change notification settings - Fork 4
/
QS2167_DateTimePopup.java
112 lines (81 loc) · 2.75 KB
/
QS2167_DateTimePopup.java
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.xored.q7.quality.mockups.issues.parts;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.xored.q7.quality.mockups.issues.BaseMockupPart;
public class QS2167_DateTimePopup extends BaseMockupPart {
public String getLabel() {
return "QS-2167, DateTime picker in pop-up window";
}
public Control construct(Composite section) {
Composite client = new Composite(section, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(client);
GridDataFactory.fillDefaults().grab(true, false).applyTo(client);
final Text text = new Text(client, SWT.BORDER);
text.setText("click here");
GridDataFactory.fillDefaults().grab(true, false).applyTo(text);
text.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
new DateTimePicker(text);
}
});
return client;
}
private static class DateTimePicker {
public DateTimePicker(final Text text) {
final Shell shell = new Shell(SWT.NONE);
shell.setText("Pick a Date");
final DateTime calendar = new DateTime(shell, SWT.CALENDAR);
calendar.pack();
shell.pack();
Point location = text.getLocation();
location.y += text.getBounds().height;
shell.setLocation(text.toDisplay(location));
calendar.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
public void widgetDefaultSelected(SelectionEvent e) {
text.setText(String.format("%s/%s/%s",
calendar.getMonth() + 1, calendar.getDay(),
calendar.getYear()));
shell.dispose();
}
});
shell.addShellListener(new ShellListener() {
public void shellIconified(ShellEvent e) {
// TODO Auto-generated method stub
}
public void shellDeiconified(ShellEvent e) {
// TODO Auto-generated method stub
}
public void shellDeactivated(ShellEvent e) {
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
shell.dispose();
}
});
}
public void shellClosed(ShellEvent e) {
// TODO Auto-generated method stub
}
public void shellActivated(ShellEvent e) {
// TODO Auto-generated method stub
}
});
shell.open();
}
}
}