root / src / gr / ebs / gss / client / commands / RestoreTrashCommand.java @ f1112116
History | View | Annotate | Download (5.9 kB)
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.commands; |
20 |
|
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.TrashFolderResource; |
28 |
import gr.ebs.gss.client.rest.resource.TrashResource; |
29 |
|
30 |
import java.util.ArrayList; |
31 |
import java.util.List; |
32 |
|
33 |
import com.google.gwt.core.client.GWT; |
34 |
import com.google.gwt.user.client.Command; |
35 |
import com.google.gwt.user.client.DeferredCommand; |
36 |
import com.google.gwt.user.client.ui.PopupPanel; |
37 |
|
38 |
|
39 |
/**
|
40 |
*
|
41 |
* Restore trashed files and folders.
|
42 |
*
|
43 |
* @author kman
|
44 |
*/
|
45 |
public class RestoreTrashCommand implements Command{ |
46 |
private PopupPanel containerPanel;
|
47 |
|
48 |
public RestoreTrashCommand(PopupPanel _containerPanel){
|
49 |
containerPanel = _containerPanel; |
50 |
} |
51 |
|
52 |
@Override
|
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)); |
62 |
return;
|
63 |
} |
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){ |
68 |
|
69 |
@Override
|
70 |
public void onComplete() { |
71 |
//TODO:CELLTREE
|
72 |
//GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
|
73 |
|
74 |
GSS.get().showFileList(true);
|
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void onError(Throwable t) { |
79 |
GWT.log("", t);
|
80 |
if(t instanceof RestException){ |
81 |
int statusCode = ((RestException)t).getHttpStatusCode();
|
82 |
if(statusCode == 405) |
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");
|
90 |
else
|
91 |
GSS.get().displayError("Unable to restore file:"+((RestException)t).getHttpStatusText());
|
92 |
} |
93 |
else
|
94 |
GSS.get().displayError("System error restoring file:"+t.getMessage());
|
95 |
} |
96 |
}; |
97 |
DeferredCommand.addCommand(rt); |
98 |
} |
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){ |
105 |
|
106 |
@Override
|
107 |
public void onComplete() { |
108 |
//TODO:CELLTREE
|
109 |
//GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
|
110 |
GSS.get().showFileList(true);
|
111 |
} |
112 |
|
113 |
@Override
|
114 |
public void onError(String p, Throwable t) { |
115 |
GWT.log("", 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");
|
126 |
else
|
127 |
GSS.get().displayError("Unable to restore file::"+((RestException)t).getHttpStatusText());
|
128 |
} |
129 |
else
|
130 |
GSS.get().displayError("System error restoring file:"+t.getMessage());
|
131 |
} |
132 |
}; |
133 |
DeferredCommand.addCommand(rt); |
134 |
} |
135 |
else if (selection instanceof TrashFolderResource) { |
136 |
final FolderResource resource = ((TrashFolderResource)selection).getResource();
|
137 |
PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){ |
138 |
|
139 |
@Override
|
140 |
public void onComplete() { |
141 |
//TODO:CELLTREE
|
142 |
/*
|
143 |
GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getRootItem());
|
144 |
|
145 |
GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
|
146 |
*/
|
147 |
|
148 |
GSS.get().getTreeView().updateTrashNode(); |
149 |
GSS.get().getTreeView().updateRootNode(); |
150 |
} |
151 |
|
152 |
@Override
|
153 |
public void onError(Throwable t) { |
154 |
GWT.log("", t);
|
155 |
if(t instanceof RestException){ |
156 |
int statusCode = ((RestException)t).getHttpStatusCode();
|
157 |
if(statusCode == 405) |
158 |
GSS.get().displayError("You don't have the necessary permissions");
|
159 |
else if(statusCode == 404) |
160 |
GSS.get().displayError("Folder does not exist");
|
161 |
else if(statusCode == 409) |
162 |
GSS.get().displayError("A folder with the same name already exists");
|
163 |
else if(statusCode == 413) |
164 |
GSS.get().displayError("Your quota has been exceeded");
|
165 |
else
|
166 |
GSS.get().displayError("Unable to restore folder::"+((RestException)t).getHttpStatusText());
|
167 |
} |
168 |
else
|
169 |
GSS.get().displayError("System error restoring folder:"+t.getMessage());
|
170 |
} |
171 |
}; |
172 |
DeferredCommand.addCommand(rt); |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
} |