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
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 FormDatePicker extends AbstractTextFieldWithPicker
{
    private String mDateFormat;
    private TemporalParser mTemporalParser;

    public FormDatePicker( String pFieldLabel, UiFont pLabelFont, String pTooltip, String pCancelText, String pTodayText, DateFormatControl pDateFormatControl )
    {
        // 1234567-101
        // 04 JAN 1957
        super( pTooltip, true, pDateFormatControl.getFormat().length(), "Calendar", new MyPicker( pCancelText, pTodayText ) );
        initialize( pFieldLabel, pLabelFont, pTooltip );

        mDateFormat = pDateFormatControl.getFormat();
        String zFieldOrder = pDateFormatControl.getFieldOrder();
        if ( zFieldOrder.equals( "dMy" ) && mDateFormat.contains( "MMM" ) )
        {
            zFieldOrder = "Mdy";
        }
        mTemporalParser = new TemporalParser( zFieldOrder );
    }

    protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue )
            throws IllegalArgumentException
    {
        UtilDateAdaptor zInadequatePartsSource = (pLastValidInternalFormValue instanceof SimpleDate) ? ((SimpleDate) pLastValidInternalFormValue).getUtilDateAdaptor() : null;
        return mTemporalParser.parseDate( mDateFormat, pText, zInadequatePartsSource );
    }

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

        if ( value != null )
        {
            setTextValueFromPicker( new SimpleDate( mDateFormat, value ).toString() );
        }
    }

    protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue )
    {
        Date zDate;
        if ( pCurrentValue instanceof SimpleDate )
        {
            zDate = ((SimpleDate) pCurrentValue).getDate();
        }
        else if ( pLastValidInternalFormValue instanceof SimpleDate )
        {
            zDate = ((SimpleDate) pLastValidInternalFormValue).getDate();
        }
        else
        {
            zDate = new Date();
        }
        getPicker().setFullDate( zDate );
        super.showPicker( pAbsoluteLeft, pAbsoluteTop, pCurrentValue, pLastValidInternalFormValue );
    }

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

    private static class MyPicker extends ExtendableDatePicker
    {
        private Date mExitValue = null;

        public MyPicker( String pCancelText, String pTodayText )
        {
            addDialogButtonPanel( pCancelText, pTodayText, null );
        }

        protected void dialogButtonPanelClicked( int pButtonIndex )
        {
            if ( pButtonIndex != 0 ) // 'Today' button
            {
                mExitValue = new Date();
            }
            hide();
        }

        public Date getExitValue()
        {
            return mExitValue;
        }

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

        protected void dateSelectedByClick( Date pDate )
        {
            mExitValue = selectedDate();
            hide();
        }
    }
}

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

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