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
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.forms.client.components.impls.input;

import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.forms.client.components.nonpublic.*;
import org.litesoft.commonfoundation.typeutils.gregorian.*;
import org.litesoft.core.simpletypes.temporal.*;
import org.litesoft.core.simpletypes.temporal.nonpublic.*;
import org.litesoft.uispecification.*;

import java.util.*;

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

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

    private static int calcLength( TimeRes pTimeRes ) {
        switch ( deNull( pTimeRes ).getIndex() ) {
            default:
            case TimeRes.MSECindex: // 13:32:59.999
                return 12; // .........1234567-1012
            case TimeRes.SECindex: //. 13:32:59
                return 8; // ..........12345678
            case TimeRes.MINindex: //. 13:32
                return 5; // ..........12345
            case TimeRes.HOURindex: // 13
                return 2; // ..........12
        }
    }

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

    @Override
    protected void pickerClosed( boolean autoClosed ) {
        super.pickerClosed( autoClosed );
        SimpleTime value = getPicker().getExitValue();

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

    @Override
    protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue ) {
        SimpleTime zTime;
        if ( pCurrentValue instanceof SimpleTime ) {
            zTime = (SimpleTime) pCurrentValue;
        } else if ( pLastValidInternalFormValue instanceof SimpleTime ) {
            zTime = (SimpleTime) pLastValidInternalFormValue;
        } else {
            zTime = SimpleTime.timeComponents( new Date() );
        }
        getPicker().setInitialValues( zTime );
        super.showPicker( pAbsoluteLeft, pAbsoluteTop, pCurrentValue, pLastValidInternalFormValue );
    }

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

    private static class MyPicker extends ExtendableDialogPicker {
        private SimpleTime mExitValue = null;
        private int mTimeFields;
        private TimePickerFieldsPanel mTimeFieldsPanel;
        private Button mOkButton;

        public MyPicker( String pCancelText, String pOKText, TimeRes pTimeRes ) {
            mTimeFields = pTimeRes.getIndex() + 1;
            mTimeFieldsPanel = new TimePickerFieldsPanel( "litesoft-TimePickerFieldsPanel", mTimeFields, null );
            addExtensionPanel( mTimeFieldsPanel );
            addDialogButtonPanel( CancelButton.factory( pCancelText ).create(), //
                                  mOkButton = OKButton.factory( pOKText ).create() );
        }

        public int getTimeFields() {
            return mTimeFields;
        }

        @Override
        protected void dialogButtonClicked( Button pButton ) {
            if ( mOkButton == pButton ) {
                mExitValue = mTimeFieldsPanel.getSimpleTime();
            }
            hide();
        }

        public SimpleTime getExitValue() {
            return mExitValue;
        }

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

        public void setInitialValues( SimpleTime pTime ) {
            mTimeFieldsPanel.setTimeFields( pTime.getUtilDateAdaptor() );
        }
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

942 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:41:46 +0000

Extracting commonfoundation

151 Diff Diff GeorgeS picture GeorgeS Thu 17 Mar, 2011 04:16:22 +0000
136 Diff Diff GeorgeS picture GeorgeS Wed 09 Mar, 2011 21:09:51 +0000
133 Diff Diff GeorgeS picture GeorgeS Wed 09 Mar, 2011 00:33:28 +0000
105 Diff Diff GeorgeS picture GeorgeS Thu 17 Feb, 2011 20:51:19 +0000
103 Diff Diff GeorgeS picture GeorgeS Tue 15 Feb, 2011 01:54:45 +0000
49 GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text