Subversion Repository Public Repository

litesoft

Diff Revisions 948 vs 950 for /trunk/Java/DATT/src/org/litesoft/datt/client/ui/views/home/Home.java

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