|
@@ -1,368 +1,368 @@ |
1 |
|
- |
package org.litesoft.prioritizer.client.ui.views.stories; |
2 |
|
- |
|
3 |
|
- |
import org.litesoft.GWT.client.*; |
4 |
|
- |
import org.litesoft.GWT.client.view.*; |
5 |
|
- |
import org.litesoft.GWT.client.widgets.Button; |
6 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
7 |
|
- |
import org.litesoft.GWT.client.widgets.datatables.*; |
8 |
|
- |
import org.litesoft.GWT.forms.client.*; |
9 |
|
- |
import org.litesoft.bo.views.*; |
10 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
11 |
|
- |
import org.litesoft.core.util.*; |
12 |
|
- |
import org.litesoft.prioritizer.client.boviews.*; |
13 |
|
- |
import org.litesoft.prioritizer.client.support.*; |
14 |
|
- |
import org.litesoft.uispecification.*; |
15 |
|
- |
|
16 |
|
- |
import com.google.gwt.core.client.*; |
17 |
|
- |
import com.google.gwt.event.dom.client.*; |
18 |
|
- |
import com.google.gwt.event.logical.shared.*; |
19 |
|
- |
import com.google.gwt.user.client.*; |
20 |
|
- |
import com.google.gwt.user.client.ui.*; |
21 |
|
- |
|
22 |
|
- |
import java.util.*; |
23 |
|
- |
|
24 |
|
- |
public abstract class AbstractPrioritizeScreenView extends ScreenView implements StoryViewNames, |
25 |
|
- |
SimpleDataProviderCallBack, |
26 |
|
- |
DataAvailableCallBack<StoryView> { |
27 |
|
- |
protected final String mWhat; |
28 |
|
- |
protected final StoryViewDataProvider mDP = StoryViewDataProvider.getInstance(); |
29 |
|
- |
protected final ListTableModel<StoryView> mTableModel = new ListTableModel<StoryView>(); |
30 |
|
- |
protected final CheckBoxSelectRegularTable<StoryView> mTable; |
31 |
|
- |
protected final MoveControlPanel mMoveControlPanel; |
32 |
|
- |
private Set<StoryView> mSavedSelectedValues = null; |
33 |
|
- |
|
34 |
|
- |
private Integer mTopRowOffset = null; |
35 |
|
- |
|
36 |
|
- |
@Override |
37 |
|
- |
protected UriFragmentIdParams createRefreshParams() { |
38 |
|
- |
return ReprioritizeFactory.encodeParams( mTopRowOffset ); |
39 |
|
- |
} |
40 |
|
- |
|
41 |
|
- |
public AbstractPrioritizeScreenView( String pSection, ViewDef pViewDef, String pWhat, boolean pAddUpDown, BoTableDefinition<StoryView> pTableDef, |
42 |
|
- |
Integer pTopRowOffset ) { |
43 |
|
- |
super( title( pSection, pViewDef ) ); |
44 |
|
- |
|
45 |
|
- |
mTopRowOffset = pTopRowOffset; |
46 |
|
- |
|
47 |
|
- |
mWhat = pWhat; |
48 |
|
- |
|
49 |
|
- |
addRight( Button.named( "Refresh" ).blue().text().add( new ClickHandler() { |
50 |
|
- |
@Override |
51 |
|
- |
public void onClick( ClickEvent event ) { |
52 |
|
- |
fetchRows(); |
53 |
|
- |
} |
54 |
|
- |
} ).create() ); |
55 |
|
- |
addStandardTitleBar(); |
56 |
|
- |
|
57 |
|
- |
addSectionTitle( mWhat ); |
58 |
|
- |
|
59 |
|
- |
mMoveControlPanel = new MoveControlPanel( pAddUpDown ); |
60 |
|
- |
mTable = new CheckBoxSelectRegularTable<StoryView>( mTableModel, pTableDef, mMoveControlPanel ); |
61 |
|
- |
|
62 |
|
- |
SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchable(); |
63 |
|
- |
zPanel.add( mTable ); |
64 |
|
- |
zPanel.add( mMoveControlPanel ); |
65 |
|
- |
add( zPanel ); |
66 |
|
- |
} |
67 |
|
- |
|
68 |
|
- |
@Override |
69 |
|
- |
protected void justLoaded() { |
70 |
|
- |
super.justLoaded(); |
71 |
|
- |
fetchRows(); |
72 |
|
- |
} |
73 |
|
- |
|
74 |
|
- |
abstract protected void fetchRows(); |
75 |
|
- |
|
76 |
|
- |
protected FetchRowsDataProviderCallBack<StoryView> createFetchRowsCallBack() { |
77 |
|
- |
return new FetchRowsDataProviderCallBack<StoryView>() { |
78 |
|
- |
@Override |
79 |
|
- |
public void tooMany( long pCount ) { |
80 |
|
- |
systemError( "System Error: Should not happen", // |
81 |
|
- |
"Found " + pCount + " " + mWhat + ".", // |
82 |
|
- |
"This is more than the application is willing to display." ); |
83 |
|
- |
} |
84 |
|
- |
|
85 |
|
- |
@Override |
86 |
|
- |
public void error( String pError ) { |
87 |
|
- |
systemError( "Requesting " + mWhat + " - Errored", // |
88 |
|
- |
"", // |
89 |
|
- |
"Error: " + pError ); |
90 |
|
- |
} |
91 |
|
- |
|
92 |
|
- |
@Override |
93 |
|
- |
public void success( ImmutableArrayList<StoryView> pRows ) { |
94 |
|
- |
if ( pRows.isEmpty() ) { |
95 |
|
- |
backToHome( "Nothing to " + mWhat ); |
96 |
|
- |
return; |
97 |
|
- |
} |
98 |
|
- |
mTableModel.clear(); |
99 |
|
- |
mTableModel.addAll( pRows ); |
100 |
|
- |
Collections.sort( mTableModel ); |
101 |
|
- |
mTable.loadData(); |
102 |
|
- |
mTable.deselectAll(); |
103 |
|
- |
mMoveControlPanel.handleButtons( reselectAll() ); |
104 |
|
- |
} |
105 |
|
- |
|
106 |
|
- |
private Set<StoryView> reselectAll() { |
107 |
|
- |
boolean zFound = false; |
108 |
|
- |
if ( mSavedSelectedValues != null ) { |
109 |
|
- |
for ( StoryView zValue : mSavedSelectedValues ) { |
110 |
|
- |
if ( mTable.selectRow( zValue ) ) { |
111 |
|
- |
zFound = true; |
112 |
|
- |
} |
113 |
|
- |
} |
114 |
|
- |
mSavedSelectedValues = null; |
115 |
|
- |
} |
116 |
|
- |
return zFound ? mTable.getSelectedValues() : null; |
117 |
|
- |
} |
118 |
|
- |
}; |
119 |
|
- |
} |
120 |
|
- |
|
121 |
|
- |
@Override |
122 |
|
- |
public void error( String pError ) { |
123 |
|
- |
if ( Strings.isNotNullOrEmpty( pError ) ) { |
124 |
|
- |
systemError( "Requested Prioritizing - Errored", // |
125 |
|
- |
"", // |
126 |
|
- |
"Error: " + pError ); |
127 |
|
- |
} else { |
128 |
|
- |
fetchRows(); |
129 |
|
- |
} |
130 |
|
- |
} |
131 |
|
- |
|
132 |
|
- |
@Override |
133 |
|
- |
public Widget getBottomBar() { |
134 |
|
- |
return null; |
135 |
|
- |
} |
136 |
|
- |
|
137 |
|
- |
protected static class TableDef extends BoTableDefinition<StoryView> implements StoryViewNames, |
138 |
|
- |
DataTableStyle { |
139 |
|
- |
public TableDef() { |
140 |
|
- |
StoryViewMetaData zMD = StoryViewMetaData.getInstance(); |
141 |
|
- |
|
142 |
|
- |
addColumn( zMD.getBoAttribute( aName ) ); // .initialWidth( FontSizer.get( TABLE_TEXT ).EMsPlus( 20, CELL_PADDING ) ); |
143 |
|
- |
addColumn( zMD.getBoAttribute( aDescriptionThreeLines ), "Description" ); // .initialWidth( FontSizer.get( TABLE_TEXT ).EMsPlus( 40, CELL_PADDING ) ); |
144 |
|
- |
} |
145 |
|
- |
} |
146 |
|
- |
|
147 |
|
- |
private class MoveControlPanel extends VerticalPanel implements SelectionHandler<StoryView> { |
148 |
|
- |
private final Button mBetweenButton, mUpButton, mDownButton; |
149 |
|
- |
private final List<GroupMover> mGroupMovers = new ArrayList<GroupMover>(); |
150 |
|
- |
|
151 |
|
- |
private MoveControlPanel( boolean pAddUpDown ) { |
152 |
|
- |
mBetweenButton = Button.named( "Between" ).blue().text( "To There" ).add( new ClickHandler() { |
153 |
|
- |
@Override |
154 |
|
- |
public void onClick( ClickEvent event ) { |
155 |
|
- |
reprioritizeBetween(); |
156 |
|
- |
} |
157 |
|
- |
} ).create().disable(); |
158 |
|
- |
mUpButton = Button.named( "Up" ).blue().text().add( new ClickHandler() { |
159 |
|
- |
@Override |
160 |
|
- |
public void onClick( ClickEvent event ) { |
161 |
|
- |
reprioritizeUp(); |
162 |
|
- |
} |
163 |
|
- |
} ).create().disable(); |
164 |
|
- |
mDownButton = Button.named( "Down" ).blue().text().add( new ClickHandler() { |
165 |
|
- |
@Override |
166 |
|
- |
public void onClick( ClickEvent event ) { |
167 |
|
- |
reprioritizeDown(); |
168 |
|
- |
} |
169 |
|
- |
} ).create().disable(); |
170 |
|
- |
|
171 |
|
- |
setHorizontalAlignment( VerticalPanel.ALIGN_CENTER ); |
172 |
|
- |
add( new Label( "Move..." ) ); |
173 |
|
- |
add( new Spacer( 20 ) ); |
174 |
|
- |
add( mBetweenButton ); |
175 |
|
- |
add( new Spacer( 20 ) ); |
176 |
|
- |
PriorityGroup[] zGroups = PriorityGroup.values(); |
177 |
|
- |
for ( int i = zGroups.length; --i >= 0; ) { |
178 |
|
- |
PriorityGroup zGroup = zGroups[i]; |
179 |
|
- |
if ( PriorityGroup.Initial != zGroup ) { |
180 |
|
- |
GroupMover zMover = new GroupMover( zGroup ); |
181 |
|
- |
mGroupMovers.add( zMover ); |
182 |
|
- |
add( zMover.getButton() ); |
183 |
|
- |
} |
184 |
|
- |
} |
185 |
|
- |
add( new Spacer( 20 ) ); |
186 |
|
- |
if ( pAddUpDown ) { |
187 |
|
- |
add( mUpButton ); |
188 |
|
- |
add( mDownButton ); |
189 |
|
- |
} |
190 |
|
- |
} |
191 |
|
- |
|
192 |
|
- |
@Override |
193 |
|
- |
protected void onAttach() { |
194 |
|
- |
super.onAttach(); |
195 |
|
- |
sameSizeButtons(); |
196 |
|
- |
} |
197 |
|
- |
|
198 |
|
- |
private void sameSizeButtons() { |
199 |
|
- |
if ( isAttached() ) { |
200 |
|
- |
Integer zMaxWidth = getMaxControlButtonWidth(); |
201 |
|
- |
if ( zMaxWidth != null ) { |
202 |
|
- |
setControlButtonSameWidth( zMaxWidth ); |
203 |
|
- |
return; |
204 |
|
- |
} |
205 |
|
- |
} |
206 |
|
- |
Scheduler.get().scheduleDeferred( new Command() { |
207 |
|
- |
@Override |
208 |
|
- |
public void execute() { |
209 |
|
- |
sameSizeButtons(); |
210 |
|
- |
} |
211 |
|
- |
} ); |
212 |
|
- |
} |
213 |
|
- |
|
214 |
|
- |
private Integer getMaxControlButtonWidth() { |
215 |
|
- |
int zMaxWidth = mBetweenButton.getOffsetWidth(); |
216 |
|
- |
for ( Widget zWidget : getChildren() ) { |
217 |
|
- |
if ( zWidget instanceof Button ) { |
218 |
|
- |
zMaxWidth = Math.max( zMaxWidth, zWidget.getOffsetWidth() ); |
219 |
|
- |
} |
220 |
|
- |
} |
221 |
|
- |
return (zMaxWidth > 30) ? zMaxWidth : null; |
222 |
|
- |
} |
223 |
|
- |
|
224 |
|
- |
private void setControlButtonSameWidth( int pWidth ) { |
225 |
|
- |
String zWidth = "" + pWidth; |
226 |
|
- |
for ( Widget zWidget : getChildren() ) { |
227 |
|
- |
if ( zWidget instanceof Button ) { |
228 |
|
- |
zWidget.setWidth( zWidth ); |
229 |
|
- |
} |
230 |
|
- |
} |
231 |
|
- |
} |
232 |
|
- |
|
233 |
|
- |
@Override |
234 |
|
- |
public void onSelection( SelectionEvent<StoryView> event ) { |
235 |
|
- |
handleButtons( mTable.getSelectedValues() ); |
236 |
|
- |
} |
237 |
|
- |
|
238 |
|
- |
private void handleButtons( Set<StoryView> pSelectedValues ) { |
239 |
|
- |
boolean zAnySelected = (pSelectedValues != null) && !pSelectedValues.isEmpty(); |
240 |
|
- |
mBetweenButton.setEnabled( zAnySelected && betweenable( pSelectedValues ) ); |
241 |
|
- |
mUpButton.setEnabled( zAnySelected && upable( pSelectedValues ) ); |
242 |
|
- |
mDownButton.setEnabled( zAnySelected && downable( pSelectedValues ) ); |
243 |
|
- |
for ( GroupMover zMover : mGroupMovers ) { |
244 |
|
- |
zMover.setEnable( zAnySelected, pSelectedValues ); |
245 |
|
- |
} |
246 |
|
- |
} |
247 |
|
- |
} |
248 |
|
- |
|
249 |
|
- |
private class GroupMover implements ClickHandler { |
250 |
|
- |
private PriorityGroup mGroup; |
251 |
|
- |
private Button mButton; |
252 |
|
- |
|
253 |
|
- |
private GroupMover( PriorityGroup pGroup ) { |
254 |
|
- |
mGroup = pGroup; |
255 |
|
- |
mButton = Button.named( mGroup.name() ).blue().text().add( this ).create().disable(); |
256 |
|
- |
} |
257 |
|
- |
|
258 |
|
- |
public Button getButton() { |
259 |
|
- |
return mButton; |
260 |
|
- |
} |
261 |
|
- |
|
262 |
|
- |
@Override |
263 |
|
- |
public void onClick( ClickEvent event ) { |
264 |
|
- |
reprioritizeToGroup( mGroup ); |
265 |
|
- |
} |
266 |
|
- |
|
267 |
|
- |
public void setEnable( boolean pAnySelected, Set<StoryView> pSelectedValues ) { |
268 |
|
- |
mButton.setEnabled( pAnySelected && applicable( pSelectedValues ) ); |
269 |
|
- |
} |
270 |
|
- |
|
271 |
|
- |
private boolean applicable( Set<StoryView> pSelectedValues ) { |
272 |
|
- |
for ( StoryView zStoryView : pSelectedValues ) { |
273 |
|
- |
if ( mGroup != PriorityGroup.from( zStoryView.getPriority() ) ) { |
274 |
|
- |
return true; |
275 |
|
- |
} |
276 |
|
- |
} |
277 |
|
- |
return false; |
278 |
|
- |
} |
279 |
|
- |
} |
280 |
|
- |
|
281 |
|
- |
abstract protected boolean betweenable( Set<StoryView> pSelectedValues ); |
282 |
|
- |
|
283 |
|
- |
protected boolean upable( Set<StoryView> pSelectedValues ) { |
284 |
|
- |
return !isAtEdge( pSelectedValues, 0 ); |
285 |
|
- |
} |
286 |
|
- |
|
287 |
|
- |
protected boolean downable( Set<StoryView> pSelectedValues ) { |
288 |
|
- |
return !isAtEdge( pSelectedValues, mTableModel.size() - 1 ); |
289 |
|
- |
} |
290 |
|
- |
|
291 |
|
- |
protected boolean isAtEdge( Set<StoryView> pSelectedValues, int pEdge ) { |
292 |
|
- |
for ( StoryView zStoryView : pSelectedValues ) { |
293 |
|
- |
if ( mTableModel.indexOf( zStoryView ) == pEdge ) { |
294 |
|
- |
return true; |
295 |
|
- |
} |
296 |
|
- |
} |
297 |
|
- |
return false; |
298 |
|
- |
} |
299 |
|
- |
|
300 |
|
- |
private void reprioritizeUp() { |
301 |
|
- |
int zMin = mTableModel.size(); |
302 |
|
- |
for ( StoryView zStoryView : mTable.getSelectedValues() ) { |
303 |
|
- |
zMin = Math.min( zMin, mTableModel.indexOf( zStoryView ) ); |
304 |
|
- |
} |
305 |
|
- |
if ( zMin != mTableModel.size() ) { |
306 |
|
- |
reprioritizeBetween( mSavedSelectedValues = mTable.getSelectedValues(), getStoryView( zMin - 1 ), getStoryView( zMin - 2 ) ); |
307 |
|
- |
} |
308 |
|
- |
} |
309 |
|
- |
|
310 |
|
- |
private void reprioritizeDown() { |
311 |
|
- |
int zMax = -1; |
312 |
|
- |
for ( StoryView zStoryView : mTable.getSelectedValues() ) { |
313 |
|
- |
zMax = Math.max( zMax, mTableModel.indexOf( zStoryView ) ); |
314 |
|
- |
} |
315 |
|
- |
if ( zMax != -1 ) { |
316 |
|
- |
reprioritizeBetween( mSavedSelectedValues = mTable.getSelectedValues(), getStoryView( zMax + 2 ), getStoryView( zMax + 1 ) ); |
317 |
|
- |
} |
318 |
|
- |
} |
319 |
|
- |
|
320 |
|
- |
private void reprioritizeBetween( StoryView pLowerBound, StoryView pUpperBound ) { |
321 |
|
- |
reprioritizeBetween( mTable.getSelectedValues(), pLowerBound, pUpperBound ); |
322 |
|
- |
} |
323 |
|
- |
|
324 |
|
- |
private void reprioritizeBetween( Set<StoryView> pSelectedValues, StoryView pLowerBound, StoryView pUpperBound ) { |
325 |
|
- |
mDP.reprioritizeBetween( pLowerBound, pUpperBound, pSelectedValues, this ); |
326 |
|
- |
} |
327 |
|
- |
|
328 |
|
- |
private void reprioritizeToGroup( PriorityGroup pGroup ) { |
329 |
|
- |
mDP.reprioritizeToGroup( pGroup, mTable.getSelectedValues(), this ); |
330 |
|
- |
} |
331 |
|
- |
|
332 |
|
- |
private StoryView getStoryView( int pIndex ) { |
333 |
|
- |
return ((0 <= pIndex) && (pIndex < mTableModel.size())) ? mTableModel.get( pIndex ) : null; |
334 |
|
- |
} |
335 |
|
- |
|
336 |
|
- |
abstract protected void fetchTargetBetweenRows( final DataAvailableCallBack<StoryView> pCallBack ); |
337 |
|
- |
|
338 |
|
- |
private void reprioritizeBetween() { |
339 |
|
- |
fetchTargetBetweenRows( this ); |
340 |
|
- |
} |
341 |
|
- |
|
342 |
|
- |
@Override |
343 |
|
- |
public void dataAvailable( List<StoryView> pData ) // called when we can proceed with the InjectionPointSelector |
344 |
|
- |
{ |
345 |
|
- |
if ( pData.isEmpty() ) { |
346 |
|
- |
error( "There are Nothing but " + PriorityGroup.Initial + " priority Stories" ); |
347 |
|
- |
return; |
348 |
|
- |
} |
349 |
|
- |
Set<StoryView> zSelectedRows = mTable.getSelectedValues(); |
350 |
|
- |
List<StoryView> zNonSelectedRows = new ArrayList<StoryView>( pData.size() ); |
351 |
|
- |
for ( StoryView zStoryView : pData ) { |
352 |
|
- |
if ( !zSelectedRows.contains( zStoryView ) ) { |
353 |
|
- |
zNonSelectedRows.add( zStoryView ); |
354 |
|
- |
} |
355 |
|
- |
} |
356 |
|
- |
if ( zNonSelectedRows.isEmpty() ) { |
357 |
|
- |
error( "At least one Story must not be selected" ); |
358 |
|
- |
return; |
359 |
|
- |
} |
360 |
|
- |
new InjectionPointSelectionDialog<StoryView>( "Select 'There' to Move Selected Rows", 4, zNonSelectedRows, |
361 |
|
- |
new InjectionPointSelector.Callback<StoryView>() { |
362 |
|
- |
@Override |
363 |
|
- |
public void injectBetween( StoryView pLowerBound, StoryView pUpperBound ) { |
364 |
|
- |
reprioritizeBetween( pLowerBound, pUpperBound ); |
365 |
|
- |
} |
366 |
|
- |
} ).show(); |
367 |
|
- |
} |
368 |
|
- |
} |
|
1 |
+ |
package org.litesoft.prioritizer.client.ui.views.stories; |
|
2 |
+ |
|
|
3 |
+ |
import org.litesoft.GWT.client.*; |
|
4 |
+ |
import org.litesoft.GWT.client.view.*; |
|
5 |
+ |
import org.litesoft.GWT.client.widgets.Button; |
|
6 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
7 |
+ |
import org.litesoft.GWT.client.widgets.datatables.*; |
|
8 |
+ |
import org.litesoft.GWT.forms.client.*; |
|
9 |
+ |
import org.litesoft.bo.views.*; |
|
10 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
11 |
+ |
import org.litesoft.core.util.*; |
|
12 |
+ |
import org.litesoft.prioritizer.client.boviews.*; |
|
13 |
+ |
import org.litesoft.prioritizer.client.support.*; |
|
14 |
+ |
import org.litesoft.uispecification.*; |
|
15 |
+ |
|
|
16 |
+ |
import com.google.gwt.core.client.*; |
|
17 |
+ |
import com.google.gwt.event.dom.client.*; |
|
18 |
+ |
import com.google.gwt.event.logical.shared.*; |
|
19 |
+ |
import com.google.gwt.user.client.*; |
|
20 |
+ |
import com.google.gwt.user.client.ui.*; |
|
21 |
+ |
|
|
22 |
+ |
import java.util.*; |
|
23 |
+ |
|
|
24 |
+ |
public abstract class AbstractPrioritizeScreenView extends ScreenView implements StoryViewNames, |
|
25 |
+ |
SimpleDataProviderCallBack, |
|
26 |
+ |
DataAvailableCallBack<StoryView> { |
|
27 |
+ |
protected final String mWhat; |
|
28 |
+ |
protected final StoryViewDataProvider mDP = StoryViewDataProvider.getInstance(); |
|
29 |
+ |
protected final ListTableModel<StoryView> mTableModel = new ListTableModel<StoryView>(); |
|
30 |
+ |
protected final CheckBoxSelectRegularTable<StoryView> mTable; |
|
31 |
+ |
protected final MoveControlPanel mMoveControlPanel; |
|
32 |
+ |
private Set<StoryView> mSavedSelectedValues = null; |
|
33 |
+ |
|
|
34 |
+ |
private Integer mTopRowOffset = null; |
|
35 |
+ |
|
|
36 |
+ |
@Override |
|
37 |
+ |
protected UriFragmentIdParams createRefreshParams() { |
|
38 |
+ |
return ReprioritizeFactory.encodeParams( mTopRowOffset ); |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
public AbstractPrioritizeScreenView( String pSection, ViewDef pViewDef, String pWhat, boolean pAddUpDown, BoTableDefinition<StoryView> pTableDef, |
|
42 |
+ |
Integer pTopRowOffset ) { |
|
43 |
+ |
super( title( pSection, pViewDef ) ); |
|
44 |
+ |
|
|
45 |
+ |
mTopRowOffset = pTopRowOffset; |
|
46 |
+ |
|
|
47 |
+ |
mWhat = pWhat; |
|
48 |
+ |
|
|
49 |
+ |
addRight( Button.named( "Refresh" ).blue().text().add( new ClickHandler() { |
|
50 |
+ |
@Override |
|
51 |
+ |
public void onClick( ClickEvent event ) { |
|
52 |
+ |
fetchRows(); |
|
53 |
+ |
} |
|
54 |
+ |
} ).create() ); |
|
55 |
+ |
addStandardTitleBar(); |
|
56 |
+ |
|
|
57 |
+ |
addSectionTitle( mWhat ); |
|
58 |
+ |
|
|
59 |
+ |
mMoveControlPanel = new MoveControlPanel( pAddUpDown ); |
|
60 |
+ |
mTable = new CheckBoxSelectRegularTable<StoryView>( mTableModel, pTableDef, mMoveControlPanel ); |
|
61 |
+ |
|
|
62 |
+ |
SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchable(); |
|
63 |
+ |
zPanel.add( mTable ); |
|
64 |
+ |
zPanel.add( mMoveControlPanel ); |
|
65 |
+ |
add( zPanel ); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
@Override |
|
69 |
+ |
protected void justLoaded() { |
|
70 |
+ |
super.justLoaded(); |
|
71 |
+ |
fetchRows(); |
|
72 |
+ |
} |
|
73 |
+ |
|
|
74 |
+ |
abstract protected void fetchRows(); |
|
75 |
+ |
|
|
76 |
+ |
protected FetchRowsDataProviderCallBack<StoryView> createFetchRowsCallBack() { |
|
77 |
+ |
return new FetchRowsDataProviderCallBack<StoryView>() { |
|
78 |
+ |
@Override |
|
79 |
+ |
public void tooMany( long pCount ) { |
|
80 |
+ |
systemError( "System Error: Should not happen", // |
|
81 |
+ |
"Found " + pCount + " " + mWhat + ".", // |
|
82 |
+ |
"This is more than the application is willing to display." ); |
|
83 |
+ |
} |
|
84 |
+ |
|
|
85 |
+ |
@Override |
|
86 |
+ |
public void error( String pError ) { |
|
87 |
+ |
systemError( "Requesting " + mWhat + " - Errored", // |
|
88 |
+ |
"", // |
|
89 |
+ |
"Error: " + pError ); |
|
90 |
+ |
} |
|
91 |
+ |
|
|
92 |
+ |
@Override |
|
93 |
+ |
public void success( ImmutableArrayList<StoryView> pRows ) { |
|
94 |
+ |
if ( pRows.isEmpty() ) { |
|
95 |
+ |
backToHome( "Nothing to " + mWhat ); |
|
96 |
+ |
return; |
|
97 |
+ |
} |
|
98 |
+ |
mTableModel.clear(); |
|
99 |
+ |
mTableModel.addAll( pRows ); |
|
100 |
+ |
Collections.sort( mTableModel ); |
|
101 |
+ |
mTable.loadData(); |
|
102 |
+ |
mTable.deselectAll(); |
|
103 |
+ |
mMoveControlPanel.handleButtons( reselectAll() ); |
|
104 |
+ |
} |
|
105 |
+ |
|
|
106 |
+ |
private Set<StoryView> reselectAll() { |
|
107 |
+ |
boolean zFound = false; |
|
108 |
+ |
if ( mSavedSelectedValues != null ) { |
|
109 |
+ |
for ( StoryView zValue : mSavedSelectedValues ) { |
|
110 |
+ |
if ( mTable.selectRow( zValue ) ) { |
|
111 |
+ |
zFound = true; |
|
112 |
+ |
} |
|
113 |
+ |
} |
|
114 |
+ |
mSavedSelectedValues = null; |
|
115 |
+ |
} |
|
116 |
+ |
return zFound ? mTable.getSelectedValues() : null; |
|
117 |
+ |
} |
|
118 |
+ |
}; |
|
119 |
+ |
} |
|
120 |
+ |
|
|
121 |
+ |
@Override |
|
122 |
+ |
public void error( String pError ) { |
|
123 |
+ |
if ( Currently.isNotNullOrEmpty( pError ) ) { |
|
124 |
+ |
systemError( "Requested Prioritizing - Errored", // |
|
125 |
+ |
"", // |
|
126 |
+ |
"Error: " + pError ); |
|
127 |
+ |
} else { |
|
128 |
+ |
fetchRows(); |
|
129 |
+ |
} |
|
130 |
+ |
} |
|
131 |
+ |
|
|
132 |
+ |
@Override |
|
133 |
+ |
public Widget getBottomBar() { |
|
134 |
+ |
return null; |
|
135 |
+ |
} |
|
136 |
+ |
|
|
137 |
+ |
protected static class TableDef extends BoTableDefinition<StoryView> implements StoryViewNames, |
|
138 |
+ |
DataTableStyle { |
|
139 |
+ |
public TableDef() { |
|
140 |
+ |
StoryViewMetaData zMD = StoryViewMetaData.getInstance(); |
|
141 |
+ |
|
|
142 |
+ |
addColumn( zMD.getBoAttribute( aName ) ); // .initialWidth( FontSizer.get( TABLE_TEXT ).EMsPlus( 20, CELL_PADDING ) ); |
|
143 |
+ |
addColumn( zMD.getBoAttribute( aDescriptionThreeLines ), "Description" ); // .initialWidth( FontSizer.get( TABLE_TEXT ).EMsPlus( 40, CELL_PADDING ) ); |
|
144 |
+ |
} |
|
145 |
+ |
} |
|
146 |
+ |
|
|
147 |
+ |
private class MoveControlPanel extends VerticalPanel implements SelectionHandler<StoryView> { |
|
148 |
+ |
private final Button mBetweenButton, mUpButton, mDownButton; |
|
149 |
+ |
private final List<GroupMover> mGroupMovers = new ArrayList<GroupMover>(); |
|
150 |
+ |
|
|
151 |
+ |
private MoveControlPanel( boolean pAddUpDown ) { |
|
152 |
+ |
mBetweenButton = Button.named( "Between" ).blue().text( "To There" ).add( new ClickHandler() { |
|
153 |
+ |
@Override |
|
154 |
+ |
public void onClick( ClickEvent event ) { |
|
155 |
+ |
reprioritizeBetween(); |
|
156 |
+ |
} |
|
157 |
+ |
} ).create().disable(); |
|
158 |
+ |
mUpButton = Button.named( "Up" ).blue().text().add( new ClickHandler() { |
|
159 |
+ |
@Override |
|
160 |
+ |
public void onClick( ClickEvent event ) { |
|
161 |
+ |
reprioritizeUp(); |
|
162 |
+ |
} |
|
163 |
+ |
} ).create().disable(); |
|
164 |
+ |
mDownButton = Button.named( "Down" ).blue().text().add( new ClickHandler() { |
|
165 |
+ |
@Override |
|
166 |
+ |
public void onClick( ClickEvent event ) { |
|
167 |
+ |
reprioritizeDown(); |
|
168 |
+ |
} |
|
169 |
+ |
} ).create().disable(); |
|
170 |
+ |
|
|
171 |
+ |
setHorizontalAlignment( VerticalPanel.ALIGN_CENTER ); |
|
172 |
+ |
add( new Label( "Move..." ) ); |
|
173 |
+ |
add( new Spacer( 20 ) ); |
|
174 |
+ |
add( mBetweenButton ); |
|
175 |
+ |
add( new Spacer( 20 ) ); |
|
176 |
+ |
PriorityGroup[] zGroups = PriorityGroup.values(); |
|
177 |
+ |
for ( int i = zGroups.length; --i >= 0; ) { |
|
178 |
+ |
PriorityGroup zGroup = zGroups[i]; |
|
179 |
+ |
if ( PriorityGroup.Initial != zGroup ) { |
|
180 |
+ |
GroupMover zMover = new GroupMover( zGroup ); |
|
181 |
+ |
mGroupMovers.add( zMover ); |
|
182 |
+ |
add( zMover.getButton() ); |
|
183 |
+ |
} |
|
184 |
+ |
} |
|
185 |
+ |
add( new Spacer( 20 ) ); |
|
186 |
+ |
if ( pAddUpDown ) { |
|
187 |
+ |
add( mUpButton ); |
|
188 |
+ |
add( mDownButton ); |
|
189 |
+ |
} |
|
190 |
+ |
} |
|
191 |
+ |
|
|
192 |
+ |
@Override |
|
193 |
+ |
protected void onAttach() { |
|
194 |
+ |
super.onAttach(); |
|
195 |
+ |
sameSizeButtons(); |
|
196 |
+ |
} |
|
197 |
+ |
|
|
198 |
+ |
private void sameSizeButtons() { |
|
199 |
+ |
if ( isAttached() ) { |
|
200 |
+ |
Integer zMaxWidth = getMaxControlButtonWidth(); |
|
201 |
+ |
if ( zMaxWidth != null ) { |
|
202 |
+ |
setControlButtonSameWidth( zMaxWidth ); |
|
203 |
+ |
return; |
|
204 |
+ |
} |
|
205 |
+ |
} |
|
206 |
+ |
Scheduler.get().scheduleDeferred( new Command() { |
|
207 |
+ |
@Override |
|
208 |
+ |
public void execute() { |
|
209 |
+ |
sameSizeButtons(); |
|
210 |
+ |
} |
|
211 |
+ |
} ); |
|
212 |
+ |
} |
|
213 |
+ |
|
|
214 |
+ |
private Integer getMaxControlButtonWidth() { |
|
215 |
+ |
int zMaxWidth = mBetweenButton.getOffsetWidth(); |
|
216 |
+ |
for ( Widget zWidget : getChildren() ) { |
|
217 |
+ |
if ( zWidget instanceof Button ) { |
|
218 |
+ |
zMaxWidth = Math.max( zMaxWidth, zWidget.getOffsetWidth() ); |
|
219 |
+ |
} |
|
220 |
+ |
} |
|
221 |
+ |
return (zMaxWidth > 30) ? zMaxWidth : null; |
|
222 |
+ |
} |
|
223 |
+ |
|
|
224 |
+ |
private void setControlButtonSameWidth( int pWidth ) { |
|
225 |
+ |
String zWidth = "" + pWidth; |
|
226 |
+ |
for ( Widget zWidget : getChildren() ) { |
|
227 |
+ |
if ( zWidget instanceof Button ) { |
|
228 |
+ |
zWidget.setWidth( zWidth ); |
|
229 |
+ |
} |
|
230 |
+ |
} |
|
231 |
+ |
} |
|
232 |
+ |
|
|
233 |
+ |
@Override |
|
234 |
+ |
public void onSelection( SelectionEvent<StoryView> event ) { |
|
235 |
+ |
handleButtons( mTable.getSelectedValues() ); |
|
236 |
+ |
} |
|
237 |
+ |
|
|
238 |
+ |
private void handleButtons( Set<StoryView> pSelectedValues ) { |
|
239 |
+ |
boolean zAnySelected = (pSelectedValues != null) && !pSelectedValues.isEmpty(); |
|
240 |
+ |
mBetweenButton.setEnabled( zAnySelected && betweenable( pSelectedValues ) ); |
|
241 |
+ |
mUpButton.setEnabled( zAnySelected && upable( pSelectedValues ) ); |
|
242 |
+ |
mDownButton.setEnabled( zAnySelected && downable( pSelectedValues ) ); |
|
243 |
+ |
for ( GroupMover zMover : mGroupMovers ) { |
|
244 |
+ |
zMover.setEnable( zAnySelected, pSelectedValues ); |
|
245 |
+ |
} |
|
246 |
+ |
} |
|
247 |
+ |
} |
|
248 |
+ |
|
|
249 |
+ |
private class GroupMover implements ClickHandler { |
|
250 |
+ |
private PriorityGroup mGroup; |
|
251 |
+ |
private Button mButton; |
|
252 |
+ |
|
|
253 |
+ |
private GroupMover( PriorityGroup pGroup ) { |
|
254 |
+ |
mGroup = pGroup; |
|
255 |
+ |
mButton = Button.named( mGroup.name() ).blue().text().add( this ).create().disable(); |
|
256 |
+ |
} |
|
257 |
+ |
|
|
258 |
+ |
public Button getButton() { |
|
259 |
+ |
return mButton; |
|
260 |
+ |
} |
|
261 |
+ |
|
|
262 |
+ |
@Override |
|
263 |
+ |
public void onClick( ClickEvent event ) { |
|
264 |
+ |
reprioritizeToGroup( mGroup ); |
|
265 |
+ |
} |
|
266 |
+ |
|
|
267 |
+ |
public void setEnable( boolean pAnySelected, Set<StoryView> pSelectedValues ) { |
|
268 |
+ |
mButton.setEnabled( pAnySelected && applicable( pSelectedValues ) ); |
|
269 |
+ |
} |
|
270 |
+ |
|
|
271 |
+ |
private boolean applicable( Set<StoryView> pSelectedValues ) { |
|
272 |
+ |
for ( StoryView zStoryView : pSelectedValues ) { |
|
273 |
+ |
if ( mGroup != PriorityGroup.from( zStoryView.getPriority() ) ) { |
|
274 |
+ |
return true; |
|
275 |
+ |
} |
|
276 |
+ |
} |
|
277 |
+ |
return false; |
|
278 |
+ |
} |
|
279 |
+ |
} |
|
280 |
+ |
|
|
281 |
+ |
abstract protected boolean betweenable( Set<StoryView> pSelectedValues ); |
|
282 |
+ |
|
|
283 |
+ |
protected boolean upable( Set<StoryView> pSelectedValues ) { |
|
284 |
+ |
return !isAtEdge( pSelectedValues, 0 ); |
|
285 |
+ |
} |
|
286 |
+ |
|
|
287 |
+ |
protected boolean downable( Set<StoryView> pSelectedValues ) { |
|
288 |
+ |
return !isAtEdge( pSelectedValues, mTableModel.size() - 1 ); |
|
289 |
+ |
} |
|
290 |
+ |
|
|
291 |
+ |
protected boolean isAtEdge( Set<StoryView> pSelectedValues, int pEdge ) { |
|
292 |
+ |
for ( StoryView zStoryView : pSelectedValues ) { |
|
293 |
+ |
if ( mTableModel.indexOf( zStoryView ) == pEdge ) { |
|
294 |
+ |
return true; |
|
295 |
+ |
} |
|
296 |
+ |
} |
|
297 |
+ |
return false; |
|
298 |
+ |
} |
|
299 |
+ |
|
|
300 |
+ |
private void reprioritizeUp() { |
|
301 |
+ |
int zMin = mTableModel.size(); |
|
302 |
+ |
for ( StoryView zStoryView : mTable.getSelectedValues() ) { |
|
303 |
+ |
zMin = Math.min( zMin, mTableModel.indexOf( zStoryView ) ); |
|
304 |
+ |
} |
|
305 |
+ |
if ( zMin != mTableModel.size() ) { |
|
306 |
+ |
reprioritizeBetween( mSavedSelectedValues = mTable.getSelectedValues(), getStoryView( zMin - 1 ), getStoryView( zMin - 2 ) ); |
|
307 |
+ |
} |
|
308 |
+ |
} |
|
309 |
+ |
|
|
310 |
+ |
private void reprioritizeDown() { |
|
311 |
+ |
int zMax = -1; |
|
312 |
+ |
for ( StoryView zStoryView : mTable.getSelectedValues() ) { |
|
313 |
+ |
zMax = Math.max( zMax, mTableModel.indexOf( zStoryView ) ); |
|
314 |
+ |
} |
|
315 |
+ |
if ( zMax != -1 ) { |
|
316 |
+ |
reprioritizeBetween( mSavedSelectedValues = mTable.getSelectedValues(), getStoryView( zMax + 2 ), getStoryView( zMax + 1 ) ); |
|
317 |
+ |
} |
|
318 |
+ |
} |
|
319 |
+ |
|
|
320 |
+ |
private void reprioritizeBetween( StoryView pLowerBound, StoryView pUpperBound ) { |
|
321 |
+ |
reprioritizeBetween( mTable.getSelectedValues(), pLowerBound, pUpperBound ); |
|
322 |
+ |
} |
|
323 |
+ |
|
|
324 |
+ |
private void reprioritizeBetween( Set<StoryView> pSelectedValues, StoryView pLowerBound, StoryView pUpperBound ) { |
|
325 |
+ |
mDP.reprioritizeBetween( pLowerBound, pUpperBound, pSelectedValues, this ); |
|
326 |
+ |
} |
|
327 |
+ |
|
|
328 |
+ |
private void reprioritizeToGroup( PriorityGroup pGroup ) { |
|
329 |
+ |
mDP.reprioritizeToGroup( pGroup, mTable.getSelectedValues(), this ); |
|
330 |
+ |
} |
|
331 |
+ |
|
|
332 |
+ |
private StoryView getStoryView( int pIndex ) { |
|
333 |
+ |
return ((0 <= pIndex) && (pIndex < mTableModel.size())) ? mTableModel.get( pIndex ) : null; |
|
334 |
+ |
} |
|
335 |
+ |
|
|
336 |
+ |
abstract protected void fetchTargetBetweenRows( final DataAvailableCallBack<StoryView> pCallBack ); |
|
337 |
+ |
|
|
338 |
+ |
private void reprioritizeBetween() { |
|
339 |
+ |
fetchTargetBetweenRows( this ); |
|
340 |
+ |
} |
|
341 |
+ |
|
|
342 |
+ |
@Override |
|
343 |
+ |
public void dataAvailable( List<StoryView> pData ) // called when we can proceed with the InjectionPointSelector |
|
344 |
+ |
{ |
|
345 |
+ |
if ( pData.isEmpty() ) { |
|
346 |
+ |
error( "There are Nothing but " + PriorityGroup.Initial + " priority Stories" ); |
|
347 |
+ |
return; |
|
348 |
+ |
} |
|
349 |
+ |
Set<StoryView> zSelectedRows = mTable.getSelectedValues(); |
|
350 |
+ |
List<StoryView> zNonSelectedRows = new ArrayList<StoryView>( pData.size() ); |
|
351 |
+ |
for ( StoryView zStoryView : pData ) { |
|
352 |
+ |
if ( !zSelectedRows.contains( zStoryView ) ) { |
|
353 |
+ |
zNonSelectedRows.add( zStoryView ); |
|
354 |
+ |
} |
|
355 |
+ |
} |
|
356 |
+ |
if ( zNonSelectedRows.isEmpty() ) { |
|
357 |
+ |
error( "At least one Story must not be selected" ); |
|
358 |
+ |
return; |
|
359 |
+ |
} |
|
360 |
+ |
new InjectionPointSelectionDialog<StoryView>( "Select 'There' to Move Selected Rows", 4, zNonSelectedRows, |
|
361 |
+ |
new InjectionPointSelector.Callback<StoryView>() { |
|
362 |
+ |
@Override |
|
363 |
+ |
public void injectBetween( StoryView pLowerBound, StoryView pUpperBound ) { |
|
364 |
+ |
reprioritizeBetween( pLowerBound, pUpperBound ); |
|
365 |
+ |
} |
|
366 |
+ |
} ).show(); |
|
367 |
+ |
} |
|
368 |
+ |
} |