root / gss / src / gr / ebs / gss / client / tree / Subtree.java @ 555e8e59
History | View | Annotate | Download (3.6 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 gr.ebs.gss.client.tree; |
20 |
|
21 |
import gr.ebs.gss.client.PopupTree; |
22 |
import gr.ebs.gss.client.Folders.Images; |
23 |
import gr.ebs.gss.client.dnd.DnDTreeItem; |
24 |
import gr.ebs.gss.client.rest.resource.FolderResource; |
25 |
|
26 |
import java.util.LinkedList; |
27 |
import java.util.List; |
28 |
|
29 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
30 |
import com.google.gwt.user.client.ui.HTML; |
31 |
import com.google.gwt.user.client.ui.TreeItem; |
32 |
|
33 |
/**
|
34 |
* @author kman
|
35 |
*/
|
36 |
public abstract class Subtree { |
37 |
|
38 |
protected PopupTree tree;
|
39 |
|
40 |
final Images images;
|
41 |
|
42 |
public Subtree(PopupTree tree, final Images _images) { |
43 |
images = _images; |
44 |
this.tree = tree;
|
45 |
|
46 |
} |
47 |
|
48 |
/**
|
49 |
* A helper method to simplify adding tree items that have attached images.
|
50 |
* {@link #addImageItem(TreeItem, String) code}
|
51 |
*
|
52 |
* @param parent the tree item to which the new item will be added.
|
53 |
* @param title the text associated with this item.
|
54 |
* @param imageProto the image of the item
|
55 |
* @return
|
56 |
*/
|
57 |
protected TreeItem addImageItem(final TreeItem parent, final String title, final AbstractImagePrototype imageProto, boolean draggable) { |
58 |
final DnDTreeItem item = new DnDTreeItem(imageItemHTML(imageProto, title), title, draggable); |
59 |
parent.addItem(item); |
60 |
return item;
|
61 |
} |
62 |
|
63 |
|
64 |
|
65 |
/**
|
66 |
* Generates HTML for a tree item with an attached icon.
|
67 |
*
|
68 |
* @param imageProto the image icon
|
69 |
* @param title the title of the item
|
70 |
* @return the resultant HTML
|
71 |
*/
|
72 |
protected HTML imageItemHTML(final AbstractImagePrototype imageProto, final String title) { |
73 |
HTML html = new HTML("<a class='hidden-link' href='javascript:;'><span >" + imageProto.getHTML() + " " + title + "</span></a>"); |
74 |
return html;
|
75 |
} |
76 |
|
77 |
public void updateSubFoldersLazily(DnDTreeItem folderItem, List<FolderResource> subfolders, AbstractImagePrototype image) { |
78 |
for (int i = 0; i < folderItem.getChildCount(); i++) { |
79 |
DnDTreeItem c = (DnDTreeItem) folderItem.getChild(i); |
80 |
FolderResource f = (FolderResource) c.getUserObject(); |
81 |
if (!listContainsFolder(f, subfolders)) {
|
82 |
c.undoDraggable(); |
83 |
folderItem.removeItem(c); |
84 |
} |
85 |
} |
86 |
|
87 |
LinkedList<DnDTreeItem> itemList = new LinkedList(); |
88 |
for (FolderResource subfolder : subfolders) {
|
89 |
DnDTreeItem item = folderItem.getChild(subfolder); |
90 |
if (item == null) |
91 |
item = (DnDTreeItem) addImageItem(folderItem, subfolder.getName(), image, true);
|
92 |
else
|
93 |
item.updateWidget(imageItemHTML(image, subfolder.getName())); |
94 |
item.setUserObject(subfolder); |
95 |
itemList.add(item); |
96 |
|
97 |
} |
98 |
for (DnDTreeItem it : itemList)
|
99 |
it.remove(); |
100 |
for (DnDTreeItem it : itemList)
|
101 |
folderItem.addItem(it); |
102 |
for (int i = 0; i < folderItem.getChildCount(); i++) { |
103 |
DnDTreeItem c = (DnDTreeItem) folderItem.getChild(i); |
104 |
c.doDraggable(); |
105 |
FolderResource f = (FolderResource) c.getUserObject(); |
106 |
} |
107 |
} |
108 |
|
109 |
|
110 |
|
111 |
private boolean listContainsFolder(FolderResource folder, List<FolderResource> subfolders) { |
112 |
for (FolderResource f : subfolders)
|
113 |
if (f.getUri().equals(folder.getUri()))
|
114 |
return true; |
115 |
return false; |
116 |
} |
117 |
|
118 |
|
119 |
} |