View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   package org.directdemocracyportal.democracy.web.views;
6   
7   import java.util.Set;
8   
9   import org.directdemocracyportal.democracy.model.application.Portal;
10  import org.directdemocracyportal.democracy.model.core.GroupAgent;
11  import org.directdemocracyportal.democracy.model.world.Person;
12  import org.directdemocracyportal.democracy.web.ApplicationMessageHolder;
13  import org.directdemocracyportal.democracy.web.ImageConstants;
14  import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans;
15  
16  import thinwire.ui.Panel;
17  import thinwire.ui.Tree;
18  import thinwire.ui.layout.TableLayout;
19  
20  /***
21   * The Class StartContentPanel.
22   */
23  public class StartContentPanel extends Panel
24  {
25  
26      /***
27       * Instantiates a new start content panel.
28       *
29       * @param portal the portal
30       */
31      public StartContentPanel(Portal portal) {
32          setLayout(new TableLayout(new double[][] { { 0 }, // Column Widths
33                  { 0 } }, // Row Heights
34                  1, // Margin around edge of container
35                  5)); // Spacing between cells
36  
37          Tree globalPortalTree = createGlobalPortalTree(portal);
38          globalPortalTree.setLimit("0,0,1,1");
39          getChildren().add(globalPortalTree);
40      }
41  
42      /***
43       * Creates the global portal tree.
44       *
45       * @param portal the portal
46       * @return the tree
47       */
48      private Tree createGlobalPortalTree(Portal portal) {
49          Tree tree = new Tree();
50          tree.setRootItemVisible(true);
51  
52          Tree.Item root = tree.getRootItem();
53          root.setText(ApplicationMessageHolder.getMessage(MessageConstans.APPLICATION_NAME));
54          root.setExpanded(true);
55  
56          Tree.Item orgTree = new Tree.Item(ApplicationMessageHolder.getMessage(MessageConstans.GROUPS), ImageConstants.GROUP_HOME_ICON);
57          root.getChildren().add(orgTree);
58  
59          Set<GroupAgent> groups = portal.getChildren();
60  
61          for(GroupAgent group : groups) {
62              Tree.Item orgItem = new Tree.Item(group.getName());
63              orgTree.getChildren().add(orgItem);
64          }
65  
66          Tree.Item memberTree = new Tree.Item(ApplicationMessageHolder.getMessage(MessageConstans.MEMBERS), ImageConstants.AGENT_ICON);
67          root.getChildren().add(memberTree);
68  
69          Set<Person> personsActive = portal.personsActive();
70  
71          for(Person person : personsActive) {
72              Tree.Item memberItem = new Tree.Item(person.getName());
73              memberTree.getChildren().add(memberItem);
74          }
75  
76          return tree;
77      }
78  }