Remove the redundant gss top-level directory.
[pithos] / src / gr / ebs / gss / client / dnd / DnDDropController.java
1 /*
2  * Copyright 2008, 2009 Electronic Business Systems Ltd.
3  *
4  * This file is part of GSS.
5  *
6  * GSS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 package gr.ebs.gss.client.dnd;
20
21 import gr.ebs.gss.client.GSS;
22 import gr.ebs.gss.client.rest.resource.FileResource;
23 import gr.ebs.gss.client.rest.resource.FolderResource;
24
25 import java.util.List;
26
27 import com.allen_sauer.gwt.dnd.client.DragContext;
28 import com.allen_sauer.gwt.dnd.client.drop.SimpleDropController;
29
30 /**
31  * @author kman
32  */
33 public class DnDDropController extends SimpleDropController {
34
35         DnDFocusPanel nodeHolder;
36
37         public DnDDropController(DnDFocusPanel widget) {
38                 super(widget);
39                 nodeHolder = widget;
40         }
41
42         @Override
43         public void onDrop(DragContext context) {
44                 super.onDrop(context);
45                 DnDFocusPanel toDrop = (DnDFocusPanel) context.draggable;
46                 if (toDrop.getItem() != null) {
47                         if (toDrop.getItem().getUserObject() != null && toDrop.getItem().getUserObject() instanceof FolderResource) {
48                                 FolderResource folderToDrop = (FolderResource) toDrop.getItem().getUserObject();
49                                 FolderResource initialFolder = null;
50                                 if (nodeHolder.getItem().getUserObject() instanceof FolderResource)
51                                         initialFolder = (FolderResource) nodeHolder.getItem().getUserObject();
52                                 boolean othersShared = false;
53                                 if (GSS.get().getFolders().isOthersSharedItem(nodeHolder.getItem()))
54                                         othersShared = true;
55                                 DnDFolderPopupMenu popup = new DnDFolderPopupMenu(GSS.get().getFolders().getImages(), initialFolder, folderToDrop, othersShared);
56                                 int left = nodeHolder.getItem().getAbsoluteLeft() + 40;
57                                 int top = nodeHolder.getItem().getAbsoluteTop() + 20;
58                                 popup.setPopupPosition(left, top);
59                                 popup.show();
60                         }
61                 } else if (toDrop.getFiles() != null) {
62                         List<FileResource> folderToDrop = toDrop.getFiles();
63                         FolderResource initialFolder = null;
64                         if (GSS.get().getFolders().isTrash(nodeHolder.getItem())) {
65                         } else if (nodeHolder.getItem().getUserObject() instanceof FolderResource)
66                                 initialFolder = (FolderResource) nodeHolder.getItem().getUserObject();
67                         boolean othersShared = false;
68                         if (GSS.get().getFolders().isOthersSharedItem(nodeHolder.getItem()))
69                                 othersShared = true;
70                         DnDFolderPopupMenu popup = new DnDFolderPopupMenu(GSS.get().getFolders().getImages(), initialFolder, folderToDrop, othersShared);
71                         int left = nodeHolder.getItem().getAbsoluteLeft() + 40;
72                         int top = nodeHolder.getItem().getAbsoluteTop() + 20;
73                         popup.setPopupPosition(left, top);
74                         popup.show();
75                 }
76         }
77
78         @Override
79         public void onEnter(DragContext context) {
80                 super.onEnter(context);
81                 nodeHolder.getItem().getWidget().addStyleName("gss-SelectedRow");
82                 nodeHolder.getItem().setState(true);
83                 GSS.get().getDragController().resetCache();
84         }
85
86         @Override
87         public void onLeave(DragContext context) {
88                 nodeHolder.getItem().getWidget().removeStyleName("gss-SelectedRow");
89                 super.onLeave(context);
90         }
91
92 }