root / src / gr / ebs / gss / client / CellTreeViewModel.java @ 20211689
History | View | Annotate | Download (25.5 kB)
1 | e8b6efa2 | koutsoub | /*
|
---|---|---|---|
2 | e8b6efa2 | koutsoub | * Copyright 2011 Electronic Business Systems Ltd.
|
3 | e8b6efa2 | koutsoub | *
|
4 | e8b6efa2 | koutsoub | * This file is part of GSS.
|
5 | e8b6efa2 | koutsoub | *
|
6 | e8b6efa2 | koutsoub | * GSS is free software: you can redistribute it and/or modify
|
7 | e8b6efa2 | koutsoub | * it under the terms of the GNU General Public License as published by
|
8 | e8b6efa2 | koutsoub | * the Free Software Foundation, either version 3 of the License, or
|
9 | e8b6efa2 | koutsoub | * (at your option) any later version.
|
10 | e8b6efa2 | koutsoub | *
|
11 | e8b6efa2 | koutsoub | * GSS is distributed in the hope that it will be useful,
|
12 | e8b6efa2 | koutsoub | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | e8b6efa2 | koutsoub | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | e8b6efa2 | koutsoub | * GNU General Public License for more details.
|
15 | e8b6efa2 | koutsoub | *
|
16 | e8b6efa2 | koutsoub | * You should have received a copy of the GNU General Public License
|
17 | e8b6efa2 | koutsoub | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | e8b6efa2 | koutsoub | */
|
19 | e8b6efa2 | koutsoub | package gr.ebs.gss.client; |
20 | e8b6efa2 | koutsoub | |
21 | 1f959b7e | koutsoub | import static com.google.gwt.query.client.GQuery.$; |
22 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.CellTreeView.Images; |
23 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.CellTreeView.RefreshHandler; |
24 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.GetCommand; |
25 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.MultipleGetCommand; |
26 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.RestException; |
27 | 1a4a7064 | koutsoub | import gr.ebs.gss.client.rest.resource.FileResource; |
28 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.FolderResource; |
29 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.MyFolderResource; |
30 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.OtherUserResource; |
31 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.OthersFolderResource; |
32 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.OthersResource; |
33 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.RestResource; |
34 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.RestResourceWrapper; |
35 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.SharedFolderResource; |
36 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.SharedResource; |
37 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.TrashFolderResource; |
38 | e8b6efa2 | koutsoub | import gr.ebs.gss.client.rest.resource.TrashResource; |
39 | caf363d2 | koutsoub | import gwtquery.plugins.draggable.client.DragAndDropManager; |
40 | 1a4a7064 | koutsoub | import gwtquery.plugins.draggable.client.DraggableOptions; |
41 | 20211689 | koutsoub | import gwtquery.plugins.draggable.client.StopDragException; |
42 | 1a4a7064 | koutsoub | import gwtquery.plugins.draggable.client.DraggableOptions.CursorAt; |
43 | 1a4a7064 | koutsoub | import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction; |
44 | 1a4a7064 | koutsoub | import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption; |
45 | 1a4a7064 | koutsoub | import gwtquery.plugins.draggable.client.events.DragContext; |
46 | e8b6efa2 | koutsoub | import gwtquery.plugins.droppable.client.DroppableOptions; |
47 | e8b6efa2 | koutsoub | import gwtquery.plugins.droppable.client.DroppableOptions.DroppableFunction; |
48 | e8b6efa2 | koutsoub | import gwtquery.plugins.droppable.client.events.DragAndDropContext; |
49 | e8b6efa2 | koutsoub | import gwtquery.plugins.droppable.client.gwt.DragAndDropNodeInfo; |
50 | e8b6efa2 | koutsoub | |
51 | e8b6efa2 | koutsoub | import java.util.ArrayList; |
52 | 1a4a7064 | koutsoub | import java.util.Arrays; |
53 | e8b6efa2 | koutsoub | import java.util.HashMap; |
54 | e8b6efa2 | koutsoub | import java.util.List; |
55 | e8b6efa2 | koutsoub | import java.util.Map; |
56 | e8b6efa2 | koutsoub | |
57 | e8b6efa2 | koutsoub | import com.google.gwt.cell.client.AbstractCell; |
58 | e8b6efa2 | koutsoub | import com.google.gwt.cell.client.Cell; |
59 | e8b6efa2 | koutsoub | import com.google.gwt.cell.client.ValueUpdater; |
60 | e8b6efa2 | koutsoub | import com.google.gwt.core.client.GWT; |
61 | 1a4a7064 | koutsoub | import com.google.gwt.dom.client.Style.Cursor; |
62 | caf363d2 | koutsoub | import com.google.gwt.query.client.plugins.GQueryUi; |
63 | 1a4a7064 | koutsoub | import com.google.gwt.safehtml.client.SafeHtmlTemplates; |
64 | 1a4a7064 | koutsoub | import com.google.gwt.safehtml.shared.SafeHtml; |
65 | e8b6efa2 | koutsoub | import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
66 | e8b6efa2 | koutsoub | import com.google.gwt.user.client.DeferredCommand; |
67 | caf363d2 | koutsoub | import com.google.gwt.user.client.Window; |
68 | e8b6efa2 | koutsoub | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
69 | e8b6efa2 | koutsoub | import com.google.gwt.view.client.AsyncDataProvider; |
70 | e8b6efa2 | koutsoub | import com.google.gwt.view.client.HasData; |
71 | e8b6efa2 | koutsoub | import com.google.gwt.view.client.ListDataProvider; |
72 | e8b6efa2 | koutsoub | import com.google.gwt.view.client.ProvidesKey; |
73 | e8b6efa2 | koutsoub | import com.google.gwt.view.client.SingleSelectionModel; |
74 | e8b6efa2 | koutsoub | import com.google.gwt.view.client.TreeViewModel; |
75 | e8b6efa2 | koutsoub | |
76 | e8b6efa2 | koutsoub | |
77 | e8b6efa2 | koutsoub | |
78 | e8b6efa2 | koutsoub | /**
|
79 | e8b6efa2 | koutsoub | * @author kman
|
80 | e8b6efa2 | koutsoub | *
|
81 | e8b6efa2 | koutsoub | */
|
82 | e8b6efa2 | koutsoub | public class CellTreeViewModel implements TreeViewModel{ |
83 | 20211689 | koutsoub | |
84 | e8b6efa2 | koutsoub | private final ListDataProvider<RestResource> rootNodes = new ListDataProvider<RestResource>(); |
85 | 56c1ca4b | koutsoub | private Map<String,FolderResource> folderCache=new HashMap<String, FolderResource>(); |
86 | e8b6efa2 | koutsoub | final Images images;
|
87 | e8b6efa2 | koutsoub | SingleSelectionModel<RestResource> selectionModel;
|
88 | e8b6efa2 | koutsoub | Map<String, MyFolderDataProvider> mymap = new HashMap<String, MyFolderDataProvider>(); |
89 | caf363d2 | koutsoub | Map<String, MyFolderDataProvider> sharedmap = new HashMap<String, MyFolderDataProvider>(); |
90 | caf363d2 | koutsoub | Map<String, MyFolderDataProvider> othersmap = new HashMap<String, MyFolderDataProvider>(); |
91 | 1a4a7064 | koutsoub | static interface Templates extends SafeHtmlTemplates { |
92 | 1a4a7064 | koutsoub | Templates INSTANCE = GWT.create(Templates.class); |
93 | 1a4a7064 | koutsoub | |
94 | 1a4a7064 | koutsoub | @Template(" <div id='dragHelper' class='{0}'></div>") |
95 | 1a4a7064 | koutsoub | SafeHtml outerHelper(String cssClassName);
|
96 | 1a4a7064 | koutsoub | } |
97 | 1a4a7064 | koutsoub | |
98 | 20211689 | koutsoub | static void configureDragOperation(final DraggableOptions options) { |
99 | 1a4a7064 | koutsoub | |
100 | 1a4a7064 | koutsoub | // set a custom element as drag helper. The content of the helper will be
|
101 | 1a4a7064 | koutsoub | // set when the drag will start
|
102 | 1a4a7064 | koutsoub | options.setHelper($(Templates.INSTANCE.outerHelper( |
103 | 1a4a7064 | koutsoub | "drag").asString()));
|
104 | 1a4a7064 | koutsoub | // opacity of the drag helper
|
105 | 1a4a7064 | koutsoub | options.setOpacity((float) 0.9); |
106 | 1a4a7064 | koutsoub | // cursor during the drag operation
|
107 | 1a4a7064 | koutsoub | options.setCursor(Cursor.MOVE);
|
108 | 1a4a7064 | koutsoub | // the cell being greater than the helper, force the position of the
|
109 | 1a4a7064 | koutsoub | // helper on the mouse cursor.
|
110 | 1a4a7064 | koutsoub | options.setCursorAt(new CursorAt(10, 10, null, null)); |
111 | 1a4a7064 | koutsoub | // append the helper to the body element
|
112 | 1a4a7064 | koutsoub | options.setAppendTo("body");
|
113 | 1a4a7064 | koutsoub | // set the revert option
|
114 | 1a4a7064 | koutsoub | options.setRevert(RevertOption.ON_INVALID_DROP); |
115 | 20211689 | koutsoub | options.setOnBeforeDragStart(new DragFunction() {
|
116 | 20211689 | koutsoub | |
117 | 20211689 | koutsoub | @Override
|
118 | 20211689 | koutsoub | public void f(DragContext context) { |
119 | 20211689 | koutsoub | RestResource value = context.getDraggableData(); |
120 | 20211689 | koutsoub | if(value instanceof TrashResource || value instanceof SharedResource || value instanceof OthersResource || value instanceof OtherUserResource){ |
121 | 20211689 | koutsoub | throw new StopDragException(); |
122 | 20211689 | koutsoub | } |
123 | 20211689 | koutsoub | |
124 | 20211689 | koutsoub | } |
125 | 20211689 | koutsoub | }); |
126 | 1a4a7064 | koutsoub | // use a Function to fill the content of the helper
|
127 | 1a4a7064 | koutsoub | // we could also add a DragStartEventHandler on the DragAndDropTreeCell and
|
128 | 1a4a7064 | koutsoub | // DragAndDropCellList.
|
129 | 20211689 | koutsoub | |
130 | 1a4a7064 | koutsoub | options.setOnDragStart(new DragFunction() {
|
131 | 1a4a7064 | koutsoub | public void f(DragContext context) { |
132 | 1a4a7064 | koutsoub | RestResourceWrapper memberInfo = context.getDraggableData(); |
133 | 1a4a7064 | koutsoub | context.getHelper().setInnerHTML(memberInfo.getName()); |
134 | 1a4a7064 | koutsoub | } |
135 | 1a4a7064 | koutsoub | }); |
136 | 1a4a7064 | koutsoub | |
137 | 1a4a7064 | koutsoub | } |
138 | 1a4a7064 | koutsoub | |
139 | e8b6efa2 | koutsoub | /**
|
140 | e8b6efa2 | koutsoub | *
|
141 | e8b6efa2 | koutsoub | */
|
142 | e8b6efa2 | koutsoub | public CellTreeViewModel(final Images _images,SingleSelectionModel<RestResource> selectionModel ) { |
143 | e8b6efa2 | koutsoub | super();
|
144 | e8b6efa2 | koutsoub | images=_images; |
145 | e8b6efa2 | koutsoub | this.selectionModel=selectionModel;
|
146 | e8b6efa2 | koutsoub | } |
147 | e8b6efa2 | koutsoub | |
148 | e8b6efa2 | koutsoub | private final Cell<RestResource> departmentCell = new AbstractCell<RestResource>("contextmenu"){ |
149 | e8b6efa2 | koutsoub | |
150 | e8b6efa2 | koutsoub | @Override
|
151 | e8b6efa2 | koutsoub | public void render(com.google.gwt.cell.client.Cell.Context arg0, RestResource arg1, SafeHtmlBuilder arg2) { |
152 | adbda23d | Natasa Kapravelou | String id = null; |
153 | adbda23d | Natasa Kapravelou | String html = null; |
154 | adbda23d | Natasa Kapravelou | String name = null; |
155 | e8b6efa2 | koutsoub | if(arg1 instanceof TrashFolderResource){ |
156 | e8b6efa2 | koutsoub | html = AbstractImagePrototype.create(images.folderYellow()).getHTML(); |
157 | e8b6efa2 | koutsoub | FolderResource res = ((RestResourceWrapper)arg1).getResource(); |
158 | adbda23d | Natasa Kapravelou | name = res.getName(); |
159 | adbda23d | Natasa Kapravelou | id = res.getParentName() +"."+name;
|
160 | e8b6efa2 | koutsoub | } |
161 | e8b6efa2 | koutsoub | else if(arg1 instanceof RestResourceWrapper){ |
162 | e8b6efa2 | koutsoub | FolderResource res = ((RestResourceWrapper)arg1).getResource(); |
163 | e8b6efa2 | koutsoub | if(res.isShared())
|
164 | e8b6efa2 | koutsoub | html = AbstractImagePrototype.create(images.sharedFolder()).getHTML(); |
165 | e8b6efa2 | koutsoub | else if(res.getParentName()==null){ |
166 | e8b6efa2 | koutsoub | html = AbstractImagePrototype.create(images.home()).getHTML(); |
167 | e8b6efa2 | koutsoub | } |
168 | e8b6efa2 | koutsoub | else
|
169 | e8b6efa2 | koutsoub | html = AbstractImagePrototype.create(images.folderYellow()).getHTML(); |
170 | e8b6efa2 | koutsoub | name = res.getName(); |
171 | adbda23d | Natasa Kapravelou | if(res.getParentName() != null){ |
172 | adbda23d | Natasa Kapravelou | id = res.getParentName()+"."+name;
|
173 | adbda23d | Natasa Kapravelou | }else{
|
174 | adbda23d | Natasa Kapravelou | id = name; |
175 | adbda23d | Natasa Kapravelou | } |
176 | e8b6efa2 | koutsoub | |
177 | e8b6efa2 | koutsoub | } |
178 | e8b6efa2 | koutsoub | else if(arg1 instanceof TrashResource){ |
179 | e8b6efa2 | koutsoub | html = AbstractImagePrototype.create(images.trash()).getHTML(); |
180 | e8b6efa2 | koutsoub | name="Trash";
|
181 | adbda23d | Natasa Kapravelou | id = name; |
182 | e8b6efa2 | koutsoub | } |
183 | e8b6efa2 | koutsoub | |
184 | e8b6efa2 | koutsoub | else if(arg1 instanceof SharedResource){ |
185 | e8b6efa2 | koutsoub | html = AbstractImagePrototype.create(images.myShared()).getHTML(); |
186 | adbda23d | Natasa Kapravelou | name = "My Shared";
|
187 | adbda23d | Natasa Kapravelou | id = name; |
188 | e8b6efa2 | koutsoub | } |
189 | e8b6efa2 | koutsoub | else if(arg1 instanceof OthersResource){ |
190 | e8b6efa2 | koutsoub | html = AbstractImagePrototype.create(images.othersShared()).getHTML(); |
191 | e8b6efa2 | koutsoub | name = "Other's Shared";
|
192 | adbda23d | Natasa Kapravelou | id = "others";
|
193 | e8b6efa2 | koutsoub | } |
194 | e8b6efa2 | koutsoub | else if(arg1 instanceof OtherUserResource){ |
195 | e8b6efa2 | koutsoub | html = AbstractImagePrototype.create(images.permUser()).getHTML(); |
196 | e8b6efa2 | koutsoub | name = ((OtherUserResource)arg1).getName(); |
197 | adbda23d | Natasa Kapravelou | id = name; |
198 | e8b6efa2 | koutsoub | } |
199 | e8b6efa2 | koutsoub | arg2.appendHtmlConstant(html); |
200 | adbda23d | Natasa Kapravelou | arg2.appendHtmlConstant("<span id='"+id +"'"+ " class='papala'>"); |
201 | e8b6efa2 | koutsoub | arg2.appendEscaped(name); |
202 | e8b6efa2 | koutsoub | arg2.appendHtmlConstant("</span>");
|
203 | e8b6efa2 | koutsoub | } |
204 | e8b6efa2 | koutsoub | |
205 | e8b6efa2 | koutsoub | public void onBrowserEvent(Cell.Context context, com.google.gwt.dom.client.Element parent, RestResource value, com.google.gwt.dom.client.NativeEvent event, com.google.gwt.cell.client.ValueUpdater<RestResource> valueUpdater) { |
206 | e8b6efa2 | koutsoub | if(event.getType().equals("contextmenu")){ |
207 | e8b6efa2 | koutsoub | selectionModel.setSelected(value, true);
|
208 | e8b6efa2 | koutsoub | GSS.get().getTreeView().showPopup(event.getClientX(), event.getClientY()); |
209 | e8b6efa2 | koutsoub | } |
210 | e8b6efa2 | koutsoub | }; |
211 | e8b6efa2 | koutsoub | |
212 | e8b6efa2 | koutsoub | }; |
213 | e8b6efa2 | koutsoub | |
214 | e8b6efa2 | koutsoub | |
215 | e8b6efa2 | koutsoub | @Override
|
216 | 1a4a7064 | koutsoub | public <T> NodeInfo<?> getNodeInfo(final T value) { |
217 | e8b6efa2 | koutsoub | |
218 | e8b6efa2 | koutsoub | if(value==null){ |
219 | 20211689 | koutsoub | DragAndDropNodeInfo n = new DragAndDropNodeInfo<RestResource>(getRootNodes(), departmentCell,
|
220 | e8b6efa2 | koutsoub | selectionModel, null);
|
221 | 20211689 | koutsoub | configureFolderDrop(n); |
222 | 20211689 | koutsoub | configureDragOperation(n.getDraggableOptions()); |
223 | 20211689 | koutsoub | return n;
|
224 | e8b6efa2 | koutsoub | } |
225 | e8b6efa2 | koutsoub | else if (value instanceof MyFolderResource) { |
226 | e8b6efa2 | koutsoub | // Second level.
|
227 | e8b6efa2 | koutsoub | MyFolderDataProvider dataProvider = new MyFolderDataProvider(
|
228 | e8b6efa2 | koutsoub | ((MyFolderResource) value),MyFolderResource.class); |
229 | e8b6efa2 | koutsoub | DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
|
230 | e8b6efa2 | koutsoub | selectionModel, new ResourceValueUpdater());
|
231 | caf363d2 | koutsoub | |
232 | e8b6efa2 | koutsoub | //nodeInfos.put(((MyFolderResource) value).getUri(), n);
|
233 | e8b6efa2 | koutsoub | mymap.put(((MyFolderResource) value).getUri(), dataProvider); |
234 | 20211689 | koutsoub | |
235 | e8b6efa2 | koutsoub | // permission cell are not draggable
|
236 | 1a4a7064 | koutsoub | //n.setCellDroppableOnly();
|
237 | 20211689 | koutsoub | configureFolderDrop(n); |
238 | 1a4a7064 | koutsoub | configureDragOperation(n.getDraggableOptions()); |
239 | caf363d2 | koutsoub | |
240 | e8b6efa2 | koutsoub | return n;
|
241 | e8b6efa2 | koutsoub | } |
242 | e8b6efa2 | koutsoub | else if (value instanceof SharedResource) { |
243 | e8b6efa2 | koutsoub | // Second level.
|
244 | e8b6efa2 | koutsoub | MyFolderDataProvider dataProvider = new MyFolderDataProvider(
|
245 | e8b6efa2 | koutsoub | ((SharedResource) value), SharedFolderResource.class); |
246 | caf363d2 | koutsoub | sharedmap.put(((SharedResource) value).getUri(), dataProvider); |
247 | 20211689 | koutsoub | DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
|
248 | e8b6efa2 | koutsoub | selectionModel, new ResourceValueUpdater());
|
249 | 20211689 | koutsoub | configureFolderDrop(n); |
250 | 20211689 | koutsoub | configureDragOperation(n.getDraggableOptions()); |
251 | 20211689 | koutsoub | return n;
|
252 | e8b6efa2 | koutsoub | } |
253 | e8b6efa2 | koutsoub | else if (value instanceof TrashResource) { |
254 | e8b6efa2 | koutsoub | // Second level.
|
255 | e8b6efa2 | koutsoub | ListDataProvider<RestResource> trashProvider = new ListDataProvider<RestResource>();
|
256 | e8b6efa2 | koutsoub | List<RestResource> r = new ArrayList<RestResource>(); |
257 | e8b6efa2 | koutsoub | for(FolderResource f : GSS.get().getTreeView().getTrash().getFolders()){
|
258 | e8b6efa2 | koutsoub | r.add(new TrashFolderResource(f));
|
259 | e8b6efa2 | koutsoub | } |
260 | e8b6efa2 | koutsoub | trashProvider.setList(r); |
261 | 20211689 | koutsoub | DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(trashProvider, departmentCell,
|
262 | e8b6efa2 | koutsoub | selectionModel, new ResourceValueUpdater());
|
263 | 20211689 | koutsoub | configureFolderDrop(n); |
264 | 20211689 | koutsoub | configureDragOperation(n.getDraggableOptions()); |
265 | 20211689 | koutsoub | return n;
|
266 | e8b6efa2 | koutsoub | } |
267 | e8b6efa2 | koutsoub | else if (value instanceof OthersResource) { |
268 | e8b6efa2 | koutsoub | // Second level.
|
269 | e8b6efa2 | koutsoub | OthersDataProvider dataProvider = new OthersDataProvider(
|
270 | e8b6efa2 | koutsoub | ((OthersResource) value), SharedFolderResource.class); |
271 | 20211689 | koutsoub | DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
|
272 | e8b6efa2 | koutsoub | selectionModel, null);
|
273 | 20211689 | koutsoub | configureFolderDrop(n); |
274 | 20211689 | koutsoub | configureDragOperation(n.getDraggableOptions()); |
275 | 20211689 | koutsoub | return n;
|
276 | e8b6efa2 | koutsoub | } |
277 | e8b6efa2 | koutsoub | else if (value instanceof SharedFolderResource) { |
278 | e8b6efa2 | koutsoub | // Second level.
|
279 | e8b6efa2 | koutsoub | MyFolderDataProvider dataProvider = new MyFolderDataProvider(
|
280 | e8b6efa2 | koutsoub | ((SharedFolderResource) value),SharedFolderResource.class); |
281 | e8b6efa2 | koutsoub | DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
|
282 | e8b6efa2 | koutsoub | selectionModel, new ResourceValueUpdater());
|
283 | caf363d2 | koutsoub | sharedmap.put(((SharedFolderResource) value).getUri(), dataProvider); |
284 | 20211689 | koutsoub | configureFolderDrop(n); |
285 | 20211689 | koutsoub | configureDragOperation(n.getDraggableOptions()); |
286 | e8b6efa2 | koutsoub | return n;
|
287 | e8b6efa2 | koutsoub | } |
288 | e8b6efa2 | koutsoub | else if (value instanceof OthersFolderResource) { |
289 | e8b6efa2 | koutsoub | // Second level.
|
290 | e8b6efa2 | koutsoub | MyFolderDataProvider dataProvider = new MyFolderDataProvider(
|
291 | e8b6efa2 | koutsoub | ((OthersFolderResource) value),OthersFolderResource.class); |
292 | e8b6efa2 | koutsoub | DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
|
293 | e8b6efa2 | koutsoub | selectionModel, new ResourceValueUpdater());
|
294 | e8b6efa2 | koutsoub | //nodeInfos.put(((OthersFolderResource) value).getUri(), n);
|
295 | caf363d2 | koutsoub | othersmap.put(((SharedFolderResource) value).getUri(), dataProvider); |
296 | 20211689 | koutsoub | configureFolderDrop(n); |
297 | 20211689 | koutsoub | configureDragOperation(n.getDraggableOptions()); |
298 | e8b6efa2 | koutsoub | return n;
|
299 | e8b6efa2 | koutsoub | } |
300 | e8b6efa2 | koutsoub | else if (value instanceof OtherUserResource) { |
301 | e8b6efa2 | koutsoub | // Second level.
|
302 | e8b6efa2 | koutsoub | MyFolderDataProvider dataProvider = new MyFolderDataProvider(
|
303 | e8b6efa2 | koutsoub | ((OtherUserResource) value),OthersFolderResource.class); |
304 | e8b6efa2 | koutsoub | DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
|
305 | e8b6efa2 | koutsoub | selectionModel, new ResourceValueUpdater());
|
306 | 20211689 | koutsoub | configureFolderDrop(n); |
307 | 20211689 | koutsoub | configureDragOperation(n.getDraggableOptions()); |
308 | e8b6efa2 | koutsoub | return n;
|
309 | e8b6efa2 | koutsoub | } |
310 | e8b6efa2 | koutsoub | // TODO Auto-generated method stub
|
311 | e8b6efa2 | koutsoub | return null; |
312 | e8b6efa2 | koutsoub | } |
313 | 20211689 | koutsoub | |
314 | 20211689 | koutsoub | private void configureFolderDrop(DragAndDropNodeInfo<RestResource> n){ |
315 | 20211689 | koutsoub | DroppableOptions options = n.getDroppableOptions(); |
316 | 20211689 | koutsoub | options.setDroppableHoverClass("droppableHover");
|
317 | 20211689 | koutsoub | // use a DroppableFunction here. We can also add a DropHandler in the tree
|
318 | 20211689 | koutsoub | // itself
|
319 | 20211689 | koutsoub | |
320 | 20211689 | koutsoub | options.setOnOver(new DroppableFunction() {
|
321 | 20211689 | koutsoub | |
322 | 20211689 | koutsoub | @Override
|
323 | 20211689 | koutsoub | public void f(final DragAndDropContext context) { |
324 | 20211689 | koutsoub | if(context.getDroppableData()!=null && context.getDroppableData() instanceof RestResource){ |
325 | 20211689 | koutsoub | |
326 | 20211689 | koutsoub | GSS.get().getTreeView().getUtils().openNodeContainingResource((RestResource) context.getDroppableData(), new RefreshHandler() {
|
327 | 20211689 | koutsoub | |
328 | 20211689 | koutsoub | @Override
|
329 | 20211689 | koutsoub | public void onRefresh() { |
330 | 20211689 | koutsoub | |
331 | 20211689 | koutsoub | DragAndDropManager.getInstance().update(context);//initialize(context, GQueryUi.Event.create(com.google.gwt.user.client.Event.getCurrentEvent()));
|
332 | 20211689 | koutsoub | |
333 | 20211689 | koutsoub | } |
334 | 20211689 | koutsoub | }); |
335 | 20211689 | koutsoub | |
336 | 20211689 | koutsoub | } |
337 | 20211689 | koutsoub | |
338 | 20211689 | koutsoub | |
339 | 20211689 | koutsoub | |
340 | 20211689 | koutsoub | } |
341 | 20211689 | koutsoub | }); |
342 | 20211689 | koutsoub | options.setOnDrop(new DroppableFunction() {
|
343 | 20211689 | koutsoub | |
344 | 20211689 | koutsoub | public void f(DragAndDropContext context) { |
345 | 20211689 | koutsoub | |
346 | 20211689 | koutsoub | DnDFolderPopupMenu popup ; |
347 | 20211689 | koutsoub | if(context.getDraggableData() instanceof FileResource){ |
348 | 20211689 | koutsoub | popup = new DnDFolderPopupMenu(images, ((MyFolderResource) context.getDroppableData()).getResource(), Arrays.asList(context.getDraggableData())); |
349 | 20211689 | koutsoub | } |
350 | 20211689 | koutsoub | else
|
351 | 20211689 | koutsoub | popup = new DnDFolderPopupMenu(images, ((MyFolderResource) context.getDroppableData()).getResource(), context.getDraggableData());
|
352 | 20211689 | koutsoub | int left = context.getDroppable().getAbsoluteLeft() + 40; |
353 | 20211689 | koutsoub | int top = context.getDroppable().getAbsoluteTop() + 20; |
354 | 20211689 | koutsoub | popup.setPopupPosition(left, top); |
355 | 20211689 | koutsoub | |
356 | 20211689 | koutsoub | popup.show(); |
357 | 20211689 | koutsoub | } |
358 | 20211689 | koutsoub | }); |
359 | 20211689 | koutsoub | } |
360 | e8b6efa2 | koutsoub | |
361 | e8b6efa2 | koutsoub | @Override
|
362 | e8b6efa2 | koutsoub | public boolean isLeaf(Object value) { |
363 | e8b6efa2 | koutsoub | if(value instanceof RestResourceWrapper) |
364 | e8b6efa2 | koutsoub | return ((RestResourceWrapper)value).getResource().getFolders().size()==0; |
365 | 802a2ef5 | koutsoub | else if(value instanceof TrashResource) |
366 | e8b6efa2 | koutsoub | return ((TrashResource)value).getFolders().size()==0; |
367 | 802a2ef5 | koutsoub | else if(value instanceof SharedResource) |
368 | 802a2ef5 | koutsoub | return ((SharedResource)value).getFolders().size()==0; |
369 | 802a2ef5 | koutsoub | else if(value instanceof OthersResource) |
370 | 802a2ef5 | koutsoub | return ((OthersResource)value).getOtherUsers().size()==0; |
371 | 802a2ef5 | koutsoub | else if(value instanceof OtherUserResource) |
372 | 802a2ef5 | koutsoub | return ((OtherUserResource)value).getFolders().size()==0; |
373 | e8b6efa2 | koutsoub | return false; |
374 | e8b6efa2 | koutsoub | } |
375 | e8b6efa2 | koutsoub | |
376 | e8b6efa2 | koutsoub | class ResourceValueUpdater implements ValueUpdater<RestResource>{ |
377 | e8b6efa2 | koutsoub | |
378 | e8b6efa2 | koutsoub | @Override
|
379 | e8b6efa2 | koutsoub | public void update(final RestResource value) { |
380 | e8b6efa2 | koutsoub | if(value instanceof MyFolderResource){ |
381 | e8b6efa2 | koutsoub | GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, value.getUri(), null) { |
382 | e8b6efa2 | koutsoub | |
383 | e8b6efa2 | koutsoub | @Override
|
384 | e8b6efa2 | koutsoub | public void onComplete() { |
385 | e8b6efa2 | koutsoub | FolderResource rootResource = getResult(); |
386 | 56c1ca4b | koutsoub | //((MyFolderResource)value).getResource().setFiles(rootResource.getFiles());
|
387 | 56c1ca4b | koutsoub | ((MyFolderResource)value).setResource(rootResource); |
388 | e8b6efa2 | koutsoub | if(GSS.get().getTreeView().getSelection().getUri().equals(value.getUri()))
|
389 | e8b6efa2 | koutsoub | selectionModel.setSelected(value, true);
|
390 | e8b6efa2 | koutsoub | GSS.get().onResourceUpdate(value); |
391 | e8b6efa2 | koutsoub | |
392 | e8b6efa2 | koutsoub | } |
393 | e8b6efa2 | koutsoub | |
394 | e8b6efa2 | koutsoub | @Override
|
395 | e8b6efa2 | koutsoub | public void onError(Throwable t) { |
396 | e8b6efa2 | koutsoub | GWT.log("Error fetching root folder", t);
|
397 | e8b6efa2 | koutsoub | GSS.get().displayError("Unable to fetch root folder");
|
398 | e8b6efa2 | koutsoub | } |
399 | e8b6efa2 | koutsoub | |
400 | e8b6efa2 | koutsoub | }; |
401 | e8b6efa2 | koutsoub | DeferredCommand.addCommand(gf); |
402 | e8b6efa2 | koutsoub | } |
403 | caf363d2 | koutsoub | else if(value instanceof TrashResource){ |
404 | e8b6efa2 | koutsoub | DeferredCommand.addCommand(new GetCommand<TrashResource>(TrashResource.class, GSS.get().getCurrentUserResource().getTrashPath(), null) { |
405 | e8b6efa2 | koutsoub | @Override
|
406 | e8b6efa2 | koutsoub | public void onComplete() { |
407 | e8b6efa2 | koutsoub | //trash = getResult();
|
408 | e8b6efa2 | koutsoub | for(RestResource r : getRootNodes().getList()){
|
409 | e8b6efa2 | koutsoub | if(r instanceof TrashResource) |
410 | e8b6efa2 | koutsoub | getRootNodes().getList().set(getRootNodes().getList().indexOf(r),GSS.get().getTreeView().getTrash()); |
411 | e8b6efa2 | koutsoub | } |
412 | e8b6efa2 | koutsoub | GSS.get().getTreeView().updateNodeChildren(GSS.get().getTreeView().getTrash()); |
413 | e8b6efa2 | koutsoub | } |
414 | e8b6efa2 | koutsoub | |
415 | e8b6efa2 | koutsoub | @Override
|
416 | e8b6efa2 | koutsoub | public void onError(Throwable t) { |
417 | e8b6efa2 | koutsoub | if(t instanceof RestException){ |
418 | e8b6efa2 | koutsoub | int statusCode = ((RestException)t).getHttpStatusCode();
|
419 | e8b6efa2 | koutsoub | // On IE status code 1223 may be returned instead of 204.
|
420 | e8b6efa2 | koutsoub | if(statusCode == 204 || statusCode == 1223){ |
421 | e8b6efa2 | koutsoub | //trash = new TrashResource(GSS.get().getCurrentUserResource().getTrashPath());
|
422 | e8b6efa2 | koutsoub | } |
423 | e8b6efa2 | koutsoub | else{
|
424 | e8b6efa2 | koutsoub | GWT.log("", t);
|
425 | e8b6efa2 | koutsoub | GSS.get().displayError("Unable to fetch trash folder:"+t.getMessage());
|
426 | e8b6efa2 | koutsoub | //GSS.get().getTreeView().getTrash() = new TrashResource(GSS.get().getCurrentUserResource().getTrashPath());
|
427 | e8b6efa2 | koutsoub | } |
428 | e8b6efa2 | koutsoub | } |
429 | e8b6efa2 | koutsoub | } |
430 | e8b6efa2 | koutsoub | }); |
431 | e8b6efa2 | koutsoub | } |
432 | caf363d2 | koutsoub | else if(value instanceof OthersFolderResource){ |
433 | caf363d2 | koutsoub | |
434 | caf363d2 | koutsoub | } |
435 | e8b6efa2 | koutsoub | |
436 | e8b6efa2 | koutsoub | } |
437 | e8b6efa2 | koutsoub | |
438 | e8b6efa2 | koutsoub | } |
439 | e8b6efa2 | koutsoub | class MyFolderDataProvider extends AsyncDataProvider<RestResource>{ |
440 | e8b6efa2 | koutsoub | private RestResource restResource;
|
441 | e8b6efa2 | koutsoub | private Class resourceClass; |
442 | e8b6efa2 | koutsoub | public MyFolderDataProvider(RestResource department, Class resourceClass) { |
443 | e8b6efa2 | koutsoub | super(new ProvidesKey<RestResource>() { |
444 | e8b6efa2 | koutsoub | |
445 | e8b6efa2 | koutsoub | @Override
|
446 | e8b6efa2 | koutsoub | public Object getKey(RestResource item) { |
447 | e8b6efa2 | koutsoub | return item.getUri();
|
448 | e8b6efa2 | koutsoub | }}); |
449 | e8b6efa2 | koutsoub | this.restResource = department;
|
450 | e8b6efa2 | koutsoub | this.resourceClass=resourceClass;
|
451 | 20211689 | koutsoub | //getMymap().put(department.getUri(), MyFolderDataProvider.this);
|
452 | e8b6efa2 | koutsoub | } |
453 | e8b6efa2 | koutsoub | |
454 | e8b6efa2 | koutsoub | @Override
|
455 | e8b6efa2 | koutsoub | protected void onRangeChanged(final HasData<RestResource> view) { |
456 | e8b6efa2 | koutsoub | refresh(null);
|
457 | e8b6efa2 | koutsoub | } |
458 | e8b6efa2 | koutsoub | |
459 | e8b6efa2 | koutsoub | /**
|
460 | e8b6efa2 | koutsoub | * Retrieve the restResource.
|
461 | e8b6efa2 | koutsoub | *
|
462 | e8b6efa2 | koutsoub | * @return the restResource
|
463 | e8b6efa2 | koutsoub | */
|
464 | e8b6efa2 | koutsoub | public RestResource getRestResource() {
|
465 | e8b6efa2 | koutsoub | return restResource;
|
466 | e8b6efa2 | koutsoub | } |
467 | e8b6efa2 | koutsoub | |
468 | e8b6efa2 | koutsoub | |
469 | e8b6efa2 | koutsoub | /**
|
470 | e8b6efa2 | koutsoub | * Modify the restResource.
|
471 | e8b6efa2 | koutsoub | *
|
472 | e8b6efa2 | koutsoub | * @param restResource the restResource to set
|
473 | e8b6efa2 | koutsoub | */
|
474 | e8b6efa2 | koutsoub | public void setRestResource(RestResource restResource) { |
475 | e8b6efa2 | koutsoub | this.restResource = restResource;
|
476 | e8b6efa2 | koutsoub | } |
477 | 56c1ca4b | koutsoub | List<RestResource> res =null; |
478 | e8b6efa2 | koutsoub | public void refresh(final RefreshHandler refresh){ |
479 | 56c1ca4b | koutsoub | FolderResource cache = null;
|
480 | ad9133fe | koutsoub | if(restResource instanceof RestResourceWrapper && !((RestResourceWrapper)restResource).getResource().isNeedsExpanding()) |
481 | 56c1ca4b | koutsoub | cache = ((RestResourceWrapper)restResource).getResource(); |
482 | 56c1ca4b | koutsoub | GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, restResource.getUri(),cache ) {
|
483 | e8b6efa2 | koutsoub | |
484 | e8b6efa2 | koutsoub | @Override
|
485 | e8b6efa2 | koutsoub | public void onComplete() { |
486 | ad9133fe | koutsoub | if(restResource instanceof RestResourceWrapper){ |
487 | e8b6efa2 | koutsoub | ((RestResourceWrapper)restResource).setResource(getResult());//restResource = getResult();
|
488 | ad9133fe | koutsoub | ((RestResourceWrapper)restResource).getResource().setNeedsExpanding(false);
|
489 | ad9133fe | koutsoub | } |
490 | 56c1ca4b | koutsoub | if(usedCachedVersion()&&res!=null){ |
491 | caf363d2 | koutsoub | |
492 | caf363d2 | koutsoub | updateRowCount(res.size(), true);
|
493 | caf363d2 | koutsoub | updateRowData(0,res);
|
494 | 56c1ca4b | koutsoub | return;
|
495 | 56c1ca4b | koutsoub | } |
496 | e8b6efa2 | koutsoub | String[] folderPaths = null; |
497 | e8b6efa2 | koutsoub | if(resourceClass.equals(MyFolderResource.class))
|
498 | e8b6efa2 | koutsoub | folderPaths=((MyFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {}); |
499 | e8b6efa2 | koutsoub | else if(resourceClass.equals(SharedFolderResource.class) && restResource instanceof SharedResource) |
500 | e8b6efa2 | koutsoub | folderPaths=((SharedResource) restResource).getSubfolderPaths().toArray(new String[] {}); |
501 | e8b6efa2 | koutsoub | else if(resourceClass.equals(SharedFolderResource.class)){ |
502 | e8b6efa2 | koutsoub | folderPaths=((SharedFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {}); |
503 | e8b6efa2 | koutsoub | GWT.log("------------>"+folderPaths);
|
504 | e8b6efa2 | koutsoub | } |
505 | e8b6efa2 | koutsoub | else if(resourceClass.equals(TrashFolderResource.class)) |
506 | e8b6efa2 | koutsoub | folderPaths=((TrashFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {}); |
507 | e8b6efa2 | koutsoub | else if(resourceClass.equals(OthersFolderResource.class) && restResource instanceof OtherUserResource) |
508 | e8b6efa2 | koutsoub | folderPaths=((OtherUserResource) restResource).getSubfolderPaths().toArray(new String[] {}); |
509 | e8b6efa2 | koutsoub | else if(resourceClass.equals(OthersFolderResource.class)) |
510 | e8b6efa2 | koutsoub | folderPaths=((OthersFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {}); |
511 | ad9133fe | koutsoub | MultipleGetCommand.Cached[] cached = null; |
512 | ad9133fe | koutsoub | if(restResource instanceof RestResourceWrapper) |
513 | ad9133fe | koutsoub | cached=((RestResourceWrapper)restResource).getResource().getCache(); |
514 | e8b6efa2 | koutsoub | MultipleGetCommand<FolderResource> gf2 = new MultipleGetCommand<FolderResource>(FolderResource.class,
|
515 | ad9133fe | koutsoub | folderPaths, cached) { |
516 | e8b6efa2 | koutsoub | |
517 | e8b6efa2 | koutsoub | @Override
|
518 | e8b6efa2 | koutsoub | public void onComplete() { |
519 | 56c1ca4b | koutsoub | res = new ArrayList<RestResource>(); |
520 | e8b6efa2 | koutsoub | for(FolderResource r : getResult()){
|
521 | e8b6efa2 | koutsoub | if(r.isDeleted()){
|
522 | e8b6efa2 | koutsoub | |
523 | e8b6efa2 | koutsoub | } |
524 | e8b6efa2 | koutsoub | else if(resourceClass.equals(MyFolderResource.class)) |
525 | e8b6efa2 | koutsoub | res.add(new MyFolderResource(r));
|
526 | e8b6efa2 | koutsoub | else if(resourceClass.equals(SharedFolderResource.class)){ |
527 | e8b6efa2 | koutsoub | res.add(new SharedFolderResource(r));
|
528 | e8b6efa2 | koutsoub | } |
529 | e8b6efa2 | koutsoub | else if(resourceClass.equals(TrashFolderResource.class)) |
530 | e8b6efa2 | koutsoub | res.add(new TrashFolderResource(r));
|
531 | e8b6efa2 | koutsoub | else if(resourceClass.equals(OthersFolderResource.class)) |
532 | e8b6efa2 | koutsoub | res.add(new OthersFolderResource(r));
|
533 | e8b6efa2 | koutsoub | } |
534 | ad9133fe | koutsoub | if(restResource instanceof RestResourceWrapper) |
535 | ad9133fe | koutsoub | ((RestResourceWrapper)restResource).getResource().setFolders(getResult()); |
536 | e8b6efa2 | koutsoub | updateRowCount(res.size(), true);
|
537 | e8b6efa2 | koutsoub | updateRowData(0,res);
|
538 | e8b6efa2 | koutsoub | if(refresh!=null) |
539 | e8b6efa2 | koutsoub | refresh.onRefresh(); |
540 | e8b6efa2 | koutsoub | } |
541 | e8b6efa2 | koutsoub | |
542 | e8b6efa2 | koutsoub | @Override
|
543 | e8b6efa2 | koutsoub | public void onError(Throwable t) { |
544 | e8b6efa2 | koutsoub | GSS.get().displayError("Unable to fetch subfolders");
|
545 | e8b6efa2 | koutsoub | GWT.log("Unable to fetch subfolders", t);
|
546 | e8b6efa2 | koutsoub | } |
547 | e8b6efa2 | koutsoub | |
548 | e8b6efa2 | koutsoub | @Override
|
549 | e8b6efa2 | koutsoub | public void onError(String p, Throwable throwable) { |
550 | e8b6efa2 | koutsoub | GWT.log("Path:"+p, throwable);
|
551 | e8b6efa2 | koutsoub | } |
552 | e8b6efa2 | koutsoub | |
553 | e8b6efa2 | koutsoub | }; |
554 | e8b6efa2 | koutsoub | DeferredCommand.addCommand(gf2); |
555 | e8b6efa2 | koutsoub | |
556 | e8b6efa2 | koutsoub | } |
557 | e8b6efa2 | koutsoub | |
558 | e8b6efa2 | koutsoub | @Override
|
559 | e8b6efa2 | koutsoub | public void onError(Throwable t) { |
560 | 56c1ca4b | koutsoub | |
561 | e8b6efa2 | koutsoub | GWT.log("Error fetching root folder", t);
|
562 | e8b6efa2 | koutsoub | GSS.get().displayError("Unable to fetch root folder");
|
563 | e8b6efa2 | koutsoub | } |
564 | e8b6efa2 | koutsoub | |
565 | e8b6efa2 | koutsoub | }; |
566 | e8b6efa2 | koutsoub | DeferredCommand.addCommand(gf); |
567 | e8b6efa2 | koutsoub | } |
568 | e8b6efa2 | koutsoub | } |
569 | e8b6efa2 | koutsoub | |
570 | e8b6efa2 | koutsoub | |
571 | e8b6efa2 | koutsoub | class OthersDataProvider extends AsyncDataProvider<RestResource>{ |
572 | e8b6efa2 | koutsoub | private RestResource restResource;
|
573 | e8b6efa2 | koutsoub | private Class resourceClass; |
574 | e8b6efa2 | koutsoub | public OthersDataProvider(RestResource department, Class resourceClass) { |
575 | e8b6efa2 | koutsoub | super(new ProvidesKey<RestResource>() { |
576 | e8b6efa2 | koutsoub | |
577 | e8b6efa2 | koutsoub | @Override
|
578 | e8b6efa2 | koutsoub | public Object getKey(RestResource item) { |
579 | e8b6efa2 | koutsoub | return item.getUri();
|
580 | e8b6efa2 | koutsoub | }}); |
581 | e8b6efa2 | koutsoub | this.restResource = department;
|
582 | e8b6efa2 | koutsoub | this.resourceClass=resourceClass;
|
583 | e8b6efa2 | koutsoub | //CellTreeView.this.mymap.put(department.getUri(), OthersDataProvider.this);
|
584 | e8b6efa2 | koutsoub | } |
585 | e8b6efa2 | koutsoub | |
586 | e8b6efa2 | koutsoub | @Override
|
587 | e8b6efa2 | koutsoub | protected void onRangeChanged(final HasData<RestResource> view) { |
588 | e8b6efa2 | koutsoub | refresh(null);
|
589 | e8b6efa2 | koutsoub | } |
590 | e8b6efa2 | koutsoub | |
591 | e8b6efa2 | koutsoub | /**
|
592 | e8b6efa2 | koutsoub | * Retrieve the restResource.
|
593 | e8b6efa2 | koutsoub | *
|
594 | e8b6efa2 | koutsoub | * @return the restResource
|
595 | e8b6efa2 | koutsoub | */
|
596 | e8b6efa2 | koutsoub | public RestResource getRestResource() {
|
597 | e8b6efa2 | koutsoub | return restResource;
|
598 | e8b6efa2 | koutsoub | } |
599 | e8b6efa2 | koutsoub | |
600 | e8b6efa2 | koutsoub | |
601 | e8b6efa2 | koutsoub | /**
|
602 | e8b6efa2 | koutsoub | * Modify the restResource.
|
603 | e8b6efa2 | koutsoub | *
|
604 | e8b6efa2 | koutsoub | * @param restResource the restResource to set
|
605 | e8b6efa2 | koutsoub | */
|
606 | e8b6efa2 | koutsoub | public void setRestResource(RestResource restResource) { |
607 | e8b6efa2 | koutsoub | this.restResource = restResource;
|
608 | e8b6efa2 | koutsoub | } |
609 | e8b6efa2 | koutsoub | |
610 | e8b6efa2 | koutsoub | public void refresh(final RefreshHandler refresh){ |
611 | e8b6efa2 | koutsoub | GetCommand<OthersResource> go = new GetCommand<OthersResource>(OthersResource.class,
|
612 | e8b6efa2 | koutsoub | restResource.getUri(), null) {
|
613 | e8b6efa2 | koutsoub | |
614 | e8b6efa2 | koutsoub | @Override
|
615 | e8b6efa2 | koutsoub | public void onComplete() { |
616 | e8b6efa2 | koutsoub | final OthersResource others = getResult();
|
617 | e8b6efa2 | koutsoub | MultipleGetCommand<OtherUserResource> gogo = new MultipleGetCommand<OtherUserResource>(OtherUserResource.class,
|
618 | e8b6efa2 | koutsoub | others.getOthers().toArray(new String[] {}), null) { |
619 | e8b6efa2 | koutsoub | |
620 | e8b6efa2 | koutsoub | @Override
|
621 | e8b6efa2 | koutsoub | public void onComplete() { |
622 | e8b6efa2 | koutsoub | List<OtherUserResource> res = getResult();
|
623 | e8b6efa2 | koutsoub | updateRowCount(res.size(), true);
|
624 | e8b6efa2 | koutsoub | List<RestResource> r = new ArrayList<RestResource>(); |
625 | e8b6efa2 | koutsoub | r.addAll(res); |
626 | e8b6efa2 | koutsoub | updateRowData(0,r);
|
627 | e8b6efa2 | koutsoub | } |
628 | e8b6efa2 | koutsoub | |
629 | e8b6efa2 | koutsoub | @Override
|
630 | e8b6efa2 | koutsoub | public void onError(Throwable t) { |
631 | e8b6efa2 | koutsoub | GWT.log("Error fetching Others Root folder", t);
|
632 | e8b6efa2 | koutsoub | GSS.get().displayError("Unable to fetch Others Root folder");
|
633 | e8b6efa2 | koutsoub | } |
634 | e8b6efa2 | koutsoub | |
635 | e8b6efa2 | koutsoub | @Override
|
636 | e8b6efa2 | koutsoub | public void onError(String p, Throwable throwable) { |
637 | e8b6efa2 | koutsoub | GWT.log("Path:"+p, throwable);
|
638 | e8b6efa2 | koutsoub | } |
639 | e8b6efa2 | koutsoub | }; |
640 | e8b6efa2 | koutsoub | DeferredCommand.addCommand(gogo); |
641 | e8b6efa2 | koutsoub | } |
642 | e8b6efa2 | koutsoub | |
643 | e8b6efa2 | koutsoub | @Override
|
644 | e8b6efa2 | koutsoub | public void onError(Throwable t) { |
645 | e8b6efa2 | koutsoub | GWT.log("Error fetching Others Root folder", t);
|
646 | e8b6efa2 | koutsoub | GSS.get().displayError("Unable to fetch Others Root folder");
|
647 | e8b6efa2 | koutsoub | } |
648 | e8b6efa2 | koutsoub | }; |
649 | e8b6efa2 | koutsoub | DeferredCommand.addCommand(go); |
650 | e8b6efa2 | koutsoub | } |
651 | e8b6efa2 | koutsoub | } |
652 | e8b6efa2 | koutsoub | |
653 | e8b6efa2 | koutsoub | |
654 | e8b6efa2 | koutsoub | |
655 | e8b6efa2 | koutsoub | /**
|
656 | e8b6efa2 | koutsoub | * Retrieve the rootNodes.
|
657 | e8b6efa2 | koutsoub | *
|
658 | e8b6efa2 | koutsoub | * @return the rootNodes
|
659 | e8b6efa2 | koutsoub | */
|
660 | e8b6efa2 | koutsoub | public ListDataProvider<RestResource> getRootNodes() {
|
661 | e8b6efa2 | koutsoub | return rootNodes;
|
662 | e8b6efa2 | koutsoub | } |
663 | e8b6efa2 | koutsoub | |
664 | e8b6efa2 | koutsoub | |
665 | e8b6efa2 | koutsoub | /**
|
666 | e8b6efa2 | koutsoub | * Retrieve the mymap.
|
667 | e8b6efa2 | koutsoub | *
|
668 | e8b6efa2 | koutsoub | * @return the mymap
|
669 | e8b6efa2 | koutsoub | */
|
670 | e8b6efa2 | koutsoub | public Map<String, MyFolderDataProvider> getMymap() { |
671 | e8b6efa2 | koutsoub | return mymap;
|
672 | e8b6efa2 | koutsoub | } |
673 | caf363d2 | koutsoub | |
674 | caf363d2 | koutsoub | |
675 | caf363d2 | koutsoub | /**
|
676 | caf363d2 | koutsoub | * Retrieve the sharedmap.
|
677 | caf363d2 | koutsoub | *
|
678 | caf363d2 | koutsoub | * @return the sharedmap
|
679 | caf363d2 | koutsoub | */
|
680 | caf363d2 | koutsoub | public Map<String, MyFolderDataProvider> getSharedmap() { |
681 | caf363d2 | koutsoub | return sharedmap;
|
682 | caf363d2 | koutsoub | } |
683 | caf363d2 | koutsoub | |
684 | caf363d2 | koutsoub | |
685 | caf363d2 | koutsoub | /**
|
686 | caf363d2 | koutsoub | * Retrieve the othersmap.
|
687 | caf363d2 | koutsoub | *
|
688 | caf363d2 | koutsoub | * @return the othersmap
|
689 | caf363d2 | koutsoub | */
|
690 | caf363d2 | koutsoub | public Map<String, MyFolderDataProvider> getOthersmap() { |
691 | caf363d2 | koutsoub | return othersmap;
|
692 | caf363d2 | koutsoub | } |
693 | caf363d2 | koutsoub | |
694 | caf363d2 | koutsoub | |
695 | e8b6efa2 | koutsoub | |
696 | e8b6efa2 | koutsoub | |
697 | e8b6efa2 | koutsoub | |
698 | e8b6efa2 | koutsoub | |
699 | e8b6efa2 | koutsoub | } |