Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / tree / OthersSharesSubtree.java @ 4856bcbf

History | View | Annotate | Download (7.7 kB)

1 14ad7326 pastith
/*
2 14ad7326 pastith
 * Copyright 2008, 2009 Electronic Business Systems Ltd.
3 14ad7326 pastith
 *
4 14ad7326 pastith
 * This file is part of GSS.
5 14ad7326 pastith
 *
6 14ad7326 pastith
 * GSS is free software: you can redistribute it and/or modify
7 14ad7326 pastith
 * it under the terms of the GNU General Public License as published by
8 14ad7326 pastith
 * the Free Software Foundation, either version 3 of the License, or
9 14ad7326 pastith
 * (at your option) any later version.
10 14ad7326 pastith
 *
11 14ad7326 pastith
 * GSS is distributed in the hope that it will be useful,
12 14ad7326 pastith
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14ad7326 pastith
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14ad7326 pastith
 * GNU General Public License for more details.
15 14ad7326 pastith
 *
16 14ad7326 pastith
 * You should have received a copy of the GNU General Public License
17 14ad7326 pastith
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 14ad7326 pastith
 */
19 a52ea5e4 pastith
20 14ad7326 pastith
package gr.ebs.gss.client.tree;
21 14ad7326 pastith
22 14ad7326 pastith
import gr.ebs.gss.client.GSS;
23 14ad7326 pastith
import gr.ebs.gss.client.PopupTree;
24 9ab5db6d Natasa Kapravelou
import gr.ebs.gss.client.Folders.Images;
25 14ad7326 pastith
import gr.ebs.gss.client.dnd.DnDTreeItem;
26 895035a2 pastith
import gr.ebs.gss.client.rest.GetCommand;
27 895035a2 pastith
import gr.ebs.gss.client.rest.MultipleGetCommand;
28 a52ea5e4 pastith
import gr.ebs.gss.client.rest.resource.FolderResource;
29 a52ea5e4 pastith
import gr.ebs.gss.client.rest.resource.OtherUserResource;
30 a52ea5e4 pastith
import gr.ebs.gss.client.rest.resource.OthersResource;
31 a52ea5e4 pastith
import gr.ebs.gss.client.rest.resource.UserResource;
32 14ad7326 pastith
33 14ad7326 pastith
import java.util.List;
34 14ad7326 pastith
35 14ad7326 pastith
import com.google.gwt.core.client.GWT;
36 14ad7326 pastith
import com.google.gwt.user.client.DeferredCommand;
37 14ad7326 pastith
import com.google.gwt.user.client.IncrementalCommand;
38 14ad7326 pastith
import com.google.gwt.user.client.ui.TreeItem;
39 a60ea262 Natasa Kapravelou
import com.google.gwt.user.client.ui.Widget;
40 14ad7326 pastith
41 14ad7326 pastith
/**
42 14ad7326 pastith
 * @author kman
43 14ad7326 pastith
 */
44 14ad7326 pastith
public class OthersSharesSubtree extends Subtree {
45 14ad7326 pastith
46 14ad7326 pastith
        /**
47 14ad7326 pastith
         * A constant that denotes the completion of an IncrementalCommand.
48 14ad7326 pastith
         */
49 14ad7326 pastith
        public static final boolean DONE = false;
50 14ad7326 pastith
51 14ad7326 pastith
        private DnDTreeItem rootItem;
52 14ad7326 pastith
53 35c3e1bc pastith
        public OthersSharesSubtree(PopupTree aTree, final Images _images) {
54 35c3e1bc pastith
                super(aTree, _images);
55 14ad7326 pastith
                DeferredCommand.addCommand(new IncrementalCommand() {
56 14ad7326 pastith
57 023f6f1e Panagiotis Astithas
                        @Override
58 14ad7326 pastith
                        public boolean execute() {
59 14ad7326 pastith
                                return updateInit();
60 14ad7326 pastith
                        }
61 14ad7326 pastith
                });
62 14ad7326 pastith
        }
63 14ad7326 pastith
64 14ad7326 pastith
        public boolean updateInit() {
65 a52ea5e4 pastith
                UserResource userResource = GSS.get().getCurrentUserResource();
66 35c3e1bc pastith
                if (userResource == null ||
67 35c3e1bc pastith
                                        GSS.get().getFolders().getRootItem() == null ||
68 35c3e1bc pastith
                                        GSS.get().getFolders().getTrashItem() == null ||
69 35c3e1bc pastith
                                        GSS.get().getFolders().getMySharesItem() == null)
70 14ad7326 pastith
                        return !DONE;
71 14ad7326 pastith
72 895035a2 pastith
                GetCommand<OthersResource> go = new GetCommand<OthersResource>(OthersResource.class,
73 62f168b2 Giannis Koutsoubos
                                        userResource.getOthersPath(), null) {
74 14ad7326 pastith
75 35c3e1bc pastith
                        @Override
76 a52ea5e4 pastith
                        public void onComplete() {
77 a60ea262 Natasa Kapravelou
                                Widget rootItemWidget = imageItemHTML(images.othersShared(), "Other's Shared");
78 a60ea262 Natasa Kapravelou
                                rootItemWidget.getElement().setId("tree.othersShared");
79 a60ea262 Natasa Kapravelou
                                rootItem = new DnDTreeItem(rootItemWidget, false,tree,true);
80 a52ea5e4 pastith
                                rootItem.setUserObject(getResult());
81 14ad7326 pastith
                                tree.addItem(rootItem);
82 f7c2e76a Giannis Koutsoubos
                                //rootItem.removeItems();
83 f7c2e76a Giannis Koutsoubos
                                //update(rootItem);
84 14ad7326 pastith
                                GSS.get().removeGlassPanel();
85 14ad7326 pastith
                        }
86 14ad7326 pastith
87 35c3e1bc pastith
                        @Override
88 a52ea5e4 pastith
                        public void onError(Throwable t) {
89 a52ea5e4 pastith
                                GWT.log("Error fetching Others Root folder", t);
90 a52ea5e4 pastith
                                GSS.get().displayError("Unable to fetch Others Root folder");
91 a52ea5e4 pastith
                                if(rootItem != null){
92 ff8eb545 Giannis Koutsoubos
                                        rootItem = new DnDTreeItem(imageItemHTML(images.othersShared(), "ERROR"), false,tree);
93 a52ea5e4 pastith
                                        tree.addItem(rootItem);
94 a52ea5e4 pastith
                                }
95 14ad7326 pastith
                        }
96 a52ea5e4 pastith
                };
97 a52ea5e4 pastith
                DeferredCommand.addCommand(go);
98 14ad7326 pastith
                return DONE;
99 14ad7326 pastith
        }
100 14ad7326 pastith
101 a52ea5e4 pastith
        public void update(final DnDTreeItem folderItem) {
102 a52ea5e4 pastith
                if (folderItem.getOthersResource() != null) {
103 e1813e25 Dimitris Routsis
                        UserResource userResource = GSS.get().getCurrentUserResource();
104 e1813e25 Dimitris Routsis
                        GetCommand<OthersResource> go = new GetCommand<OthersResource>(OthersResource.class,
105 62f168b2 Giannis Koutsoubos
                                                userResource.getOthersPath(), null) {
106 a52ea5e4 pastith
107 35c3e1bc pastith
                                @Override
108 a52ea5e4 pastith
                                public void onComplete() {
109 d98c561b Giannis Koutsoubos
                                        final OthersResource others = getResult();
110 d98c561b Giannis Koutsoubos
                                        rootItem.setUserObject(others);
111 e1813e25 Dimitris Routsis
                                        MultipleGetCommand<OtherUserResource> gogo = new MultipleGetCommand<OtherUserResource>(OtherUserResource.class,
112 62f168b2 Giannis Koutsoubos
                                                                folderItem.getOthersResource().getOthers().toArray(new String[] {}), null) {
113 e1813e25 Dimitris Routsis
114 e1813e25 Dimitris Routsis
                                                @Override
115 e1813e25 Dimitris Routsis
                                                public void onComplete() {
116 e1813e25 Dimitris Routsis
                                                        List<OtherUserResource> res = getResult();
117 e1813e25 Dimitris Routsis
                                                        folderItem.removeItems();
118 e1813e25 Dimitris Routsis
                                                        for (OtherUserResource r : res) {
119 e1813e25 Dimitris Routsis
                                                                DnDTreeItem child = (DnDTreeItem) addImageItem(folderItem,
120 e1813e25 Dimitris Routsis
                                                                                        r.getName(), images.folderYellow(), true);
121 d98c561b Giannis Koutsoubos
                                                                r.setUsername(others.getUsernameOfUri(r.getUri()));
122 d98c561b Giannis Koutsoubos
                                                                GWT.log("Setting username:"+r.getUsername(), null );
123 e1813e25 Dimitris Routsis
                                                                child.setUserObject(r);
124 e1813e25 Dimitris Routsis
                                                                child.setState(false);
125 e1813e25 Dimitris Routsis
                                                        }
126 e1813e25 Dimitris Routsis
                                                }
127 e1813e25 Dimitris Routsis
128 e1813e25 Dimitris Routsis
                                                @Override
129 e1813e25 Dimitris Routsis
                                                public void onError(Throwable t) {
130 e1813e25 Dimitris Routsis
                                                        GWT.log("Error fetching Others Root folder", t);
131 e1813e25 Dimitris Routsis
                                                        GSS.get().displayError("Unable to fetch Others Root folder");
132 e1813e25 Dimitris Routsis
                                                }
133 e1813e25 Dimitris Routsis
134 e1813e25 Dimitris Routsis
                                                @Override
135 e1813e25 Dimitris Routsis
                                                public void onError(String p, Throwable throwable) {
136 e1813e25 Dimitris Routsis
                                                        GWT.log("Path:"+p, throwable);
137 e1813e25 Dimitris Routsis
                                                }
138 e1813e25 Dimitris Routsis
                                        };
139 e1813e25 Dimitris Routsis
                                        DeferredCommand.addCommand(gogo);
140 14ad7326 pastith
                                }
141 14ad7326 pastith
142 35c3e1bc pastith
                                @Override
143 a52ea5e4 pastith
                                public void onError(Throwable t) {
144 a52ea5e4 pastith
                                        GWT.log("Error fetching Others Root folder", t);
145 a52ea5e4 pastith
                                        GSS.get().displayError("Unable to fetch Others Root folder");
146 14ad7326 pastith
                                }
147 14ad7326 pastith
148 a52ea5e4 pastith
                        };
149 e1813e25 Dimitris Routsis
150 a52ea5e4 pastith
                        DeferredCommand.addCommand(go);
151 a52ea5e4 pastith
                } else if (folderItem.getOtherUserResource() != null) {
152 a52ea5e4 pastith
153 6cf8fb8b Dimitris Routsis
                        GetCommand<OtherUserResource> go = new GetCommand<OtherUserResource>(OtherUserResource.class,
154 62f168b2 Giannis Koutsoubos
                                                folderItem.getOtherUserResource().getUri(), null) {
155 a52ea5e4 pastith
156 35c3e1bc pastith
                                @Override
157 a52ea5e4 pastith
                                public void onComplete() {
158 6cf8fb8b Dimitris Routsis
                                        OtherUserResource res = getResult();
159 a52ea5e4 pastith
                                        folderItem.removeItems();
160 6cf8fb8b Dimitris Routsis
                                        for (FolderResource r : res.getFolders()) {
161 35c3e1bc pastith
                                                DnDTreeItem child = (DnDTreeItem) addImageItem(folderItem,
162 35c3e1bc pastith
                                                                        r.getName(), images.folderYellow(), true);
163 a52ea5e4 pastith
                                                child.setUserObject(r);
164 903c2182 koutsoub
                                                child.doDraggable();
165 6cf8fb8b Dimitris Routsis
                                                updateFolderAndSubfolders(child);
166 14ad7326 pastith
                                        }
167 a52ea5e4 pastith
                                }
168 14ad7326 pastith
169 35c3e1bc pastith
                                @Override
170 a52ea5e4 pastith
                                public void onError(Throwable t) {
171 a52ea5e4 pastith
                                        GWT.log("Error fetching Others Root folder", t);
172 a52ea5e4 pastith
                                        GSS.get().displayError("Unable to fetch Others Root folder");
173 a52ea5e4 pastith
                                }
174 14ad7326 pastith
175 a52ea5e4 pastith
                        };
176 a52ea5e4 pastith
                        DeferredCommand.addCommand(go);
177 a52ea5e4 pastith
                } else if (folderItem.getFolderResource() != null) {
178 f7c2e76a Giannis Koutsoubos
                        GWT.log("UPDATING :"+folderItem.getFolderResource().getName(), null);
179 895035a2 pastith
                        MultipleGetCommand<FolderResource> go = new MultipleGetCommand<FolderResource>(FolderResource.class,
180 62f168b2 Giannis Koutsoubos
                                                folderItem.getFolderResource().getSubfolderPaths().toArray(new String[] {}), folderItem.getFolderResource().getCache()) {
181 a52ea5e4 pastith
182 35c3e1bc pastith
                                @Override
183 a52ea5e4 pastith
                                public void onComplete() {
184 a52ea5e4 pastith
                                        List<FolderResource> res = getResult();
185 a52ea5e4 pastith
                                        folderItem.removeItems();
186 f7c2e76a Giannis Koutsoubos
                                        GWT.log("UPDATING :"+folderItem.getFolderResource().getName()+" :"+res.size(), null);
187 a52ea5e4 pastith
                                        for (FolderResource r : res) {
188 35c3e1bc pastith
                                                DnDTreeItem child = (DnDTreeItem) addImageItem(folderItem,
189 35c3e1bc pastith
                                                                        r.getName(), images.folderYellow(), true);
190 a52ea5e4 pastith
                                                child.setUserObject(r);
191 903c2182 koutsoub
                                                child.doDraggable();
192 a52ea5e4 pastith
                                        }
193 a52ea5e4 pastith
                                }
194 14ad7326 pastith
195 35c3e1bc pastith
                                @Override
196 a52ea5e4 pastith
                                public void onError(Throwable t) {
197 a52ea5e4 pastith
                                        GWT.log("Error fetching Others Root folder", t);
198 a52ea5e4 pastith
                                        GSS.get().displayError("Unable to fetch Others Root folder");
199 a52ea5e4 pastith
                                }
200 14ad7326 pastith
201 a52ea5e4 pastith
                                @Override
202 a52ea5e4 pastith
                                public void onError(String p, Throwable throwable) {
203 a52ea5e4 pastith
                                        GWT.log("Path:"+p, throwable);
204 a52ea5e4 pastith
                                }
205 a52ea5e4 pastith
                        };
206 a52ea5e4 pastith
                        DeferredCommand.addCommand(go);
207 a52ea5e4 pastith
                }
208 14ad7326 pastith
209 14ad7326 pastith
        }
210 14ad7326 pastith
211 a52ea5e4 pastith
        public void updateFolderAndSubfolders(final DnDTreeItem folderItem) {
212 a52ea5e4 pastith
                if (folderItem.getFolderResource() != null) {
213 555e8e59 pastith
                        final String path = folderItem.getFolderResource().getUri();
214 62f168b2 Giannis Koutsoubos
                        GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, path, folderItem.getFolderResource()) {
215 a52ea5e4 pastith
216 35c3e1bc pastith
                                @Override
217 a52ea5e4 pastith
                                public void onComplete() {
218 a52ea5e4 pastith
                                        FolderResource rootResource = getResult();
219 a52ea5e4 pastith
                                        folderItem.undoDraggable();
220 a52ea5e4 pastith
                                        folderItem.updateWidget(imageItemHTML(images.folderYellow(), rootResource.getName()));
221 a52ea5e4 pastith
                                        folderItem.setUserObject(rootResource);
222 a52ea5e4 pastith
                                        folderItem.doDraggable();
223 a52ea5e4 pastith
                                }
224 14ad7326 pastith
225 35c3e1bc pastith
                                @Override
226 a52ea5e4 pastith
                                public void onError(Throwable t) {
227 a52ea5e4 pastith
                                        GWT.log("Error fetching folder", t);
228 a52ea5e4 pastith
                                        GSS.get().displayError("Unable to fetch folder:" + folderItem.getFolderResource().getName());
229 a52ea5e4 pastith
                                }
230 a52ea5e4 pastith
                        };
231 a52ea5e4 pastith
                        DeferredCommand.addCommand(gf);
232 a52ea5e4 pastith
                }
233 14ad7326 pastith
        }
234 14ad7326 pastith
235 14ad7326 pastith
        /**
236 14ad7326 pastith
         * Retrieve the rootItem.
237 14ad7326 pastith
         *
238 14ad7326 pastith
         * @return the rootItem
239 14ad7326 pastith
         */
240 14ad7326 pastith
        public TreeItem getRootItem() {
241 14ad7326 pastith
                return rootItem;
242 14ad7326 pastith
        }
243 14ad7326 pastith
244 a52ea5e4 pastith
245 14ad7326 pastith
}