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.rest.MultiplePostCommand;
23 import gr.ebs.gss.client.rest.PostCommand;
24 import gr.ebs.gss.client.rest.RestException;
25 import gr.ebs.gss.client.rest.resource.FileResource;
26 import gr.ebs.gss.client.rest.resource.FolderResource;
27 import gr.ebs.gss.client.rest.resource.TrashResource;
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;
53 public void execute() {
54 containerPanel.hide();
55 Object selection = GSS.get().getCurrentSelection();
56 if (selection == null){
57 // Check to see if Trash Node is selected.
58 List folderList = new ArrayList();
59 TrashResource trashItem = GSS.get().getTreeView().getTrash();
60 for(int i=0 ; i < trashItem.getFolders().size() ; i++)
61 folderList.add(trashItem.getFolders().get(i));
64 GWT.log("selection: " + selection.toString(), null);
65 if (selection instanceof FileResource) {
66 final FileResource resource = (FileResource)selection;
67 PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){
70 public void onComplete() {
72 //GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
74 GSS.get().showFileList(true);
78 public void onError(Throwable t) {
80 if(t instanceof RestException){
81 int statusCode = ((RestException)t).getHttpStatusCode();
83 GSS.get().displayError("You don't have the necessary permissions");
84 else if(statusCode == 404)
85 GSS.get().displayError("File does not exist");
86 else if(statusCode == 409)
87 GSS.get().displayError("A file with the same name already exists");
88 else if(statusCode == 413)
89 GSS.get().displayError("Your quota has been exceeded");
91 GSS.get().displayError("Unable to restore file:"+((RestException)t).getHttpStatusText());
94 GSS.get().displayError("System error restoring file:"+t.getMessage());
97 DeferredCommand.addCommand(rt);
99 else if (selection instanceof List) {
100 final List<FileResource> fdtos = (List<FileResource>) selection;
101 final List<String> fileIds = new ArrayList<String>();
102 for(FileResource f : fdtos)
103 fileIds.add(f.getUri()+"?restore=");
104 MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), 200){
107 public void onComplete() {
109 //GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
110 GSS.get().showFileList(true);
114 public void onError(String p, Throwable t) {
116 if(t instanceof RestException){
117 int statusCode = ((RestException)t).getHttpStatusCode();
118 if(statusCode == 405)
119 GSS.get().displayError("You don't have the necessary permissions");
120 else if(statusCode == 404)
121 GSS.get().displayError("File does not exist");
122 else if(statusCode == 409)
123 GSS.get().displayError("A file with the same name already exists");
124 else if(statusCode == 413)
125 GSS.get().displayError("Your quota has been exceeded");
127 GSS.get().displayError("Unable to restore file::"+((RestException)t).getHttpStatusText());
130 GSS.get().displayError("System error restoring file:"+t.getMessage());
133 DeferredCommand.addCommand(rt);
135 else if (selection instanceof FolderResource) {
136 final FolderResource resource = (FolderResource)selection;
137 PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){
140 public void onComplete() {
143 GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getRootItem());
145 GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
150 public void onError(Throwable t) {
152 if(t instanceof RestException){
153 int statusCode = ((RestException)t).getHttpStatusCode();
154 if(statusCode == 405)
155 GSS.get().displayError("You don't have the necessary permissions");
156 else if(statusCode == 404)
157 GSS.get().displayError("Folder does not exist");
158 else if(statusCode == 409)
159 GSS.get().displayError("A folder with the same name already exists");
160 else if(statusCode == 413)
161 GSS.get().displayError("Your quota has been exceeded");
163 GSS.get().displayError("Unable to restore folder::"+((RestException)t).getHttpStatusText());
166 GSS.get().displayError("System error restoring folder:"+t.getMessage());
169 DeferredCommand.addCommand(rt);