01: package net.sourceforge.squirrel_sql.plugins.editextras;
02:
03: import net.sourceforge.squirrel_sql.client.session.ISession;
04: import net.sourceforge.squirrel_sql.client.gui.mainframe.MainFrame;
05: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
06:
07: import java.awt.event.ActionEvent;
08: import java.awt.event.ActionListener;
09: import java.util.Calendar;
10:
11: public class EscapeDateController {
12: private EscapeDateFrame _frame;
13: private ISession _session;
14:
15: public EscapeDateController(ISession session, MainFrame mainFrame) {
16: _session = session;
17: _frame = new EscapeDateFrame(mainFrame);
18:
19: _frame.btnTimestamp.addActionListener(new ActionListener() {
20: public void actionPerformed(ActionEvent e) {
21: onTimeStamp();
22: }
23: });
24: _frame.btnDate.addActionListener(new ActionListener() {
25: public void actionPerformed(ActionEvent e) {
26: onDate();
27: }
28: });
29: _frame.btnTime.addActionListener(new ActionListener() {
30: public void actionPerformed(ActionEvent e) {
31: onTime();
32: }
33: });
34:
35: Calendar cal = Calendar.getInstance();
36:
37: _frame.txtYear.setText("" + cal.get(Calendar.YEAR));
38: _frame.txtMonth.setText("" + (cal.get(Calendar.MONTH) + 1));
39: _frame.txtDay.setText("" + cal.get(Calendar.DAY_OF_MONTH));
40: _frame.txtHour.setText("" + cal.get(Calendar.HOUR_OF_DAY));
41: _frame.txtMinute.setText("" + cal.get(Calendar.MINUTE));
42: _frame.txtSecond.setText("" + cal.get(Calendar.SECOND));
43:
44: GUIUtils.centerWithinParent(_frame);
45: _frame.setVisible(true);
46:
47: }
48:
49: private String prefixNulls(String toPrefix, int digitCount) {
50: String ret = "" + toPrefix;
51:
52: while (ret.length() < digitCount) {
53: ret = 0 + ret;
54: }
55:
56: return ret;
57: }
58:
59: private void onTime() {
60: String esc = "{t '" + prefixNulls(_frame.txtHour.getText(), 2)
61: + ":" + prefixNulls(_frame.txtMinute.getText(), 2)
62: + ":" + prefixNulls(_frame.txtSecond.getText(), 2)
63: + "'}";
64:
65: _session.getSQLPanelAPIOfActiveSessionWindow()
66: .getSQLEntryPanel().replaceSelection(esc);
67: _frame.setVisible(false);
68: _frame.dispose();
69: }
70:
71: private void onDate() {
72: String esc = "{d '" + prefixNulls(_frame.txtYear.getText(), 4)
73: + "-" + prefixNulls(_frame.txtMonth.getText(), 2) + "-"
74: + prefixNulls(_frame.txtDay.getText(), 2) + "'}";
75:
76: _session.getSQLPanelAPIOfActiveSessionWindow()
77: .getSQLEntryPanel().replaceSelection(esc);
78: _frame.setVisible(false);
79: _frame.dispose();
80: }
81:
82: private void onTimeStamp() {
83: String esc = "{ts '" + prefixNulls(_frame.txtYear.getText(), 4)
84: + "-" + prefixNulls(_frame.txtMonth.getText(), 2) + "-"
85: + prefixNulls(_frame.txtDay.getText(), 2) + " "
86: + prefixNulls(_frame.txtHour.getText(), 2) + ":"
87: + prefixNulls(_frame.txtMinute.getText(), 2) + ":"
88: + prefixNulls(_frame.txtSecond.getText(), 2) + "'}";
89:
90: _session.getSQLPanelAPIOfActiveSessionWindow()
91: .getSQLEntryPanel().replaceSelection(esc);
92: _frame.setVisible(false);
93: _frame.dispose();
94: }
95:
96: }
|