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.tree;
21 import gr.ebs.gss.client.GSS;
22 import gr.ebs.gss.client.PopupTree;
23 import gr.ebs.gss.client.Folders.Images;
24 import gr.ebs.gss.client.dnd.DnDTreeItem;
25 import gr.ebs.gss.client.rest.GetCommand;
26 import gr.ebs.gss.client.rest.RestException;
27 import gr.ebs.gss.client.rest.resource.FolderResource;
28 import gr.ebs.gss.client.rest.resource.TrashResource;
29 import gr.ebs.gss.client.rest.resource.UserResource;
31 import java.util.List;
33 import com.google.gwt.core.client.GWT;
34 import com.google.gwt.user.client.DeferredCommand;
35 import com.google.gwt.user.client.IncrementalCommand;
36 import com.google.gwt.user.client.ui.TreeItem;
43 public class TrashSubtree extends Subtree {
46 * A constant that denotes the completion of an IncrementalCommand.
48 public static final boolean DONE = false;
50 private DnDTreeItem rootItem;
52 public TrashSubtree(PopupTree tree, final Images _images) {
55 DeferredCommand.addCommand(new IncrementalCommand() {
57 public boolean execute() {
63 public boolean updateInit() {
65 UserResource userResource = GSS.get().getCurrentUserResource();
66 if ( userResource == null || GSS.get().getFolders().getRootItem() == null)
73 public void update() {
74 DeferredCommand.addCommand(new GetCommand<TrashResource>(TrashResource.class, GSS.get().getCurrentUserResource().getTrashPath()) {
75 public void onComplete() {
77 rootItem = new DnDTreeItem(imageItemHTML(images.trash(), "Trash"), "Trash", false);
78 tree.addItem(rootItem);
79 rootItem.doDroppable();
81 rootItem.setUserObject(getResult());
82 rootItem.removeItems();
83 List<FolderResource> res = rootItem.getTrashResource().getTrashedFolders();
84 for (FolderResource r : res) {
85 DnDTreeItem child = (DnDTreeItem) addImageItem(rootItem, r.getName(), images.folderYellow(), true);
86 child.setUserObject(r);
87 child.setState(false);
91 public void onError(Throwable t) {
92 if(t instanceof RestException){
93 int statusCode = ((RestException)t).getHttpStatusCode();
94 //empty trash ie returns 1223 status code instead of 204
95 if(statusCode == 204 || statusCode == 1223){
96 GWT.log("Trash is empty", null);
98 rootItem = new DnDTreeItem(imageItemHTML(images.trash(), "Trash"), "Trash", false);
99 tree.addItem(rootItem);
100 rootItem.doDroppable();
102 rootItem.setUserObject(new TrashResource(GSS.get().getCurrentUserResource().getTrashPath()));
103 rootItem.removeItems();
105 if(rootItem == null){
106 rootItem = new DnDTreeItem(imageItemHTML(images.trash(), "Trash"), "Trash", false);
107 tree.addItem(rootItem);
109 rootItem.setUserObject(new TrashResource(GSS.get().getCurrentUserResource().getTrashPath()));
110 GSS.get().displayError("Unable to fetch trash folder:"+((RestException)t).getHttpStatusText());
115 GSS.get().displayError("Unable to fetch trash folder:"+t.getMessage());
116 if(rootItem == null){
117 rootItem = new DnDTreeItem(imageItemHTML(images.trash(), "Trash"), "Trash", false);
118 tree.addItem(rootItem);
119 rootItem.doDroppable();
121 rootItem.setUserObject(new TrashResource(GSS.get().getCurrentUserResource().getTrashPath()));
129 * Retrieve the rootItem.
131 * @return the rootItem
133 public TreeItem getRootItem() {