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
package org.litesoft.GWT.forms.client.components.factories.others;

import com.google.gwt.user.client.ui.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;
import org.litesoft.GWT.forms.client.components.nonpublic.*;
import org.litesoft.GWT.forms.client.components.*;
import org.litesoft.GWT.forms.client.nonpublic.*;
import org.litesoft.rpcpassable.*;
import org.litesoft.ui.def.*;
import org.litesoft.ui.def.nonpublic.*;
import org.litesoft.ui.def.nonpublic.support.*;

import java.util.*;

public class CardsWidgetFactory implements ContainerFactory
{
    public Widget createContainerWidget( FormInstanceComponentHandler pComponentHandler,
                                         UiDef pUiDef, FormMetaData pFormMetaData,
                                         DefWidgetStruct[] pChildDefWidgets )
    {
        UiCardsDef zCardsDef = (UiCardsDef) pUiDef;
        SizeableDeckPanel zSDP = new SizeableDeckPanel();
        HashMap<String, Integer> zCardKeyToIndexMap = new HashMap<String, Integer>();
        boolean anyFloodX = false;
        boolean anyFloodY = false;
        for ( int i = 0; i < pChildDefWidgets.length; i++ )
        {
            DefWidgetStruct zChild = pChildDefWidgets[i];
            UiCardDef zCardDef = (UiCardDef) zChild.getUiDef();
            Widget zWidget = zChild.getWidget(); // !null
            zCardKeyToIndexMap.put( zCardDef.getCardKey(), i );
            zSDP.add( zWidget );
            if ( !anyFloodX )
            {
                anyFloodX = WidthStretchableAdjustor.isStretchable( zWidget );
            }
            if ( !anyFloodY )
            {
                anyFloodY = HeightStretchableAdjustor.isStretchable( zWidget );
            }
        }
        if ( anyFloodX )
        {
            zSDP.stretchableHorizontally();
        }
        if ( anyFloodY )
        {
            zSDP.stretchableVertically();
        }

        AttributeMetaData zMD = pFormMetaData.getAttribute( zCardsDef );
        if ( zMD != null )
        {
            new MyFormAdapter( pComponentHandler, zCardKeyToIndexMap, zSDP, zMD, new NullFormComponent() ).init();
        }
        return zSDP;
    }

    private static final class MyFormAdapter extends AbstractFormAttributeAdapter
    {
        private HashMap<String, Integer> mCardKeyToIndexMap;
        private SizeableDeckPanel mSDP;

        public MyFormAdapter( FormInstanceComponentHandler pComponentHandler, HashMap<String, Integer> pCardKeyToIndexMap, //
                              SizeableDeckPanel pSDP, AttributeMetaData pMD, IFormComponent pComponent )
        {
            super( pComponentHandler, pMD, pComponent );
            mCardKeyToIndexMap = pCardKeyToIndexMap;
            mSDP = pSDP;
        }

        protected Widget initWidget()
        {
            return null;
        }

        protected Object convertSendableToComponentValue( RPCpassable pValue )
        {
            return pValue;
        }

        protected String convertComponentValueToString( Object pValue )
        {
            return null;
        }

        protected Object convertStringToComponentValue( String pValue )
        {
            return null;
        }

        protected void setComponentCurrentValue( Object pNewComponentCurrentValue )
        {
            super.setComponentCurrentValue( pNewComponentCurrentValue );
            if ( pNewComponentCurrentValue != null )
            {
                Integer zIndex = mCardKeyToIndexMap.get( pNewComponentCurrentValue.toString() );
                if ( zIndex != null )
                {
                    mSDP.showWidget( zIndex );
                }
            }
        }
    }
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/components/factories/others/CardsWidgetFactory.java

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