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
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.client.view;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.bo.views.*;
import org.litesoft.commonfoundation.base.*;
import org.litesoft.core.*;
import org.litesoft.security.*;
import org.litesoft.uispecification.*;

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

/**
 * Controls which screen is showing. Coordinates w/ the GWT {@link History}
 * mechanism.
 */
public class ViewManagerImpl extends AbstractViewManager implements ValueChangeHandler<String>,
                                                                    SecurityIssueable {
    private final TransientScreenProperties mNextScreenProperties = new TransientScreenProperties();

    public ViewManagerImpl( ViewAccessControlManager pAccessControlManager, ViewFactory... pFactories ) {
        super( pAccessControlManager, pFactories );
    }

    public void initialize() {
        History.addValueChangeHandler( this );
        onValueChangeImpl( History.getToken() );
    }

    @Override
    public void showDialog( ViewDef pViewDef, Object pParams ) {
        Confirm.isNotNull( "(Dialog) ViewDef", pViewDef );
        ViewFactory zFactory = getViewFactory( pViewDef );
        if ( zFactory instanceof DialogViewFactory ) {
            new DialogViewDialog( ((DialogViewFactory) zFactory).createDialog( ClientContext.get(), pParams ) ).show();
        } else {
            AlertManager.alert( "ViewManager", "No Dialog Factory", "No Dialog for: " + pViewDef );
        }
    }

    @Override
    public void showScreen( ViewDef pViewDef, UriFragmentIdParams pParams, TransientScreenProperties pNextScreenProperties ) {
        UtilsGwt.busyCursor();
        Confirm.isNotNull( "(Screen) ViewDef", pViewDef );
        mNextScreenProperties.putAll( pNextScreenProperties );
        ParameterizedUriFragmentId zFragmentId = new ParameterizedUriFragmentId( pViewDef.getFragmentID(), //
                                                                                 UriFragmentIdParams.toParamsString( pParams ) );
        History.newItem( zFragmentId.toNewUriFragmentId( History.getToken() ), true ); // will "eventually" cause an AttachScreenCommand to be issued
    }

    void showScreen( String pHistoryToken, TransientScreenProperties pNextScreenProperties ) {
        mNextScreenProperties.putAll( pNextScreenProperties );
        onValueChangeImpl( pHistoryToken );
    }

    void onValueChangeImpl( final String pHistoryToken ) // Everything that follows the '#' in the url.
    {
        String zUriFragmentId = ParameterizedUriFragmentId.removePrefix( pHistoryToken );
        ParameterizedUriFragmentId zFragmentId;
        try {
            zFragmentId = new ParameterizedUriFragmentId( zUriFragmentId );
        }
        catch ( IllegalArgumentException e ) {
            LOGGER.warn.log( e, zUriFragmentId );
            zFragmentId = ParameterizedUriFragmentId.DEFAULT;
        }

        if ( mAccessControlManager.loginRequired() ) {
            LoginServerStateChecker zChecker = ClientContext.get().checkGet( LoginServerStateChecker.class );
            if ( zChecker == null ) {
                requestUserLogin( pHistoryToken, null );
            } else {
                zChecker.checkServerLogin( new SimpleDataProviderCallBack() {
                    @Override
                    public void error( String pError ) {
                        if ( mAccessControlManager.loginRequired() ) {
                            requestUserLogin( pHistoryToken, pError );
                        } else {
                            new LoginSuccessCommand( pHistoryToken, mNextScreenProperties ).execute();
                        }
                    }
                } );
            }
            return;
        }

        LoginPasswordResetAccessor zAccessor = ClientContext.get().get( LoginPasswordResetAccessor.class );
        if ( zAccessor.isPasswordResetRequired() ) {
            LoginPasswordResetDialogViewFactory zFactory = ClientContext.get().get( LoginPasswordResetDialogViewFactory.class );
            if ( zFactory != null ) {
                DialogView zView =
                        zFactory.createDialog( ClientContext.get(), new LoginSuccessCommand( pHistoryToken, mNextScreenProperties, "Password updated" ) );
                ClientContext.get().get( SingleWidgetPanel.class ).setWidget( new SizeableSpacer().stretchable() );
                new DialogViewDialog( zView ).show();
                return;
            }
        }

        String viewDefId = zFragmentId.getFragmentReference();
        String viewParams = zFragmentId.getParameters();
        ViewDef zViewDef = getViewDef( viewDefId );

        UriFragmentIdParams zParams = UriFragmentIdParams.fromParamsString( viewParams );
        if ( zViewDef == null ) {
            zViewDef = ViewDef.HOME;
            zParams = null;
            if ( Currently.isNotNullOrEmpty( viewDefId ) ) {
                mNextScreenProperties.ERROR.set( "No Screen for: " + viewDefId );
            }
        }
        ViewFactory zFactory = getViewFactory( zViewDef );
        if ( !(zFactory instanceof ScreenViewFactory) ) {
            zParams = null;
            mNextScreenProperties.ERROR.set( "No Screen for: " + viewDefId );
            zFactory = getViewFactory( zViewDef = ViewDef.HOME );
        }

        if ( zFactory == null ) {
            throw new IllegalStateException( "No Screen for: " + zViewDef );
        }

        StatusMessageSinc zMessageSinc = ClientContext.get().checkGet( StatusMessageSinc.class );
        if ( zMessageSinc != null ) {
            zMessageSinc.setErrorMessage( mNextScreenProperties.ERROR.get() );
            if ( Currently.isNullOrEmpty( mNextScreenProperties.ERROR.get() ) ) {
                zMessageSinc.setWarningMessage( mNextScreenProperties.WARNING.get() );
            }
        }
        mNextScreenProperties.clear();

        ScreenView zView = ((ScreenViewFactory) zFactory).createScreen( ClientContext.get(), zParams );
        Widget zViewWidget = zView.augmentView( zView.getTopBar(), null );
        ClientContext.get().get( SingleWidgetPanel.class ).setWidget( zViewWidget ); // This line MUST BE last!
    }

    @Override
    public void handleSecurityIssue( String pError ) {
        requestUserLogin( ViewDef.HOME.getFragmentID(), pError );
    }

    private void requestUserLogin( String pHistoryToken, String pError ) {
        LoginDialogViewFactory zFactory = ClientContext.get().get( LoginDialogViewFactory.class );
        DialogView zView = zFactory.createDialog( false, new LoginSuccessCommand( pHistoryToken, mNextScreenProperties ) );
        zView.setDialogErrorMessage( pError );
        ClientContext.get().get( SingleWidgetPanel.class ).setWidget( new SizeableSpacer().stretchable() );
        new DialogViewDialog( zView ).show();
    }

    @Override
    public void onValueChange( ValueChangeEvent<String> pEvent ) {
        onValueChangeImpl( pEvent.getValue() );
    }

    private class LoginSuccessCommand implements Command {
        private final String mHistoryToken;
        private final TransientScreenProperties mNextScreenProperties;

        public LoginSuccessCommand( String pHistoryToken, TransientScreenProperties pNextScreenProperties ) {
            this( pHistoryToken, pNextScreenProperties, null );
        }

        private LoginSuccessCommand( String pHistoryToken, TransientScreenProperties pNextScreenProperties, String pWarning ) {
            mHistoryToken = pHistoryToken;
            mNextScreenProperties = pNextScreenProperties.copy();
            if ( pWarning != null ) {
                mNextScreenProperties.WARNING.set( pWarning );
            }
        }

        @Override
        public void execute() {
            showScreen( mHistoryToken, mNextScreenProperties );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/view/ViewManagerImpl.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

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

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

Extracting commonfoundation

804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +0000
802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
151 Diff Diff GeorgeS picture GeorgeS Thu 17 Mar, 2011 04:16:22 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

23 Diff Diff GeorgeS picture GeorgeS Wed 24 Feb, 2010 00:34:32 +0000
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000