2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
35 package gr.grnet.pithos.web.client.commands;
37 import gr.grnet.pithos.web.client.GSS;
38 import gr.grnet.pithos.web.client.rest.MultiplePostCommand;
39 import gr.grnet.pithos.web.client.rest.PostCommand;
40 import gr.grnet.pithos.web.client.rest.RestException;
41 import gr.grnet.pithos.web.client.rest.resource.FileResource;
42 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
43 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
45 import java.util.ArrayList;
46 import java.util.List;
49 import com.google.gwt.core.client.GWT;
50 import com.google.gwt.user.client.Command;
51 import com.google.gwt.user.client.DeferredCommand;
52 import com.google.gwt.user.client.ui.PopupPanel;
56 * Move file or folder to trash.
60 public class ToTrashCommand implements Command{
61 private PopupPanel containerPanel;
63 public ToTrashCommand(PopupPanel _containerPanel){
64 containerPanel = _containerPanel;
68 public void execute() {
69 containerPanel.hide();
70 Object selection = GSS.get().getCurrentSelection();
71 if (selection == null)
73 GWT.log("selection: " + selection.toString(), null);
74 if (selection instanceof RestResourceWrapper) {
75 FolderResource fdto = ((RestResourceWrapper) selection).getResource();
76 PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){
79 public void onComplete() {
82 TreeItem folder = GSS.get().getFolders().getCurrent();
83 if(folder.getParentItem() != null){
84 GSS.get().getFolders().select(folder.getParentItem());
85 GSS.get().getFolders().updateFolder((DnDTreeItem) folder.getParentItem());
87 GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
89 FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();
90 GSS.get().getTreeView().updateNodeChildrenForRemove(fres.getParentURI());
91 GSS.get().getTreeView().clearSelection();
92 //GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getTrash());
93 GSS.get().getTreeView().updateTrashNode();
94 GSS.get().showFileList(true);
98 public void onError(Throwable t) {
100 if(t instanceof RestException){
101 int statusCode = ((RestException)t).getHttpStatusCode();
102 if(statusCode == 405)
103 GSS.get().displayError("You don't have the necessary permissions");
104 else if(statusCode == 404)
105 GSS.get().displayError("Folder does not exist");
107 GSS.get().displayError("Unable to trash folder:"+((RestException)t).getHttpStatusText());
110 GSS.get().displayError("System error trashing folder:"+t.getMessage());
113 DeferredCommand.addCommand(tot);
114 } else if (selection instanceof FileResource) {
115 FileResource fdto = (FileResource) selection;
116 PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){
119 public void onComplete() {
120 GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
124 public void onError(Throwable t) {
126 if(t instanceof RestException){
127 int statusCode = ((RestException)t).getHttpStatusCode();
128 if(statusCode == 405)
129 GSS.get().displayError("You don't have the necessary permissions");
130 else if(statusCode == 404)
131 GSS.get().displayError("File does not exist");
133 GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
136 GSS.get().displayError("System error trashing file:"+t.getMessage());
139 DeferredCommand.addCommand(tot);
142 else if (selection instanceof List) {
143 List<FileResource> fdtos = (List<FileResource>) selection;
144 final List<String> fileIds = new ArrayList<String>();
145 for(FileResource f : fdtos)
146 fileIds.add(f.getUri()+"?trash=");
147 MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]),200){
150 public void onComplete() {
151 GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
155 public void onError(String p, Throwable t) {
157 if(t instanceof RestException){
158 int statusCode = ((RestException)t).getHttpStatusCode();
159 if(statusCode == 405)
160 GSS.get().displayError("You don't have the necessary permissions");
161 else if(statusCode == 404)
162 GSS.get().displayError("File does not exist");
164 GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
167 GSS.get().displayError("System error trashing file:"+t.getMessage());
170 DeferredCommand.addCommand(tot);