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
package org.litesoft.initfrom.client.ui.views.home;

import java.util.*;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.command.*;
import org.litesoft.GWT.client.dev.*;
import org.litesoft.GWT.client.view.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.bo.views.*;
import org.litesoft.core.*;
import org.litesoft.core.simpletypes.*;
import org.litesoft.initfrom.client.*;
import org.litesoft.initfrom.client.boviews.*;
import org.litesoft.uispecification.*;

import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.ui.*;

public class Home extends AbstractInitFromscreenView implements ViewDefs
{
    public static final String InitFromTITLE = "Init From";
    @Override
    protected UriFragmentIdParams createRefreshParams()
    {
        return null;
    }

    @Override protected void addHome()
    {
    }

    @Override
    public Widget getBottomBar()
    {
        return null;
    }

    @Override
    protected void logoutButtonClicked()
    {
        if ( UtilsGwt.wasCtrlKeyDownOnCurrentEvent() && Dev.isDevMode() )
        {
            ClientContext.get().get( NextDemoUserRequestHandler.class ).nextDemoUser();
            return;
        }
        super.logoutButtonClicked();
    }

    public Home()
    {
        addStandardTitleBar();
        addTitle( InitFromTITLE );

        add( new BigButtonScreenHelper()
        {
            @Override
            public Widget build()
            {
                UserView zUser = ClientContext.get().get( CurrentUserViewAccessor.class ).getUser();
                List<Widget> zSections = new ArrayList<Widget>();
                Role zLastRole = Role.valueFor( zUser.getLastRestrictedResourceRole() );
                switch ( zLastRole )
                {
                    default:
                        zLastRole = Role.EndUser;
                        // Fall Thru
                    case EndUser:
                        populateSections_EndUser( zSections );
                        break;
                    case EndUserManager:
                        populateSections_EndUserManager( zSections );
                        break;
                    case Developer:
                        populateSections_Developer( zSections );
                        break;
                    case Customer:
                        populateSections_Customer( zSections );
                        break;
                    case ProjectAdmin:
                        populateSections_ProjectAdmin( zSections );
                        break;
                }
                Widget zRestrictedResource = createButton( ADMIN_RESTRICTED_RESOURCE_MANAGEMENT );
                if ( zRestrictedResource == null )
                {
                    zRestrictedResource = createButton( ADMIN_RESTRICTED_RESOURCE_EDITOR );
                }
                zSections.add( createSection( HOME_SECTION_ADMIN, zRestrictedResource, ADMIN_CHANGE_PASSWORD, ADMIN_MY_PROFILE, ADMIN_REPORTS, ADMIN_USERS ) );
                zSections.add( createSection( HOME_SECTION_HOME_SWITCH_VIEW, createSwitchHomeButtons( zUser.getCurrentRestrictedResourceAllowedRoles(), zLastRole ) ) );
                return addVerticallyDistributed( zSections );
            }

            @Override
            protected Widget createScreenButton( ViewDef pViewDef )
            {
                String zUiString = pViewDef.getUiString();
                ShowScreenCommand zScreenCommand = new ShowScreenCommand( pViewDef );
                return ScreenBigButton.factory( zUiString ).add( zScreenCommand ).create();
            }

            private SizeableHorizontalPanel createSwitchHomeButtons( TextLines pAllowedRoles, Role pCurrentRole )
            {
                Set<Role> zAllowedRoles = new HashSet<Role>();
                for ( TextLine zAllowedRole : pAllowedRoles )
                {
                    zAllowedRoles.add( Role.valueFor( zAllowedRole.getLine() ) );
                }
                List<Widget> zButtons = new ArrayList<Widget>();
                for ( Role zRole : Role.values() )
                {
                    if ( (zRole != pCurrentRole) && zAllowedRoles.contains( zRole ) )
                    {
                        ViewDef[] zViewDefs = ViewDefs.ROLES_MAP.get( zRole );
                        if ( (zViewDefs != null) && (zViewDefs.length > 0) )
                        {
                            ViewDef zViewDef = zViewDefs[0];
                            if ( zViewDef != null )
                            {
                                zButtons.add( createSwitchHomeButton( zViewDef, zRole ) );
                            }
                        }
                    }
                }
                return createButtons( zButtons );
            }

            private Widget createSwitchHomeButton( ViewDef pViewDef, final Role pRole )
            {
                return ScreenBigButton.factory( pViewDef.getUiString() ).add( new ClickHandler()
                {
                    @Override
                    public void onClick( ClickEvent event )
                    {
                        CurrentUserViewAccessor zAccessor = ClientContext.get().get( CurrentUserViewAccessor.class );
                        UserView zUser = zAccessor.getUser();
                        if ( zUser.getTransactionSet() == null )
                        {
                            zAccessor.setUser( zUser = zUser.copyInto( ClientTransactionSet.create() ) );
                        }
                        zUser.setLastRestrictedResourceRole( pRole.toString() );
                        // todo: send it to the Server
                        refreshPage();
                    }
                } ).create();
            }

            private void populateSections_EndUser( List<Widget> pSections )
            {
                pSections.add( createSection( "END USERS", ENDUSERS_SAMPLE ) );
            }

            private void populateSections_EndUserManager( List<Widget> pSections )
            {
                pSections.add( createSection( "END USER MANAGER", ENDUSERMANAGERS_SAMPLE ) );
            }

            private void populateSections_Developer( List<Widget> pSections )
            {
                pSections.add( createSection( "DEVELOPER", DEVELOPERS_SAMPLE ) );
            }

            private void populateSections_Customer( List<Widget> pSections )
            {
                pSections.add( createSection( "CUSTOMER", CUSTOMERS_SAMPLE ) );
            }

            private void populateSections_ProjectAdmin( List<Widget> pSections )
            {
                pSections.add( createSection( "PROJECT ADMINISTRATOR", PROJECTADMINS_SAMPLE ) );
            }
        }.build() );
    }
}

Commits for litesoft/trunk/GWT_Sandbox/InitFrom/src/org/litesoft/initfrom/client/ui/views/home/Home.java

Diff revisions: vs.
Revision Author Commited Message
491 Diff Diff GeorgeS picture GeorgeS Sun 11 Sep, 2011 12:57:02 +0000

Initial Transform of InitFrom

459 GeorgeS picture GeorgeS Sun 21 Aug, 2011 00:42:41 +0000