root / src / gr / ebs / gss / client / commands / ToTrashCommand.java @ 623:66f69a7348ed
History | View | Annotate | Download (4.8 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.dnd.DnDTreeItem; |
23 |
import gr.ebs.gss.client.rest.MultiplePostCommand; |
24 |
import gr.ebs.gss.client.rest.PostCommand; |
25 |
import gr.ebs.gss.client.rest.RestException; |
26 |
import gr.ebs.gss.client.rest.resource.FileResource; |
27 |
import gr.ebs.gss.client.rest.resource.FolderResource; |
28 |
|
29 |
import java.util.ArrayList; |
30 |
import java.util.List; |
31 |
|
32 |
import com.google.gwt.core.client.GWT; |
33 |
import com.google.gwt.user.client.Command; |
34 |
import com.google.gwt.user.client.DeferredCommand; |
35 |
import com.google.gwt.user.client.ui.PopupPanel; |
36 |
import com.google.gwt.user.client.ui.TreeItem; |
37 |
|
38 |
/**
|
39 |
*
|
40 |
* Move file or folder to trash.
|
41 |
*
|
42 |
* @author kman
|
43 |
*
|
44 |
*/
|
45 |
public class ToTrashCommand implements Command{ |
46 |
private PopupPanel containerPanel;
|
47 |
|
48 |
public ToTrashCommand(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 |
return;
|
58 |
GWT.log("selection: " + selection.toString(), null); |
59 |
if (selection instanceof FolderResource) { |
60 |
FolderResource fdto = (FolderResource) selection; |
61 |
PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){ |
62 |
|
63 |
@Override
|
64 |
public void onComplete() { |
65 |
TreeItem folder = GSS.get().getFolders().getCurrent(); |
66 |
if(folder.getParentItem() != null){ |
67 |
GSS.get().getFolders().select(folder.getParentItem()); |
68 |
GSS.get().getFolders().updateFolder((DnDTreeItem) folder.getParentItem()); |
69 |
} |
70 |
GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem()); |
71 |
GSS.get().showFileList(true);
|
72 |
} |
73 |
|
74 |
@Override
|
75 |
public void onError(Throwable t) { |
76 |
GWT.log("", t);
|
77 |
if(t instanceof RestException){ |
78 |
int statusCode = ((RestException)t).getHttpStatusCode();
|
79 |
if(statusCode == 405) |
80 |
GSS.get().displayError("You don't have the necessary permissions");
|
81 |
else if(statusCode == 404) |
82 |
GSS.get().displayError("Folder does not exist");
|
83 |
else
|
84 |
GSS.get().displayError("Unable to trash folder:"+((RestException)t).getHttpStatusText());
|
85 |
} |
86 |
else
|
87 |
GSS.get().displayError("System error trashing folder:"+t.getMessage());
|
88 |
} |
89 |
}; |
90 |
DeferredCommand.addCommand(tot); |
91 |
} else if (selection instanceof FileResource) { |
92 |
FileResource fdto = (FileResource) selection; |
93 |
PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){ |
94 |
|
95 |
@Override
|
96 |
public void onComplete() { |
97 |
GSS.get().showFileList(true);
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public void onError(Throwable t) { |
102 |
GWT.log("", t);
|
103 |
if(t instanceof RestException){ |
104 |
int statusCode = ((RestException)t).getHttpStatusCode();
|
105 |
if(statusCode == 405) |
106 |
GSS.get().displayError("You don't have the necessary permissions");
|
107 |
else if(statusCode == 404) |
108 |
GSS.get().displayError("File does not exist");
|
109 |
else
|
110 |
GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
|
111 |
} |
112 |
else
|
113 |
GSS.get().displayError("System error trashing file:"+t.getMessage());
|
114 |
} |
115 |
}; |
116 |
DeferredCommand.addCommand(tot); |
117 |
|
118 |
} |
119 |
else if (selection instanceof List) { |
120 |
List<FileResource> fdtos = (List<FileResource>) selection; |
121 |
final List<String> fileIds = new ArrayList<String>(); |
122 |
for(FileResource f : fdtos)
|
123 |
fileIds.add(f.getUri()+"?trash=");
|
124 |
MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]),200){ |
125 |
|
126 |
@Override
|
127 |
public void onComplete() { |
128 |
GSS.get().showFileList(true);
|
129 |
} |
130 |
|
131 |
@Override
|
132 |
public void onError(String p, Throwable t) { |
133 |
GWT.log("", t);
|
134 |
if(t instanceof RestException){ |
135 |
int statusCode = ((RestException)t).getHttpStatusCode();
|
136 |
if(statusCode == 405) |
137 |
GSS.get().displayError("You don't have the necessary permissions");
|
138 |
else if(statusCode == 404) |
139 |
GSS.get().displayError("File does not exist");
|
140 |
else
|
141 |
GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
|
142 |
} |
143 |
else
|
144 |
GSS.get().displayError("System error trashing file:"+t.getMessage());
|
145 |
} |
146 |
}; |
147 |
DeferredCommand.addCommand(tot); |
148 |
} |
149 |
} |
150 |
|
151 |
} |