|
@@ -1,151 +1,151 @@ |
1 |
|
- |
package org.litesoft.initfrom.client.ui.views.home; |
2 |
|
- |
|
3 |
|
- |
import org.litesoft.GWT.client.*; |
4 |
|
- |
import org.litesoft.GWT.client.command.*; |
5 |
|
- |
import org.litesoft.GWT.client.dev.*; |
6 |
|
- |
import org.litesoft.GWT.client.view.*; |
7 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
8 |
|
- |
import org.litesoft.bo.views.*; |
9 |
|
- |
import org.litesoft.core.*; |
10 |
|
- |
import org.litesoft.core.simpletypes.*; |
11 |
|
- |
import org.litesoft.initfrom.client.*; |
12 |
|
- |
import org.litesoft.initfrom.client.boviews.*; |
13 |
|
- |
import org.litesoft.uispecification.*; |
14 |
|
- |
|
15 |
|
- |
import com.google.gwt.event.dom.client.*; |
16 |
|
- |
import com.google.gwt.user.client.ui.*; |
17 |
|
- |
|
18 |
|
- |
import java.util.*; |
19 |
|
- |
|
20 |
|
- |
public class Home extends ScreenView implements ViewDefs { |
21 |
|
- |
public static final String InitFromTITLE = "Init From"; |
22 |
|
- |
|
23 |
|
- |
@Override |
24 |
|
- |
protected UriFragmentIdParams createRefreshParams() { |
25 |
|
- |
return null; |
26 |
|
- |
} |
27 |
|
- |
|
28 |
|
- |
@Override |
29 |
|
- |
protected void addHome() { |
30 |
|
- |
} |
31 |
|
- |
|
32 |
|
- |
@Override |
33 |
|
- |
public Widget getBottomBar() { |
34 |
|
- |
return null; |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
@Override |
38 |
|
- |
protected void logoutButtonClicked() { |
39 |
|
- |
if ( UtilsGwt.wasCtrlKeyDownOnCurrentEvent() && Dev.isDevMode() ) { |
40 |
|
- |
ClientContext.get().get( NextDemoUserRequestHandler.class ).nextDemoUser(); |
41 |
|
- |
return; |
42 |
|
- |
} |
43 |
|
- |
super.logoutButtonClicked(); |
44 |
|
- |
} |
45 |
|
- |
|
46 |
|
- |
public Home() { |
47 |
|
- |
super( null ); |
48 |
|
- |
addStandardTitleBar(); |
49 |
|
- |
addTitle( InitFromTITLE ); |
50 |
|
- |
|
51 |
|
- |
add( new BigButtonScreenHelper() { |
52 |
|
- |
@Override |
53 |
|
- |
public Widget build() { |
54 |
|
- |
UserView zUser = ClientContext.get().get( CurrentUserViewAccessor.class ).getUser(); |
55 |
|
- |
List<Widget> zSections = new ArrayList<Widget>(); |
56 |
|
- |
Role zLastRole = Role.valueFor( zUser.getLastRestrictedResourceRole() ); |
57 |
|
- |
switch ( zLastRole ) { |
58 |
|
- |
default: |
59 |
|
- |
zLastRole = Role.EndUser; |
60 |
|
- |
// Fall Thru |
61 |
|
- |
case EndUser: |
62 |
|
- |
populateSections_EndUser( zSections ); |
63 |
|
- |
break; |
64 |
|
- |
case EndUserManager: |
65 |
|
- |
populateSections_EndUserManager( zSections ); |
66 |
|
- |
break; |
67 |
|
- |
case Developer: |
68 |
|
- |
populateSections_Developer( zSections ); |
69 |
|
- |
break; |
70 |
|
- |
case Customer: |
71 |
|
- |
populateSections_Customer( zSections ); |
72 |
|
- |
break; |
73 |
|
- |
case ProjectAdmin: |
74 |
|
- |
populateSections_ProjectAdmin( zSections ); |
75 |
|
- |
break; |
76 |
|
- |
} |
77 |
|
- |
Widget zRestrictedResource = createButton( ADMIN_RESTRICTED_RESOURCE_MANAGEMENT ); |
78 |
|
- |
if ( zRestrictedResource == null ) { |
79 |
|
- |
zRestrictedResource = createButton( ADMIN_RESTRICTED_RESOURCE_EDITOR ); |
80 |
|
- |
} |
81 |
|
- |
zSections.add( createSection( HOME_SECTION_ADMIN, zRestrictedResource, ADMIN_CHANGE_PASSWORD, ADMIN_MY_PROFILE, ADMIN_REPORTS, ADMIN_USERS ) ); |
82 |
|
- |
zSections.add( createSection( HOME_SECTION_HOME_SWITCH_VIEW, |
83 |
|
- |
createSwitchHomeButtons( zUser.getCurrentRestrictedResourceAllowedRoles(), zLastRole ) ) ); |
84 |
|
- |
return addVerticallyDistributed( zSections ); |
85 |
|
- |
} |
86 |
|
- |
|
87 |
|
- |
@Override |
88 |
|
- |
protected Widget createScreenButton( ViewDef pViewDef ) { |
89 |
|
- |
String zUiString = pViewDef.getUiString(); |
90 |
|
- |
ShowScreenCommand zScreenCommand = new ShowScreenCommand( pViewDef ); |
91 |
|
- |
return ScreenBigButton.factory( zUiString ).add( zScreenCommand ).create(); |
92 |
|
- |
} |
93 |
|
- |
|
94 |
|
- |
private SizeableHorizontalPanel createSwitchHomeButtons( TextLines pAllowedRoles, Role pCurrentRole ) { |
95 |
|
- |
Set<Role> zAllowedRoles = new HashSet<Role>(); |
96 |
|
- |
for ( TextLine zAllowedRole : pAllowedRoles ) { |
97 |
|
- |
zAllowedRoles.add( Role.valueFor( zAllowedRole.getLine() ) ); |
98 |
|
- |
} |
99 |
|
- |
List<Widget> zButtons = new ArrayList<Widget>(); |
100 |
|
- |
for ( Role zRole : Role.values() ) { |
101 |
|
- |
if ( (zRole != pCurrentRole) && zAllowedRoles.contains( zRole ) ) { |
102 |
|
- |
ViewDef[] zViewDefs = ViewDefs.ROLES_MAP.get( zRole ); |
103 |
|
- |
if ( (zViewDefs != null) && (zViewDefs.length > 0) ) { |
104 |
|
- |
ViewDef zViewDef = zViewDefs[0]; |
105 |
|
- |
if ( zViewDef != null ) { |
106 |
|
- |
zButtons.add( createSwitchHomeButton( zViewDef, zRole ) ); |
107 |
|
- |
} |
108 |
|
- |
} |
109 |
|
- |
} |
110 |
|
- |
} |
111 |
|
- |
return createButtons( zButtons ); |
112 |
|
- |
} |
113 |
|
- |
|
114 |
|
- |
private Widget createSwitchHomeButton( ViewDef pViewDef, final Role pRole ) { |
115 |
|
- |
return ScreenBigButton.factory( pViewDef.getUiString() ).add( new ClickHandler() { |
116 |
|
- |
@Override |
117 |
|
- |
public void onClick( ClickEvent event ) { |
118 |
|
- |
CurrentUserViewAccessor zAccessor = ClientContext.get().get( CurrentUserViewAccessor.class ); |
119 |
|
- |
UserView zUser = zAccessor.getUser(); |
120 |
|
- |
if ( zUser.getTransactionSet() == null ) { |
121 |
|
- |
zAccessor.setUser( zUser = zUser.copyInto( ClientTransactionSet.create() ) ); |
122 |
|
- |
} |
123 |
|
- |
zUser.setLastRestrictedResourceRole( pRole.toString() ); |
124 |
|
- |
// todo: send it to the Server |
125 |
|
- |
refreshPage(); |
126 |
|
- |
} |
127 |
|
- |
} ).create(); |
128 |
|
- |
} |
129 |
|
- |
|
130 |
|
- |
private void populateSections_EndUser( List<Widget> pSections ) { |
131 |
|
- |
pSections.add( createSection( "END USERS", ENDUSERS_SAMPLE ) ); |
132 |
|
- |
} |
133 |
|
- |
|
134 |
|
- |
private void populateSections_EndUserManager( List<Widget> pSections ) { |
135 |
|
- |
pSections.add( createSection( "END USER MANAGER", ENDUSERMANAGERS_SAMPLE ) ); |
136 |
|
- |
} |
137 |
|
- |
|
138 |
|
- |
private void populateSections_Developer( List<Widget> pSections ) { |
139 |
|
- |
pSections.add( createSection( "DEVELOPER", DEVELOPERS_SAMPLE ) ); |
140 |
|
- |
} |
141 |
|
- |
|
142 |
|
- |
private void populateSections_Customer( List<Widget> pSections ) { |
143 |
|
- |
pSections.add( createSection( "CUSTOMER", CUSTOMERS_SAMPLE ) ); |
144 |
|
- |
} |
145 |
|
- |
|
146 |
|
- |
private void populateSections_ProjectAdmin( List<Widget> pSections ) { |
147 |
|
- |
pSections.add( createSection( "PROJECT ADMINISTRATOR", PROJECTADMINS_SAMPLE ) ); |
148 |
|
- |
} |
149 |
|
- |
}.build() ); |
150 |
|
- |
} |
151 |
|
- |
} |
|
1 |
+ |
package org.litesoft.initfrom.client.ui.views.home; |
|
2 |
+ |
|
|
3 |
+ |
import org.litesoft.GWT.client.*; |
|
4 |
+ |
import org.litesoft.GWT.client.command.*; |
|
5 |
+ |
import org.litesoft.GWT.client.dev.*; |
|
6 |
+ |
import org.litesoft.GWT.client.view.*; |
|
7 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
8 |
+ |
import org.litesoft.bo.views.*; |
|
9 |
+ |
import org.litesoft.core.*; |
|
10 |
+ |
import org.litesoft.core.simpletypes.*; |
|
11 |
+ |
import org.litesoft.initfrom.client.*; |
|
12 |
+ |
import org.litesoft.initfrom.client.boviews.*; |
|
13 |
+ |
import org.litesoft.uispecification.*; |
|
14 |
+ |
|
|
15 |
+ |
import com.google.gwt.event.dom.client.*; |
|
16 |
+ |
import com.google.gwt.user.client.ui.*; |
|
17 |
+ |
|
|
18 |
+ |
import java.util.*; |
|
19 |
+ |
|
|
20 |
+ |
public class Home extends ScreenView implements ViewDefs { |
|
21 |
+ |
public static final String InitFromTITLE = "Init From"; |
|
22 |
+ |
|
|
23 |
+ |
@Override |
|
24 |
+ |
protected UriFragmentIdParams createRefreshParams() { |
|
25 |
+ |
return null; |
|
26 |
+ |
} |
|
27 |
+ |
|
|
28 |
+ |
@Override |
|
29 |
+ |
protected void addHome() { |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
@Override |
|
33 |
+ |
public Widget getBottomBar() { |
|
34 |
+ |
return null; |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
@Override |
|
38 |
+ |
protected void logoutButtonClicked() { |
|
39 |
+ |
if ( UtilsGwt.wasCtrlKeyDownOnCurrentEvent() && Dev.isDevMode() ) { |
|
40 |
+ |
ClientContext.get().get( NextDemoUserRequestHandler.class ).nextDemoUser(); |
|
41 |
+ |
return; |
|
42 |
+ |
} |
|
43 |
+ |
super.logoutButtonClicked(); |
|
44 |
+ |
} |
|
45 |
+ |
|
|
46 |
+ |
public Home() { |
|
47 |
+ |
super( null ); |
|
48 |
+ |
addStandardTitleBar(); |
|
49 |
+ |
addTitle( InitFromTITLE ); |
|
50 |
+ |
|
|
51 |
+ |
add( new BigButtonScreenHelper() { |
|
52 |
+ |
@Override |
|
53 |
+ |
public Widget build() { |
|
54 |
+ |
UserView zUser = ClientContext.get().get( CurrentUserViewAccessor.class ).getUser(); |
|
55 |
+ |
List<Widget> zSections = new ArrayList<Widget>(); |
|
56 |
+ |
Role zLastRole = Role.valueFor( zUser.getLastRestrictedResourceRole() ); |
|
57 |
+ |
switch ( zLastRole ) { |
|
58 |
+ |
default: |
|
59 |
+ |
zLastRole = Role.EndUser; |
|
60 |
+ |
// Fall Thru |
|
61 |
+ |
case EndUser: |
|
62 |
+ |
populateSections_EndUser( zSections ); |
|
63 |
+ |
break; |
|
64 |
+ |
case EndUserManager: |
|
65 |
+ |
populateSections_EndUserManager( zSections ); |
|
66 |
+ |
break; |
|
67 |
+ |
case Developer: |
|
68 |
+ |
populateSections_Developer( zSections ); |
|
69 |
+ |
break; |
|
70 |
+ |
case Customer: |
|
71 |
+ |
populateSections_Customer( zSections ); |
|
72 |
+ |
break; |
|
73 |
+ |
case ProjectAdmin: |
|
74 |
+ |
populateSections_ProjectAdmin( zSections ); |
|
75 |
+ |
break; |
|
76 |
+ |
} |
|
77 |
+ |
Widget zRestrictedResource = createButton( ADMIN_RESTRICTED_RESOURCE_MANAGEMENT ); |
|
78 |
+ |
if ( zRestrictedResource == null ) { |
|
79 |
+ |
zRestrictedResource = createButton( ADMIN_RESTRICTED_RESOURCE_EDITOR ); |
|
80 |
+ |
} |
|
81 |
+ |
zSections.add( createSection( HOME_SECTION_ADMIN, zRestrictedResource, ADMIN_CHANGE_PASSWORD, ADMIN_MY_PROFILE, ADMIN_REPORTS, ADMIN_USERS ) ); |
|
82 |
+ |
zSections.add( createSection( HOME_SECTION_HOME_SWITCH_VIEW, |
|
83 |
+ |
createSwitchHomeButtons( zUser.getCurrentRestrictedResourceAllowedRoles(), zLastRole ) ) ); |
|
84 |
+ |
return addVerticallyDistributed( zSections ); |
|
85 |
+ |
} |
|
86 |
+ |
|
|
87 |
+ |
@Override |
|
88 |
+ |
protected Widget createScreenButton( ViewDef pViewDef ) { |
|
89 |
+ |
String zUiString = pViewDef.getUiString(); |
|
90 |
+ |
ShowScreenCommand zScreenCommand = new ShowScreenCommand( pViewDef ); |
|
91 |
+ |
return ScreenBigButton.factory( zUiString ).add( zScreenCommand ).create(); |
|
92 |
+ |
} |
|
93 |
+ |
|
|
94 |
+ |
private SizeableHorizontalPanel createSwitchHomeButtons( TextLines pAllowedRoles, Role pCurrentRole ) { |
|
95 |
+ |
Set<Role> zAllowedRoles = new HashSet<Role>(); |
|
96 |
+ |
for ( TextLine zAllowedRole : pAllowedRoles ) { |
|
97 |
+ |
zAllowedRoles.add( Role.valueFor( zAllowedRole.getLine() ) ); |
|
98 |
+ |
} |
|
99 |
+ |
List<Widget> zButtons = new ArrayList<Widget>(); |
|
100 |
+ |
for ( Role zRole : Role.values() ) { |
|
101 |
+ |
if ( (zRole != pCurrentRole) && zAllowedRoles.contains( zRole ) ) { |
|
102 |
+ |
ViewDef[] zViewDefs = ViewDefs.ROLES_MAP.get( zRole ); |
|
103 |
+ |
if ( (zViewDefs != null) && (zViewDefs.length > 0) ) { |
|
104 |
+ |
ViewDef zViewDef = zViewDefs[0]; |
|
105 |
+ |
if ( zViewDef != null ) { |
|
106 |
+ |
zButtons.add( createSwitchHomeButton( zViewDef, zRole ) ); |
|
107 |
+ |
} |
|
108 |
+ |
} |
|
109 |
+ |
} |
|
110 |
+ |
} |
|
111 |
+ |
return createButtons( zButtons ); |
|
112 |
+ |
} |
|
113 |
+ |
|
|
114 |
+ |
private Widget createSwitchHomeButton( ViewDef pViewDef, final Role pRole ) { |
|
115 |
+ |
return ScreenBigButton.factory( pViewDef.getUiString() ).add( new ClickHandler() { |
|
116 |
+ |
@Override |
|
117 |
+ |
public void onClick( ClickEvent event ) { |
|
118 |
+ |
CurrentUserViewAccessor zAccessor = ClientContext.get().get( CurrentUserViewAccessor.class ); |
|
119 |
+ |
UserView zUser = zAccessor.getUser(); |
|
120 |
+ |
if ( zUser.getTransactionSet() == null ) { |
|
121 |
+ |
zAccessor.setUser( zUser = zUser.copyInto( ClientTransactionSet.create() ) ); |
|
122 |
+ |
} |
|
123 |
+ |
zUser.setLastRestrictedResourceRole( pRole.toString() ); |
|
124 |
+ |
// todo: send it to the Server |
|
125 |
+ |
refreshPage(); |
|
126 |
+ |
} |
|
127 |
+ |
} ).create(); |
|
128 |
+ |
} |
|
129 |
+ |
|
|
130 |
+ |
private void populateSections_EndUser( List<Widget> pSections ) { |
|
131 |
+ |
pSections.add( createSection( "END USERS", ENDUSERS_SAMPLE ) ); |
|
132 |
+ |
} |
|
133 |
+ |
|
|
134 |
+ |
private void populateSections_EndUserManager( List<Widget> pSections ) { |
|
135 |
+ |
pSections.add( createSection( "END USER MANAGER", ENDUSERMANAGERS_SAMPLE ) ); |
|
136 |
+ |
} |
|
137 |
+ |
|
|
138 |
+ |
private void populateSections_Developer( List<Widget> pSections ) { |
|
139 |
+ |
pSections.add( createSection( "DEVELOPER", DEVELOPERS_SAMPLE ) ); |
|
140 |
+ |
} |
|
141 |
+ |
|
|
142 |
+ |
private void populateSections_Customer( List<Widget> pSections ) { |
|
143 |
+ |
pSections.add( createSection( "CUSTOMER", CUSTOMERS_SAMPLE ) ); |
|
144 |
+ |
} |
|
145 |
+ |
|
|
146 |
+ |
private void populateSections_ProjectAdmin( List<Widget> pSections ) { |
|
147 |
+ |
pSections.add( createSection( "PROJECT ADMINISTRATOR", PROJECTADMINS_SAMPLE ) ); |
|
148 |
+ |
} |
|
149 |
+ |
}.build() ); |
|
150 |
+ |
} |
|
151 |
+ |
} |