Revision 555e8e59 gss/src/gr/ebs/gss/client/commands/RestoreTrashCommand.java

b/gss/src/gr/ebs/gss/client/commands/RestoreTrashCommand.java
25 25
import gr.ebs.gss.client.rest.RestException;
26 26
import gr.ebs.gss.client.rest.resource.FileResource;
27 27
import gr.ebs.gss.client.rest.resource.FolderResource;
28
import gr.ebs.gss.client.rest.resource.GroupResource;
29
import gr.ebs.gss.client.rest.resource.GroupUserResource;
30 28

  
31 29
import java.util.ArrayList;
32 30
import java.util.List;
......
40 38

  
41 39
/**
42 40
 *
43
 * Restore trashed files and folders
44
 * @author kman
41
 * Restore trashed files and folders.
45 42
 *
43
 * @author kman
46 44
 */
47 45
public class RestoreTrashCommand implements Command{
48 46
	private PopupPanel containerPanel;
......
50 48
	public RestoreTrashCommand(PopupPanel _containerPanel){
51 49
		containerPanel = _containerPanel;
52 50
	}
53
	/* (non-Javadoc)
54
	 * @see com.google.gwt.user.client.Command#execute()
55
	 */
51

  
56 52
	public void execute() {
57 53
		containerPanel.hide();
58 54
		Object selection = GSS.get().getCurrentSelection();
59 55
		if (selection == null){
60
			//check to see if Trash Node is selected
61
			final List folderList = new ArrayList();
56
			// Check to see if Trash Node is selected.
57
			List folderList = new ArrayList();
62 58
			TreeItem trashItem = GSS.get().getFolders().getTrashItem();
63 59
			for(int i=0 ; i < trashItem.getChildCount() ; i++)
64 60
				folderList.add(trashItem.getChild(i).getUserObject());
65
			if(GSS.get().getFolders().getCurrent().equals(GSS.get().getFolders().getTrashItem()))
66
				/*
67
				GSS.get().getRemoteService().restoreTrash(GSS.get().getCurrentUser().getId(), new AsyncCallback() {
68

  
69
					public void onSuccess(final Object result) {
70
						for(int k=0 ; k < folderList.size(); k++){
71
							FolderDTO fdto = (FolderDTO)folderList.get(k);
72
							GSS.get().getFolders().update(GSS.get().getCurrentUser().getId(), GSS.get().getFolders().getUserItem(fdto.getParent()));
73
						}
74
						GSS.get().getFolders().update(GSS.get().getCurrentUser().getId(), GSS.get().getFolders().getTrashItem());
75
						GSS.get().getFolders().update(GSS.get().getCurrentUser().getId(), GSS.get().getFolders().getMySharesItem());
76
						GSS.get().getFileList().updateFileCache(GSS.get().getCurrentUser().getId());
77

  
78
					}
79

  
80
					public void onFailure(final Throwable caught) {
81
						GWT.log("", caught);
82
						if (caught instanceof RpcException)
83
							GSS.get().displayError("An error occurred while " + "communicating with the server: " + caught.getMessage());
84
						else
85
							GSS.get().displayError(caught.getMessage());
86
					}
87
				});
88
				*/
89 61
			return;
90 62
		}
91 63
		GWT.log("selection: " + selection.toString(), null);
92 64
		if (selection instanceof FileResource) {
93 65
			final FileResource resource = (FileResource)selection;
94
			ExecutePost rt = new ExecutePost(resource.getPath()+"?restore=","", 200){
66
			ExecutePost rt = new ExecutePost(resource.getUri()+"?restore=","", 200){
95 67

  
68
				@Override
96 69
				public void onComplete() {
97 70
					GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
98 71
					GSS.get().showFileList(true);
99 72
				}
100 73

  
74
				@Override
101 75
				public void onError(Throwable t) {
102 76
					GWT.log("", t);
103 77
					if(t instanceof RestException){
......
123 97
			final List<FileResource> fdtos = (List<FileResource>) selection;
124 98
			final List<String> fileIds = new ArrayList<String>();
125 99
			for(FileResource f : fdtos)
126
				fileIds.add(f.getPath()+"?restore=");
100
				fileIds.add(f.getUri()+"?restore=");
127 101
			ExecuteMultiplePost rt = new ExecuteMultiplePost(fileIds.toArray(new String[0]), 200){
128 102

  
103
				@Override
129 104
				public void onComplete() {
130 105
					GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
131 106
					GSS.get().showFileList(true);
132 107
				}
133 108

  
134

  
109
				@Override
135 110
				public void onError(String p, Throwable t) {
136 111
					GWT.log("", t);
137 112
					if(t instanceof RestException){
......
149 124
					}
150 125
					else
151 126
						GSS.get().displayError("System error restoring file:"+t.getMessage());
152

  
153 127
				}
154 128
			};
155 129
			DeferredCommand.addCommand(rt);
156 130
		}
157 131
		else if (selection instanceof FolderResource) {
158 132
			final FolderResource resource = (FolderResource)selection;
159
			ExecutePost rt = new ExecutePost(resource.getPath()+"?restore=","", 200){
133
			ExecutePost rt = new ExecutePost(resource.getUri()+"?restore=","", 200){
160 134

  
135
				@Override
161 136
				public void onComplete() {
162 137
					GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getRootItem());
163 138

  
164 139
					GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
165 140
				}
166 141

  
142
				@Override
167 143
				public void onError(Throwable t) {
168 144
					GWT.log("", t);
169 145
					if(t instanceof RestException){
......
184 160
				}
185 161
			};
186 162
			DeferredCommand.addCommand(rt);
187
		} else if (selection instanceof GroupUserResource) {
188
			// TODO do we need trash in users?
189
		} else if (selection instanceof GroupResource) {
190
			// TODO do we need trash for groups?
191 163
		}
192 164

  
193 165
	}

Also available in: Unified diff