/v3.2/nimbits-tds/src/com/nimbits/client/panels/MainPanel.java

http://nimbits-server.googlecode.com/ · Java · 195 lines · 120 code · 63 blank · 12 comment · 2 complexity · 6acebfe8556d2089d1a5e47be9885021 MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 Tonic Solutions LLC.
  3. *
  4. * http://www.nimbits.com
  5. *
  6. *
  7. * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * http://www.gnu.org/licenses/gpl.html
  10. *
  11. * 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.
  12. */
  13. package com.nimbits.client.panels;
  14. import com.extjs.gxt.ui.client.Style.LayoutRegion;
  15. import com.extjs.gxt.ui.client.Style.Orientation;
  16. import com.extjs.gxt.ui.client.util.Margins;
  17. import com.extjs.gxt.ui.client.widget.ContentPanel;
  18. import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
  19. import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
  20. import com.extjs.gxt.ui.client.widget.layout.FillLayout;
  21. import com.nimbits.client.exception.NimbitsException;
  22. import com.nimbits.client.model.LoginInfo;
  23. import com.nimbits.client.model.category.Category;
  24. import com.nimbits.client.model.diagram.Diagram;
  25. import com.nimbits.client.model.email.EmailAddress;
  26. import com.nimbits.client.model.point.Point;
  27. public class MainPanel extends NavigationEventProvider {
  28. private final CenterPanel center = new CenterPanel();
  29. private final EmailAddress emailAddress;
  30. final NavigationPanel createNavigationPanel() {
  31. final NavigationPanel navTree = new NavigationPanel(emailAddress, false);
  32. navTree.addCategoryClickedListeners(new NavigationEventProvider.CategoryClickedListener() {
  33. @Override
  34. public void onCategoryClicked(final Category c, boolean readOnly) throws NimbitsException {
  35. notifyCategoryClickedListener(c, readOnly);
  36. }
  37. });
  38. navTree.addPointClickedListeners(new NavigationEventProvider.PointClickedListener() {
  39. @Override
  40. public void onPointClicked(final Point p) {
  41. notifyPointClickedListener(p);
  42. }
  43. });
  44. navTree.addDiagramClickedListeners(new NavigationEventProvider.DiagramClickedListener() {
  45. @Override
  46. public void onDiagramClicked(final Diagram p) {
  47. notifyDiagramClickedListener(p);
  48. }
  49. });
  50. navTree.addPointDeletedListeners(new NavigationEventProvider.PointDeletedListener() {
  51. @Override
  52. public void onPointDeleted(final Point c) throws NimbitsException {
  53. notifyPointDeletedListener(c);
  54. center.removePoint(c);
  55. }
  56. });
  57. navTree.addDiagramDeletedListeners(new NavigationEventProvider.DiagramDeletedListener() {
  58. @Override
  59. public void onDiagramDeleted(final Diagram c, final boolean readOnly) throws NimbitsException {
  60. notifyDiagramDeletedListener(c, readOnly);
  61. }
  62. });
  63. return navTree;
  64. }
  65. public void addPoint(final Point point) {
  66. center.addPoint(point);
  67. }
  68. public MainPanel(final LoginInfo loginInfo, final boolean loadConnections) throws NimbitsException {
  69. final BorderLayout layout = new BorderLayout();
  70. this.emailAddress = loginInfo.getEmailAddress();
  71. setLayout(layout);
  72. final ContentPanel west = new ContentPanel();
  73. final ContentPanel east = new ContentPanel();
  74. east.setHeading("Connections");
  75. if (loadConnections) {
  76. ConnectionPanel connections = createConnections(loginInfo.getEmailAddress());
  77. east.add(connections);
  78. }
  79. final NavigationPanel navigationPanel = createNavigationPanel();
  80. navigationPanel.setLayout(new FillLayout());
  81. west.add(navigationPanel);
  82. west.setHeight("100%");
  83. west.setHeading("Navigator");
  84. final BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 250);
  85. westData.setSplit(true);
  86. westData.setCollapsible(true);
  87. westData.setMargins(new Margins(5));
  88. final BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
  89. centerData.setMargins(new Margins(5, 5, 5, 0));
  90. final BorderLayoutData eastData = new BorderLayoutData(LayoutRegion.EAST, 175);
  91. eastData.setSplit(true);
  92. eastData.setCollapsible(true);
  93. eastData.setMargins(new Margins(5));
  94. final BorderLayoutData southData = new BorderLayoutData(LayoutRegion.SOUTH,
  95. 125);
  96. southData.setSplit(true);
  97. southData.setCollapsible(true);
  98. southData.setMargins(new Margins(0, 0, 0, 0));
  99. west.setLayout(new FillLayout(Orientation.VERTICAL));
  100. add(west, westData);
  101. if (loadConnections) {
  102. add(east, eastData);
  103. }
  104. center.setLayout(new FillLayout());
  105. add(center, centerData);
  106. }
  107. private ConnectionPanel createConnections(final EmailAddress email) throws NimbitsException {
  108. final ConnectionPanel connections = new ConnectionPanel(email);
  109. connections.addCategoryClickedListeners(new NavigationEventProvider.CategoryClickedListener() {
  110. @Override
  111. public void onCategoryClicked(final Category c, boolean readOnly) throws NimbitsException {
  112. notifyCategoryClickedListener(c, readOnly);
  113. }
  114. });
  115. connections.addPointClickedListeners(new NavigationEventProvider.PointClickedListener() {
  116. @Override
  117. public void onPointClicked(final Point p) {
  118. notifyPointClickedListener(p);
  119. }
  120. });
  121. connections.addDiagramClickedListeners(new NavigationEventProvider.DiagramClickedListener() {
  122. @Override
  123. public void onDiagramClicked(final Diagram p) {
  124. notifyDiagramClickedListener(p);
  125. }
  126. });
  127. return connections;
  128. }
  129. public void addDiagram(final Diagram d) {
  130. center.addDiagram(d);
  131. }
  132. }