Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/view/UiView.java

Diff revisions: vs.
  @@ -23,160 +23,130 @@
23 23
24 24 import static org.litesoft.uispecification.FormWidgetCtrl.*;
25 25
26 - public abstract class UiView implements ViewErrorSupport
27 - {
26 + public abstract class UiView implements ViewErrorSupport {
28 27 public static final Logger LOGGER = LoggerFactory.getLogger( UiView.class );
29 28
30 29 protected ViewDef mViewDef = null;
31 30 protected String mTitle = null;
32 31
33 - protected SizeableVerticalPanel mContent = new SizeableVerticalPanel()
34 - {
32 + protected SizeableVerticalPanel mContent = new SizeableVerticalPanel() {
35 33 @Override
36 - protected void onLoad()
37 - {
34 + protected void onLoad() {
38 35 super.onLoad();
39 36 justLoaded();
40 37 }
41 38
42 39 @Override
43 - protected void onUnload()
44 - {
40 + protected void onUnload() {
45 41 super.onUnload();
46 42 justUnloaded();
47 43 }
48 44 }.stretchable().style( "Content" );
49 45
50 - protected void justLoaded()
51 - {
46 + protected void justLoaded() {
52 47 }
53 48
54 - protected void justUnloaded()
55 - {
49 + protected void justUnloaded() {
56 50
57 51 }
58 52
59 - protected UiView( CO pCO )
60 - {
53 + protected UiView( CO pCO ) {
61 54 pCO = deNull( pCO );
62 55 mViewDef = pCO.mViewDef;
63 56 mTitle = pCO.mTitle;
64 57 }
65 58
66 - public final boolean hasViewTitle()
67 - {
59 + public final boolean hasViewTitle() {
68 60 return (mTitle != null);
69 61 }
70 62
71 - public final String getViewTitle()
72 - {
63 + public final String getViewTitle() {
73 64 return hasViewTitle() ? mTitle : "No Title";
74 65 }
75 66
76 - public void aboutToShow()
77 - {
67 + public void aboutToShow() {
78 68 }
79 69
80 - protected final void setViewTitle( String pTitle )
81 - {
70 + protected final void setViewTitle( String pTitle ) {
82 71 mTitle = Strings.assertNotNullNotEmpty( "Title", pTitle );
83 72 }
84 73
85 74 abstract public Widget getContent();
86 75
87 - public Widget getBottomBar()
88 - {
76 + public Widget getBottomBar() {
89 77 return null;
90 78 }
91 79
92 - protected CenterHorizontalPanel createSectionTitle( String pText )
93 - {
80 + protected CenterHorizontalPanel createSectionTitle( String pText ) {
94 81 return createSectionTitle( new OurLabel( pText ) );
95 82 }
96 83
97 - protected CenterHorizontalPanel createSectionTitle( OurLabel pLabel )
98 - {
84 + protected CenterHorizontalPanel createSectionTitle( OurLabel pLabel ) {
99 85 return new CenterHorizontalPanel().add( pLabel ).style( "SectionTitle" );
100 86 }
101 87
102 - protected LeftCenterRightHorizontalPanel createSectionTitle( OurLabel pLabel, Widget pRightWidget )
103 - {
88 + protected LeftCenterRightHorizontalPanel createSectionTitle( OurLabel pLabel, Widget pRightWidget ) {
104 89 LeftCenterRightHorizontalPanel zPanel = new LeftCenterRightHorizontalPanel().style( "SectionTitle" );
105 90 zPanel.addCenter( pLabel );
106 91 zPanel.addRight( pRightWidget );
107 92 return zPanel;
108 93 }
109 94
110 - protected static OurLabel createFormLabel( String pText )
111 - {
95 + protected static OurLabel createFormLabel( String pText ) {
112 96 return new OurLabel( pText + ": " ).style( AbstractFormElement.FORM_COMPONENT_LABEL_LEFT_STYLE );
113 97 }
114 98
115 - protected Widget disable( Enableable pComponent )
116 - {
99 + protected Widget disable( Enableable pComponent ) {
117 100 return enabled( false, pComponent );
118 101 }
119 102
120 - protected Widget enabled( boolean pEnabled, Enableable pComponent )
121 - {
103 + protected Widget enabled( boolean pEnabled, Enableable pComponent ) {
122 104 pComponent.setEnabled( pEnabled );
123 105 return (Widget) pComponent;
124 106 }
125 107
126 - public void error( String pError )
127 - {
108 + public void error( String pError ) {
128 109 backToHome( pError );
129 110 }
130 111
131 112 @Override
132 - public final void backToHome( String pError )
133 - {
113 + public final void backToHome( String pError ) {
134 114 backTo( ViewDef.HOME, pError );
135 115 }
136 116
137 - protected final void backTo( ViewDef pViewDef, String pError )
138 - {
117 + protected final void backTo( ViewDef pViewDef, String pError ) {
139 118 Scheduler.get().scheduleDeferred( new ShowScreenCommand( pViewDef, pError ) );
140 119 }
141 120
142 121 @Override
143 - public StatusMessageSinc getStatusMessageSinc()
144 - {
122 + public StatusMessageSinc getStatusMessageSinc() {
145 123 StatusMessageSinc zMessageSinc = ClientContext.get().checkGet( StatusMessageSinc.class );
146 - if ( zMessageSinc != null )
147 - {
124 + if ( zMessageSinc != null ) {
148 125 return zMessageSinc;
149 126 }
150 127 return null; // todo... Dialog
151 128 }
152 129
153 - public Widget augmentView( Widget pTopBar, Widget pAboveBottomBar )
154 - {
130 + public Widget augmentView( Widget pTopBar, Widget pAboveBottomBar ) {
155 131 Widget zViewWidget = getContent();
156 132 Widget zBottomBar = getBottomBar();
157 133 ISizeableWidget zSizeable = (zViewWidget instanceof ISizeableWidget) ? (ISizeableWidget) zViewWidget : ISizeableWidget.NULL;
158 - if ( !zSizeable.getHeightHelper().isStretchable() || (pTopBar != null) || (pAboveBottomBar != null) || (zBottomBar != null) )
159 - {
134 + if ( !zSizeable.getHeightHelper().isStretchable() || (pTopBar != null) || (pAboveBottomBar != null) || (zBottomBar != null) ) {
160 135 SizeableVerticalPanel zNewScreen = new SizeableVerticalPanel().stretchableVertically();
161 - if ( zSizeable.getWidthHelper().isStretchable() )
162 - {
136 + if ( zSizeable.getWidthHelper().isStretchable() ) {
163 137 zNewScreen.stretchableHorizontally();
164 138 }
165 - if ( pTopBar != null )
166 - {
139 + if ( pTopBar != null ) {
167 140 zNewScreen.add( pTopBar );
168 141 }
169 142 zNewScreen.add( zViewWidget );
170 - if ( !zSizeable.getHeightHelper().isStretchable() )
171 - {
143 + if ( !zSizeable.getHeightHelper().isStretchable() ) {
172 144 zNewScreen.add( new SizeableSpacer().stretchableVertically() );
173 145 }
174 - if ( pAboveBottomBar != null )
175 - {
146 + if ( pAboveBottomBar != null ) {
176 147 zNewScreen.add( pAboveBottomBar );
177 148 }
178 - if ( zBottomBar != null )
179 - {
149 + if ( zBottomBar != null ) {
180 150 zNewScreen.add( zBottomBar );
181 151 }
182 152 zViewWidget = zNewScreen;
  @@ -186,59 +156,50 @@
186 156 return zViewWidget;
187 157 }
188 158
189 - protected ButtonBase createRevertButton()
190 - {
159 + protected ButtonBase createRevertButton() {
191 160 return RevertButton.factory().create();
192 161 }
193 162
194 - protected <T extends IViewObject<T>> ButtonBase createSubmitButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, ViewUpdatable<T> pViewUpdatable )
195 - {
163 + protected <T extends IViewObject<T>> ButtonBase createSubmitButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder,
164 + ViewUpdatable<T> pViewUpdatable ) {
196 165 Objects.assertNotNull( "ViewUpdatable", pViewUpdatable );
197 166 return SubmitButton.factory().add( createCommitClickHandler( pDataProvider, pFormBinder, null, pViewUpdatable ) ).create();
198 167 }
199 168
200 - protected <T extends IViewObject<T>> ButtonBase createSubmitButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, ViewDef pNavigateToOnSuccess )
201 - {
169 + protected <T extends IViewObject<T>> ButtonBase createSubmitButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder,
170 + ViewDef pNavigateToOnSuccess ) {
202 171 Objects.assertNotNull( "NavigateToOnSuccess", pNavigateToOnSuccess );
203 172 return Button.named( "SaveClose" ).green().text( "Save & Close" ) //
204 173 .enabledToolTip( SubmitButton.TOOL_TIP + " and then close" ) //
205 174 .add( createCommitClickHandler( pDataProvider, pFormBinder, pNavigateToOnSuccess, null ) ).create();
206 175 }
207 176
208 - protected <T extends IViewObject<T>> ButtonBase createSubmitNextButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, ViewDef pNavigateToOnSuccess )
209 - {
177 + protected <T extends IViewObject<T>> ButtonBase createSubmitNextButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder,
178 + ViewDef pNavigateToOnSuccess ) {
210 179 return NextButton.justButtonFactory( pNavigateToOnSuccess ). //
211 180 add( createCommitClickHandler( pDataProvider, pFormBinder, pNavigateToOnSuccess, null ) ).create();
212 181 }
213 182
214 - private <T extends IViewObject<T>> ClickHandler createCommitClickHandler( final VoDataProvider<T> pDataProvider, final FormBinder<T> pFormBinder, final ViewDef pNavigateToOnSuccess, final ViewUpdatable<T> pViewUpdatable )
215 - {
216 - return new ClickHandler()
217 - {
183 + private <T extends IViewObject<T>> ClickHandler createCommitClickHandler( final VoDataProvider<T> pDataProvider, final FormBinder<T> pFormBinder,
184 + final ViewDef pNavigateToOnSuccess, final ViewUpdatable<T> pViewUpdatable ) {
185 + return new ClickHandler() {
218 186 @Override
219 - public void onClick( ClickEvent event )
220 - {
187 + public void onClick( ClickEvent event ) {
221 188 pFormBinder.commitForm();
222 189 T zVO = pFormBinder.getObject();
223 - pDataProvider.commit( zVO, new CommitCallBack<T>()
224 - {
190 + pDataProvider.commit( zVO, new CommitCallBack<T>() {
225 191 @Override
226 - public void success( ImmutableArrayList<T> pRows )
227 - {
192 + public void success( ImmutableArrayList<T> pRows ) {
228 193 T zVO = pRows.get( 0 ); // Updated VO
229 - if ( pNavigateToOnSuccess != null )
230 - {
194 + if ( pNavigateToOnSuccess != null ) {
231 195 new ShowScreenCommand( pNavigateToOnSuccess ).execute();
232 - }
233 - else
234 - {
196 + } else {
235 197 pViewUpdatable.viewUpdated( zVO );
236 198 }
237 199 }
238 200
239 201 @Override
240 - public void error( String pError )
241 - {
202 + public void error( String pError ) {
242 203 AlertManager.alert( this.getClass().getName(), "Submit Failed", pError );
243 204 }
244 205 } );
  @@ -246,15 +207,11 @@
246 207 };
247 208 }
248 209
249 - protected void systemError( String pTitle, String... pLines )
250 - {
210 + protected void systemError( String pTitle, String... pLines ) {
251 211 StringBuilder sb = new StringBuilder();
252 - if ( pLines != null )
253 - {
254 - for ( String zLine : pLines )
255 - {
256 - if ( zLine != null )
257 - {
212 + if ( pLines != null ) {
213 + for ( String zLine : pLines ) {
214 + if ( zLine != null ) {
258 215 sb.append( zLine ).append( "<br>" );
259 216 }
260 217 }
  @@ -265,145 +222,116 @@
265 222 LOGGER.error.log( zBody );
266 223 }
267 224
268 - protected boolean disabled( IFormComponent pComponent, Boolean pEnable )
269 - {
270 - if ( pEnable != null )
271 - {
225 + protected boolean disabled( IFormComponent pComponent, Boolean pEnable ) {
226 + if ( pEnable != null ) {
272 227 pComponent.setEnabled( pEnable );
273 228 }
274 - if ( !pComponent.isEnabled() )
275 - {
229 + if ( !pComponent.isEnabled() ) {
276 230 pComponent.setError( null );
277 231 return true;
278 232 }
279 233 return false;
280 234 }
281 235
282 - protected String stringify( Object pObject )
283 - {
236 + protected String stringify( Object pObject ) {
284 237 return (pObject != null) ? pObject.toString() : null;
285 238 }
286 239
287 - protected FormWidgetCtrl userViewable( boolean pFlag )
288 - {
240 + protected FormWidgetCtrl userViewable( boolean pFlag ) {
289 241 return pFlag ? VISIBLE_BUT_DISABLED : HIDDEN;
290 242 }
291 243
292 - protected FormWidgetCtrl userEditable( boolean pFlag )
293 - {
244 + protected FormWidgetCtrl userEditable( boolean pFlag ) {
294 245 return pFlag ? EDIT_ONLY : HIDDEN;
295 246 }
296 247
297 - protected ClickHandler todoClickHandler( final String pTitle )
298 - {
299 - return new ClickHandler()
300 - {
248 + protected ClickHandler todoClickHandler( final String pTitle ) {
249 + return new ClickHandler() {
301 250 @Override
302 - public void onClick( ClickEvent event )
303 - {
251 + public void onClick( ClickEvent event ) {
304 252 todo( pTitle );
305 253 }
306 254 };
307 255 }
308 256
309 - protected void todo( String pTitle )
310 - {
257 + protected void todo( String pTitle ) {
311 258 InfoManager.info( this.getClass().getName(), pTitle, pTitle + " Not Implimented Yet" );
312 259 }
313 260
314 - private static CO deNull( CO pCO )
315 - {
261 + private static CO deNull( CO pCO ) {
316 262 return (pCO != null) ? pCO : new CO();
317 263 }
318 264
319 - protected static CO title( String pTitle )
320 - {
265 + protected static CO title( String pTitle ) {
321 266 return new CO().title( pTitle );
322 267 }
323 268
324 - protected static CO title( String pSection, String pSubTitle )
325 - {
269 + protected static CO title( String pSection, String pSubTitle ) {
326 270 return new CO().title( pSection, pSubTitle );
327 271 }
328 272
329 - protected static CO title( String pSection, ViewDef pViewDef )
330 - {
273 + protected static CO title( String pSection, ViewDef pViewDef ) {
331 274 return new CO().title( pSection, pViewDef );
332 275 }
333 276
334 - protected static CO title( ViewDef pViewDef )
335 - {
277 + protected static CO title( ViewDef pViewDef ) {
336 278 return new CO().title( pViewDef );
337 279 }
338 280
339 - protected static CO set( ViewDef pViewDef )
340 - {
281 + protected static CO set( ViewDef pViewDef ) {
341 282 return new CO().set( pViewDef );
342 283 }
343 284
344 - protected static CO set( CO pCO, ViewDef pViewDef )
345 - {
285 + protected static CO set( CO pCO, ViewDef pViewDef ) {
346 286 return deNull( pCO ).set( pViewDef );
347 287 }
348 288
349 - protected static CO title( CO pCO, ViewDef pViewDef )
350 - {
289 + protected static CO title( CO pCO, ViewDef pViewDef ) {
351 290 return deNull( pCO ).title( pViewDef );
352 291 }
353 292
354 - protected static CO title( CO pCO, String pSection, ViewDef pViewDef )
355 - {
293 + protected static CO title( CO pCO, String pSection, ViewDef pViewDef ) {
356 294 return deNull( pCO ).title( pSection, pViewDef );
357 295 }
358 296
359 - protected static CO title( CO pCO, String pSection, String pSubTitle )
360 - {
297 + protected static CO title( CO pCO, String pSection, String pSubTitle ) {
361 298 return deNull( pCO ).title( pSection, pSubTitle );
362 299 }
363 300
364 - protected static CO title( CO pCO, String pTitle )
365 - {
301 + protected static CO title( CO pCO, String pTitle ) {
366 302 return deNull( pCO ).title( pTitle );
367 303 }
368 304
369 - public static class CO
370 - {
305 + public static class CO {
371 306 private ViewDef mViewDef;
372 307 private String mTitle;
373 308
374 - private CO()
375 - {
309 + private CO() {
376 310 }
377 311
378 - public CO set( ViewDef pViewDef )
379 - {
312 + public CO set( ViewDef pViewDef ) {
380 313 mViewDef = pViewDef;
381 314 return this;
382 315 }
383 316
384 - public CO title( String pTitle )
385 - {
317 + public CO title( String pTitle ) {
386 318 mTitle = Strings.assertNotNullNotEmpty( "Title", pTitle );
387 319 return this;
388 320 }
389 321
390 - public CO title( ViewDef pViewDef )
391 - {
322 + public CO title( ViewDef pViewDef ) {
392 323 return title( (mViewDef = pViewDef).getUiString() );
393 324 }
394 325
395 - public CO title( String pSection, ViewDef pViewDef )
396 - {
326 + public CO title( String pSection, ViewDef pViewDef ) {
397 327 return title( formatSection( pSection ) + (mViewDef = pViewDef) );
398 328 }
399 329
400 - public CO title( String pSection, String pSubTitle )
401 - {
330 + public CO title( String pSection, String pSubTitle ) {
402 331 return title( formatSection( pSection ) + pSubTitle );
403 332 }
404 333
405 - private String formatSection( String pSection )
406 - {
334 + private String formatSection( String pSection ) {
407 335 return (pSection == null) ? "" : pSection + ": ";
408 336 }
409 337 }