root / src / gr / ebs / gss / client / commands / RestoreTrashCommand.java @ 44d84dc0
History | View | Annotate | Download (5.7 kB)
1 | 14ad7326 | pastith | /*
|
---|---|---|---|
2 | 14ad7326 | pastith | * Copyright 2008, 2009 Electronic Business Systems Ltd.
|
3 | 14ad7326 | pastith | *
|
4 | 14ad7326 | pastith | * This file is part of GSS.
|
5 | 14ad7326 | pastith | *
|
6 | 14ad7326 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 14ad7326 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 14ad7326 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 14ad7326 | pastith | * (at your option) any later version.
|
10 | 14ad7326 | pastith | *
|
11 | 14ad7326 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 14ad7326 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 14ad7326 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 14ad7326 | pastith | * GNU General Public License for more details.
|
15 | 14ad7326 | pastith | *
|
16 | 14ad7326 | pastith | * You should have received a copy of the GNU General Public License
|
17 | 14ad7326 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 14ad7326 | pastith | */
|
19 | 14ad7326 | pastith | package gr.ebs.gss.client.commands; |
20 | 14ad7326 | pastith | |
21 | 14ad7326 | pastith | import gr.ebs.gss.client.GSS; |
22 | 67b23651 | koutsoub | import gr.ebs.gss.client.dnd.DnDTreeItem; |
23 | 895035a2 | pastith | import gr.ebs.gss.client.rest.MultiplePostCommand; |
24 | 895035a2 | pastith | import gr.ebs.gss.client.rest.PostCommand; |
25 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.RestException; |
26 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.FileResource; |
27 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.FolderResource; |
28 | 14ad7326 | pastith | |
29 | 14ad7326 | pastith | import java.util.ArrayList; |
30 | 14ad7326 | pastith | import java.util.List; |
31 | 14ad7326 | pastith | |
32 | 14ad7326 | pastith | import com.google.gwt.core.client.GWT; |
33 | 14ad7326 | pastith | import com.google.gwt.user.client.Command; |
34 | a52ea5e4 | pastith | import com.google.gwt.user.client.DeferredCommand; |
35 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.PopupPanel; |
36 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.TreeItem; |
37 | 14ad7326 | pastith | |
38 | 14ad7326 | pastith | |
39 | 14ad7326 | pastith | /**
|
40 | 14ad7326 | pastith | *
|
41 | 555e8e59 | pastith | * Restore trashed files and folders.
|
42 | 14ad7326 | pastith | *
|
43 | 555e8e59 | pastith | * @author kman
|
44 | 14ad7326 | pastith | */
|
45 | 14ad7326 | pastith | public class RestoreTrashCommand implements Command{ |
46 | 14ad7326 | pastith | private PopupPanel containerPanel;
|
47 | 14ad7326 | pastith | |
48 | 14ad7326 | pastith | public RestoreTrashCommand(PopupPanel _containerPanel){
|
49 | 14ad7326 | pastith | containerPanel = _containerPanel; |
50 | 14ad7326 | pastith | } |
51 | 555e8e59 | pastith | |
52 | 14ad7326 | pastith | public void execute() { |
53 | 14ad7326 | pastith | containerPanel.hide(); |
54 | 14ad7326 | pastith | Object selection = GSS.get().getCurrentSelection();
|
55 | 14ad7326 | pastith | if (selection == null){ |
56 | 555e8e59 | pastith | // Check to see if Trash Node is selected.
|
57 | 555e8e59 | pastith | List folderList = new ArrayList(); |
58 | 14ad7326 | pastith | TreeItem trashItem = GSS.get().getFolders().getTrashItem(); |
59 | 14ad7326 | pastith | for(int i=0 ; i < trashItem.getChildCount() ; i++) |
60 | 14ad7326 | pastith | folderList.add(trashItem.getChild(i).getUserObject()); |
61 | 14ad7326 | pastith | return;
|
62 | 14ad7326 | pastith | } |
63 | 14ad7326 | pastith | GWT.log("selection: " + selection.toString(), null); |
64 | a52ea5e4 | pastith | if (selection instanceof FileResource) { |
65 | a52ea5e4 | pastith | final FileResource resource = (FileResource)selection;
|
66 | 895035a2 | pastith | PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){ |
67 | 14ad7326 | pastith | |
68 | 555e8e59 | pastith | @Override
|
69 | a52ea5e4 | pastith | public void onComplete() { |
70 | a52ea5e4 | pastith | GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem()); |
71 | a52ea5e4 | pastith | GSS.get().showFileList(true);
|
72 | 14ad7326 | pastith | } |
73 | 14ad7326 | pastith | |
74 | 555e8e59 | pastith | @Override
|
75 | a52ea5e4 | pastith | public void onError(Throwable t) { |
76 | a52ea5e4 | pastith | GWT.log("", t);
|
77 | a52ea5e4 | pastith | if(t instanceof RestException){ |
78 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
79 | a52ea5e4 | pastith | if(statusCode == 405) |
80 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
81 | a52ea5e4 | pastith | else if(statusCode == 404) |
82 | a52ea5e4 | pastith | GSS.get().displayError("File does not exist");
|
83 | a52ea5e4 | pastith | else if(statusCode == 409) |
84 | a52ea5e4 | pastith | GSS.get().displayError("A file with the same name already exists");
|
85 | a52ea5e4 | pastith | else if(statusCode == 413) |
86 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
87 | a52ea5e4 | pastith | else
|
88 | 8218842e | koutsoub | GSS.get().displayError("Unable to restore file:"+((RestException)t).getHttpStatusText());
|
89 | a52ea5e4 | pastith | } |
90 | 14ad7326 | pastith | else
|
91 | a52ea5e4 | pastith | GSS.get().displayError("System error restoring file:"+t.getMessage());
|
92 | 14ad7326 | pastith | } |
93 | a52ea5e4 | pastith | }; |
94 | a52ea5e4 | pastith | DeferredCommand.addCommand(rt); |
95 | 14ad7326 | pastith | } |
96 | 14ad7326 | pastith | else if (selection instanceof List) { |
97 | a52ea5e4 | pastith | final List<FileResource> fdtos = (List<FileResource>) selection; |
98 | a52ea5e4 | pastith | final List<String> fileIds = new ArrayList<String>(); |
99 | a52ea5e4 | pastith | for(FileResource f : fdtos)
|
100 | 555e8e59 | pastith | fileIds.add(f.getUri()+"?restore=");
|
101 | 895035a2 | pastith | MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), 200){ |
102 | a52ea5e4 | pastith | |
103 | 555e8e59 | pastith | @Override
|
104 | a52ea5e4 | pastith | public void onComplete() { |
105 | a52ea5e4 | pastith | GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem()); |
106 | a52ea5e4 | pastith | GSS.get().showFileList(true);
|
107 | 14ad7326 | pastith | } |
108 | 14ad7326 | pastith | |
109 | 555e8e59 | pastith | @Override
|
110 | a52ea5e4 | pastith | public void onError(String p, Throwable t) { |
111 | a52ea5e4 | pastith | GWT.log("", t);
|
112 | a52ea5e4 | pastith | if(t instanceof RestException){ |
113 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
114 | a52ea5e4 | pastith | if(statusCode == 405) |
115 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
116 | a52ea5e4 | pastith | else if(statusCode == 404) |
117 | a52ea5e4 | pastith | GSS.get().displayError("File does not exist");
|
118 | a52ea5e4 | pastith | else if(statusCode == 409) |
119 | a52ea5e4 | pastith | GSS.get().displayError("A file with the same name already exists");
|
120 | a52ea5e4 | pastith | else if(statusCode == 413) |
121 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
122 | a52ea5e4 | pastith | else
|
123 | 8218842e | koutsoub | GSS.get().displayError("Unable to restore file::"+((RestException)t).getHttpStatusText());
|
124 | a52ea5e4 | pastith | } |
125 | 14ad7326 | pastith | else
|
126 | a52ea5e4 | pastith | GSS.get().displayError("System error restoring file:"+t.getMessage());
|
127 | a52ea5e4 | pastith | } |
128 | a52ea5e4 | pastith | }; |
129 | a52ea5e4 | pastith | DeferredCommand.addCommand(rt); |
130 | 14ad7326 | pastith | } |
131 | a52ea5e4 | pastith | else if (selection instanceof FolderResource) { |
132 | a52ea5e4 | pastith | final FolderResource resource = (FolderResource)selection;
|
133 | 895035a2 | pastith | PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){ |
134 | a52ea5e4 | pastith | |
135 | 555e8e59 | pastith | @Override
|
136 | a52ea5e4 | pastith | public void onComplete() { |
137 | 67b23651 | koutsoub | GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getRootItem()); |
138 | 67b23651 | koutsoub | |
139 | a52ea5e4 | pastith | GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem()); |
140 | 14ad7326 | pastith | } |
141 | 14ad7326 | pastith | |
142 | 555e8e59 | pastith | @Override
|
143 | a52ea5e4 | pastith | public void onError(Throwable t) { |
144 | a52ea5e4 | pastith | GWT.log("", t);
|
145 | a52ea5e4 | pastith | if(t instanceof RestException){ |
146 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
147 | a52ea5e4 | pastith | if(statusCode == 405) |
148 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
149 | a52ea5e4 | pastith | else if(statusCode == 404) |
150 | a52ea5e4 | pastith | GSS.get().displayError("Folder does not exist");
|
151 | a52ea5e4 | pastith | else if(statusCode == 409) |
152 | a52ea5e4 | pastith | GSS.get().displayError("A folder with the same name already exists");
|
153 | a52ea5e4 | pastith | else if(statusCode == 413) |
154 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
155 | a52ea5e4 | pastith | else
|
156 | 8218842e | koutsoub | GSS.get().displayError("Unable to restore folder::"+((RestException)t).getHttpStatusText());
|
157 | a52ea5e4 | pastith | } |
158 | 14ad7326 | pastith | else
|
159 | a52ea5e4 | pastith | GSS.get().displayError("System error restoring folder:"+t.getMessage());
|
160 | 14ad7326 | pastith | } |
161 | a52ea5e4 | pastith | }; |
162 | a52ea5e4 | pastith | DeferredCommand.addCommand(rt); |
163 | 14ad7326 | pastith | } |
164 | 14ad7326 | pastith | |
165 | 14ad7326 | pastith | } |
166 | 14ad7326 | pastith | |
167 | 14ad7326 | pastith | } |