|
@@ -1,112 +1,112 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.client.components.impls.input; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
5 |
|
- |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
6 |
|
- |
import org.litesoft.commonfoundation.typeutils.gregorian.*; |
7 |
|
- |
import org.litesoft.core.simpletypes.temporal.*; |
8 |
|
- |
import org.litesoft.core.simpletypes.temporal.nonpublic.*; |
9 |
|
- |
import org.litesoft.uispecification.*; |
10 |
|
- |
|
11 |
|
- |
import java.util.*; |
12 |
|
- |
|
13 |
|
- |
public class FormTimePicker extends AbstractTextFieldWithPicker { |
14 |
|
- |
public FormTimePicker( String pLabel, UiFont pLabelFont, String pTooltip, TimeRes pTimeRes, String pCancelText, String pOKText ) { |
15 |
|
- |
super( pTooltip, false, calcLength( pTimeRes ), "Time", new MyPicker( pCancelText, pOKText, deNull( pTimeRes ) ) ); |
16 |
|
- |
initialize( pLabel, pLabelFont, pTooltip ); |
17 |
|
- |
} |
18 |
|
- |
|
19 |
|
- |
private static TimeRes deNull( TimeRes pTimeRes ) { |
20 |
|
- |
return (pTimeRes != null) ? pTimeRes : TimeRes.ToSEC; |
21 |
|
- |
} |
22 |
|
- |
|
23 |
|
- |
private static int calcLength( TimeRes pTimeRes ) { |
24 |
|
- |
switch ( deNull( pTimeRes ).getIndex() ) { |
25 |
|
- |
default: |
26 |
|
- |
case TimeRes.MSECindex: // 13:32:59.999 |
27 |
|
- |
return 12; // .........1234567-1012 |
28 |
|
- |
case TimeRes.SECindex: //. 13:32:59 |
29 |
|
- |
return 8; // ..........12345678 |
30 |
|
- |
case TimeRes.MINindex: //. 13:32 |
31 |
|
- |
return 5; // ..........12345 |
32 |
|
- |
case TimeRes.HOURindex: // 13 |
33 |
|
- |
return 2; // ..........12 |
34 |
|
- |
} |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
@Override |
38 |
|
- |
protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue ) { |
39 |
|
- |
UtilDateAdaptor zInadequatePartsSource = |
40 |
|
- |
(pLastValidInternalFormValue instanceof SimpleTime) ? ((SimpleTime) pLastValidInternalFormValue).getUtilDateAdaptor() : null; |
41 |
|
- |
return TemporalParser.YMD.parseTime( pText, getPicker().getTimeFields(), zInadequatePartsSource ); |
42 |
|
- |
} |
43 |
|
- |
|
44 |
|
- |
@Override |
45 |
|
- |
protected void pickerClosed( boolean autoClosed ) { |
46 |
|
- |
super.pickerClosed( autoClosed ); |
47 |
|
- |
SimpleTime value = getPicker().getExitValue(); |
48 |
|
- |
|
49 |
|
- |
if ( value != null ) { |
50 |
|
- |
setTextValueFromPicker( value.toString() ); |
51 |
|
- |
} |
52 |
|
- |
} |
53 |
|
- |
|
54 |
|
- |
@Override |
55 |
|
- |
protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue ) { |
56 |
|
- |
SimpleTime zTime; |
57 |
|
- |
if ( pCurrentValue instanceof SimpleTime ) { |
58 |
|
- |
zTime = (SimpleTime) pCurrentValue; |
59 |
|
- |
} else if ( pLastValidInternalFormValue instanceof SimpleTime ) { |
60 |
|
- |
zTime = (SimpleTime) pLastValidInternalFormValue; |
61 |
|
- |
} else { |
62 |
|
- |
zTime = SimpleTime.timeComponents( new Date() ); |
63 |
|
- |
} |
64 |
|
- |
getPicker().setInitialValues( zTime ); |
65 |
|
- |
super.showPicker( pAbsoluteLeft, pAbsoluteTop, pCurrentValue, pLastValidInternalFormValue ); |
66 |
|
- |
} |
67 |
|
- |
|
68 |
|
- |
private MyPicker getPicker() { |
69 |
|
- |
return (MyPicker) mPicker; |
70 |
|
- |
} |
71 |
|
- |
|
72 |
|
- |
private static class MyPicker extends ExtendableDialogPicker { |
73 |
|
- |
private SimpleTime mExitValue = null; |
74 |
|
- |
private int mTimeFields; |
75 |
|
- |
private TimePickerFieldsPanel mTimeFieldsPanel; |
76 |
|
- |
private Button mOkButton; |
77 |
|
- |
|
78 |
|
- |
public MyPicker( String pCancelText, String pOKText, TimeRes pTimeRes ) { |
79 |
|
- |
mTimeFields = pTimeRes.getIndex() + 1; |
80 |
|
- |
mTimeFieldsPanel = new TimePickerFieldsPanel( "litesoft-TimePickerFieldsPanel", mTimeFields, null ); |
81 |
|
- |
addExtensionPanel( mTimeFieldsPanel ); |
82 |
|
- |
addDialogButtonPanel( CancelButton.factory( pCancelText ).create(), // |
83 |
|
- |
mOkButton = OKButton.factory( pOKText ).create() ); |
84 |
|
- |
} |
85 |
|
- |
|
86 |
|
- |
public int getTimeFields() { |
87 |
|
- |
return mTimeFields; |
88 |
|
- |
} |
89 |
|
- |
|
90 |
|
- |
@Override |
91 |
|
- |
protected void dialogButtonClicked( Button pButton ) { |
92 |
|
- |
if ( mOkButton == pButton ) { |
93 |
|
- |
mExitValue = mTimeFieldsPanel.getSimpleTime(); |
94 |
|
- |
} |
95 |
|
- |
hide(); |
96 |
|
- |
} |
97 |
|
- |
|
98 |
|
- |
public SimpleTime getExitValue() { |
99 |
|
- |
return mExitValue; |
100 |
|
- |
} |
101 |
|
- |
|
102 |
|
- |
@Override |
103 |
|
- |
public void show() { |
104 |
|
- |
mExitValue = null; |
105 |
|
- |
super.show(); |
106 |
|
- |
} |
107 |
|
- |
|
108 |
|
- |
public void setInitialValues( SimpleTime pTime ) { |
109 |
|
- |
mTimeFieldsPanel.setTimeFields( pTime.getUtilDateAdaptor() ); |
110 |
|
- |
} |
111 |
|
- |
} |
112 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.client.components.impls.input; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
5 |
+ |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.typeutils.gregorian.*; |
|
7 |
+ |
import org.litesoft.core.simpletypes.temporal.*; |
|
8 |
+ |
import org.litesoft.core.simpletypes.temporal.nonpublic.*; |
|
9 |
+ |
import org.litesoft.uispecification.*; |
|
10 |
+ |
|
|
11 |
+ |
import java.util.*; |
|
12 |
+ |
|
|
13 |
+ |
public class FormTimePicker extends AbstractTextFieldWithPicker { |
|
14 |
+ |
public FormTimePicker( String pLabel, UiFont pLabelFont, String pTooltip, TimeRes pTimeRes, String pCancelText, String pOKText ) { |
|
15 |
+ |
super( pTooltip, false, calcLength( pTimeRes ), "Time", new MyPicker( pCancelText, pOKText, deNull( pTimeRes ) ) ); |
|
16 |
+ |
initialize( pLabel, pLabelFont, pTooltip ); |
|
17 |
+ |
} |
|
18 |
+ |
|
|
19 |
+ |
private static TimeRes deNull( TimeRes pTimeRes ) { |
|
20 |
+ |
return (pTimeRes != null) ? pTimeRes : TimeRes.ToSEC; |
|
21 |
+ |
} |
|
22 |
+ |
|
|
23 |
+ |
private static int calcLength( TimeRes pTimeRes ) { |
|
24 |
+ |
switch ( deNull( pTimeRes ).getIndex() ) { |
|
25 |
+ |
default: |
|
26 |
+ |
case TimeRes.MSECindex: // 13:32:59.999 |
|
27 |
+ |
return 12; // .........1234567-1012 |
|
28 |
+ |
case TimeRes.SECindex: //. 13:32:59 |
|
29 |
+ |
return 8; // ..........12345678 |
|
30 |
+ |
case TimeRes.MINindex: //. 13:32 |
|
31 |
+ |
return 5; // ..........12345 |
|
32 |
+ |
case TimeRes.HOURindex: // 13 |
|
33 |
+ |
return 2; // ..........12 |
|
34 |
+ |
} |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
@Override |
|
38 |
+ |
protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue ) { |
|
39 |
+ |
UtilDateAdaptor zInadequatePartsSource = |
|
40 |
+ |
(pLastValidInternalFormValue instanceof SimpleTime) ? ((SimpleTime) pLastValidInternalFormValue).getUtilDateAdaptor() : null; |
|
41 |
+ |
return TemporalParser.YMD.parseTime( pText, getPicker().getTimeFields(), zInadequatePartsSource ); |
|
42 |
+ |
} |
|
43 |
+ |
|
|
44 |
+ |
@Override |
|
45 |
+ |
protected void pickerClosed( boolean autoClosed ) { |
|
46 |
+ |
super.pickerClosed( autoClosed ); |
|
47 |
+ |
SimpleTime value = getPicker().getExitValue(); |
|
48 |
+ |
|
|
49 |
+ |
if ( value != null ) { |
|
50 |
+ |
setTextValueFromPicker( value.toString() ); |
|
51 |
+ |
} |
|
52 |
+ |
} |
|
53 |
+ |
|
|
54 |
+ |
@Override |
|
55 |
+ |
protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue ) { |
|
56 |
+ |
SimpleTime zTime; |
|
57 |
+ |
if ( pCurrentValue instanceof SimpleTime ) { |
|
58 |
+ |
zTime = (SimpleTime) pCurrentValue; |
|
59 |
+ |
} else if ( pLastValidInternalFormValue instanceof SimpleTime ) { |
|
60 |
+ |
zTime = (SimpleTime) pLastValidInternalFormValue; |
|
61 |
+ |
} else { |
|
62 |
+ |
zTime = SimpleTime.timeComponents( new Date() ); |
|
63 |
+ |
} |
|
64 |
+ |
getPicker().setInitialValues( zTime ); |
|
65 |
+ |
super.showPicker( pAbsoluteLeft, pAbsoluteTop, pCurrentValue, pLastValidInternalFormValue ); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
private MyPicker getPicker() { |
|
69 |
+ |
return (MyPicker) mPicker; |
|
70 |
+ |
} |
|
71 |
+ |
|
|
72 |
+ |
private static class MyPicker extends ExtendableDialogPicker { |
|
73 |
+ |
private SimpleTime mExitValue = null; |
|
74 |
+ |
private int mTimeFields; |
|
75 |
+ |
private TimePickerFieldsPanel mTimeFieldsPanel; |
|
76 |
+ |
private Button mOkButton; |
|
77 |
+ |
|
|
78 |
+ |
public MyPicker( String pCancelText, String pOKText, TimeRes pTimeRes ) { |
|
79 |
+ |
mTimeFields = pTimeRes.getIndex() + 1; |
|
80 |
+ |
mTimeFieldsPanel = new TimePickerFieldsPanel( "litesoft-TimePickerFieldsPanel", mTimeFields, null ); |
|
81 |
+ |
addExtensionPanel( mTimeFieldsPanel ); |
|
82 |
+ |
addDialogButtonPanel( CancelButton.factory( pCancelText ).create(), // |
|
83 |
+ |
mOkButton = OKButton.factory( pOKText ).create() ); |
|
84 |
+ |
} |
|
85 |
+ |
|
|
86 |
+ |
public int getTimeFields() { |
|
87 |
+ |
return mTimeFields; |
|
88 |
+ |
} |
|
89 |
+ |
|
|
90 |
+ |
@Override |
|
91 |
+ |
protected void dialogButtonClicked( Button pButton ) { |
|
92 |
+ |
if ( mOkButton == pButton ) { |
|
93 |
+ |
mExitValue = mTimeFieldsPanel.getSimpleTime(); |
|
94 |
+ |
} |
|
95 |
+ |
hide(); |
|
96 |
+ |
} |
|
97 |
+ |
|
|
98 |
+ |
public SimpleTime getExitValue() { |
|
99 |
+ |
return mExitValue; |
|
100 |
+ |
} |
|
101 |
+ |
|
|
102 |
+ |
@Override |
|
103 |
+ |
public void show() { |
|
104 |
+ |
mExitValue = null; |
|
105 |
+ |
super.show(); |
|
106 |
+ |
} |
|
107 |
+ |
|
|
108 |
+ |
public void setInitialValues( SimpleTime pTime ) { |
|
109 |
+ |
mTimeFieldsPanel.setTimeFields( pTime.getUtilDateAdaptor() ); |
|
110 |
+ |
} |
|
111 |
+ |
} |
|
112 |
+ |
} |