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.RestResourceWrapper;
29 import java.util.ArrayList;
30 import java.util.List;
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;
40 * Move file or folder to trash.
45 public class ToTrashCommand implements Command{
46 private PopupPanel containerPanel;
48 public ToTrashCommand(PopupPanel _containerPanel){
49 containerPanel = _containerPanel;
53 public void execute() {
54 containerPanel.hide();
55 Object selection = GSS.get().getCurrentSelection();
56 if (selection == null)
58 GWT.log("selection: " + selection.toString(), null);
59 if (selection instanceof RestResourceWrapper) {
60 FolderResource fdto = ((RestResourceWrapper) selection).getResource();
61 PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){
64 public void onComplete() {
67 TreeItem folder = GSS.get().getFolders().getCurrent();
68 if(folder.getParentItem() != null){
69 GSS.get().getFolders().select(folder.getParentItem());
70 GSS.get().getFolders().updateFolder((DnDTreeItem) folder.getParentItem());
72 GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
74 FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();
75 GSS.get().getTreeView().updateNodeChildrenForRemove(fres.getParentURI());
76 //GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getTrash());
77 GSS.get().getTreeView().updateTrashNode();
78 GSS.get().showFileList(true);
82 public void onError(Throwable t) {
84 if(t instanceof RestException){
85 int statusCode = ((RestException)t).getHttpStatusCode();
87 GSS.get().displayError("You don't have the necessary permissions");
88 else if(statusCode == 404)
89 GSS.get().displayError("Folder does not exist");
91 GSS.get().displayError("Unable to trash folder:"+((RestException)t).getHttpStatusText());
94 GSS.get().displayError("System error trashing folder:"+t.getMessage());
97 DeferredCommand.addCommand(tot);
98 } else if (selection instanceof FileResource) {
99 FileResource fdto = (FileResource) selection;
100 PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){
103 public void onComplete() {
104 GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
108 public void onError(Throwable t) {
110 if(t instanceof RestException){
111 int statusCode = ((RestException)t).getHttpStatusCode();
112 if(statusCode == 405)
113 GSS.get().displayError("You don't have the necessary permissions");
114 else if(statusCode == 404)
115 GSS.get().displayError("File does not exist");
117 GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
120 GSS.get().displayError("System error trashing file:"+t.getMessage());
123 DeferredCommand.addCommand(tot);
126 else if (selection instanceof List) {
127 List<FileResource> fdtos = (List<FileResource>) selection;
128 final List<String> fileIds = new ArrayList<String>();
129 for(FileResource f : fdtos)
130 fileIds.add(f.getUri()+"?trash=");
131 MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]),200){
134 public void onComplete() {
135 GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
139 public void onError(String p, Throwable t) {
141 if(t instanceof RestException){
142 int statusCode = ((RestException)t).getHttpStatusCode();
143 if(statusCode == 405)
144 GSS.get().displayError("You don't have the necessary permissions");
145 else if(statusCode == 404)
146 GSS.get().displayError("File does not exist");
148 GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
151 GSS.get().displayError("System error trashing file:"+t.getMessage());
154 DeferredCommand.addCommand(tot);