PageRenderTime 24ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 14package com.nimbits.client.panels;
 15
 16import com.extjs.gxt.ui.client.Style.LayoutRegion;
 17import com.extjs.gxt.ui.client.Style.Orientation;
 18import com.extjs.gxt.ui.client.util.Margins;
 19import com.extjs.gxt.ui.client.widget.ContentPanel;
 20import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
 21import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
 22import com.extjs.gxt.ui.client.widget.layout.FillLayout;
 23import com.nimbits.client.exception.NimbitsException;
 24import com.nimbits.client.model.LoginInfo;
 25import com.nimbits.client.model.category.Category;
 26import com.nimbits.client.model.diagram.Diagram;
 27import com.nimbits.client.model.email.EmailAddress;
 28import com.nimbits.client.model.point.Point;
 29
 30public class MainPanel extends NavigationEventProvider {
 31
 32    private final CenterPanel center = new CenterPanel();
 33    private final EmailAddress emailAddress;
 34
 35
 36    final NavigationPanel createNavigationPanel() {
 37        final NavigationPanel navTree = new NavigationPanel(emailAddress, false);
 38
 39
 40        navTree.addCategoryClickedListeners(new NavigationEventProvider.CategoryClickedListener() {
 41
 42            @Override
 43            public void onCategoryClicked(final Category c, boolean readOnly) throws NimbitsException {
 44
 45                notifyCategoryClickedListener(c, readOnly);
 46
 47            }
 48
 49        });
 50
 51        navTree.addPointClickedListeners(new NavigationEventProvider.PointClickedListener() {
 52
 53            @Override
 54            public void onPointClicked(final Point p) {
 55
 56                notifyPointClickedListener(p);
 57            }
 58
 59        });
 60
 61        navTree.addDiagramClickedListeners(new NavigationEventProvider.DiagramClickedListener() {
 62
 63            @Override
 64            public void onDiagramClicked(final Diagram p) {
 65
 66                notifyDiagramClickedListener(p);
 67            }
 68
 69        });
 70
 71
 72        navTree.addPointDeletedListeners(new NavigationEventProvider.PointDeletedListener() {
 73
 74            @Override
 75            public void onPointDeleted(final Point c) throws NimbitsException {
 76                notifyPointDeletedListener(c);
 77                center.removePoint(c);
 78            }
 79
 80        });
 81
 82        navTree.addDiagramDeletedListeners(new NavigationEventProvider.DiagramDeletedListener() {
 83
 84            @Override
 85            public void onDiagramDeleted(final Diagram c, final boolean readOnly) throws NimbitsException {
 86                notifyDiagramDeletedListener(c, readOnly);
 87            }
 88
 89        });
 90        return navTree;
 91
 92
 93    }
 94
 95
 96    public void addPoint(final Point point) {
 97        center.addPoint(point);
 98    }
 99
100
101    public MainPanel(final LoginInfo loginInfo, final boolean loadConnections) throws NimbitsException {
102
103        final BorderLayout layout = new BorderLayout();
104        this.emailAddress = loginInfo.getEmailAddress();
105        setLayout(layout);
106
107
108        final ContentPanel west = new ContentPanel();
109        final ContentPanel east = new ContentPanel();
110
111        east.setHeading("Connections");
112        if (loadConnections) {
113            ConnectionPanel connections = createConnections(loginInfo.getEmailAddress());
114            east.add(connections);
115        }
116
117        final NavigationPanel navigationPanel = createNavigationPanel();
118        navigationPanel.setLayout(new FillLayout());
119        west.add(navigationPanel);
120        west.setHeight("100%");
121        west.setHeading("Navigator");
122
123
124        final BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 250);
125        westData.setSplit(true);
126        westData.setCollapsible(true);
127        westData.setMargins(new Margins(5));
128
129        final BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
130        centerData.setMargins(new Margins(5, 5, 5, 0));
131
132        final BorderLayoutData eastData = new BorderLayoutData(LayoutRegion.EAST, 175);
133        eastData.setSplit(true);
134        eastData.setCollapsible(true);
135        eastData.setMargins(new Margins(5));
136
137        final BorderLayoutData southData = new BorderLayoutData(LayoutRegion.SOUTH,
138                125);
139        southData.setSplit(true);
140        southData.setCollapsible(true);
141        southData.setMargins(new Margins(0, 0, 0, 0));
142        west.setLayout(new FillLayout(Orientation.VERTICAL));
143
144        add(west, westData);
145        if (loadConnections) {
146            add(east, eastData);
147        }
148
149        center.setLayout(new FillLayout());
150        add(center, centerData);
151
152
153    }
154
155
156    private ConnectionPanel createConnections(final EmailAddress email) throws NimbitsException {
157        final ConnectionPanel connections = new ConnectionPanel(email);
158
159        connections.addCategoryClickedListeners(new NavigationEventProvider.CategoryClickedListener() {
160
161            @Override
162            public void onCategoryClicked(final Category c, boolean readOnly) throws NimbitsException {
163
164                notifyCategoryClickedListener(c, readOnly);
165
166            }
167
168        });
169
170        connections.addPointClickedListeners(new NavigationEventProvider.PointClickedListener() {
171
172            @Override
173            public void onPointClicked(final Point p) {
174
175                notifyPointClickedListener(p);
176            }
177
178        });
179        connections.addDiagramClickedListeners(new NavigationEventProvider.DiagramClickedListener() {
180
181            @Override
182            public void onDiagramClicked(final Diagram p) {
183
184                notifyDiagramClickedListener(p);
185            }
186
187        });
188
189        return connections;
190    }
191
192    public void addDiagram(final Diagram d) {
193        center.addDiagram(d);
194    }
195}