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().clearSelection();
77 //GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getTrash());
78 GSS.get().getTreeView().updateTrashNode();
79 GSS.get().showFileList(true);
83 public void onError(Throwable t) {
85 if(t instanceof RestException){
86 int statusCode = ((RestException)t).getHttpStatusCode();
88 GSS.get().displayError("You don't have the necessary permissions");
89 else if(statusCode == 404)
90 GSS.get().displayError("Folder does not exist");
92 GSS.get().displayError("Unable to trash folder:"+((RestException)t).getHttpStatusText());
95 GSS.get().displayError("System error trashing folder:"+t.getMessage());
98 DeferredCommand.addCommand(tot);
99 } else if (selection instanceof FileResource) {
100 FileResource fdto = (FileResource) selection;
101 PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){
104 public void onComplete() {
105 GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
109 public void onError(Throwable t) {
111 if(t instanceof RestException){
112 int statusCode = ((RestException)t).getHttpStatusCode();
113 if(statusCode == 405)
114 GSS.get().displayError("You don't have the necessary permissions");
115 else if(statusCode == 404)
116 GSS.get().displayError("File does not exist");
118 GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
121 GSS.get().displayError("System error trashing file:"+t.getMessage());
124 DeferredCommand.addCommand(tot);
127 else if (selection instanceof List) {
128 List<FileResource> fdtos = (List<FileResource>) selection;
129 final List<String> fileIds = new ArrayList<String>();
130 for(FileResource f : fdtos)
131 fileIds.add(f.getUri()+"?trash=");
132 MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]),200){
135 public void onComplete() {
136 GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
140 public void onError(String p, Throwable t) {
142 if(t instanceof RestException){
143 int statusCode = ((RestException)t).getHttpStatusCode();
144 if(statusCode == 405)
145 GSS.get().displayError("You don't have the necessary permissions");
146 else if(statusCode == 404)
147 GSS.get().displayError("File does not exist");
149 GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
152 GSS.get().displayError("System error trashing file:"+t.getMessage());
155 DeferredCommand.addCommand(tot);