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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package org.litesoft.prioritizer.client.ui.views.stories;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.view.*;
import org.litesoft.GWT.client.widgets.Button;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.client.widgets.datatables.*;
import org.litesoft.GWT.forms.client.*;
import org.litesoft.bo.views.*;
import org.litesoft.commonfoundation.base.*;
import org.litesoft.core.util.*;
import org.litesoft.prioritizer.client.boviews.*;
import org.litesoft.prioritizer.client.support.*;
import org.litesoft.uispecification.*;

import com.google.gwt.core.client.*;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.event.logical.shared.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;

import java.util.*;

public abstract class AbstractPrioritizeScreenView extends ScreenView implements StoryViewNames,
                                                                                 SimpleDataProviderCallBack,
                                                                                 DataAvailableCallBack<StoryView> {
    protected final String mWhat;
    protected final StoryViewDataProvider mDP = StoryViewDataProvider.getInstance();
    protected final ListTableModel<StoryView> mTableModel = new ListTableModel<StoryView>();
    protected final CheckBoxSelectRegularTable<StoryView> mTable;
    protected final MoveControlPanel mMoveControlPanel;
    private Set<StoryView> mSavedSelectedValues = null;

    private Integer mTopRowOffset = null;

    @Override
    protected UriFragmentIdParams createRefreshParams() {
        return ReprioritizeFactory.encodeParams( mTopRowOffset );
    }

    public AbstractPrioritizeScreenView( String pSection, ViewDef pViewDef, String pWhat, boolean pAddUpDown, BoTableDefinition<StoryView> pTableDef,
                                         Integer pTopRowOffset ) {
        super( title( pSection, pViewDef ) );

        mTopRowOffset = pTopRowOffset;

        mWhat = pWhat;

        addRight( Button.named( "Refresh" ).blue().text().add( new ClickHandler() {
            @Override
            public void onClick( ClickEvent event ) {
                fetchRows();
            }
        } ).create() );
        addStandardTitleBar();

        addSectionTitle( mWhat );

        mMoveControlPanel = new MoveControlPanel( pAddUpDown );
        mTable = new CheckBoxSelectRegularTable<StoryView>( mTableModel, pTableDef, mMoveControlPanel );

        SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchable();
        zPanel.add( mTable );
        zPanel.add( mMoveControlPanel );
        add( zPanel );
    }

    @Override
    protected void justLoaded() {
        super.justLoaded();
        fetchRows();
    }

    abstract protected void fetchRows();

    protected FetchRowsDataProviderCallBack<StoryView> createFetchRowsCallBack() {
        return new FetchRowsDataProviderCallBack<StoryView>() {
            @Override
            public void tooMany( long pCount ) {
                systemError( "System Error: Should not happen", //
                             "Found " + pCount + " " + mWhat + ".", //
                             "This is more than the application is willing to display." );
            }

            @Override
            public void error( String pError ) {
                systemError( "Requesting " + mWhat + " - Errored", //
                             "", //
                             "Error: " + pError );
            }

            @Override
            public void success( ImmutableArrayList<StoryView> pRows ) {
                if ( pRows.isEmpty() ) {
                    backToHome( "Nothing to " + mWhat );
                    return;
                }
                mTableModel.clear();
                mTableModel.addAll( pRows );
                Collections.sort( mTableModel );
                mTable.loadData();
                mTable.deselectAll();
                mMoveControlPanel.handleButtons( reselectAll() );
            }

            private Set<StoryView> reselectAll() {
                boolean zFound = false;
                if ( mSavedSelectedValues != null ) {
                    for ( StoryView zValue : mSavedSelectedValues ) {
                        if ( mTable.selectRow( zValue ) ) {
                            zFound = true;
                        }
                    }
                    mSavedSelectedValues = null;
                }
                return zFound ? mTable.getSelectedValues() : null;
            }
        };
    }

    @Override
    public void error( String pError ) {
        if ( Currently.isNotNullOrEmpty( pError ) ) {
            systemError( "Requested Prioritizing - Errored", //
                         "", //
                         "Error: " + pError );
        } else {
            fetchRows();
        }
    }

    @Override
    public Widget getBottomBar() {
        return null;
    }

    protected static class TableDef extends BoTableDefinition<StoryView> implements StoryViewNames,
                                                                                    DataTableStyle {
        public TableDef() {
            StoryViewMetaData zMD = StoryViewMetaData.getInstance();

            addColumn( zMD.getBoAttribute( aName ) ); // .initialWidth( FontSizer.get( TABLE_TEXT ).EMsPlus( 20, CELL_PADDING ) );
            addColumn( zMD.getBoAttribute( aDescriptionThreeLines ), "Description" ); // .initialWidth( FontSizer.get( TABLE_TEXT ).EMsPlus( 40, CELL_PADDING ) );
        }
    }

    private class MoveControlPanel extends VerticalPanel implements SelectionHandler<StoryView> {
        private final Button mBetweenButton, mUpButton, mDownButton;
        private final List<GroupMover> mGroupMovers = new ArrayList<GroupMover>();

        private MoveControlPanel( boolean pAddUpDown ) {
            mBetweenButton = Button.named( "Between" ).blue().text( "To There" ).add( new ClickHandler() {
                @Override
                public void onClick( ClickEvent event ) {
                    reprioritizeBetween();
                }
            } ).create().disable();
            mUpButton = Button.named( "Up" ).blue().text().add( new ClickHandler() {
                @Override
                public void onClick( ClickEvent event ) {
                    reprioritizeUp();
                }
            } ).create().disable();
            mDownButton = Button.named( "Down" ).blue().text().add( new ClickHandler() {
                @Override
                public void onClick( ClickEvent event ) {
                    reprioritizeDown();
                }
            } ).create().disable();

            setHorizontalAlignment( VerticalPanel.ALIGN_CENTER );
            add( new Label( "Move..." ) );
            add( new Spacer( 20 ) );
            add( mBetweenButton );
            add( new Spacer( 20 ) );
            PriorityGroup[] zGroups = PriorityGroup.values();
            for ( int i = zGroups.length; --i >= 0; ) {
                PriorityGroup zGroup = zGroups[i];
                if ( PriorityGroup.Initial != zGroup ) {
                    GroupMover zMover = new GroupMover( zGroup );
                    mGroupMovers.add( zMover );
                    add( zMover.getButton() );
                }
            }
            add( new Spacer( 20 ) );
            if ( pAddUpDown ) {
                add( mUpButton );
                add( mDownButton );
            }
        }

        @Override
        protected void onAttach() {
            super.onAttach();
            sameSizeButtons();
        }

        private void sameSizeButtons() {
            if ( isAttached() ) {
                Integer zMaxWidth = getMaxControlButtonWidth();
                if ( zMaxWidth != null ) {
                    setControlButtonSameWidth( zMaxWidth );
                    return;
                }
            }
            Scheduler.get().scheduleDeferred( new Command() {
                @Override
                public void execute() {
                    sameSizeButtons();
                }
            } );
        }

        private Integer getMaxControlButtonWidth() {
            int zMaxWidth = mBetweenButton.getOffsetWidth();
            for ( Widget zWidget : getChildren() ) {
                if ( zWidget instanceof Button ) {
                    zMaxWidth = Math.max( zMaxWidth, zWidget.getOffsetWidth() );
                }
            }
            return (zMaxWidth > 30) ? zMaxWidth : null;
        }

        private void setControlButtonSameWidth( int pWidth ) {
            String zWidth = "" + pWidth;
            for ( Widget zWidget : getChildren() ) {
                if ( zWidget instanceof Button ) {
                    zWidget.setWidth( zWidth );
                }
            }
        }

        @Override
        public void onSelection( SelectionEvent<StoryView> event ) {
            handleButtons( mTable.getSelectedValues() );
        }

        private void handleButtons( Set<StoryView> pSelectedValues ) {
            boolean zAnySelected = (pSelectedValues != null) && !pSelectedValues.isEmpty();
            mBetweenButton.setEnabled( zAnySelected && betweenable( pSelectedValues ) );
            mUpButton.setEnabled( zAnySelected && upable( pSelectedValues ) );
            mDownButton.setEnabled( zAnySelected && downable( pSelectedValues ) );
            for ( GroupMover zMover : mGroupMovers ) {
                zMover.setEnable( zAnySelected, pSelectedValues );
            }
        }
    }

    private class GroupMover implements ClickHandler {
        private PriorityGroup mGroup;
        private Button mButton;

        private GroupMover( PriorityGroup pGroup ) {
            mGroup = pGroup;
            mButton = Button.named( mGroup.name() ).blue().text().add( this ).create().disable();
        }

        public Button getButton() {
            return mButton;
        }

        @Override
        public void onClick( ClickEvent event ) {
            reprioritizeToGroup( mGroup );
        }

        public void setEnable( boolean pAnySelected, Set<StoryView> pSelectedValues ) {
            mButton.setEnabled( pAnySelected && applicable( pSelectedValues ) );
        }

        private boolean applicable( Set<StoryView> pSelectedValues ) {
            for ( StoryView zStoryView : pSelectedValues ) {
                if ( mGroup != PriorityGroup.from( zStoryView.getPriority() ) ) {
                    return true;
                }
            }
            return false;
        }
    }

    abstract protected boolean betweenable( Set<StoryView> pSelectedValues );

    protected boolean upable( Set<StoryView> pSelectedValues ) {
        return !isAtEdge( pSelectedValues, 0 );
    }

    protected boolean downable( Set<StoryView> pSelectedValues ) {
        return !isAtEdge( pSelectedValues, mTableModel.size() - 1 );
    }

    protected boolean isAtEdge( Set<StoryView> pSelectedValues, int pEdge ) {
        for ( StoryView zStoryView : pSelectedValues ) {
            if ( mTableModel.indexOf( zStoryView ) == pEdge ) {
                return true;
            }
        }
        return false;
    }

    private void reprioritizeUp() {
        int zMin = mTableModel.size();
        for ( StoryView zStoryView : mTable.getSelectedValues() ) {
            zMin = Math.min( zMin, mTableModel.indexOf( zStoryView ) );
        }
        if ( zMin != mTableModel.size() ) {
            reprioritizeBetween( mSavedSelectedValues = mTable.getSelectedValues(), getStoryView( zMin - 1 ), getStoryView( zMin - 2 ) );
        }
    }

    private void reprioritizeDown() {
        int zMax = -1;
        for ( StoryView zStoryView : mTable.getSelectedValues() ) {
            zMax = Math.max( zMax, mTableModel.indexOf( zStoryView ) );
        }
        if ( zMax != -1 ) {
            reprioritizeBetween( mSavedSelectedValues = mTable.getSelectedValues(), getStoryView( zMax + 2 ), getStoryView( zMax + 1 ) );
        }
    }

    private void reprioritizeBetween( StoryView pLowerBound, StoryView pUpperBound ) {
        reprioritizeBetween( mTable.getSelectedValues(), pLowerBound, pUpperBound );
    }

    private void reprioritizeBetween( Set<StoryView> pSelectedValues, StoryView pLowerBound, StoryView pUpperBound ) {
        mDP.reprioritizeBetween( pLowerBound, pUpperBound, pSelectedValues, this );
    }

    private void reprioritizeToGroup( PriorityGroup pGroup ) {
        mDP.reprioritizeToGroup( pGroup, mTable.getSelectedValues(), this );
    }

    private StoryView getStoryView( int pIndex ) {
        return ((0 <= pIndex) && (pIndex < mTableModel.size())) ? mTableModel.get( pIndex ) : null;
    }

    abstract protected void fetchTargetBetweenRows( final DataAvailableCallBack<StoryView> pCallBack );

    private void reprioritizeBetween() {
        fetchTargetBetweenRows( this );
    }

    @Override
    public void dataAvailable( List<StoryView> pData ) // called when we can proceed with the InjectionPointSelector
    {
        if ( pData.isEmpty() ) {
            error( "There are Nothing but " + PriorityGroup.Initial + " priority Stories" );
            return;
        }
        Set<StoryView> zSelectedRows = mTable.getSelectedValues();
        List<StoryView> zNonSelectedRows = new ArrayList<StoryView>( pData.size() );
        for ( StoryView zStoryView : pData ) {
            if ( !zSelectedRows.contains( zStoryView ) ) {
                zNonSelectedRows.add( zStoryView );
            }
        }
        if ( zNonSelectedRows.isEmpty() ) {
            error( "At least one Story must not be selected" );
            return;
        }
        new InjectionPointSelectionDialog<StoryView>( "Select 'There' to Move Selected Rows", 4, zNonSelectedRows,
                                                      new InjectionPointSelector.Callback<StoryView>() {
                                                          @Override
                                                          public void injectBetween( StoryView pLowerBound, StoryView pUpperBound ) {
                                                              reprioritizeBetween( pLowerBound, pUpperBound );
                                                          }
                                                      } ).show();
    }
}

Commits for litesoft/trunk/GWT_Sandbox/Prioritizer/src/org/litesoft/prioritizer/client/ui/views/stories/AbstractPrioritizeScreenView.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

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

Extracting commonfoundation

802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
487 Diff Diff GeorgeS picture GeorgeS Thu 08 Sep, 2011 12:06:30 +0000

More elimination of uniqueness

480 Diff Diff GeorgeS picture GeorgeS Sun 04 Sep, 2011 02:38:20 +0000

Progress on common User Support...

398 GeorgeS picture GeorgeS Mon 15 Aug, 2011 19:57:47 +0000