root / src / org / gss_project / gss / web / client / commands / ToTrashCommand.java @ ab3fae7b
History | View | Annotate | Download (5.4 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 org.gss_project.gss.web.client.commands; |
20 |
|
21 |
import org.gss_project.gss.web.client.GSS; |
22 |
import org.gss_project.gss.web.client.rest.MultiplePostCommand; |
23 |
import org.gss_project.gss.web.client.rest.PostCommand; |
24 |
import org.gss_project.gss.web.client.rest.RestException; |
25 |
import org.gss_project.gss.web.client.rest.resource.FileResource; |
26 |
import org.gss_project.gss.web.client.rest.resource.FolderResource; |
27 |
import org.gss_project.gss.web.client.rest.resource.RestResourceWrapper; |
28 |
|
29 |
import java.util.ArrayList; |
30 |
import java.util.List; |
31 |
|
32 |
|
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; |
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 RestResourceWrapper) { |
60 |
FolderResource fdto = ((RestResourceWrapper) selection).getResource(); |
61 |
PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){ |
62 |
|
63 |
@Override
|
64 |
public void onComplete() { |
65 |
//TODO:CELLTREE
|
66 |
/*
|
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());
|
71 |
}
|
72 |
GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
|
73 |
*/
|
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);
|
80 |
} |
81 |
|
82 |
@Override
|
83 |
public void onError(Throwable t) { |
84 |
GWT.log("", t);
|
85 |
if(t instanceof RestException){ |
86 |
int statusCode = ((RestException)t).getHttpStatusCode();
|
87 |
if(statusCode == 405) |
88 |
GSS.get().displayError("You don't have the necessary permissions");
|
89 |
else if(statusCode == 404) |
90 |
GSS.get().displayError("Folder does not exist");
|
91 |
else
|
92 |
GSS.get().displayError("Unable to trash folder:"+((RestException)t).getHttpStatusText());
|
93 |
} |
94 |
else
|
95 |
GSS.get().displayError("System error trashing folder:"+t.getMessage());
|
96 |
} |
97 |
}; |
98 |
DeferredCommand.addCommand(tot); |
99 |
} else if (selection instanceof FileResource) { |
100 |
FileResource fdto = (FileResource) selection; |
101 |
PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){ |
102 |
|
103 |
@Override
|
104 |
public void onComplete() { |
105 |
GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); |
106 |
} |
107 |
|
108 |
@Override
|
109 |
public void onError(Throwable t) { |
110 |
GWT.log("", 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");
|
117 |
else
|
118 |
GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
|
119 |
} |
120 |
else
|
121 |
GSS.get().displayError("System error trashing file:"+t.getMessage());
|
122 |
} |
123 |
}; |
124 |
DeferredCommand.addCommand(tot); |
125 |
|
126 |
} |
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){ |
133 |
|
134 |
@Override
|
135 |
public void onComplete() { |
136 |
GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); |
137 |
} |
138 |
|
139 |
@Override
|
140 |
public void onError(String p, Throwable t) { |
141 |
GWT.log("", 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");
|
148 |
else
|
149 |
GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
|
150 |
} |
151 |
else
|
152 |
GSS.get().displayError("System error trashing file:"+t.getMessage());
|
153 |
} |
154 |
}; |
155 |
DeferredCommand.addCommand(tot); |
156 |
} |
157 |
} |
158 |
|
159 |
} |