Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/impls/input/FormTimestampPicker.java

Diff revisions: vs.
  @@ -1,125 +1,125 @@
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 FormTimestampPicker extends AbstractTextFieldWithPicker {
14 - public FormTimestampPicker( String pFieldLabel, UiFont pLabelFont, String pTooltip, TimeRes pTimeRes, String pCancelText, String pOKText ) {
15 - super( pTooltip, false, calcLength( pTimeRes ), "CalendarTime", new MyPicker( pCancelText, pOKText, deNull( pTimeRes ) ) );
16 - initialize( pFieldLabel, pLabelFont, pTooltip );
17 - }
18 -
19 - private static TimeRes deNull( TimeRes pTimeRes ) {
20 - return (pTimeRes != null) ? pTimeRes : TimeRes.ToMSEC;
21 - }
22 -
23 - private static int calcLength( TimeRes pTimeRes ) {
24 - switch ( deNull( pTimeRes ).getIndex() ) {
25 - default:
26 - case TimeRes.MSECindex: // 1957/01/04 13:32:59.999
27 - return 23; // .........1234567-101234567-20123
28 - case TimeRes.SECindex: //. 1957/01/04 13:32:59
29 - return 19; // .........1234567-10123456789
30 - case TimeRes.MINindex: //. 1957/01/04 13:32
31 - return 16; // .........1234567-10123456
32 - case TimeRes.HOURindex: // 1957/01/04 13
33 - return 13; // .........1234567-10123
34 - }
35 - }
36 -
37 - @Override
38 - protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue ) {
39 - UtilDateAdaptor zInadequatePartsSource =
40 - (pLastValidInternalFormValue instanceof SimpleTimestamp) ? ((SimpleTimestamp) pLastValidInternalFormValue).getUtilDateAdaptor() : null;
41 - return TemporalParser.YMD.parseTimestamp( pText, getPicker().getTimeFields(), zInadequatePartsSource );
42 - }
43 -
44 - @Override
45 - protected void pickerClosed( boolean autoClosed ) {
46 - super.pickerClosed( autoClosed );
47 - SimpleTimestamp 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 - SimpleTimestamp zTimestamp;
57 - if ( pCurrentValue instanceof SimpleTimestamp ) {
58 - zTimestamp = (SimpleTimestamp) pCurrentValue;
59 - } else if ( pLastValidInternalFormValue instanceof SimpleTimestamp ) {
60 - zTimestamp = (SimpleTimestamp) pLastValidInternalFormValue;
61 - } else {
62 - zTimestamp = new SimpleTimestamp( new Date() );
63 - }
64 - getPicker().setInitialValues( zTimestamp );
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 ExtendableDatePicker implements HigherOrderAdjustable {
73 - private SimpleTimestamp mExitValue = null;
74 - private int mTimeFields;
75 - private Button mOkButton;
76 -
77 - public MyPicker( String pCancelText, String pOKText, TimeRes pTimeRes ) {
78 - mTimeFields = pTimeRes.getIndex() + 1;
79 - mTimeFieldsPanel = new TimePickerFieldsPanel( "litesoft-TimestampTimePickerFieldsPanel", mTimeFields, this );
80 - addExtensionPanel( mTimeFieldsPanel );
81 - addDialogButtonPanel( CancelButton.factory( pCancelText ).create(), //
82 - mOkButton = OKButton.factory( pOKText ).create() );
83 - }
84 -
85 - public int getTimeFields() {
86 - return mTimeFields;
87 - }
88 -
89 - public SimpleTimestamp getExitValue() {
90 - return mExitValue;
91 - }
92 -
93 - @Override
94 - public void show() {
95 - mExitValue = null;
96 - super.show();
97 - }
98 -
99 - @Override
100 - protected void dateSelectedByClick( Date pDate ) {
101 - }
102 -
103 - @Override
104 - protected void dialogButtonClicked( Button pButton ) {
105 - if ( mOkButton == pButton ) {
106 - mExitValue = new SimpleTimestamp( new CalendarYMD( selectedDate() ), mTimeFieldsPanel.getSimpleTime() );
107 - }
108 - hide();
109 - }
110 -
111 - private TimePickerFieldsPanel mTimeFieldsPanel;
112 -
113 - public void setInitialValues( SimpleTimestamp pTimestamp ) {
114 - UtilDateAdaptor adaptor = pTimestamp.getUtilDateAdaptor();
115 - setFullDate( adaptor.getWallDate() );
116 - mTimeFieldsPanel.setTimeFields( adaptor );
117 - }
118 -
119 - @Override
120 - public void adjustValue( int pAdjustBy ) {
121 - CalendarYMD date = new CalendarYMD( selectedDate() ).addDays( pAdjustBy );
122 - setFullDate( date.toUtilDate() );
123 - }
124 - }
125 - }
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 FormTimestampPicker extends AbstractTextFieldWithPicker {
14 + public FormTimestampPicker( String pFieldLabel, UiFont pLabelFont, String pTooltip, TimeRes pTimeRes, String pCancelText, String pOKText ) {
15 + super( pTooltip, false, calcLength( pTimeRes ), "CalendarTime", new MyPicker( pCancelText, pOKText, deNull( pTimeRes ) ) );
16 + initialize( pFieldLabel, pLabelFont, pTooltip );
17 + }
18 +
19 + private static TimeRes deNull( TimeRes pTimeRes ) {
20 + return (pTimeRes != null) ? pTimeRes : TimeRes.ToMSEC;
21 + }
22 +
23 + private static int calcLength( TimeRes pTimeRes ) {
24 + switch ( deNull( pTimeRes ).getIndex() ) {
25 + default:
26 + case TimeRes.MSECindex: // 1957/01/04 13:32:59.999
27 + return 23; // .........1234567-101234567-20123
28 + case TimeRes.SECindex: //. 1957/01/04 13:32:59
29 + return 19; // .........1234567-10123456789
30 + case TimeRes.MINindex: //. 1957/01/04 13:32
31 + return 16; // .........1234567-10123456
32 + case TimeRes.HOURindex: // 1957/01/04 13
33 + return 13; // .........1234567-10123
34 + }
35 + }
36 +
37 + @Override
38 + protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue ) {
39 + UtilDateAdaptor zInadequatePartsSource =
40 + (pLastValidInternalFormValue instanceof SimpleTimestamp) ? ((SimpleTimestamp) pLastValidInternalFormValue).getUtilDateAdaptor() : null;
41 + return TemporalParser.YMD.parseTimestamp( pText, getPicker().getTimeFields(), zInadequatePartsSource );
42 + }
43 +
44 + @Override
45 + protected void pickerClosed( boolean autoClosed ) {
46 + super.pickerClosed( autoClosed );
47 + SimpleTimestamp 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 + SimpleTimestamp zTimestamp;
57 + if ( pCurrentValue instanceof SimpleTimestamp ) {
58 + zTimestamp = (SimpleTimestamp) pCurrentValue;
59 + } else if ( pLastValidInternalFormValue instanceof SimpleTimestamp ) {
60 + zTimestamp = (SimpleTimestamp) pLastValidInternalFormValue;
61 + } else {
62 + zTimestamp = new SimpleTimestamp( new Date() );
63 + }
64 + getPicker().setInitialValues( zTimestamp );
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 ExtendableDatePicker implements HigherOrderAdjustable {
73 + private SimpleTimestamp mExitValue = null;
74 + private int mTimeFields;
75 + private Button mOkButton;
76 +
77 + public MyPicker( String pCancelText, String pOKText, TimeRes pTimeRes ) {
78 + mTimeFields = pTimeRes.getIndex() + 1;
79 + mTimeFieldsPanel = new TimePickerFieldsPanel( "litesoft-TimestampTimePickerFieldsPanel", mTimeFields, this );
80 + addExtensionPanel( mTimeFieldsPanel );
81 + addDialogButtonPanel( CancelButton.factory( pCancelText ).create(), //
82 + mOkButton = OKButton.factory( pOKText ).create() );
83 + }
84 +
85 + public int getTimeFields() {
86 + return mTimeFields;
87 + }
88 +
89 + public SimpleTimestamp getExitValue() {
90 + return mExitValue;
91 + }
92 +
93 + @Override
94 + public void show() {
95 + mExitValue = null;
96 + super.show();
97 + }
98 +
99 + @Override
100 + protected void dateSelectedByClick( Date pDate ) {
101 + }
102 +
103 + @Override
104 + protected void dialogButtonClicked( Button pButton ) {
105 + if ( mOkButton == pButton ) {
106 + mExitValue = new SimpleTimestamp( new CalendarYMD( selectedDate() ), mTimeFieldsPanel.getSimpleTime() );
107 + }
108 + hide();
109 + }
110 +
111 + private TimePickerFieldsPanel mTimeFieldsPanel;
112 +
113 + public void setInitialValues( SimpleTimestamp pTimestamp ) {
114 + UtilDateAdaptor adaptor = pTimestamp.getUtilDateAdaptor();
115 + setFullDate( adaptor.getWallDate() );
116 + mTimeFieldsPanel.setTimeFields( adaptor );
117 + }
118 +
119 + @Override
120 + public void adjustValue( int pAdjustBy ) {
121 + CalendarYMD date = new CalendarYMD( selectedDate() ).addDays( pAdjustBy );
122 + setFullDate( date.toUtilDate() );
123 + }
124 + }
125 + }