|
@@ -1,338 +1,338 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.view; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.*; |
5 |
|
- |
import org.litesoft.GWT.client.command.*; |
6 |
|
- |
import org.litesoft.GWT.client.widgets.Button; |
7 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
8 |
|
- |
import org.litesoft.GWT.client.widgets.SubmitButton; |
9 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
10 |
|
- |
import org.litesoft.GWT.forms.client.*; |
11 |
|
- |
import org.litesoft.GWT.forms.client.components.*; |
12 |
|
- |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
13 |
|
- |
import org.litesoft.bo.views.*; |
14 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
15 |
|
- |
import org.litesoft.core.*; |
16 |
|
- |
import org.litesoft.core.util.*; |
17 |
|
- |
import org.litesoft.logger.*; |
18 |
|
- |
import org.litesoft.uispecification.*; |
19 |
|
- |
|
20 |
|
- |
import com.google.gwt.core.client.*; |
21 |
|
- |
import com.google.gwt.event.dom.client.*; |
22 |
|
- |
import com.google.gwt.user.client.ui.*; |
23 |
|
- |
|
24 |
|
- |
import static org.litesoft.uispecification.FormWidgetCtrl.*; |
25 |
|
- |
|
26 |
|
- |
public abstract class UiView implements ViewErrorSupport { |
27 |
|
- |
public static final Logger LOGGER = LoggerFactory.getLogger( UiView.class ); |
28 |
|
- |
|
29 |
|
- |
protected ViewDef mViewDef = null; |
30 |
|
- |
protected String mTitle = null; |
31 |
|
- |
|
32 |
|
- |
protected SizeableVerticalPanel mContent = new SizeableVerticalPanel() { |
33 |
|
- |
@Override |
34 |
|
- |
protected void onLoad() { |
35 |
|
- |
super.onLoad(); |
36 |
|
- |
justLoaded(); |
37 |
|
- |
} |
38 |
|
- |
|
39 |
|
- |
@Override |
40 |
|
- |
protected void onUnload() { |
41 |
|
- |
super.onUnload(); |
42 |
|
- |
justUnloaded(); |
43 |
|
- |
} |
44 |
|
- |
}.stretchable().style( "Content" ); |
45 |
|
- |
|
46 |
|
- |
protected void justLoaded() { |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
protected void justUnloaded() { |
50 |
|
- |
|
51 |
|
- |
} |
52 |
|
- |
|
53 |
|
- |
protected UiView( CO pCO ) { |
54 |
|
- |
pCO = deNull( pCO ); |
55 |
|
- |
mViewDef = pCO.mViewDef; |
56 |
|
- |
mTitle = pCO.mTitle; |
57 |
|
- |
} |
58 |
|
- |
|
59 |
|
- |
public final boolean hasViewTitle() { |
60 |
|
- |
return (mTitle != null); |
61 |
|
- |
} |
62 |
|
- |
|
63 |
|
- |
public final String getViewTitle() { |
64 |
|
- |
return hasViewTitle() ? mTitle : "No Title"; |
65 |
|
- |
} |
66 |
|
- |
|
67 |
|
- |
public void aboutToShow() { |
68 |
|
- |
} |
69 |
|
- |
|
70 |
|
- |
protected final void setViewTitle( String pTitle ) { |
71 |
|
- |
mTitle = Strings.assertNotNullNotEmpty( "Title", pTitle ); |
72 |
|
- |
} |
73 |
|
- |
|
74 |
|
- |
abstract public Widget getContent(); |
75 |
|
- |
|
76 |
|
- |
public Widget getBottomBar() { |
77 |
|
- |
return null; |
78 |
|
- |
} |
79 |
|
- |
|
80 |
|
- |
protected CenterHorizontalPanel createSectionTitle( String pText ) { |
81 |
|
- |
return createSectionTitle( new OurLabel( pText ) ); |
82 |
|
- |
} |
83 |
|
- |
|
84 |
|
- |
protected CenterHorizontalPanel createSectionTitle( OurLabel pLabel ) { |
85 |
|
- |
return new CenterHorizontalPanel().add( pLabel ).style( "SectionTitle" ); |
86 |
|
- |
} |
87 |
|
- |
|
88 |
|
- |
protected LeftCenterRightHorizontalPanel createSectionTitle( OurLabel pLabel, Widget pRightWidget ) { |
89 |
|
- |
LeftCenterRightHorizontalPanel zPanel = new LeftCenterRightHorizontalPanel().style( "SectionTitle" ); |
90 |
|
- |
zPanel.addCenter( pLabel ); |
91 |
|
- |
zPanel.addRight( pRightWidget ); |
92 |
|
- |
return zPanel; |
93 |
|
- |
} |
94 |
|
- |
|
95 |
|
- |
protected static OurLabel createFormLabel( String pText ) { |
96 |
|
- |
return new OurLabel( pText + ": " ).style( AbstractFormElement.FORM_COMPONENT_LABEL_LEFT_STYLE ); |
97 |
|
- |
} |
98 |
|
- |
|
99 |
|
- |
protected Widget disable( Enableable pComponent ) { |
100 |
|
- |
return enabled( false, pComponent ); |
101 |
|
- |
} |
102 |
|
- |
|
103 |
|
- |
protected Widget enabled( boolean pEnabled, Enableable pComponent ) { |
104 |
|
- |
pComponent.setEnabled( pEnabled ); |
105 |
|
- |
return (Widget) pComponent; |
106 |
|
- |
} |
107 |
|
- |
|
108 |
|
- |
public void error( String pError ) { |
109 |
|
- |
backToHome( pError ); |
110 |
|
- |
} |
111 |
|
- |
|
112 |
|
- |
@Override |
113 |
|
- |
public final void backToHome( String pError ) { |
114 |
|
- |
backTo( ViewDef.HOME, pError ); |
115 |
|
- |
} |
116 |
|
- |
|
117 |
|
- |
protected final void backTo( ViewDef pViewDef, String pError ) { |
118 |
|
- |
Scheduler.get().scheduleDeferred( new ShowScreenCommand( pViewDef, pError ) ); |
119 |
|
- |
} |
120 |
|
- |
|
121 |
|
- |
@Override |
122 |
|
- |
public StatusMessageSinc getStatusMessageSinc() { |
123 |
|
- |
StatusMessageSinc zMessageSinc = ClientContext.get().checkGet( StatusMessageSinc.class ); |
124 |
|
- |
if ( zMessageSinc != null ) { |
125 |
|
- |
return zMessageSinc; |
126 |
|
- |
} |
127 |
|
- |
return null; // todo... Dialog |
128 |
|
- |
} |
129 |
|
- |
|
130 |
|
- |
public Widget augmentView( Widget pTopBar, Widget pAboveBottomBar ) { |
131 |
|
- |
Widget zViewWidget = getContent(); |
132 |
|
- |
Widget zBottomBar = getBottomBar(); |
133 |
|
- |
ISizeableWidget zSizeable = (zViewWidget instanceof ISizeableWidget) ? (ISizeableWidget) zViewWidget : ISizeableWidget.NULL; |
134 |
|
- |
if ( !zSizeable.getHeightHelper().isStretchable() || (pTopBar != null) || (pAboveBottomBar != null) || (zBottomBar != null) ) { |
135 |
|
- |
SizeableVerticalPanel zNewScreen = new SizeableVerticalPanel().stretchableVertically(); |
136 |
|
- |
if ( zSizeable.getWidthHelper().isStretchable() ) { |
137 |
|
- |
zNewScreen.stretchableHorizontally(); |
138 |
|
- |
} |
139 |
|
- |
if ( pTopBar != null ) { |
140 |
|
- |
zNewScreen.add( pTopBar ); |
141 |
|
- |
} |
142 |
|
- |
zNewScreen.add( zViewWidget ); |
143 |
|
- |
if ( !zSizeable.getHeightHelper().isStretchable() ) { |
144 |
|
- |
zNewScreen.add( new SizeableSpacer().stretchableVertically() ); |
145 |
|
- |
} |
146 |
|
- |
if ( pAboveBottomBar != null ) { |
147 |
|
- |
zNewScreen.add( pAboveBottomBar ); |
148 |
|
- |
} |
149 |
|
- |
if ( zBottomBar != null ) { |
150 |
|
- |
zNewScreen.add( zBottomBar ); |
151 |
|
- |
} |
152 |
|
- |
zViewWidget = zNewScreen; |
153 |
|
- |
} |
154 |
|
- |
aboutToShow(); |
155 |
|
- |
UtilsGwt.regularCursor(); |
156 |
|
- |
return zViewWidget; |
157 |
|
- |
} |
158 |
|
- |
|
159 |
|
- |
protected ButtonBase createRevertButton() { |
160 |
|
- |
return RevertButton.factory().create(); |
161 |
|
- |
} |
162 |
|
- |
|
163 |
|
- |
protected <T extends IViewObject<T>> ButtonBase createSubmitButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, |
164 |
|
- |
ViewUpdatable<T> pViewUpdatable ) { |
165 |
|
- |
Objects.assertNotNull( "ViewUpdatable", pViewUpdatable ); |
166 |
|
- |
return SubmitButton.factory().add( createCommitClickHandler( pDataProvider, pFormBinder, null, pViewUpdatable ) ).create(); |
167 |
|
- |
} |
168 |
|
- |
|
169 |
|
- |
protected <T extends IViewObject<T>> ButtonBase createSubmitButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, |
170 |
|
- |
ViewDef pNavigateToOnSuccess ) { |
171 |
|
- |
Objects.assertNotNull( "NavigateToOnSuccess", pNavigateToOnSuccess ); |
172 |
|
- |
return Button.named( "SaveClose" ).green().text( "Save & Close" ) // |
173 |
|
- |
.enabledToolTip( SubmitButton.TOOL_TIP + " and then close" ) // |
174 |
|
- |
.add( createCommitClickHandler( pDataProvider, pFormBinder, pNavigateToOnSuccess, null ) ).create(); |
175 |
|
- |
} |
176 |
|
- |
|
177 |
|
- |
protected <T extends IViewObject<T>> ButtonBase createSubmitNextButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, |
178 |
|
- |
ViewDef pNavigateToOnSuccess ) { |
179 |
|
- |
return NextButton.justButtonFactory( pNavigateToOnSuccess ). // |
180 |
|
- |
add( createCommitClickHandler( pDataProvider, pFormBinder, pNavigateToOnSuccess, null ) ).create(); |
181 |
|
- |
} |
182 |
|
- |
|
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() { |
186 |
|
- |
@Override |
187 |
|
- |
public void onClick( ClickEvent event ) { |
188 |
|
- |
pFormBinder.commitForm(); |
189 |
|
- |
T zVO = pFormBinder.getObject(); |
190 |
|
- |
pDataProvider.commit( zVO, new CommitCallBack<T>() { |
191 |
|
- |
@Override |
192 |
|
- |
public void success( ImmutableArrayList<T> pRows ) { |
193 |
|
- |
T zVO = pRows.get( 0 ); // Updated VO |
194 |
|
- |
if ( pNavigateToOnSuccess != null ) { |
195 |
|
- |
new ShowScreenCommand( pNavigateToOnSuccess ).execute(); |
196 |
|
- |
} else { |
197 |
|
- |
pViewUpdatable.viewUpdated( zVO ); |
198 |
|
- |
} |
199 |
|
- |
} |
200 |
|
- |
|
201 |
|
- |
@Override |
202 |
|
- |
public void error( String pError ) { |
203 |
|
- |
AlertManager.alert( this.getClass().getName(), "Submit Failed", pError ); |
204 |
|
- |
} |
205 |
|
- |
} ); |
206 |
|
- |
} |
207 |
|
- |
}; |
208 |
|
- |
} |
209 |
|
- |
|
210 |
|
- |
protected void systemError( String pTitle, String... pLines ) { |
211 |
|
- |
StringBuilder sb = new StringBuilder(); |
212 |
|
- |
if ( pLines != null ) { |
213 |
|
- |
for ( String zLine : pLines ) { |
214 |
|
- |
if ( zLine != null ) { |
215 |
|
- |
sb.append( zLine ).append( "<br>" ); |
216 |
|
- |
} |
217 |
|
- |
} |
218 |
|
- |
} |
219 |
|
- |
sb.append( "<br>This should not happen! Please notify the Helpdesk." ); |
220 |
|
- |
String zBody = sb.toString(); |
221 |
|
- |
AlertManager.alert( this.getClass().getName(), pTitle, zBody ); |
222 |
|
- |
LOGGER.error.log( zBody ); |
223 |
|
- |
} |
224 |
|
- |
|
225 |
|
- |
protected boolean disabled( IFormComponent pComponent, Boolean pEnable ) { |
226 |
|
- |
if ( pEnable != null ) { |
227 |
|
- |
pComponent.setEnabled( pEnable ); |
228 |
|
- |
} |
229 |
|
- |
if ( !pComponent.isEnabled() ) { |
230 |
|
- |
pComponent.setError( null ); |
231 |
|
- |
return true; |
232 |
|
- |
} |
233 |
|
- |
return false; |
234 |
|
- |
} |
235 |
|
- |
|
236 |
|
- |
protected String stringify( Object pObject ) { |
237 |
|
- |
return (pObject != null) ? pObject.toString() : null; |
238 |
|
- |
} |
239 |
|
- |
|
240 |
|
- |
protected FormWidgetCtrl userViewable( boolean pFlag ) { |
241 |
|
- |
return pFlag ? VISIBLE_BUT_DISABLED : HIDDEN; |
242 |
|
- |
} |
243 |
|
- |
|
244 |
|
- |
protected FormWidgetCtrl userEditable( boolean pFlag ) { |
245 |
|
- |
return pFlag ? EDIT_ONLY : HIDDEN; |
246 |
|
- |
} |
247 |
|
- |
|
248 |
|
- |
protected ClickHandler todoClickHandler( final String pTitle ) { |
249 |
|
- |
return new ClickHandler() { |
250 |
|
- |
@Override |
251 |
|
- |
public void onClick( ClickEvent event ) { |
252 |
|
- |
todo( pTitle ); |
253 |
|
- |
} |
254 |
|
- |
}; |
255 |
|
- |
} |
256 |
|
- |
|
257 |
|
- |
protected void todo( String pTitle ) { |
258 |
|
- |
InfoManager.info( this.getClass().getName(), pTitle, pTitle + " Not Implimented Yet" ); |
259 |
|
- |
} |
260 |
|
- |
|
261 |
|
- |
private static CO deNull( CO pCO ) { |
262 |
|
- |
return (pCO != null) ? pCO : new CO(); |
263 |
|
- |
} |
264 |
|
- |
|
265 |
|
- |
protected static CO title( String pTitle ) { |
266 |
|
- |
return new CO().title( pTitle ); |
267 |
|
- |
} |
268 |
|
- |
|
269 |
|
- |
protected static CO title( String pSection, String pSubTitle ) { |
270 |
|
- |
return new CO().title( pSection, pSubTitle ); |
271 |
|
- |
} |
272 |
|
- |
|
273 |
|
- |
protected static CO title( String pSection, ViewDef pViewDef ) { |
274 |
|
- |
return new CO().title( pSection, pViewDef ); |
275 |
|
- |
} |
276 |
|
- |
|
277 |
|
- |
protected static CO title( ViewDef pViewDef ) { |
278 |
|
- |
return new CO().title( pViewDef ); |
279 |
|
- |
} |
280 |
|
- |
|
281 |
|
- |
protected static CO set( ViewDef pViewDef ) { |
282 |
|
- |
return new CO().set( pViewDef ); |
283 |
|
- |
} |
284 |
|
- |
|
285 |
|
- |
protected static CO set( CO pCO, ViewDef pViewDef ) { |
286 |
|
- |
return deNull( pCO ).set( pViewDef ); |
287 |
|
- |
} |
288 |
|
- |
|
289 |
|
- |
protected static CO title( CO pCO, ViewDef pViewDef ) { |
290 |
|
- |
return deNull( pCO ).title( pViewDef ); |
291 |
|
- |
} |
292 |
|
- |
|
293 |
|
- |
protected static CO title( CO pCO, String pSection, ViewDef pViewDef ) { |
294 |
|
- |
return deNull( pCO ).title( pSection, pViewDef ); |
295 |
|
- |
} |
296 |
|
- |
|
297 |
|
- |
protected static CO title( CO pCO, String pSection, String pSubTitle ) { |
298 |
|
- |
return deNull( pCO ).title( pSection, pSubTitle ); |
299 |
|
- |
} |
300 |
|
- |
|
301 |
|
- |
protected static CO title( CO pCO, String pTitle ) { |
302 |
|
- |
return deNull( pCO ).title( pTitle ); |
303 |
|
- |
} |
304 |
|
- |
|
305 |
|
- |
public static class CO { |
306 |
|
- |
private ViewDef mViewDef; |
307 |
|
- |
private String mTitle; |
308 |
|
- |
|
309 |
|
- |
private CO() { |
310 |
|
- |
} |
311 |
|
- |
|
312 |
|
- |
public CO set( ViewDef pViewDef ) { |
313 |
|
- |
mViewDef = pViewDef; |
314 |
|
- |
return this; |
315 |
|
- |
} |
316 |
|
- |
|
317 |
|
- |
public CO title( String pTitle ) { |
318 |
|
- |
mTitle = Strings.assertNotNullNotEmpty( "Title", pTitle ); |
319 |
|
- |
return this; |
320 |
|
- |
} |
321 |
|
- |
|
322 |
|
- |
public CO title( ViewDef pViewDef ) { |
323 |
|
- |
return title( (mViewDef = pViewDef).getUiString() ); |
324 |
|
- |
} |
325 |
|
- |
|
326 |
|
- |
public CO title( String pSection, ViewDef pViewDef ) { |
327 |
|
- |
return title( formatSection( pSection ) + (mViewDef = pViewDef) ); |
328 |
|
- |
} |
329 |
|
- |
|
330 |
|
- |
public CO title( String pSection, String pSubTitle ) { |
331 |
|
- |
return title( formatSection( pSection ) + pSubTitle ); |
332 |
|
- |
} |
333 |
|
- |
|
334 |
|
- |
private String formatSection( String pSection ) { |
335 |
|
- |
return (pSection == null) ? "" : pSection + ": "; |
336 |
|
- |
} |
337 |
|
- |
} |
338 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.view; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.*; |
|
5 |
+ |
import org.litesoft.GWT.client.command.*; |
|
6 |
+ |
import org.litesoft.GWT.client.widgets.Button; |
|
7 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
8 |
+ |
import org.litesoft.GWT.client.widgets.SubmitButton; |
|
9 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
10 |
+ |
import org.litesoft.GWT.forms.client.*; |
|
11 |
+ |
import org.litesoft.GWT.forms.client.components.*; |
|
12 |
+ |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
|
13 |
+ |
import org.litesoft.bo.views.*; |
|
14 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
15 |
+ |
import org.litesoft.core.*; |
|
16 |
+ |
import org.litesoft.core.util.*; |
|
17 |
+ |
import org.litesoft.logger.*; |
|
18 |
+ |
import org.litesoft.uispecification.*; |
|
19 |
+ |
|
|
20 |
+ |
import com.google.gwt.core.client.*; |
|
21 |
+ |
import com.google.gwt.event.dom.client.*; |
|
22 |
+ |
import com.google.gwt.user.client.ui.*; |
|
23 |
+ |
|
|
24 |
+ |
import static org.litesoft.uispecification.FormWidgetCtrl.*; |
|
25 |
+ |
|
|
26 |
+ |
public abstract class UiView implements ViewErrorSupport { |
|
27 |
+ |
public static final Logger LOGGER = LoggerFactory.getLogger( UiView.class ); |
|
28 |
+ |
|
|
29 |
+ |
protected ViewDef mViewDef = null; |
|
30 |
+ |
protected String mTitle = null; |
|
31 |
+ |
|
|
32 |
+ |
protected SizeableVerticalPanel mContent = new SizeableVerticalPanel() { |
|
33 |
+ |
@Override |
|
34 |
+ |
protected void onLoad() { |
|
35 |
+ |
super.onLoad(); |
|
36 |
+ |
justLoaded(); |
|
37 |
+ |
} |
|
38 |
+ |
|
|
39 |
+ |
@Override |
|
40 |
+ |
protected void onUnload() { |
|
41 |
+ |
super.onUnload(); |
|
42 |
+ |
justUnloaded(); |
|
43 |
+ |
} |
|
44 |
+ |
}.stretchable().style( "Content" ); |
|
45 |
+ |
|
|
46 |
+ |
protected void justLoaded() { |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
protected void justUnloaded() { |
|
50 |
+ |
|
|
51 |
+ |
} |
|
52 |
+ |
|
|
53 |
+ |
protected UiView( CO pCO ) { |
|
54 |
+ |
pCO = deNull( pCO ); |
|
55 |
+ |
mViewDef = pCO.mViewDef; |
|
56 |
+ |
mTitle = pCO.mTitle; |
|
57 |
+ |
} |
|
58 |
+ |
|
|
59 |
+ |
public final boolean hasViewTitle() { |
|
60 |
+ |
return (mTitle != null); |
|
61 |
+ |
} |
|
62 |
+ |
|
|
63 |
+ |
public final String getViewTitle() { |
|
64 |
+ |
return hasViewTitle() ? mTitle : "No Title"; |
|
65 |
+ |
} |
|
66 |
+ |
|
|
67 |
+ |
public void aboutToShow() { |
|
68 |
+ |
} |
|
69 |
+ |
|
|
70 |
+ |
protected final void setViewTitle( String pTitle ) { |
|
71 |
+ |
mTitle = Confirm.significant( "Title", pTitle ); |
|
72 |
+ |
} |
|
73 |
+ |
|
|
74 |
+ |
abstract public Widget getContent(); |
|
75 |
+ |
|
|
76 |
+ |
public Widget getBottomBar() { |
|
77 |
+ |
return null; |
|
78 |
+ |
} |
|
79 |
+ |
|
|
80 |
+ |
protected CenterHorizontalPanel createSectionTitle( String pText ) { |
|
81 |
+ |
return createSectionTitle( new OurLabel( pText ) ); |
|
82 |
+ |
} |
|
83 |
+ |
|
|
84 |
+ |
protected CenterHorizontalPanel createSectionTitle( OurLabel pLabel ) { |
|
85 |
+ |
return new CenterHorizontalPanel().add( pLabel ).style( "SectionTitle" ); |
|
86 |
+ |
} |
|
87 |
+ |
|
|
88 |
+ |
protected LeftCenterRightHorizontalPanel createSectionTitle( OurLabel pLabel, Widget pRightWidget ) { |
|
89 |
+ |
LeftCenterRightHorizontalPanel zPanel = new LeftCenterRightHorizontalPanel().style( "SectionTitle" ); |
|
90 |
+ |
zPanel.addCenter( pLabel ); |
|
91 |
+ |
zPanel.addRight( pRightWidget ); |
|
92 |
+ |
return zPanel; |
|
93 |
+ |
} |
|
94 |
+ |
|
|
95 |
+ |
protected static OurLabel createFormLabel( String pText ) { |
|
96 |
+ |
return new OurLabel( pText + ": " ).style( AbstractFormElement.FORM_COMPONENT_LABEL_LEFT_STYLE ); |
|
97 |
+ |
} |
|
98 |
+ |
|
|
99 |
+ |
protected Widget disable( Enableable pComponent ) { |
|
100 |
+ |
return enabled( false, pComponent ); |
|
101 |
+ |
} |
|
102 |
+ |
|
|
103 |
+ |
protected Widget enabled( boolean pEnabled, Enableable pComponent ) { |
|
104 |
+ |
pComponent.setEnabled( pEnabled ); |
|
105 |
+ |
return (Widget) pComponent; |
|
106 |
+ |
} |
|
107 |
+ |
|
|
108 |
+ |
public void error( String pError ) { |
|
109 |
+ |
backToHome( pError ); |
|
110 |
+ |
} |
|
111 |
+ |
|
|
112 |
+ |
@Override |
|
113 |
+ |
public final void backToHome( String pError ) { |
|
114 |
+ |
backTo( ViewDef.HOME, pError ); |
|
115 |
+ |
} |
|
116 |
+ |
|
|
117 |
+ |
protected final void backTo( ViewDef pViewDef, String pError ) { |
|
118 |
+ |
Scheduler.get().scheduleDeferred( new ShowScreenCommand( pViewDef, pError ) ); |
|
119 |
+ |
} |
|
120 |
+ |
|
|
121 |
+ |
@Override |
|
122 |
+ |
public StatusMessageSinc getStatusMessageSinc() { |
|
123 |
+ |
StatusMessageSinc zMessageSinc = ClientContext.get().checkGet( StatusMessageSinc.class ); |
|
124 |
+ |
if ( zMessageSinc != null ) { |
|
125 |
+ |
return zMessageSinc; |
|
126 |
+ |
} |
|
127 |
+ |
return null; // todo... Dialog |
|
128 |
+ |
} |
|
129 |
+ |
|
|
130 |
+ |
public Widget augmentView( Widget pTopBar, Widget pAboveBottomBar ) { |
|
131 |
+ |
Widget zViewWidget = getContent(); |
|
132 |
+ |
Widget zBottomBar = getBottomBar(); |
|
133 |
+ |
ISizeableWidget zSizeable = (zViewWidget instanceof ISizeableWidget) ? (ISizeableWidget) zViewWidget : ISizeableWidget.NULL; |
|
134 |
+ |
if ( !zSizeable.getHeightHelper().isStretchable() || (pTopBar != null) || (pAboveBottomBar != null) || (zBottomBar != null) ) { |
|
135 |
+ |
SizeableVerticalPanel zNewScreen = new SizeableVerticalPanel().stretchableVertically(); |
|
136 |
+ |
if ( zSizeable.getWidthHelper().isStretchable() ) { |
|
137 |
+ |
zNewScreen.stretchableHorizontally(); |
|
138 |
+ |
} |
|
139 |
+ |
if ( pTopBar != null ) { |
|
140 |
+ |
zNewScreen.add( pTopBar ); |
|
141 |
+ |
} |
|
142 |
+ |
zNewScreen.add( zViewWidget ); |
|
143 |
+ |
if ( !zSizeable.getHeightHelper().isStretchable() ) { |
|
144 |
+ |
zNewScreen.add( new SizeableSpacer().stretchableVertically() ); |
|
145 |
+ |
} |
|
146 |
+ |
if ( pAboveBottomBar != null ) { |
|
147 |
+ |
zNewScreen.add( pAboveBottomBar ); |
|
148 |
+ |
} |
|
149 |
+ |
if ( zBottomBar != null ) { |
|
150 |
+ |
zNewScreen.add( zBottomBar ); |
|
151 |
+ |
} |
|
152 |
+ |
zViewWidget = zNewScreen; |
|
153 |
+ |
} |
|
154 |
+ |
aboutToShow(); |
|
155 |
+ |
UtilsGwt.regularCursor(); |
|
156 |
+ |
return zViewWidget; |
|
157 |
+ |
} |
|
158 |
+ |
|
|
159 |
+ |
protected ButtonBase createRevertButton() { |
|
160 |
+ |
return RevertButton.factory().create(); |
|
161 |
+ |
} |
|
162 |
+ |
|
|
163 |
+ |
protected <T extends IViewObject<T>> ButtonBase createSubmitButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, |
|
164 |
+ |
ViewUpdatable<T> pViewUpdatable ) { |
|
165 |
+ |
Confirm.isNotNull( "ViewUpdatable", pViewUpdatable ); |
|
166 |
+ |
return SubmitButton.factory().add( createCommitClickHandler( pDataProvider, pFormBinder, null, pViewUpdatable ) ).create(); |
|
167 |
+ |
} |
|
168 |
+ |
|
|
169 |
+ |
protected <T extends IViewObject<T>> ButtonBase createSubmitButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, |
|
170 |
+ |
ViewDef pNavigateToOnSuccess ) { |
|
171 |
+ |
Confirm.isNotNull( "NavigateToOnSuccess", pNavigateToOnSuccess ); |
|
172 |
+ |
return Button.named( "SaveClose" ).green().text( "Save & Close" ) // |
|
173 |
+ |
.enabledToolTip( SubmitButton.TOOL_TIP + " and then close" ) // |
|
174 |
+ |
.add( createCommitClickHandler( pDataProvider, pFormBinder, pNavigateToOnSuccess, null ) ).create(); |
|
175 |
+ |
} |
|
176 |
+ |
|
|
177 |
+ |
protected <T extends IViewObject<T>> ButtonBase createSubmitNextButton( VoDataProvider<T> pDataProvider, FormBinder<T> pFormBinder, |
|
178 |
+ |
ViewDef pNavigateToOnSuccess ) { |
|
179 |
+ |
return NextButton.justButtonFactory( pNavigateToOnSuccess ). // |
|
180 |
+ |
add( createCommitClickHandler( pDataProvider, pFormBinder, pNavigateToOnSuccess, null ) ).create(); |
|
181 |
+ |
} |
|
182 |
+ |
|
|
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() { |
|
186 |
+ |
@Override |
|
187 |
+ |
public void onClick( ClickEvent event ) { |
|
188 |
+ |
pFormBinder.commitForm(); |
|
189 |
+ |
T zVO = pFormBinder.getObject(); |
|
190 |
+ |
pDataProvider.commit( zVO, new CommitCallBack<T>() { |
|
191 |
+ |
@Override |
|
192 |
+ |
public void success( ImmutableArrayList<T> pRows ) { |
|
193 |
+ |
T zVO = pRows.get( 0 ); // Updated VO |
|
194 |
+ |
if ( pNavigateToOnSuccess != null ) { |
|
195 |
+ |
new ShowScreenCommand( pNavigateToOnSuccess ).execute(); |
|
196 |
+ |
} else { |
|
197 |
+ |
pViewUpdatable.viewUpdated( zVO ); |
|
198 |
+ |
} |
|
199 |
+ |
} |
|
200 |
+ |
|
|
201 |
+ |
@Override |
|
202 |
+ |
public void error( String pError ) { |
|
203 |
+ |
AlertManager.alert( this.getClass().getName(), "Submit Failed", pError ); |
|
204 |
+ |
} |
|
205 |
+ |
} ); |
|
206 |
+ |
} |
|
207 |
+ |
}; |
|
208 |
+ |
} |
|
209 |
+ |
|
|
210 |
+ |
protected void systemError( String pTitle, String... pLines ) { |
|
211 |
+ |
StringBuilder sb = new StringBuilder(); |
|
212 |
+ |
if ( pLines != null ) { |
|
213 |
+ |
for ( String zLine : pLines ) { |
|
214 |
+ |
if ( zLine != null ) { |
|
215 |
+ |
sb.append( zLine ).append( "<br>" ); |
|
216 |
+ |
} |
|
217 |
+ |
} |
|
218 |
+ |
} |
|
219 |
+ |
sb.append( "<br>This should not happen! Please notify the Helpdesk." ); |
|
220 |
+ |
String zBody = sb.toString(); |
|
221 |
+ |
AlertManager.alert( this.getClass().getName(), pTitle, zBody ); |
|
222 |
+ |
LOGGER.error.log( zBody ); |
|
223 |
+ |
} |
|
224 |
+ |
|
|
225 |
+ |
protected boolean disabled( IFormComponent pComponent, Boolean pEnable ) { |
|
226 |
+ |
if ( pEnable != null ) { |
|
227 |
+ |
pComponent.setEnabled( pEnable ); |
|
228 |
+ |
} |
|
229 |
+ |
if ( !pComponent.isEnabled() ) { |
|
230 |
+ |
pComponent.setError( null ); |
|
231 |
+ |
return true; |
|
232 |
+ |
} |
|
233 |
+ |
return false; |
|
234 |
+ |
} |
|
235 |
+ |
|
|
236 |
+ |
protected String stringify( Object pObject ) { |
|
237 |
+ |
return (pObject != null) ? pObject.toString() : null; |
|
238 |
+ |
} |
|
239 |
+ |
|
|
240 |
+ |
protected FormWidgetCtrl userViewable( boolean pFlag ) { |
|
241 |
+ |
return pFlag ? VISIBLE_BUT_DISABLED : HIDDEN; |
|
242 |
+ |
} |
|
243 |
+ |
|
|
244 |
+ |
protected FormWidgetCtrl userEditable( boolean pFlag ) { |
|
245 |
+ |
return pFlag ? EDIT_ONLY : HIDDEN; |
|
246 |
+ |
} |
|
247 |
+ |
|
|
248 |
+ |
protected ClickHandler todoClickHandler( final String pTitle ) { |
|
249 |
+ |
return new ClickHandler() { |
|
250 |
+ |
@Override |
|
251 |
+ |
public void onClick( ClickEvent event ) { |
|
252 |
+ |
todo( pTitle ); |
|
253 |
+ |
} |
|
254 |
+ |
}; |
|
255 |
+ |
} |
|
256 |
+ |
|
|
257 |
+ |
protected void todo( String pTitle ) { |
|
258 |
+ |
InfoManager.info( this.getClass().getName(), pTitle, pTitle + " Not Implimented Yet" ); |
|
259 |
+ |
} |
|
260 |
+ |
|
|
261 |
+ |
private static CO deNull( CO pCO ) { |
|
262 |
+ |
return (pCO != null) ? pCO : new CO(); |
|
263 |
+ |
} |
|
264 |
+ |
|
|
265 |
+ |
protected static CO title( String pTitle ) { |
|
266 |
+ |
return new CO().title( pTitle ); |
|
267 |
+ |
} |
|
268 |
+ |
|
|
269 |
+ |
protected static CO title( String pSection, String pSubTitle ) { |
|
270 |
+ |
return new CO().title( pSection, pSubTitle ); |
|
271 |
+ |
} |
|
272 |
+ |
|
|
273 |
+ |
protected static CO title( String pSection, ViewDef pViewDef ) { |
|
274 |
+ |
return new CO().title( pSection, pViewDef ); |
|
275 |
+ |
} |
|
276 |
+ |
|
|
277 |
+ |
protected static CO title( ViewDef pViewDef ) { |
|
278 |
+ |
return new CO().title( pViewDef ); |
|
279 |
+ |
} |
|
280 |
+ |
|
|
281 |
+ |
protected static CO set( ViewDef pViewDef ) { |
|
282 |
+ |
return new CO().set( pViewDef ); |
|
283 |
+ |
} |
|
284 |
+ |
|
|
285 |
+ |
protected static CO set( CO pCO, ViewDef pViewDef ) { |
|
286 |
+ |
return deNull( pCO ).set( pViewDef ); |
|
287 |
+ |
} |
|
288 |
+ |
|
|
289 |
+ |
protected static CO title( CO pCO, ViewDef pViewDef ) { |
|
290 |
+ |
return deNull( pCO ).title( pViewDef ); |
|
291 |
+ |
} |
|
292 |
+ |
|
|
293 |
+ |
protected static CO title( CO pCO, String pSection, ViewDef pViewDef ) { |
|
294 |
+ |
return deNull( pCO ).title( pSection, pViewDef ); |
|
295 |
+ |
} |
|
296 |
+ |
|
|
297 |
+ |
protected static CO title( CO pCO, String pSection, String pSubTitle ) { |
|
298 |
+ |
return deNull( pCO ).title( pSection, pSubTitle ); |
|
299 |
+ |
} |
|
300 |
+ |
|
|
301 |
+ |
protected static CO title( CO pCO, String pTitle ) { |
|
302 |
+ |
return deNull( pCO ).title( pTitle ); |
|
303 |
+ |
} |
|
304 |
+ |
|
|
305 |
+ |
public static class CO { |
|
306 |
+ |
private ViewDef mViewDef; |
|
307 |
+ |
private String mTitle; |
|
308 |
+ |
|
|
309 |
+ |
private CO() { |
|
310 |
+ |
} |
|
311 |
+ |
|
|
312 |
+ |
public CO set( ViewDef pViewDef ) { |
|
313 |
+ |
mViewDef = pViewDef; |
|
314 |
+ |
return this; |
|
315 |
+ |
} |
|
316 |
+ |
|
|
317 |
+ |
public CO title( String pTitle ) { |
|
318 |
+ |
mTitle = Confirm.significant( "Title", pTitle ); |
|
319 |
+ |
return this; |
|
320 |
+ |
} |
|
321 |
+ |
|
|
322 |
+ |
public CO title( ViewDef pViewDef ) { |
|
323 |
+ |
return title( (mViewDef = pViewDef).getUiString() ); |
|
324 |
+ |
} |
|
325 |
+ |
|
|
326 |
+ |
public CO title( String pSection, ViewDef pViewDef ) { |
|
327 |
+ |
return title( formatSection( pSection ) + (mViewDef = pViewDef) ); |
|
328 |
+ |
} |
|
329 |
+ |
|
|
330 |
+ |
public CO title( String pSection, String pSubTitle ) { |
|
331 |
+ |
return title( formatSection( pSection ) + pSubTitle ); |
|
332 |
+ |
} |
|
333 |
+ |
|
|
334 |
+ |
private String formatSection( String pSection ) { |
|
335 |
+ |
return (pSection == null) ? "" : pSection + ": "; |
|
336 |
+ |
} |
|
337 |
+ |
} |
|
338 |
+ |
} |