Subversion Repository Public Repository

litesoft

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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package org.litesoft.GWT.forms.client.components.impls.input;

import java.util.*;

import org.litesoft.GWT.forms.client.components.nonpublic.*;
import org.litesoft.core.simpletypes.temporal.*;
import org.litesoft.core.simpletypes.temporal.nonpublic.*;
import org.litesoft.uispecification.*;

public class FormTimestampPicker extends AbstractTextFieldWithPicker
{
    public FormTimestampPicker( String pFieldLabel, UiFont pLabelFont, String pTooltip, TimeRes pTimeRes, String pCancelText, String pOKText )
    {
        super( pTooltip, false, calcLength( pTimeRes ), "CalendarTime", new MyPicker( pCancelText, pOKText, deNull( pTimeRes ) ) );
        initialize( pFieldLabel, pLabelFont, pTooltip );
    }

    private static TimeRes deNull( TimeRes pTimeRes )
    {
        return (pTimeRes != null) ? pTimeRes : TimeRes.ToMSEC;
    }

    private static int calcLength( TimeRes pTimeRes )
    {
        switch ( deNull( pTimeRes ).getIndex() )
        {
            default:
            case TimeRes.MSECindex: // 1957/01/04 13:32:59.999
                return 23; // .........1234567-101234567-20123
            case TimeRes.SECindex: //. 1957/01/04 13:32:59
                return 19; // .........1234567-10123456789
            case TimeRes.MINindex: //. 1957/01/04 13:32
                return 16; // .........1234567-10123456
            case TimeRes.HOURindex: // 1957/01/04 13
                return 13; // .........1234567-10123
        }
    }

    protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue )
    {
        UtilDateAdaptor zInadequatePartsSource =
                (pLastValidInternalFormValue instanceof SimpleTimestamp) ? ((SimpleTimestamp) pLastValidInternalFormValue).getUtilDateAdaptor() : null;
        return TemporalParser.YMD.parseTimestamp( pText, getPicker().getTimeFields(), zInadequatePartsSource );
    }

    protected void pickerClosed( boolean autoClosed )
    {
        super.pickerClosed( autoClosed );
        SimpleTimestamp value = getPicker().getExitValue();

        if ( value != null )
        {
            setTextValueFromPicker( value.toString() );
        }
    }

    protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue )
    {
        SimpleTimestamp zTimestamp;
        if ( pCurrentValue instanceof SimpleTimestamp )
        {
            zTimestamp = (SimpleTimestamp) pCurrentValue;
        }
        else if ( pLastValidInternalFormValue instanceof SimpleTimestamp )
        {
            zTimestamp = (SimpleTimestamp) pLastValidInternalFormValue;
        }
        else
        {
            zTimestamp = new SimpleTimestamp( new Date() );
        }
        getPicker().setInitialValues( zTimestamp );
        super.showPicker( pAbsoluteLeft, pAbsoluteTop, pCurrentValue, pLastValidInternalFormValue );
    }

    private MyPicker getPicker()
    {
        return (MyPicker) mPicker;
    }

    private static class MyPicker extends ExtendableDatePicker implements HigherOrderAdjustable
    {
        private SimpleTimestamp mExitValue = null;
        private int mTimeFields;

        public MyPicker( String pCancelText, String pOKText, TimeRes pTimeRes )
        {
            mTimeFields = pTimeRes.getIndex() + 1;
            mTimeFieldsPanel = new TimePickerFieldsPanel( "litesoft-TimestampTimePickerFieldsPanel", mTimeFields, this );
            addExtensionPanel( mTimeFieldsPanel );
            addDialogButtonPanel( pCancelText, pOKText );
        }

        public int getTimeFields()
        {
            return mTimeFields;
        }

        public SimpleTimestamp getExitValue()
        {
            return mExitValue;
        }

        public void show()
        {
            mExitValue = null;
            super.show();
        }

        protected void dateSelectedByClick( Date pDate )
        {
        }

        protected void dialogButtonPanelClicked( int pButtonIndex )
        {
            if ( pButtonIndex != 0 ) // 'OK' button
            {
                mExitValue = new SimpleTimestamp( new SimpleDate( selectedDate() ), mTimeFieldsPanel.getSimpleTime() );
            }
            hide();
        }

        private TimePickerFieldsPanel mTimeFieldsPanel;

        public void setInitialValues( SimpleTimestamp pTimestamp )
        {
            UtilDateAdaptor adaptor = pTimestamp.getUtilDateAdaptor();
            setFullDate( adaptor.getDate() );
            mTimeFieldsPanel.setTimeFields( adaptor );
        }

        public void adjustValue( int pAdjustBy )
        {
            SimpleDate date = new SimpleDate( selectedDate() );
            date.addDays( pAdjustBy );
            setFullDate( date.getDate() );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/impls/input/FormTimestampPicker.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000