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/>.
20 package gr.ebs.gss.client.tree;
22 import gr.ebs.gss.client.GSS;
23 import gr.ebs.gss.client.PopupTree;
24 import gr.ebs.gss.client.Folders.Images;
25 import gr.ebs.gss.client.dnd.DnDTreeItem;
26 import gr.ebs.gss.client.rest.GetCommand;
27 import gr.ebs.gss.client.rest.MultipleGetCommand;
28 import gr.ebs.gss.client.rest.resource.FolderResource;
29 import gr.ebs.gss.client.rest.resource.OtherUserResource;
30 import gr.ebs.gss.client.rest.resource.OthersResource;
31 import gr.ebs.gss.client.rest.resource.UserResource;
33 import java.util.List;
35 import com.google.gwt.core.client.GWT;
36 import com.google.gwt.user.client.DeferredCommand;
37 import com.google.gwt.user.client.IncrementalCommand;
38 import com.google.gwt.user.client.ui.TreeItem;
39 import com.google.gwt.user.client.ui.Widget;
44 public class OthersSharesSubtree extends Subtree {
47 * A constant that denotes the completion of an IncrementalCommand.
49 public static final boolean DONE = false;
51 private DnDTreeItem rootItem;
53 public OthersSharesSubtree(PopupTree aTree, final Images _images) {
54 super(aTree, _images);
55 DeferredCommand.addCommand(new IncrementalCommand() {
58 public boolean execute() {
64 public boolean updateInit() {
65 UserResource userResource = GSS.get().getCurrentUserResource();
66 if (userResource == null ||
67 GSS.get().getFolders().getRootItem() == null ||
68 GSS.get().getFolders().getTrashItem() == null ||
69 GSS.get().getFolders().getMySharesItem() == null)
72 GetCommand<OthersResource> go = new GetCommand<OthersResource>(OthersResource.class,
73 userResource.getOthersPath(), null) {
76 public void onComplete() {
77 Widget rootItemWidget = imageItemHTML(images.othersShared(), "Other's Shared");
78 rootItemWidget.getElement().setId("tree.othersShared");
79 rootItem = new DnDTreeItem(rootItemWidget, false,tree,true);
80 rootItem.setUserObject(getResult());
81 tree.addItem(rootItem);
82 //rootItem.removeItems();
84 GSS.get().removeGlassPanel();
88 public void onError(Throwable t) {
89 GWT.log("Error fetching Others Root folder", t);
90 GSS.get().displayError("Unable to fetch Others Root folder");
92 rootItem = new DnDTreeItem(imageItemHTML(images.othersShared(), "ERROR"), false,tree);
93 tree.addItem(rootItem);
97 DeferredCommand.addCommand(go);
101 public void update(final DnDTreeItem folderItem) {
102 if (folderItem.getOthersResource() != null) {
103 UserResource userResource = GSS.get().getCurrentUserResource();
104 GetCommand<OthersResource> go = new GetCommand<OthersResource>(OthersResource.class,
105 userResource.getOthersPath(), null) {
108 public void onComplete() {
109 final OthersResource others = getResult();
110 rootItem.setUserObject(others);
111 MultipleGetCommand<OtherUserResource> gogo = new MultipleGetCommand<OtherUserResource>(OtherUserResource.class,
112 folderItem.getOthersResource().getOthers().toArray(new String[] {}), null) {
115 public void onComplete() {
116 List<OtherUserResource> res = getResult();
117 folderItem.removeItems();
118 for (OtherUserResource r : res) {
119 DnDTreeItem child = (DnDTreeItem) addImageItem(folderItem,
120 r.getName(), images.folderYellow(), true);
121 r.setUsername(others.getUsernameOfUri(r.getUri()));
122 GWT.log("Setting username:"+r.getUsername(), null );
123 child.setUserObject(r);
124 child.setState(false);
129 public void onError(Throwable t) {
130 GWT.log("Error fetching Others Root folder", t);
131 GSS.get().displayError("Unable to fetch Others Root folder");
135 public void onError(String p, Throwable throwable) {
136 GWT.log("Path:"+p, throwable);
139 DeferredCommand.addCommand(gogo);
143 public void onError(Throwable t) {
144 GWT.log("Error fetching Others Root folder", t);
145 GSS.get().displayError("Unable to fetch Others Root folder");
150 DeferredCommand.addCommand(go);
151 } else if (folderItem.getOtherUserResource() != null) {
153 GetCommand<OtherUserResource> go = new GetCommand<OtherUserResource>(OtherUserResource.class,
154 folderItem.getOtherUserResource().getUri(), null) {
157 public void onComplete() {
158 OtherUserResource res = getResult();
159 folderItem.removeItems();
160 for (FolderResource r : res.getFolders()) {
161 DnDTreeItem child = (DnDTreeItem) addImageItem(folderItem,
162 r.getName(), images.folderYellow(), true);
163 child.setUserObject(r);
165 updateFolderAndSubfolders(child);
170 public void onError(Throwable t) {
171 GWT.log("Error fetching Others Root folder", t);
172 GSS.get().displayError("Unable to fetch Others Root folder");
176 DeferredCommand.addCommand(go);
177 } else if (folderItem.getFolderResource() != null) {
178 GWT.log("UPDATING :"+folderItem.getFolderResource().getName(), null);
179 MultipleGetCommand<FolderResource> go = new MultipleGetCommand<FolderResource>(FolderResource.class,
180 folderItem.getFolderResource().getSubfolderPaths().toArray(new String[] {}), folderItem.getFolderResource().getCache()) {
183 public void onComplete() {
184 List<FolderResource> res = getResult();
185 folderItem.removeItems();
186 GWT.log("UPDATING :"+folderItem.getFolderResource().getName()+" :"+res.size(), null);
187 for (FolderResource r : res) {
188 DnDTreeItem child = (DnDTreeItem) addImageItem(folderItem,
189 r.getName(), images.folderYellow(), true);
190 child.setUserObject(r);
196 public void onError(Throwable t) {
197 GWT.log("Error fetching Others Root folder", t);
198 GSS.get().displayError("Unable to fetch Others Root folder");
202 public void onError(String p, Throwable throwable) {
203 GWT.log("Path:"+p, throwable);
206 DeferredCommand.addCommand(go);
211 public void updateFolderAndSubfolders(final DnDTreeItem folderItem) {
212 if (folderItem.getFolderResource() != null) {
213 final String path = folderItem.getFolderResource().getUri();
214 GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, path, folderItem.getFolderResource()) {
217 public void onComplete() {
218 FolderResource rootResource = getResult();
219 folderItem.undoDraggable();
220 folderItem.updateWidget(imageItemHTML(images.folderYellow(), rootResource.getName()));
221 folderItem.setUserObject(rootResource);
222 folderItem.doDraggable();
226 public void onError(Throwable t) {
227 GWT.log("Error fetching folder", t);
228 GSS.get().displayError("Unable to fetch folder:" + folderItem.getFolderResource().getName());
231 DeferredCommand.addCommand(gf);
236 * Retrieve the rootItem.
238 * @return the rootItem
240 public TreeItem getRootItem() {