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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.forms.client.nonpublic;

import org.litesoft.commonfoundation.base.*;
import org.litesoft.ui.def.nonpublic.*;
import org.litesoft.ui.def.nonpublic.support.*;
import org.litesoft.ui.support.*;

import com.google.gwt.user.client.ui.*;

import java.util.*;

public class RelSubFormInstanceComponentHandlerImpl extends AbstractFormInstanceComponentHandler
        implements RelSubFormInstanceComponentHandler {
    private RelSubFormInstanceParentable mParent;
    private RelSubFormTypeHelper mTypeHelper;
    private SubFormRowCarrier mRowCarrier;
    private FormDataRowKey mFormDataRowKey;
    private RelSubFormInstanceRenderer mRenderer = null;

    public RelSubFormInstanceComponentHandlerImpl( RelSubFormInstanceParentable pParent,
                                                   RelSubFormTypeHelper pTypeHelper,
                                                   SubFormRowCarrier pRowCarrier ) {
        Confirm.isNotNull( "Parent", mParent = pParent );
        Confirm.isNotNull( "TypeHelper", mTypeHelper = pTypeHelper );
        Confirm.isNotNull( "RowContainer", mRowCarrier = pRowCarrier );
        mParent.addChild( this );
        mFormDataRowKey = new FormDataRowKey( getFormUniqueID() );
    }

    public void setRenderer( RelSubFormInstanceRenderer pRenderer ) {
        mRenderer = pRenderer;
    }

    public FormDataRowKey getFormDataRowKey() {
        return mFormDataRowKey;
    }

    public FormDataRowKey getParentFormDataRowKey() {
        return mParent.getFormDataRowKey();
    }

    public UberFormInstanceComponentHandler getUberHandler() {
        return mParent.getUberHandler();
    }

    public Integer getFormUniqueID() {
        return mTypeHelper.getFormUniqueID();
    }

    public void addAttributeAdapter( FormAttributeAdapter pAttributeAdapter ) {
        throw new IllegalStateException( "Adding Attributes to the RelSubForm directly is NOT supported" );
    }

    public SubFormRowCarrier getRowCarrier() {
        return mRowCarrier;
    }

    protected void LLdispose( UberFormInstanceComponentHandler pUberHandler ) {
        LLdisposeChildren( pUberHandler );

        super.LLdispose( pUberHandler );

        mTypeHelper = null;

        mParent = null;

        mFormDataRowKey = null;
        mRowCarrier = null;
        mRenderer = null;
    }

    protected boolean LLsetInputDisabledOnUs( String pAttributeName, boolean pDisabled ) {
        return false;
    }

    protected void LLapplyOnUs( AttributeUpdateFormData[] pAttributeUpdates ) {
    }

    protected boolean LLanyUserInitiatedRowChangeOnUs() {
        return mUserInitiatedRowChange;
    }

    protected boolean LLrecalcAnyAttributesOnUs( FormAttributeAdapter.BooleanValueAccessor pValueAccessor ) {
        return false;
    }

    protected void LLpublishAnyPendingAttributeChangesOnUs() {
    }

    // Child Component Handler Management

    protected void LLapplyOnChildren( ActionUpdateFormData[] pActionUpdates ) {
        for ( int i = 0; i < mRows.size(); i++ ) {
            getRow( i ).apply( pActionUpdates );
        }
    }

    protected void LLupdateInputStateOnChildren( boolean pAnyChanged, boolean pAnyErrors ) {
        for ( int i = 0; i < mRows.size(); i++ ) {
            getRow( i ).updateInputState( pAnyChanged, pAnyErrors );
        }
    }

    protected boolean LLsetActionDisabledOnChildren( FormDataRowKey pFormDataRowKey, String pActionID,
                                                     boolean pDisabled ) {
        for ( int i = 0; i < mRows.size(); i++ ) {
            if ( getRow( i ).setActionDisabled( pFormDataRowKey, pActionID, pDisabled ) ) {
                return true;
            }
        }
        return false;
    }

    protected boolean LLsetInputDisabledOnChildren( FormDataRowKey pFormDataRowKey, String pAttributeName,
                                                    boolean pDisabled ) {
        for ( int i = 0; i < mRows.size(); i++ ) {
            if ( getRow( i ).setInputDisabled( pFormDataRowKey, pAttributeName, pDisabled ) ) {
                return true;
            }
        }
        return false;
    }

    protected void LLapplyOnChildren( AttributeUpdateFormData[] pAttributeUpdates ) {
        for ( int i = 0; i < mRows.size(); i++ ) {
            getRow( i ).apply( pAttributeUpdates );
        }
    }

    protected boolean LLanyUserInitiatedRowChangeOnChildren() {
        for ( int i = 0; i < mRows.size(); i++ ) {
            if ( getRow( i ).anyUserInitiatedRowChange() ) {
                return true;
            }
        }
        return false;
    }

    protected boolean LLrecalcAnyAttributesOnChildren(
            FormAttributeAdapter.BooleanValueAccessor pValueAccessor ) {
        for ( int i = 0; i < mRows.size(); i++ ) {
            if ( getRow( i ).recalcAnyAttributes( pValueAccessor ) ) {
                return true;
            }
        }
        return false;
    }

    protected void LLpublishAnyPendingAttributeChangesOnChildren() {
        for ( int i = 0; i < mRows.size(); i++ ) {
            getRow( i ).publishAnyPendingAttributeChanges();
        }
    }

    public void apply( RelSubFormRowKeys[] pList, boolean pFullUpdate, boolean pUserInitiatedAddOrRemoveRow ) {
        if ( isActive() ) {
            Integer zMyContainingFormUniqueID = mParent.getFormUniqueID();
            FormDataRowKey zMyContainingRow = mParent.getFormDataRowKey();
            String zMyRelToParentAttributeName = mTypeHelper.getRelAttribute();
            for ( int i = 0; i < pList.length; i++ ) {
                RelSubFormRowKeys zKeys = pList[i];
                if ( zMyContainingFormUniqueID.equals( zKeys.getContainingFormUniqueID() ) && // Off My Parent
                     zMyRelToParentAttributeName.equals( zKeys.getRelSubFormRef() ) && // For Me && specific
                     Currently.areEqual( zMyContainingRow, zKeys.getContainingRow() ) ) // Sub Row
                {
                    boolean zRowsWereChanged = update( zKeys.getRowKeys() );
                    boolean zSavedUserInitiatedRowChange = mUserInitiatedRowChange;
                    if ( pFullUpdate ) {
                        mUserInitiatedRowChange = false;
                    } else if ( zRowsWereChanged ) {
                        mUserInitiatedRowChange = pUserInitiatedAddOrRemoveRow;
                    }
                    if ( zSavedUserInitiatedRowChange != mUserInitiatedRowChange ) {
                        componentChangedState( mUserInitiatedRowChange );
                    }
                }
            }
            for ( int i = 0; i < mRows.size(); i++ ) {
                getRow( i ).apply( pList, pFullUpdate, pUserInitiatedAddOrRemoveRow );
            }
        }
    }

    private void LLdisposeChildren( UberFormInstanceComponentHandler pUberHandler ) {
        for ( int i = mRows.size(); --i >= 0; ) // Reverse for Safety
        {
            getRow( i ).dispose( pUberHandler );
        }
        mRows.clear();
    }

    private RelSubFormRowInstanceComponentHandlerImpl getRow( int pAt ) {
        return (RelSubFormRowInstanceComponentHandlerImpl) mRows.get( pAt );
    }

    private List mRows = new ArrayList();
    private boolean mUserInitiatedRowChange = false;

    private boolean update( String[] pRowKeys ) {
        boolean anyChange = false;
        if ( Currently.isNullOrEmpty( pRowKeys ) ) {
            if ( !mRows.isEmpty() ) {
                anyChange = true;
                mRowCarrier.clear();
                LLdisposeChildren( getUberHandler() );
            }
            return anyChange;
        }
        int i = 0;
        do {
            String zRowKey = pRowKeys[i];
            int zCurrentlyAt = locate( zRowKey, i );
            if ( zCurrentlyAt != i ) {
                if ( zCurrentlyAt == -1 ) {
                    anyChange = true;
                    insertNewAt( zRowKey, i );
                } else {
                    anyChange = true;
                    moveUpFromTo( zCurrentlyAt, i );
                }
            }
        }
        while ( ++i < pRowKeys.length );
        while ( mRows.size() > i ) {
            anyChange = true;
            removeAt( mRows.size() - 1 );
        }
        return anyChange;
    }

    private int locate( String pRowKey, int pFrom ) {
        for ( int i = pFrom; i < mRows.size(); i++ ) {
            RelSubFormRowInstanceComponentHandlerImpl zRowHandler = getRow( i );
            if ( pRowKey.equals( zRowHandler.getRowObjectKey() ) ) {
                return i;
            }
        }
        return -1; // Not Found
    }

    private void removeAt( int pAt ) {
        for ( int i = mRows.size(); --i > pAt; ) // Reverse for Safety
        {
            getRow( i ).decRowIndex();
        }
        getRow( pAt ).dispose( getUberHandler() );
        mRows.remove( pAt );
    }

    private void insertNewAt( String pRowKey, int pAt ) {
        for ( int i = mRows.size(); --i >= pAt; ) // Reverse for Safety
        {
            getRow( i ).incRowIndex();
        }
        RelSubFormRowInstanceComponentHandlerImpl zHandler =
                new RelSubFormRowInstanceComponentHandlerImpl( this, pRowKey, pAt );
        mRows.add( pAt, zHandler );
        Widget zWidget = mRenderer.renderRow( zHandler, pRowKey, pAt );
        zHandler.init( zWidget );
        FormMetaData zMetaData = mTypeHelper.getFormMetaData();
        UiRelSubFormDef zRelSubForm = mTypeHelper.getRelSubForm();
        AttributeUsage zTabAttributeUsage = zRelSubForm.getTabAttributeUsage();
        if ( (zMetaData != null) && (zTabAttributeUsage != null) ) {
            AttributeMetaData zTabAttributeMD = zMetaData.getAttribute( zTabAttributeUsage.getUniqueID() );
            if ( zTabAttributeMD != null ) {
                zHandler.createTabAttributeAdapter( zTabAttributeMD );
            }
        }
    }

    private void moveUpFromTo( int pFrom, int pTo ) {
        for ( int i = pFrom; --i >= pTo; ) // Reverse for Safety
        {
            getRow( i ).incRowIndex();
        }
        // Move the Row Handler
        RelSubFormRowInstanceComponentHandlerImpl zRowHandler =
                (RelSubFormRowInstanceComponentHandlerImpl) mRows.remove( pFrom );
        mRows.add( pTo, zRowHandler );
        // Move The Widget
        zRowHandler.setRowIndex( pTo );
    }

    public RelSubFormTypeHelper getRelSubFormTypeHelperFor( UiRelSubFormDef pSubFormDef,
                                                            FormMetaData pSubFormMetaData ) {
        RelSubFormTypeHelper zTypeHelper = mTypeHelper.getChild( pSubFormDef.getAttributeName() );
        return (zTypeHelper != null) ? zTypeHelper :
               new RelSubFormTypeHelperImpl( mTypeHelper, pSubFormDef, pSubFormMetaData );
    }
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/nonpublic/RelSubFormInstanceComponentHandlerImpl.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!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

809 Diff Diff GeorgeS picture GeorgeS Thu 16 Aug, 2012 04:10:46 +0000
804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +0000
60 Diff Diff GeorgeS picture GeorgeS Tue 24 Aug, 2010 00:37:36 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000