Revision 20211689 src/gr/ebs/gss/client/CellTreeViewModel.java

b/src/gr/ebs/gss/client/CellTreeViewModel.java
38 38
import gr.ebs.gss.client.rest.resource.TrashResource;
39 39
import gwtquery.plugins.draggable.client.DragAndDropManager;
40 40
import gwtquery.plugins.draggable.client.DraggableOptions;
41
import gwtquery.plugins.draggable.client.StopDragException;
41 42
import gwtquery.plugins.draggable.client.DraggableOptions.CursorAt;
42 43
import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction;
43 44
import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption;
......
79 80
 *
80 81
 */
81 82
public class CellTreeViewModel implements TreeViewModel{
83
	
82 84
	private final ListDataProvider<RestResource> rootNodes = new ListDataProvider<RestResource>();
83 85
	private Map<String,FolderResource> folderCache=new HashMap<String, FolderResource>();
84 86
	final Images images;
......
93 95
	    SafeHtml outerHelper(String cssClassName);
94 96
	  }
95 97

  
96
	static void configureDragOperation(DraggableOptions options) {
98
	static void configureDragOperation(final DraggableOptions options) {
97 99

  
98 100
	    // set a custom element as drag helper. The content of the helper will be
99 101
	    // set when the drag will start
......
110 112
	    options.setAppendTo("body");
111 113
	    // set the revert option
112 114
	    options.setRevert(RevertOption.ON_INVALID_DROP);
115
	    options.setOnBeforeDragStart(new DragFunction() {
116
			
117
			@Override
118
			public void f(DragContext context) {
119
				 RestResource value = context.getDraggableData();
120
			     if(value instanceof TrashResource || value instanceof SharedResource || value instanceof OthersResource || value instanceof OtherUserResource){
121
			       	throw new StopDragException();
122
			      }
123
				
124
			}
125
		});
113 126
	    // use a Function to fill the content of the helper
114 127
	    // we could also add a DragStartEventHandler on the DragAndDropTreeCell and
115 128
	    // DragAndDropCellList.
129
	    
116 130
	    options.setOnDragStart(new DragFunction() {
117 131
	      public void f(DragContext context) {
118 132
	        RestResourceWrapper memberInfo = context.getDraggableData();
......
202 216
	public <T> NodeInfo<?> getNodeInfo(final T value) {
203 217
		
204 218
		if(value==null){
205
			return new DragAndDropNodeInfo<RestResource>(getRootNodes(), departmentCell,
219
			DragAndDropNodeInfo n = new DragAndDropNodeInfo<RestResource>(getRootNodes(), departmentCell,
206 220
			            selectionModel, null);
221
			configureFolderDrop(n);
222
	        configureDragOperation(n.getDraggableOptions());
223
			return n;
207 224
		}
208 225
		else if (value instanceof MyFolderResource) {
209 226
	        // Second level.
......
214 231
	        
215 232
	        //nodeInfos.put(((MyFolderResource) value).getUri(), n);
216 233
	        mymap.put(((MyFolderResource) value).getUri(), dataProvider);
217
	        DroppableOptions options = n.getDroppableOptions();
218
	        options.setDroppableHoverClass("droppableHover");
219
	        // use a DroppableFunction here. We can also add a DropHandler in the tree
220
	        // itself
221
	        options.setOnOver(new DroppableFunction() {
222
				
223
				@Override
224
				public void f(final DragAndDropContext context) {
225
					if(context.getDroppableData()!=null && context.getDroppableData() instanceof RestResource){
226
						GSS.get().getTreeView().getUtils().openNodeContainingResource((RestResource) context.getDroppableData(), new RefreshHandler() {
227
							
228
							@Override
229
							public void onRefresh() {
230
								
231
								DragAndDropManager.getInstance().initialize(context, GQueryUi.Event.create(com.google.gwt.user.client.Event.getCurrentEvent()));
232
								
233
							}
234
						});
235
						
236
					}
237
					
238
					
239
					
240
				}
241
			});
242
	        options.setOnDrop(new DroppableFunction() {
243

  
244
	          public void f(DragAndDropContext context) {
245
	        	  
246
	        	  DnDFolderPopupMenu popup ;
247
	        	  if(context.getDraggableData() instanceof FileResource){
248
	        		  popup = new DnDFolderPopupMenu(images, ((MyFolderResource) context.getDroppableData()).getResource(), Arrays.asList(context.getDraggableData()));
249
	        	  }
250
	        	  else
251
	        		  popup = new DnDFolderPopupMenu(images, ((MyFolderResource) context.getDroppableData()).getResource(), context.getDraggableData());
252
	        	  int left = context.getDroppable().getAbsoluteLeft() + 40;
253
                  int top = context.getDroppable().getAbsoluteTop() + 20;
254
                  popup.setPopupPosition(left, top);
255
	        	 
256
	        	  popup.show();
257
	          }
258
	        });
234
	        
259 235
	        // permission cell are not draggable
260 236
	        //n.setCellDroppableOnly();
237
	        configureFolderDrop(n);
261 238
	        configureDragOperation(n.getDraggableOptions());
262 239
	        
263 240
	        return n;
......
267 244
			MyFolderDataProvider dataProvider = new MyFolderDataProvider(
268 245
	            ((SharedResource) value), SharedFolderResource.class);
269 246
			sharedmap.put(((SharedResource) value).getUri(), dataProvider);
270
	        return new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
247
			DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
271 248
	            selectionModel, new ResourceValueUpdater());
249
			 configureFolderDrop(n);
250
		        configureDragOperation(n.getDraggableOptions());
251
			return n;
272 252
		}
273 253
		else if (value instanceof TrashResource) {
274 254
	        // Second level.
......
278 258
				r.add(new TrashFolderResource(f));
279 259
			}
280 260
			trashProvider.setList(r);
281
	        return new DragAndDropNodeInfo<RestResource>(trashProvider, departmentCell,
261
			DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(trashProvider, departmentCell,
282 262
	            selectionModel, new ResourceValueUpdater());
263
			configureFolderDrop(n);
264
	        configureDragOperation(n.getDraggableOptions());
265
			return n;
283 266
		}
284 267
		else if (value instanceof OthersResource) {
285 268
	        // Second level.
286 269
			OthersDataProvider dataProvider = new OthersDataProvider(
287 270
	            ((OthersResource) value), SharedFolderResource.class);
288
	        return new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
271
	        DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
289 272
	            selectionModel, null);
273
	        configureFolderDrop(n);
274
	        configureDragOperation(n.getDraggableOptions());
275
	        return n;
290 276
		}
291 277
		else if (value instanceof SharedFolderResource) {
292 278
	        // Second level.
......
295 281
	        DragAndDropNodeInfo<RestResource> n =  new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
296 282
	            selectionModel, new ResourceValueUpdater());
297 283
	        sharedmap.put(((SharedFolderResource) value).getUri(), dataProvider);
298
	        DroppableOptions options = n.getDroppableOptions();
299
	        options.setDroppableHoverClass("droppableHover");
300
	        // use a DroppableFunction here. We can also add a DropHandler in the tree
301
	        // itself
302
	        options.setOnDrop(new DroppableFunction() {
303

  
304
	          public void f(DragAndDropContext context) {
305
	        	  GWT.log("DROPPED");
306
	            
307
	          }
308
	        });
309
	        // permission cell are not draggable
310
	        n.setCellDroppableOnly();
284
	        configureFolderDrop(n);
285
	        configureDragOperation(n.getDraggableOptions());
311 286
	        return n;
312 287
		}
313 288
		else if (value instanceof OthersFolderResource) {
......
318 293
	            selectionModel, new ResourceValueUpdater());
319 294
	        //nodeInfos.put(((OthersFolderResource) value).getUri(), n);
320 295
	        othersmap.put(((SharedFolderResource) value).getUri(), dataProvider);
321
	        DroppableOptions options = n.getDroppableOptions();
322
	        options.setDroppableHoverClass("droppableHover");
323
	        // use a DroppableFunction here. We can also add a DropHandler in the tree
324
	        // itself
325
	        options.setOnDrop(new DroppableFunction() {
326

  
327
	          public void f(DragAndDropContext context) {
328
	        	  GWT.log("DROPPED");
329
	            
330
	          }
331
	        });
332
	        // permission cell are not draggable
333
	        n.setCellDroppableOnly();
296
	        configureFolderDrop(n);
297
	        configureDragOperation(n.getDraggableOptions());
334 298
	        return n;
335 299
		}
336 300
		else if (value instanceof OtherUserResource) {
......
339 303
	            ((OtherUserResource) value),OthersFolderResource.class);
340 304
	        DragAndDropNodeInfo<RestResource> n =  new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
341 305
	            selectionModel, new ResourceValueUpdater());
342
	        //nodeInfos.put(((OtherUserResource) value).getUri(), n);
343
	        DroppableOptions options = n.getDroppableOptions();
344
	        options.setDroppableHoverClass("droppableHover");
345
	        // use a DroppableFunction here. We can also add a DropHandler in the tree
346
	        // itself
347
	        options.setOnDrop(new DroppableFunction() {
348

  
349
	          public void f(DragAndDropContext context) {
350
	        	  GWT.log("DROPPED");
351
	            
352
	          }
353
	        });
354
	        // permission cell are not draggable
355
	        n.setCellDroppableOnly();
306
	        configureFolderDrop(n);
307
	        configureDragOperation(n.getDraggableOptions());
356 308
	        return n;
357 309
		}
358 310
		// TODO Auto-generated method stub
359 311
		return null;
360 312
	}
313
	
314
	private void configureFolderDrop(DragAndDropNodeInfo<RestResource> n){
315
		DroppableOptions options = n.getDroppableOptions();
316
        options.setDroppableHoverClass("droppableHover");
317
        // use a DroppableFunction here. We can also add a DropHandler in the tree
318
        // itself
319
        
320
        options.setOnOver(new DroppableFunction() {
321
			
322
			@Override
323
			public void f(final DragAndDropContext context) {
324
				if(context.getDroppableData()!=null && context.getDroppableData() instanceof RestResource){
325

  
326
					GSS.get().getTreeView().getUtils().openNodeContainingResource((RestResource) context.getDroppableData(), new RefreshHandler() {
327
						
328
						@Override
329
						public void onRefresh() {
330
							
331
							DragAndDropManager.getInstance().update(context);//initialize(context, GQueryUi.Event.create(com.google.gwt.user.client.Event.getCurrentEvent()));
332
							
333
						}
334
					});
335
					
336
				}
337
				
338
				
339
				
340
			}
341
		});
342
        options.setOnDrop(new DroppableFunction() {
343

  
344
          public void f(DragAndDropContext context) {
345
        	  
346
        	  DnDFolderPopupMenu popup ;
347
        	  if(context.getDraggableData() instanceof FileResource){
348
        		  popup = new DnDFolderPopupMenu(images, ((MyFolderResource) context.getDroppableData()).getResource(), Arrays.asList(context.getDraggableData()));
349
        	  }
350
        	  else
351
        		  popup = new DnDFolderPopupMenu(images, ((MyFolderResource) context.getDroppableData()).getResource(), context.getDraggableData());
352
        	  int left = context.getDroppable().getAbsoluteLeft() + 40;
353
              int top = context.getDroppable().getAbsoluteTop() + 20;
354
              popup.setPopupPosition(left, top);
355
        	 
356
        	  popup.show();
357
          }
358
        });
359
	}
361 360

  
362 361
	@Override
363 362
	public boolean isLeaf(Object value) {
......
449 448
				}});
450 449
		    this.restResource = department;
451 450
		    this.resourceClass=resourceClass;
452
		    //CellTreeView.this.mymap.put(department.getUri(), MyFolderDataProvider.this);
451
		    //getMymap().put(department.getUri(), MyFolderDataProvider.this);
453 452
		  }
454 453

  
455 454
		  @Override
......
492 491
							
493 492
								updateRowCount(res.size(), true);
494 493
								updateRowData(0,res);
495
							
496 494
							return;
497 495
						}
498 496
						String[] folderPaths = null;

Also available in: Unified diff