2 * Copyright 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
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.
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.
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/>.
19 package gr.ebs.gss.client.dnd;
21 import gr.ebs.gss.client.Folders;
22 import gr.ebs.gss.client.GSS;
23 import gr.ebs.gss.client.rest.resource.FolderResource;
24 import gr.ebs.gss.client.rest.resource.OtherUserResource;
25 import gr.ebs.gss.client.rest.resource.OthersResource;
26 import gr.ebs.gss.client.rest.resource.SharedResource;
27 import gr.ebs.gss.client.rest.resource.TrashResource;
29 import java.util.ArrayList;
30 import java.util.List;
32 import com.google.gwt.user.client.DOM;
33 import com.google.gwt.user.client.ui.MouseListener;
34 import com.google.gwt.user.client.ui.SourcesMouseEvents;
35 import com.google.gwt.user.client.ui.TreeItem;
36 import com.google.gwt.user.client.ui.Widget;
43 public class DnDTreeItem extends TreeItem implements SourcesMouseEvents {
44 public static final int FOLDER = 0;
45 public static final int SHARED = 1;
46 public static final int TRASH = 2;
47 public static final int OTHERS = 3;
49 private DnDFocusPanel focus;
51 private Widget content;
52 private Widget toDrag;
53 private DnDDropController drop;
54 private List<DnDTreeItem> toRemove = new ArrayList();
55 private boolean draggable = false;
58 public DnDTreeItem(Widget widget,String name, boolean _draggable) {
60 draggable = _draggable;
62 focus = new DnDFocusPanel(content,this);
63 focus.setTabIndex(-1);
67 public void setFocus(){
68 ((DnDFocusPanel)getWidget()).setFocus(true);
71 public void updateWidget(Widget widget){
73 focus.setWidget(content);
77 public void addMouseListener(MouseListener mouseListener){
78 focus.addMouseListener(mouseListener);
81 public void removeMouseListener(MouseListener mouseListener){
82 focus.removeMouseListener(mouseListener);
91 public DnDDropController getDrop() {
97 public Widget getContent() {
103 * @see com.google.gwt.user.client.ui.TreeItem#removeItems()
106 public void removeItems() {
107 toRemove = new ArrayList();
109 for(DnDTreeItem it : toRemove)
110 if(it.getDrop() != null)
111 GSS.get().getDragController().unregisterDropController(it.getDrop());
118 * @see com.google.gwt.user.client.ui.TreeItem#removeItem(com.google.gwt.user.client.ui.TreeItem)
121 public void removeItem(TreeItem item) {
123 if(item instanceof DnDTreeItem){
124 DnDTreeItem it = (DnDTreeItem) item;
125 if(it.getDrop() != null)
126 GSS.get().getDragController().unregisterDropController(it.getDrop());
128 super.removeItem(item);
131 public void doDroppable(){
132 drop = new DnDDropController(focus);
133 GSS.get().getDragController().registerDropController(drop);
136 public void doDraggable(){
137 GSS.get().getDragController().makeDraggable(getFocus(), getContent());
138 drop = new DnDDropController(focus);
139 GSS.get().getDragController().registerDropController(drop);
142 public void undoDraggable(){
143 GSS.get().getDragController().makeNotDraggable(getFocus());
145 GSS.get().getDragController().unregisterDropController(getDrop());
148 public void undoDroppable(){
150 GSS.get().getDragController().unregisterDropController(getDrop());
153 protected void removeItems(DnDTreeItem item){
154 for(int i=0;i<item.getChildCount();i++) {
155 DnDTreeItem it = (DnDTreeItem)item.getChild(i);
163 * Retrieve the focus.
167 public DnDFocusPanel getFocus() {
173 * Retrieve the draggable.
175 * @return the draggable
177 public boolean isDraggable() {
181 public DnDTreeItem getChild(FolderResource folder){
182 for(int i=0; i< getChildCount(); i++){
183 DnDTreeItem c = (DnDTreeItem) getChild(i);
184 if(c.getUserObject() instanceof FolderResource)
185 if(((FolderResource)c.getUserObject()).getUri().equals(folder.getUri()))
191 public DnDTreeItem getChild(OtherUserResource user){
192 for(int i=0; i< getChildCount(); i++){
193 DnDTreeItem c = (DnDTreeItem) getChild(i);
194 if(c.getUserObject() instanceof OtherUserResource)
195 if(((OtherUserResource)c.getUserObject()).getUri().equals(user.getUri()))
201 public void insertItem(TreeItem item, int position) {
204 DOM.insertChild(getElement(), item.getElement(), position);
208 public int getItemType(){
209 Folders f = GSS.get().getFolders();
210 if(f.isFileItem(this))
212 if(f.isMySharedItem(this))
214 if(f.isOthersSharedItem(this))
221 * Retrieve the folderResource.
223 * @return the folderResource
225 public FolderResource getFolderResource() {
226 if(getUserObject() instanceof FolderResource)
227 return (FolderResource)getUserObject();
236 * Retrieve the sharedResource.
238 * @return the sharedResource
240 public SharedResource getSharedResource() {
241 if(getUserObject() instanceof SharedResource)
242 return (SharedResource)getUserObject();
251 * Retrieve the trashResource.
253 * @return the trashResource
255 public TrashResource getTrashResource() {
256 if(getUserObject() instanceof TrashResource)
257 return (TrashResource)getUserObject();
266 * Retrieve the othersResource.
268 * @return the othersResource
270 public OthersResource getOthersResource() {
271 if(getUserObject() instanceof OthersResource)
272 return (OthersResource)getUserObject();
278 * Retrieve the otherUserResource.
280 * @return the otherUserResource
282 public OtherUserResource getOtherUserResource() {
283 if(getUserObject() instanceof OtherUserResource)
284 return (OtherUserResource)getUserObject();
291 public boolean needExpanding(){
292 /*if(GSS.get().getFolders().isMySharedItem(this) && ! GSS.get().getFolders().isMyShares(this)){
293 if(getFolderResource() != null){
294 SharedResource sr = ((DnDTreeItem)GSS.get().getFolders().getMySharesItem()).getSharedResource();
296 for(String s : getFolderResource().getSubfolderPaths())
297 if(sr.getSubfolders().contains(s))
299 if(count != getChildCount())
304 if(getFolderResource() != null){
305 //if(equals(GSS.get().getFolders().getRootItem()))
307 if(getFolderResource().getFolders().size() > 0)
308 for(FolderResource r : getFolderResource().getFolders() )
309 if(r.isNeedsExpanding())
311 if(getFolderResource().getSubfolderPaths().size() != getChildCount())
314 else if (getOtherUserResource() != null)
315 if(getOtherUserResource().getSubfolderPaths().size() != getChildCount())