Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/view/LoginDialogFactory.java

Diff revisions: vs.
  @@ -1,128 +1,128 @@
1 - package org.litesoft.GWT.client.view;
2 -
3 - import org.litesoft.GWT.client.*;
4 - import org.litesoft.GWT.client.context.*;
5 - import org.litesoft.GWT.client.widgets.*;
6 - import org.litesoft.GWT.forms.client.*;
7 - import org.litesoft.GWT.forms.client.components.*;
8 - import org.litesoft.bo.views.*;
9 - import org.litesoft.commonfoundation.typeutils.*;
10 - import org.litesoft.core.*;
11 - import org.litesoft.security.*;
12 -
13 - import com.google.gwt.core.client.*;
14 - import com.google.gwt.user.client.*;
15 - import com.google.gwt.user.client.ui.*;
16 -
17 - import static org.litesoft.uispecification.FormWidgetCtrl.*;
18 -
19 - public class LoginDialogFactory<T extends SecurityUserView<T>> implements LoginDialogViewFactory {
20 - @Override
21 - public DialogView createDialog( boolean pCancelable, Command pOnSuccess ) {
22 - return new LoginDialog<T>( pCancelable, pOnSuccess );
23 - }
24 -
25 - private static class LoginDialog<T extends SecurityUserView<T>> extends DialogView implements SecurityUserViewNames {
26 - private FormEngine mFE;
27 -
28 - private SecurityUserViewDataProvider<T> mDataProvider;
29 - private FormBinder<T> mFormBinder;
30 - private ButtonBase mSubmitButton;
31 -
32 - private boolean mCancelable;
33 - private Command mOnSuccess;
34 -
35 - public LoginDialog( boolean pCancelable, Command pOnSuccess ) {
36 - super( title( "Login" ), Opaqueness.Full );
37 - mCancelable = pCancelable;
38 - Objects.assertNotNull( "OnSuccess", mOnSuccess = pOnSuccess );
39 -
40 - ClientContext zContext = ClientContext.get();
41 -
42 - mDataProvider = zContext.get( SecurityUserViewDataProvider.class );
43 - SecurityUserViewMetaData<T> zUserViewMetaData = zContext.get( SecurityUserViewMetaData.class );
44 -
45 - WidgetCtrlMap zWidgetCtrlMap = new WidgetCtrlMap( VISIBLE_AND_ACTIVE_ENABLED );
46 -
47 - zWidgetCtrlMap.add( EDIT_ONLY.required(), aLogonEmail, aCurrentPassword );
48 -
49 - mFE = new FormEngine( zWidgetCtrlMap, FormEngine.Mode.EditRegular, null ) {
50 - @Override
51 - protected void changeOccurredOn( String pName, IFormComponent pComponent, boolean pChanged ) {
52 - super.changeOccurredOn( pName, pComponent, pChanged );
53 - setDialogErrorMessage( null );
54 - }
55 -
56 - @Override
57 - protected void enterPressedOn( String pName, IFormComponent pComponent, KeyboardKeyModifier pModifiers ) {
58 - if ( pName.equals( aLogonEmail ) ) {
59 - getNamedComponent( aCurrentPassword ).setFocus();
60 - } else if ( pName.equals( aCurrentPassword ) && (mSubmitButton != null) && mSubmitButton.isEnabled() ) {
61 - submitRequested();
62 - } else {
63 - super.enterPressedOn( pName, pComponent, pModifiers );
64 - }
65 - }
66 - };
67 - mFormBinder = new FormBinder<T>( mFE, zUserViewMetaData );
68 -
69 - mContent.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
70 -
71 - add( createLogonAndCurrentPassword() );
72 - add( new SizeableSpacer( 5 ).stretchable() );
73 -
74 - mFormBinder.setExistingObject( mDataProvider.createNew(), FormEngine.Mode.EditRegular );
75 - }
76 -
77 - @Override
78 - public boolean isCancelable() {
79 - return mCancelable;
80 - }
81 -
82 - private Widget createLogonAndCurrentPassword() {
83 - SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchableHorizontally();
84 - zPanel.add( mFormBinder.add( aLogonEmail, 0, LOGON ) );
85 - zPanel.add( mFormBinder.add( aCurrentPassword, PASSWORD_LENGTH, PASSWORD ) );
86 - return zPanel;
87 - }
88 -
89 - @Override
90 - public Widget getBottomBar() {
91 - LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel();
92 - if ( mCancelable ) {
93 - zActionPanel.addLeft( createCancelButton() );
94 - }
95 - zActionPanel.addRight( mFE.addEditSubmitButton( mSubmitButton = createSubmitButton() ) );
96 - return zActionPanel;
97 - }
98 -
99 - @Override
100 - public void aboutToShow() {
101 - super.aboutToShow();
102 - mFE.initialize();
103 - }
104 -
105 - @Override
106 - protected void justLoaded() {
107 - super.justLoaded();
108 - mFE.setFocus();
109 - }
110 -
111 - @Override
112 - protected void submitRequested() {
113 - mFormBinder.commitForm();
114 - final T zUserView = mFormBinder.getObject();
115 - mDataProvider.attemptLogin( zUserView, new SimpleDataProviderCallBack() {
116 - @Override
117 - public void error( String pError ) {
118 - if ( Strings.isNotNullOrEmpty( pError ) ) {
119 - setDialogErrorMessage( pError );
120 - } else {
121 - Scheduler.get().scheduleDeferred( mOnSuccess );
122 - close();
123 - }
124 - }
125 - } );
126 - }
127 - }
128 - }
1 + package org.litesoft.GWT.client.view;
2 +
3 + import org.litesoft.GWT.client.*;
4 + import org.litesoft.GWT.client.context.*;
5 + import org.litesoft.GWT.client.widgets.*;
6 + import org.litesoft.GWT.forms.client.*;
7 + import org.litesoft.GWT.forms.client.components.*;
8 + import org.litesoft.bo.views.*;
9 + import org.litesoft.commonfoundation.base.*;
10 + import org.litesoft.core.*;
11 + import org.litesoft.security.*;
12 +
13 + import com.google.gwt.core.client.*;
14 + import com.google.gwt.user.client.*;
15 + import com.google.gwt.user.client.ui.*;
16 +
17 + import static org.litesoft.uispecification.FormWidgetCtrl.*;
18 +
19 + public class LoginDialogFactory<T extends SecurityUserView<T>> implements LoginDialogViewFactory {
20 + @Override
21 + public DialogView createDialog( boolean pCancelable, Command pOnSuccess ) {
22 + return new LoginDialog<T>( pCancelable, pOnSuccess );
23 + }
24 +
25 + private static class LoginDialog<T extends SecurityUserView<T>> extends DialogView implements SecurityUserViewNames {
26 + private FormEngine mFE;
27 +
28 + private SecurityUserViewDataProvider<T> mDataProvider;
29 + private FormBinder<T> mFormBinder;
30 + private ButtonBase mSubmitButton;
31 +
32 + private boolean mCancelable;
33 + private Command mOnSuccess;
34 +
35 + public LoginDialog( boolean pCancelable, Command pOnSuccess ) {
36 + super( title( "Login" ), Opaqueness.Full );
37 + mCancelable = pCancelable;
38 + Confirm.isNotNull( "OnSuccess", mOnSuccess = pOnSuccess );
39 +
40 + ClientContext zContext = ClientContext.get();
41 +
42 + mDataProvider = zContext.get( SecurityUserViewDataProvider.class );
43 + SecurityUserViewMetaData<T> zUserViewMetaData = zContext.get( SecurityUserViewMetaData.class );
44 +
45 + WidgetCtrlMap zWidgetCtrlMap = new WidgetCtrlMap( VISIBLE_AND_ACTIVE_ENABLED );
46 +
47 + zWidgetCtrlMap.add( EDIT_ONLY.required(), aLogonEmail, aCurrentPassword );
48 +
49 + mFE = new FormEngine( zWidgetCtrlMap, FormEngine.Mode.EditRegular, null ) {
50 + @Override
51 + protected void changeOccurredOn( String pName, IFormComponent pComponent, boolean pChanged ) {
52 + super.changeOccurredOn( pName, pComponent, pChanged );
53 + setDialogErrorMessage( null );
54 + }
55 +
56 + @Override
57 + protected void enterPressedOn( String pName, IFormComponent pComponent, KeyboardKeyModifier pModifiers ) {
58 + if ( pName.equals( aLogonEmail ) ) {
59 + getNamedComponent( aCurrentPassword ).setFocus();
60 + } else if ( pName.equals( aCurrentPassword ) && (mSubmitButton != null) && mSubmitButton.isEnabled() ) {
61 + submitRequested();
62 + } else {
63 + super.enterPressedOn( pName, pComponent, pModifiers );
64 + }
65 + }
66 + };
67 + mFormBinder = new FormBinder<T>( mFE, zUserViewMetaData );
68 +
69 + mContent.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
70 +
71 + add( createLogonAndCurrentPassword() );
72 + add( new SizeableSpacer( 5 ).stretchable() );
73 +
74 + mFormBinder.setExistingObject( mDataProvider.createNew(), FormEngine.Mode.EditRegular );
75 + }
76 +
77 + @Override
78 + public boolean isCancelable() {
79 + return mCancelable;
80 + }
81 +
82 + private Widget createLogonAndCurrentPassword() {
83 + SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchableHorizontally();
84 + zPanel.add( mFormBinder.add( aLogonEmail, 0, LOGON ) );
85 + zPanel.add( mFormBinder.add( aCurrentPassword, PASSWORD_LENGTH, PASSWORD ) );
86 + return zPanel;
87 + }
88 +
89 + @Override
90 + public Widget getBottomBar() {
91 + LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel();
92 + if ( mCancelable ) {
93 + zActionPanel.addLeft( createCancelButton() );
94 + }
95 + zActionPanel.addRight( mFE.addEditSubmitButton( mSubmitButton = createSubmitButton() ) );
96 + return zActionPanel;
97 + }
98 +
99 + @Override
100 + public void aboutToShow() {
101 + super.aboutToShow();
102 + mFE.initialize();
103 + }
104 +
105 + @Override
106 + protected void justLoaded() {
107 + super.justLoaded();
108 + mFE.setFocus();
109 + }
110 +
111 + @Override
112 + protected void submitRequested() {
113 + mFormBinder.commitForm();
114 + final T zUserView = mFormBinder.getObject();
115 + mDataProvider.attemptLogin( zUserView, new SimpleDataProviderCallBack() {
116 + @Override
117 + public void error( String pError ) {
118 + if ( Currently.isNotNullOrEmpty( pError ) ) {
119 + setDialogErrorMessage( pError );
120 + } else {
121 + Scheduler.get().scheduleDeferred( mOnSuccess );
122 + close();
123 + }
124 + }
125 + } );
126 + }
127 + }
128 + }