Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / Folders.java @ fc0fa492

History | View | Annotate | Download (12.2 kB)

1 023f6f1e Panagiotis Astithas
/*
2 023f6f1e Panagiotis Astithas
 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3 023f6f1e Panagiotis Astithas
 *
4 023f6f1e Panagiotis Astithas
 * This file is part of GSS.
5 023f6f1e Panagiotis Astithas
 *
6 023f6f1e Panagiotis Astithas
 * GSS is free software: you can redistribute it and/or modify
7 023f6f1e Panagiotis Astithas
 * it under the terms of the GNU General Public License as published by
8 023f6f1e Panagiotis Astithas
 * the Free Software Foundation, either version 3 of the License, or
9 023f6f1e Panagiotis Astithas
 * (at your option) any later version.
10 023f6f1e Panagiotis Astithas
 *
11 023f6f1e Panagiotis Astithas
 * GSS is distributed in the hope that it will be useful,
12 023f6f1e Panagiotis Astithas
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 023f6f1e Panagiotis Astithas
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 023f6f1e Panagiotis Astithas
 * GNU General Public License for more details.
15 023f6f1e Panagiotis Astithas
 *
16 023f6f1e Panagiotis Astithas
 * You should have received a copy of the GNU General Public License
17 023f6f1e Panagiotis Astithas
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 023f6f1e Panagiotis Astithas
 */
19 023f6f1e Panagiotis Astithas
package gr.ebs.gss.client;
20 023f6f1e Panagiotis Astithas
21 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.dnd.DnDTreeItem;
22 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.rest.resource.FolderResource;
23 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.rest.resource.OtherUserResource;
24 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.rest.resource.RestResource;
25 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.tree.FolderSubtree;
26 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.tree.MyShareSubtree;
27 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.tree.OthersSharesSubtree;
28 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.tree.TrashSubtree;
29 023f6f1e Panagiotis Astithas
30 023f6f1e Panagiotis Astithas
import java.util.ArrayList;
31 023f6f1e Panagiotis Astithas
import java.util.List;
32 023f6f1e Panagiotis Astithas
33 023f6f1e Panagiotis Astithas
import com.google.gwt.resources.client.ClientBundle;
34 023f6f1e Panagiotis Astithas
import com.google.gwt.resources.client.ImageResource;
35 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.Command;
36 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.DeferredCommand;
37 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.Composite;
38 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.Tree;
39 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.TreeItem;
40 023f6f1e Panagiotis Astithas
/**
41 023f6f1e Panagiotis Astithas
 * A tree displaying the folders in the user's file space.
42 023f6f1e Panagiotis Astithas
 */
43 023f6f1e Panagiotis Astithas
public class Folders extends Composite {
44 023f6f1e Panagiotis Astithas
45 023f6f1e Panagiotis Astithas
        /**
46 023f6f1e Panagiotis Astithas
         * A constant that denotes the completion of an IncrementalCommand.
47 023f6f1e Panagiotis Astithas
         */
48 023f6f1e Panagiotis Astithas
        public static final boolean DONE = false;
49 023f6f1e Panagiotis Astithas
50 023f6f1e Panagiotis Astithas
        /**
51 023f6f1e Panagiotis Astithas
         * Specifies the images that will be bundled for this Composite and other
52 023f6f1e Panagiotis Astithas
         * inherited images that will be included in the same bundle.
53 023f6f1e Panagiotis Astithas
         */
54 023f6f1e Panagiotis Astithas
        public interface Images extends ClientBundle,Tree.Resources, FolderContextMenu.Images {
55 023f6f1e Panagiotis Astithas
56 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/folder_home.png")
57 023f6f1e Panagiotis Astithas
                ImageResource home();
58 023f6f1e Panagiotis Astithas
59 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/folder_yellow.png")
60 023f6f1e Panagiotis Astithas
                ImageResource folderYellow();
61 023f6f1e Panagiotis Astithas
62 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/mimetypes/document.png")
63 023f6f1e Panagiotis Astithas
                ImageResource document();
64 023f6f1e Panagiotis Astithas
65 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/internet.png")
66 023f6f1e Panagiotis Astithas
                ImageResource othersShared();
67 023f6f1e Panagiotis Astithas
68 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/edit_user.png")
69 023f6f1e Panagiotis Astithas
                ImageResource myShared();
70 023f6f1e Panagiotis Astithas
71 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/folder_user.png")
72 023f6f1e Panagiotis Astithas
                ImageResource sharedFolder();
73 023f6f1e Panagiotis Astithas
74 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/trashcan_empty.png")
75 023f6f1e Panagiotis Astithas
                ImageResource trash();
76 023f6f1e Panagiotis Astithas
        }
77 023f6f1e Panagiotis Astithas
78 023f6f1e Panagiotis Astithas
        /**
79 023f6f1e Panagiotis Astithas
         * The widget's image bundle.
80 023f6f1e Panagiotis Astithas
         */
81 023f6f1e Panagiotis Astithas
        private final Images images;
82 023f6f1e Panagiotis Astithas
83 023f6f1e Panagiotis Astithas
        /**
84 023f6f1e Panagiotis Astithas
         * The tree widget that displays the folder namespace.
85 023f6f1e Panagiotis Astithas
         */
86 023f6f1e Panagiotis Astithas
        private PopupTree tree;
87 023f6f1e Panagiotis Astithas
88 023f6f1e Panagiotis Astithas
        /**
89 023f6f1e Panagiotis Astithas
         * A cached copy of the currently selected folder widget.
90 023f6f1e Panagiotis Astithas
         */
91 023f6f1e Panagiotis Astithas
        private FolderSubtree folderSubtree;
92 023f6f1e Panagiotis Astithas
93 023f6f1e Panagiotis Astithas
        private TrashSubtree trashSubtree;
94 023f6f1e Panagiotis Astithas
95 023f6f1e Panagiotis Astithas
        private MyShareSubtree myShareSubtree;
96 023f6f1e Panagiotis Astithas
97 023f6f1e Panagiotis Astithas
        private OthersSharesSubtree othersSharesSubtree;
98 023f6f1e Panagiotis Astithas
99 023f6f1e Panagiotis Astithas
        /**
100 023f6f1e Panagiotis Astithas
         * Constructs a new folders widget with a bundle of images.
101 023f6f1e Panagiotis Astithas
         *
102 023f6f1e Panagiotis Astithas
         * @param _images a bundle that provides the images for this widget
103 023f6f1e Panagiotis Astithas
         */
104 023f6f1e Panagiotis Astithas
        public Folders(final Images _images) {
105 023f6f1e Panagiotis Astithas
                images = _images;
106 023f6f1e Panagiotis Astithas
                tree = new PopupTree(images);
107 023f6f1e Panagiotis Astithas
                tree.setAnimationEnabled(true);
108 023f6f1e Panagiotis Astithas
                initWidget(tree);
109 023f6f1e Panagiotis Astithas
                folderSubtree = new FolderSubtree(tree, images);
110 023f6f1e Panagiotis Astithas
                myShareSubtree = new MyShareSubtree(tree, images);
111 023f6f1e Panagiotis Astithas
                trashSubtree = new TrashSubtree(tree, images);
112 023f6f1e Panagiotis Astithas
                othersSharesSubtree = new OthersSharesSubtree(tree, images);
113 023f6f1e Panagiotis Astithas
        }
114 023f6f1e Panagiotis Astithas
115 023f6f1e Panagiotis Astithas
        public Images getImages() {
116 023f6f1e Panagiotis Astithas
                return images;
117 023f6f1e Panagiotis Astithas
        }
118 023f6f1e Panagiotis Astithas
119 023f6f1e Panagiotis Astithas
        public void select(TreeItem item) {
120 023f6f1e Panagiotis Astithas
                tree.processItemSelected(item);
121 023f6f1e Panagiotis Astithas
        }
122 023f6f1e Panagiotis Astithas
123 023f6f1e Panagiotis Astithas
        public void clearSelection() {
124 023f6f1e Panagiotis Astithas
                tree.clearSelection();
125 023f6f1e Panagiotis Astithas
        }
126 023f6f1e Panagiotis Astithas
127 023f6f1e Panagiotis Astithas
        public void update(TreeItem item) {
128 023f6f1e Panagiotis Astithas
                if (isFileItem(item))
129 023f6f1e Panagiotis Astithas
                        folderSubtree.updateSubfolders((DnDTreeItem) item);
130 023f6f1e Panagiotis Astithas
                else if (isTrash(item))
131 023f6f1e Panagiotis Astithas
                        trashSubtree.update();
132 023f6f1e Panagiotis Astithas
                else if (isMySharedItem(item))
133 023f6f1e Panagiotis Astithas
                        myShareSubtree.update((DnDTreeItem) item);
134 023f6f1e Panagiotis Astithas
                else if (isOthersSharedItem(item))
135 023f6f1e Panagiotis Astithas
                        othersSharesSubtree.update((DnDTreeItem) item);
136 023f6f1e Panagiotis Astithas
        }
137 023f6f1e Panagiotis Astithas
138 023f6f1e Panagiotis Astithas
        public void updateFolder(final DnDTreeItem folderItem) {
139 023f6f1e Panagiotis Astithas
                if (isFileItem(folderItem)){
140 023f6f1e Panagiotis Astithas
                        folderSubtree.updateFolderAndSubfolders(folderItem);
141 023f6f1e Panagiotis Astithas
                        myShareSubtree.updateFolderAndSubfolders((DnDTreeItem) getMySharesItem());
142 023f6f1e Panagiotis Astithas
                }
143 023f6f1e Panagiotis Astithas
                else if (isMySharedItem(folderItem)){
144 023f6f1e Panagiotis Astithas
                        myShareSubtree.updateFolderAndSubfolders(folderItem);
145 023f6f1e Panagiotis Astithas
                        if (folderItem.getFolderResource() != null) {
146 023f6f1e Panagiotis Astithas
                                DnDTreeItem fitem = (DnDTreeItem) getUserItem(getRootItem(), folderItem.getFolderResource().getUri());
147 023f6f1e Panagiotis Astithas
                                if (fitem != null)
148 023f6f1e Panagiotis Astithas
                                        folderSubtree.updateFolderAndSubfolders(fitem);
149 023f6f1e Panagiotis Astithas
                                else
150 023f6f1e Panagiotis Astithas
                                        folderSubtree.updateFolderAndSubfolders((DnDTreeItem) getRootItem());
151 023f6f1e Panagiotis Astithas
                        }
152 023f6f1e Panagiotis Astithas
153 023f6f1e Panagiotis Astithas
                }
154 023f6f1e Panagiotis Astithas
                else if (isTrashItem(folderItem))
155 023f6f1e Panagiotis Astithas
                        trashSubtree.update();
156 023f6f1e Panagiotis Astithas
                else if (isOthersSharedItem(folderItem))
157 023f6f1e Panagiotis Astithas
                        othersSharesSubtree.updateFolderAndSubfolders(folderItem);
158 023f6f1e Panagiotis Astithas
        }
159 023f6f1e Panagiotis Astithas
160 023f6f1e Panagiotis Astithas
        /**
161 023f6f1e Panagiotis Astithas
         * Retrieve the current.
162 023f6f1e Panagiotis Astithas
         *
163 023f6f1e Panagiotis Astithas
         * @return the current
164 023f6f1e Panagiotis Astithas
         */
165 023f6f1e Panagiotis Astithas
        public TreeItem getCurrent() {
166 023f6f1e Panagiotis Astithas
                return tree.getTreeSelectedItem();
167 023f6f1e Panagiotis Astithas
        }
168 023f6f1e Panagiotis Astithas
169 023f6f1e Panagiotis Astithas
        /**
170 023f6f1e Panagiotis Astithas
         * Modify the current.
171 023f6f1e Panagiotis Astithas
         *
172 023f6f1e Panagiotis Astithas
         * @param _current the current to set
173 023f6f1e Panagiotis Astithas
         */
174 023f6f1e Panagiotis Astithas
        void setCurrent(final TreeItem _current) {
175 023f6f1e Panagiotis Astithas
                tree.setTreeSelectedItem(_current);
176 023f6f1e Panagiotis Astithas
        }
177 023f6f1e Panagiotis Astithas
178 023f6f1e Panagiotis Astithas
        /**
179 023f6f1e Panagiotis Astithas
         * Checks whether a TreeItem is contained in the root folder structure
180 023f6f1e Panagiotis Astithas
         *
181 023f6f1e Panagiotis Astithas
         * @param item The TreeItem to check
182 023f6f1e Panagiotis Astithas
         */
183 023f6f1e Panagiotis Astithas
        public boolean isFileItem(TreeItem item) {
184 023f6f1e Panagiotis Astithas
                if (getRootOfItem(item).equals(getRootItem()))
185 023f6f1e Panagiotis Astithas
                        return true;
186 023f6f1e Panagiotis Astithas
                return false;
187 023f6f1e Panagiotis Astithas
        }
188 023f6f1e Panagiotis Astithas
189 023f6f1e Panagiotis Astithas
        /**
190 023f6f1e Panagiotis Astithas
         * Checks whether a TreeItem is contained in the trash folder structure
191 023f6f1e Panagiotis Astithas
         *
192 023f6f1e Panagiotis Astithas
         * @param item The TreeItem to check
193 023f6f1e Panagiotis Astithas
         */
194 023f6f1e Panagiotis Astithas
        public boolean isTrashItem(TreeItem item) {
195 023f6f1e Panagiotis Astithas
                if (getRootOfItem(item).equals(getTrashItem()))
196 023f6f1e Panagiotis Astithas
                        return true;
197 023f6f1e Panagiotis Astithas
                return false;
198 023f6f1e Panagiotis Astithas
        }
199 023f6f1e Panagiotis Astithas
200 023f6f1e Panagiotis Astithas
        /**
201 023f6f1e Panagiotis Astithas
         * Checks whether a TreeItem is contained in the trash folder structure
202 023f6f1e Panagiotis Astithas
         *
203 023f6f1e Panagiotis Astithas
         * @param item The TreeItem to check
204 023f6f1e Panagiotis Astithas
         */
205 023f6f1e Panagiotis Astithas
        public boolean isOthersSharedItem(TreeItem item) {
206 023f6f1e Panagiotis Astithas
                if (getRootOfItem(item).equals(getSharesItem()))
207 023f6f1e Panagiotis Astithas
                        return true;
208 023f6f1e Panagiotis Astithas
                return false;
209 023f6f1e Panagiotis Astithas
        }
210 023f6f1e Panagiotis Astithas
211 023f6f1e Panagiotis Astithas
        /**
212 023f6f1e Panagiotis Astithas
         * Checks whether a TreeItem is contained in the trash folder structure
213 023f6f1e Panagiotis Astithas
         *
214 023f6f1e Panagiotis Astithas
         * @param item The TreeItem to check
215 023f6f1e Panagiotis Astithas
         */
216 023f6f1e Panagiotis Astithas
        public boolean isMySharedItem(TreeItem item) {
217 023f6f1e Panagiotis Astithas
                if (getRootOfItem(item).equals(getMySharesItem()))
218 023f6f1e Panagiotis Astithas
                        return true;
219 023f6f1e Panagiotis Astithas
                return false;
220 023f6f1e Panagiotis Astithas
        }
221 023f6f1e Panagiotis Astithas
222 023f6f1e Panagiotis Astithas
        private TreeItem getRootOfItem(TreeItem item) {
223 023f6f1e Panagiotis Astithas
                if (item.getParentItem() == null)
224 023f6f1e Panagiotis Astithas
                        return item;
225 023f6f1e Panagiotis Astithas
                TreeItem toCheck = item;
226 023f6f1e Panagiotis Astithas
                while (toCheck.getParentItem() != null) {
227 023f6f1e Panagiotis Astithas
                        toCheck = toCheck.getParentItem();
228 023f6f1e Panagiotis Astithas
                        toCheck = getRootOfItem(toCheck);
229 023f6f1e Panagiotis Astithas
                }
230 023f6f1e Panagiotis Astithas
                return toCheck;
231 023f6f1e Panagiotis Astithas
        }
232 023f6f1e Panagiotis Astithas
233 023f6f1e Panagiotis Astithas
        public TreeItem getUserOfSharedItem(TreeItem item) {
234 023f6f1e Panagiotis Astithas
                if (item.getUserObject() instanceof OtherUserResource)
235 023f6f1e Panagiotis Astithas
                        return item;
236 023f6f1e Panagiotis Astithas
                TreeItem test = item;
237 023f6f1e Panagiotis Astithas
                while (test.getParentItem() != null) {
238 023f6f1e Panagiotis Astithas
                        test = test.getParentItem();
239 023f6f1e Panagiotis Astithas
                        if (test.getUserObject() instanceof OtherUserResource)
240 023f6f1e Panagiotis Astithas
                                return test;
241 023f6f1e Panagiotis Astithas
                }
242 023f6f1e Panagiotis Astithas
                return null;
243 023f6f1e Panagiotis Astithas
        }
244 023f6f1e Panagiotis Astithas
245 023f6f1e Panagiotis Astithas
        public boolean isTrash(TreeItem item) {
246 023f6f1e Panagiotis Astithas
                return item.equals(getTrashItem());
247 023f6f1e Panagiotis Astithas
        }
248 023f6f1e Panagiotis Astithas
249 023f6f1e Panagiotis Astithas
        public boolean isMyShares(TreeItem item) {
250 023f6f1e Panagiotis Astithas
                return item.equals(getMySharesItem());
251 023f6f1e Panagiotis Astithas
        }
252 023f6f1e Panagiotis Astithas
253 023f6f1e Panagiotis Astithas
        public boolean isOthersShared(TreeItem item) {
254 023f6f1e Panagiotis Astithas
                return item.equals(getSharesItem());
255 023f6f1e Panagiotis Astithas
        }
256 023f6f1e Panagiotis Astithas
257 023f6f1e Panagiotis Astithas
        /*
258 023f6f1e Panagiotis Astithas
         * Returns the Tree Item corresponding to the FolderDTO object
259 023f6f1e Panagiotis Astithas
         * since we need to update main file structure for untrashed folders
260 023f6f1e Panagiotis Astithas
         */
261 023f6f1e Panagiotis Astithas
        public TreeItem getUserItem(FolderResource folder) {
262 023f6f1e Panagiotis Astithas
                return getUserItem(getRootItem(), folder);
263 023f6f1e Panagiotis Astithas
        }
264 023f6f1e Panagiotis Astithas
265 023f6f1e Panagiotis Astithas
        public TreeItem getOtherSharedItem(FolderResource folder) {
266 023f6f1e Panagiotis Astithas
                return getUserItem(getSharesItem(), folder);
267 023f6f1e Panagiotis Astithas
        }
268 023f6f1e Panagiotis Astithas
269 023f6f1e Panagiotis Astithas
        private TreeItem getUserItem(TreeItem parent, FolderResource folder) {
270 023f6f1e Panagiotis Astithas
                TreeItem tmp = null;
271 023f6f1e Panagiotis Astithas
                if (parent.getUserObject() instanceof FolderResource &&
272 023f6f1e Panagiotis Astithas
                                        (parent.getUserObject().equals(folder) ||
273 023f6f1e Panagiotis Astithas
                                        ((FolderResource) parent.getUserObject()).getUri().equals(folder.getUri())))
274 023f6f1e Panagiotis Astithas
                        return parent;
275 023f6f1e Panagiotis Astithas
                for (int i = 0; i < parent.getChildCount(); i++) {
276 023f6f1e Panagiotis Astithas
                        TreeItem child = parent.getChild(i);
277 023f6f1e Panagiotis Astithas
                        if (child.getUserObject() instanceof FolderResource) {
278 023f6f1e Panagiotis Astithas
                                FolderResource dto = (FolderResource) child.getUserObject();
279 023f6f1e Panagiotis Astithas
                                if (dto.equals(folder) || dto.getUri().equals(folder.getUri()))
280 023f6f1e Panagiotis Astithas
                                        return child;
281 023f6f1e Panagiotis Astithas
                        }
282 023f6f1e Panagiotis Astithas
                        tmp = getUserItem(child, folder);
283 023f6f1e Panagiotis Astithas
                        if (tmp != null)
284 023f6f1e Panagiotis Astithas
                                return tmp;
285 023f6f1e Panagiotis Astithas
                }
286 023f6f1e Panagiotis Astithas
                return null;
287 023f6f1e Panagiotis Astithas
        }
288 023f6f1e Panagiotis Astithas
289 023f6f1e Panagiotis Astithas
        /**
290 023f6f1e Panagiotis Astithas
         * Retrieve the trashItem.
291 023f6f1e Panagiotis Astithas
         *
292 023f6f1e Panagiotis Astithas
         * @return the trashItem
293 023f6f1e Panagiotis Astithas
         */
294 023f6f1e Panagiotis Astithas
        public TreeItem getTrashItem() {
295 023f6f1e Panagiotis Astithas
                return trashSubtree.getRootItem();
296 023f6f1e Panagiotis Astithas
        }
297 023f6f1e Panagiotis Astithas
298 023f6f1e Panagiotis Astithas
        /**
299 023f6f1e Panagiotis Astithas
         * Retrieve the rootItem.
300 023f6f1e Panagiotis Astithas
         *
301 023f6f1e Panagiotis Astithas
         * @return the rootItem
302 023f6f1e Panagiotis Astithas
         */
303 023f6f1e Panagiotis Astithas
        public TreeItem getRootItem() {
304 023f6f1e Panagiotis Astithas
                return folderSubtree.getRootItem();
305 023f6f1e Panagiotis Astithas
        }
306 023f6f1e Panagiotis Astithas
307 023f6f1e Panagiotis Astithas
        /**
308 023f6f1e Panagiotis Astithas
         * Retrieve the mySharesItem.
309 023f6f1e Panagiotis Astithas
         *
310 023f6f1e Panagiotis Astithas
         * @return the mySharesItem
311 023f6f1e Panagiotis Astithas
         */
312 023f6f1e Panagiotis Astithas
        public TreeItem getMySharesItem() {
313 023f6f1e Panagiotis Astithas
                return myShareSubtree.getRootItem();
314 023f6f1e Panagiotis Astithas
        }
315 023f6f1e Panagiotis Astithas
316 023f6f1e Panagiotis Astithas
        /**
317 023f6f1e Panagiotis Astithas
         * Retrieve the sharesItem.
318 023f6f1e Panagiotis Astithas
         *
319 023f6f1e Panagiotis Astithas
         * @return the sharesItem
320 023f6f1e Panagiotis Astithas
         */
321 023f6f1e Panagiotis Astithas
        public TreeItem getSharesItem() {
322 023f6f1e Panagiotis Astithas
                return othersSharesSubtree.getRootItem();
323 023f6f1e Panagiotis Astithas
        }
324 023f6f1e Panagiotis Astithas
325 023f6f1e Panagiotis Astithas
        public void onFolderTrash(TreeItem folder) {
326 023f6f1e Panagiotis Astithas
                if (folder.getParentItem().getUserObject() instanceof FolderResource) {
327 023f6f1e Panagiotis Astithas
                        FolderResource folderDTO = (FolderResource) folder.getParentItem().getUserObject();
328 023f6f1e Panagiotis Astithas
                        updateFileAndShareNodes(folderDTO);
329 023f6f1e Panagiotis Astithas
                } else
330 023f6f1e Panagiotis Astithas
                        update(getMySharesItem());
331 023f6f1e Panagiotis Astithas
                update(getTrashItem());
332 023f6f1e Panagiotis Astithas
                clearSelection();
333 023f6f1e Panagiotis Astithas
                GSS.get().getFileList().updateFileCache(false, true /*clear selection*/);
334 023f6f1e Panagiotis Astithas
        }
335 023f6f1e Panagiotis Astithas
336 023f6f1e Panagiotis Astithas
        public void onFolderDelete(TreeItem folder) {
337 023f6f1e Panagiotis Astithas
                if (folder.getParentItem().getUserObject() instanceof FolderResource) {
338 023f6f1e Panagiotis Astithas
                        FolderResource folderDTO = (FolderResource) folder.getParentItem().getUserObject();
339 023f6f1e Panagiotis Astithas
                        updateFileAndShareNodes(folderDTO);
340 023f6f1e Panagiotis Astithas
                } else
341 023f6f1e Panagiotis Astithas
                        update(getMySharesItem());
342 023f6f1e Panagiotis Astithas
                GSS.get().getStatusPanel().updateStats();
343 023f6f1e Panagiotis Astithas
                clearSelection();
344 023f6f1e Panagiotis Astithas
                GSS.get().getFileList().updateFileCache(false, true /*clear selection*/);
345 023f6f1e Panagiotis Astithas
        }
346 023f6f1e Panagiotis Astithas
347 023f6f1e Panagiotis Astithas
        public void onFolderCopy(TreeItem folder) {
348 023f6f1e Panagiotis Astithas
                if (!updateFileAndShareNodes((FolderResource) folder.getUserObject()))
349 023f6f1e Panagiotis Astithas
                        update(folder);
350 023f6f1e Panagiotis Astithas
                GSS.get().getFileList().updateFileCache(false, true /*clear selection*/);
351 023f6f1e Panagiotis Astithas
                GSS.get().getStatusPanel().updateStats();
352 023f6f1e Panagiotis Astithas
        }
353 023f6f1e Panagiotis Astithas
354 023f6f1e Panagiotis Astithas
        public void onFolderMove(TreeItem folder, FolderResource initialParent) {
355 023f6f1e Panagiotis Astithas
                updateFileAndShareNodes(initialParent);
356 023f6f1e Panagiotis Astithas
                updateFileAndShareNodes((FolderResource) folder.getUserObject());
357 023f6f1e Panagiotis Astithas
                update(folder);
358 023f6f1e Panagiotis Astithas
                GSS.get().getFileList().updateFileCache(false, true /*clear selection*/);
359 023f6f1e Panagiotis Astithas
                GSS.get().getStatusPanel().updateStats();
360 023f6f1e Panagiotis Astithas
                clearSelection();
361 023f6f1e Panagiotis Astithas
        }
362 023f6f1e Panagiotis Astithas
363 023f6f1e Panagiotis Astithas
        private boolean updateFileAndShareNodes(FolderResource folder) {
364 023f6f1e Panagiotis Astithas
                boolean updated = false;
365 023f6f1e Panagiotis Astithas
                TreeItem sharesFolder = getUserItem(getMySharesItem(), folder);
366 023f6f1e Panagiotis Astithas
                if (sharesFolder != null) {
367 023f6f1e Panagiotis Astithas
                        update(sharesFolder);
368 023f6f1e Panagiotis Astithas
                        updated = true;
369 023f6f1e Panagiotis Astithas
                }
370 023f6f1e Panagiotis Astithas
                TreeItem fileFolder = getUserItem(getRootItem(), folder);
371 023f6f1e Panagiotis Astithas
                if (fileFolder != null) {
372 023f6f1e Panagiotis Astithas
                        update(fileFolder);
373 023f6f1e Panagiotis Astithas
                        updated = true;
374 023f6f1e Panagiotis Astithas
                }
375 023f6f1e Panagiotis Astithas
                return updated;
376 023f6f1e Panagiotis Astithas
        }
377 023f6f1e Panagiotis Astithas
378 023f6f1e Panagiotis Astithas
        public void initialize() {
379 023f6f1e Panagiotis Astithas
                DeferredCommand.addCommand(new Command() {
380 023f6f1e Panagiotis Astithas
381 023f6f1e Panagiotis Astithas
                        @Override
382 023f6f1e Panagiotis Astithas
                        public void execute() {
383 023f6f1e Panagiotis Astithas
                                GSS.get().showLoadingIndicator();
384 023f6f1e Panagiotis Astithas
                                folderSubtree.getRootItem().removeItems();
385 023f6f1e Panagiotis Astithas
                                trashSubtree.getRootItem().removeItems();
386 023f6f1e Panagiotis Astithas
                                myShareSubtree.getRootItem().removeItems();
387 023f6f1e Panagiotis Astithas
                                othersSharesSubtree.getRootItem().removeItems();
388 023f6f1e Panagiotis Astithas
                                update(folderSubtree.getRootItem());
389 023f6f1e Panagiotis Astithas
                                update(trashSubtree.getRootItem());
390 023f6f1e Panagiotis Astithas
                                update(myShareSubtree.getRootItem());
391 023f6f1e Panagiotis Astithas
                                update(othersSharesSubtree.getRootItem());
392 023f6f1e Panagiotis Astithas
                                GSS.get().setCurrentSelection(null);
393 023f6f1e Panagiotis Astithas
                                clearSelection();
394 023f6f1e Panagiotis Astithas
                                GSS.get().getFileList().updateFileCache(false, true /*clear selection*/);
395 023f6f1e Panagiotis Astithas
                                GSS.get().hideLoadingIndicator();
396 023f6f1e Panagiotis Astithas
                        }
397 023f6f1e Panagiotis Astithas
398 023f6f1e Panagiotis Astithas
                });
399 023f6f1e Panagiotis Astithas
        }
400 023f6f1e Panagiotis Astithas
401 023f6f1e Panagiotis Astithas
        /* NEW HANDLING METHODS */
402 023f6f1e Panagiotis Astithas
        public TreeItem getUserItem(TreeItem parent, String path) {
403 023f6f1e Panagiotis Astithas
                TreeItem tmp = null;
404 023f6f1e Panagiotis Astithas
                if (parent.getUserObject() instanceof RestResource && ((RestResource) parent.getUserObject()).getUri().equals(path))
405 023f6f1e Panagiotis Astithas
                        return parent;
406 023f6f1e Panagiotis Astithas
                for (int i = 0; i < parent.getChildCount(); i++) {
407 023f6f1e Panagiotis Astithas
                        TreeItem child = parent.getChild(i);
408 023f6f1e Panagiotis Astithas
                        if (child.getUserObject() instanceof RestResource) {
409 023f6f1e Panagiotis Astithas
                                RestResource dto = (RestResource) child.getUserObject();
410 023f6f1e Panagiotis Astithas
                                if (dto.getUri().equals(path))
411 023f6f1e Panagiotis Astithas
                                        return child;
412 023f6f1e Panagiotis Astithas
                        }
413 023f6f1e Panagiotis Astithas
                        tmp = getUserItem(child, path);
414 023f6f1e Panagiotis Astithas
                        if (tmp != null)
415 023f6f1e Panagiotis Astithas
                                return tmp;
416 023f6f1e Panagiotis Astithas
                }
417 023f6f1e Panagiotis Astithas
                return null;
418 023f6f1e Panagiotis Astithas
        }
419 023f6f1e Panagiotis Astithas
420 023f6f1e Panagiotis Astithas
        public List<TreeItem> getItemsOfTreeForPath(String path) {
421 023f6f1e Panagiotis Astithas
                List<TreeItem> result = new ArrayList<TreeItem>();
422 023f6f1e Panagiotis Astithas
                TreeItem item = null;
423 023f6f1e Panagiotis Astithas
                item = getUserItem(getRootItem(), path);
424 023f6f1e Panagiotis Astithas
                if (item != null)
425 023f6f1e Panagiotis Astithas
                        result.add(item);
426 023f6f1e Panagiotis Astithas
                item = getUserItem(getMySharesItem(), path);
427 023f6f1e Panagiotis Astithas
                if (item != null)
428 023f6f1e Panagiotis Astithas
                        result.add(item);
429 023f6f1e Panagiotis Astithas
                item = getUserItem(getTrashItem(), path);
430 023f6f1e Panagiotis Astithas
                if (item != null)
431 023f6f1e Panagiotis Astithas
                        result.add(item);
432 023f6f1e Panagiotis Astithas
                item = getUserItem(getSharesItem(), path);
433 023f6f1e Panagiotis Astithas
                if (item != null)
434 023f6f1e Panagiotis Astithas
                        result.add(item);
435 023f6f1e Panagiotis Astithas
                return result;
436 023f6f1e Panagiotis Astithas
        }
437 023f6f1e Panagiotis Astithas
        /**
438 023f6f1e Panagiotis Astithas
         * This method returns the current Popup Tree
439 023f6f1e Panagiotis Astithas
         * @return the popuptree
440 023f6f1e Panagiotis Astithas
         */
441 023f6f1e Panagiotis Astithas
        public PopupTree getPopupTree(){
442 023f6f1e Panagiotis Astithas
                return tree;
443 023f6f1e Panagiotis Astithas
        }
444 023f6f1e Panagiotis Astithas
}