PageRenderTime 30ms CodeModel.GetById 16ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://nimbits-server.googlecode.com/
Java | 233 lines | 114 code | 60 blank | 59 comment | 1 complexity | ca5318063284bda441fa13d87164db54 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.event.Events;
 17import com.extjs.gxt.ui.client.event.Listener;
 18import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
 19import com.extjs.gxt.ui.client.store.ListStore;
 20import com.extjs.gxt.ui.client.util.Format;
 21import com.extjs.gxt.ui.client.widget.ContentPanel;
 22import com.extjs.gxt.ui.client.widget.ListView;
 23import com.extjs.gxt.ui.client.widget.layout.FillLayout;
 24import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
 25import com.google.gwt.core.client.GWT;
 26import com.google.gwt.user.client.Element;
 27import com.google.gwt.user.client.rpc.AsyncCallback;
 28import com.nimbits.client.exception.NimbitsException;
 29import com.nimbits.client.model.Const;
 30import com.nimbits.client.model.GxtUserModel;
 31import com.nimbits.client.model.category.Category;
 32import com.nimbits.client.model.diagram.Diagram;
 33import com.nimbits.client.model.email.EmailAddress;
 34import com.nimbits.client.model.point.Point;
 35import com.nimbits.client.model.user.User;
 36import com.nimbits.client.service.user.UserService;
 37import com.nimbits.client.service.user.UserServiceAsync;
 38
 39import java.util.List;
 40
 41class UserListPanel extends NavigationEventProvider {
 42    private final UserServiceAsync userService = GWT.create(UserService.class);
 43    // private NavigationPanel navTree;// = new NavTree();
 44    private final EmailAddress email;
 45
 46
 47    public UserListPanel(EmailAddress email) {
 48        setLayout(new FlowLayout(10));
 49        this.email = email;
 50
 51    }
 52
 53    @Override
 54    protected void onRender(Element parent, int index) {
 55        super.onRender(parent, index);
 56        final ListStore<GxtUserModel> store = new ListStore<GxtUserModel>();
 57
 58
 59        userService.getConnections(email, new AsyncCallback<List<User>>() {
 60
 61            @Override
 62            public void onFailure(Throwable caught) {
 63
 64
 65            }
 66
 67            @Override
 68            public void onSuccess(List<User> result) {
 69
 70                for (User n : result) {
 71
 72                    store.add(new GxtUserModel(n));
 73
 74                }
 75            }
 76
 77        });
 78
 79
 80        final ContentPanel panel = new ContentPanel();
 81        panel.setCollapsible(false);
 82        panel.setAnimCollapse(false);
 83        panel.setFrame(false);
 84        panel.setHeaderVisible(false);
 85
 86
 87        panel.setBorders(false);
 88        panel.setId("images-view");
 89
 90        // panel.setWidth(535);
 91        panel.setAutoHeight(true);
 92        panel.setBodyBorder(false);
 93
 94        ListView<GxtUserModel> view = new ListView<GxtUserModel>() {
 95            @Override
 96            protected GxtUserModel prepareData(GxtUserModel model) {
 97                String s = model.get(Const.PARAM_NAME);
 98                model.set("shortName", Format.ellipse(s, 15));
 99                model.set(Const.PARAM_PATH, model.get(Const.PARAM_PATH));
100
101                return model;
102            }
103
104        };
105
106        view.setTemplate(getTemplate());
107        view.setBorders(false);
108
109        view.setStore(store);
110        view.setItemSelector("div.thumb-wrap");
111        view.setWidth(100);
112        view.getSelectionModel().addListener(Events.SelectionChange,
113                new Listener<SelectionChangedEvent<GxtUserModel>>() {
114
115                    public void handleEvent(SelectionChangedEvent<GxtUserModel> be) {
116
117                        final NavigationPanel navigationPanel = createNavigationPanel(be.getSelectedItem().getEmail());
118                        navigationPanel.setLayout(new FillLayout());
119
120
121//                        initTree(true);
122                        //navigationPanel.setHeight(400);
123                        panel.removeAll();
124                        panel.add(navigationPanel);
125                        panel.setHeight("100%");
126                        //  panel.setHeight(800);
127                        //	 panel.setHeaderVisible(true);
128                        // panel.setHeading(be.getSelectedItem().getValue());
129                        doLayout();
130
131
132                    }
133
134                });
135        panel.add(view);
136        add(panel);
137    }
138
139    final NavigationPanel createNavigationPanel(final EmailAddress selectedEmail) {
140
141        final NavigationPanel navTree = new NavigationPanel(selectedEmail, true);
142
143        //  navTree.loadAuthTree();
144
145        navTree.addCategoryClickedListeners(new NavigationEventProvider.CategoryClickedListener() {
146
147            @Override
148            public void onCategoryClicked(final Category c, boolean readOnly) throws NimbitsException {
149
150                notifyCategoryClickedListener(c, readOnly);
151
152            }
153
154        });
155
156        navTree.addPointClickedListeners(new NavigationEventProvider.PointClickedListener() {
157
158            @Override
159            public void onPointClicked(final Point p) {
160
161                notifyPointClickedListener(p);
162            }
163
164        });
165
166        navTree.addDiagramClickedListeners(new NavigationEventProvider.DiagramClickedListener() {
167
168            @Override
169            public void onDiagramClicked(final Diagram p) {
170
171                notifyDiagramClickedListener(p);
172            }
173
174        });
175
176
177        navTree.addDiagramDeletedListeners(new NavigationEventProvider.DiagramDeletedListener() {
178
179            @Override
180            public void onDiagramDeleted(final Diagram c, final boolean readOnly) throws NimbitsException {
181                notifyDiagramDeletedListener(c, readOnly);
182            }
183
184        });
185        return navTree;
186
187
188    }
189
190//    private NavigationPanel createTree() {
191//        final NavigationPanel navTree = new NavigationPanel(anEmailAddress, true);
192//        navTree.addCategoryClickedListeners(new CategoryClickedListener() {
193//            @Override
194//            public void onCategoryClicked(final Category c, final boolean readOnly) throws NimbitsException {
195//                notifyCategoryClickedListener(c, readOnly);
196//            }
197//
198//        });
199//
200//        navTree.addPointClickedListeners(new PointClickedListener() {
201//
202//            @Override
203//            public void onPointClicked(final Point p) {
204//
205//                notifyPointClickedListener(p);
206//            }
207//
208//        });
209//        navTree.addDiagramClickedListeners(new NavigationEventProvider.DiagramClickedListener() {
210//
211//                    @Override
212//                    public void onDiagramClicked(Diagram p, String target) {
213//
214//                        notifyDiagramClickedListener(p, Const.WORD_BLANK);
215//                    }
216//
217//                });
218//        return navTree;
219//
220//    }
221
222    private native String getTemplate() /*-{
223        return ['<tpl for=".">',
224            '<div class="thumb-wrap" id="{name}" style="border: 0px solid white">',
225
226            '<div class="thumb"><img border="0px" src="{path}" title="{name}"></div>',
227            '<span class="x-editable">{shortName}</span></div>',
228            '</tpl>',
229            '<div class="x-clear"></div>'].join("");
230
231    }-*/;
232
233}