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.commands;
21 import gr.ebs.gss.client.GSS;
22 import gr.ebs.gss.client.dnd.DnDTreeItem;
23 import gr.ebs.gss.client.rest.MultiplePostCommand;
24 import gr.ebs.gss.client.rest.PostCommand;
25 import gr.ebs.gss.client.rest.RestException;
26 import gr.ebs.gss.client.rest.resource.FileResource;
27 import gr.ebs.gss.client.rest.resource.FolderResource;
29 import java.util.ArrayList;
30 import java.util.List;
32 import com.google.gwt.core.client.GWT;
33 import com.google.gwt.user.client.Command;
34 import com.google.gwt.user.client.DeferredCommand;
35 import com.google.gwt.user.client.ui.PopupPanel;
36 import com.google.gwt.user.client.ui.TreeItem;
41 * Restore trashed files and folders.
45 public class RestoreTrashCommand implements Command{
46 private PopupPanel containerPanel;
48 public RestoreTrashCommand(PopupPanel _containerPanel){
49 containerPanel = _containerPanel;
52 public void execute() {
53 containerPanel.hide();
54 Object selection = GSS.get().getCurrentSelection();
55 if (selection == null){
56 // Check to see if Trash Node is selected.
57 List folderList = new ArrayList();
58 TreeItem trashItem = GSS.get().getFolders().getTrashItem();
59 for(int i=0 ; i < trashItem.getChildCount() ; i++)
60 folderList.add(trashItem.getChild(i).getUserObject());
63 GWT.log("selection: " + selection.toString(), null);
64 if (selection instanceof FileResource) {
65 final FileResource resource = (FileResource)selection;
66 PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){
69 public void onComplete() {
70 GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
71 GSS.get().showFileList(true);
75 public void onError(Throwable t) {
77 if(t instanceof RestException){
78 int statusCode = ((RestException)t).getHttpStatusCode();
80 GSS.get().displayError("You don't have the necessary permissions");
81 else if(statusCode == 404)
82 GSS.get().displayError("File does not exist");
83 else if(statusCode == 409)
84 GSS.get().displayError("A file with the same name already exists");
85 else if(statusCode == 413)
86 GSS.get().displayError("Your quota has been exceeded");
88 GSS.get().displayError("Unable to restore file:"+((RestException)t).getHttpStatusText());
91 GSS.get().displayError("System error restoring file:"+t.getMessage());
94 DeferredCommand.addCommand(rt);
96 else if (selection instanceof List) {
97 final List<FileResource> fdtos = (List<FileResource>) selection;
98 final List<String> fileIds = new ArrayList<String>();
99 for(FileResource f : fdtos)
100 fileIds.add(f.getUri()+"?restore=");
101 MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), 200){
104 public void onComplete() {
105 GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
106 GSS.get().showFileList(true);
110 public void onError(String p, Throwable t) {
112 if(t instanceof RestException){
113 int statusCode = ((RestException)t).getHttpStatusCode();
114 if(statusCode == 405)
115 GSS.get().displayError("You don't have the necessary permissions");
116 else if(statusCode == 404)
117 GSS.get().displayError("File does not exist");
118 else if(statusCode == 409)
119 GSS.get().displayError("A file with the same name already exists");
120 else if(statusCode == 413)
121 GSS.get().displayError("Your quota has been exceeded");
123 GSS.get().displayError("Unable to restore file::"+((RestException)t).getHttpStatusText());
126 GSS.get().displayError("System error restoring file:"+t.getMessage());
129 DeferredCommand.addCommand(rt);
131 else if (selection instanceof FolderResource) {
132 final FolderResource resource = (FolderResource)selection;
133 PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){
136 public void onComplete() {
137 GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getRootItem());
139 GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
143 public void onError(Throwable t) {
145 if(t instanceof RestException){
146 int statusCode = ((RestException)t).getHttpStatusCode();
147 if(statusCode == 405)
148 GSS.get().displayError("You don't have the necessary permissions");
149 else if(statusCode == 404)
150 GSS.get().displayError("Folder does not exist");
151 else if(statusCode == 409)
152 GSS.get().displayError("A folder with the same name already exists");
153 else if(statusCode == 413)
154 GSS.get().displayError("Your quota has been exceeded");
156 GSS.get().displayError("Unable to restore folder::"+((RestException)t).getHttpStatusText());
159 GSS.get().displayError("System error restoring folder:"+t.getMessage());
162 DeferredCommand.addCommand(rt);