2 * Copyright 2011 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/>.
19 package gr.ebs.gss.client;
21 import gr.ebs.gss.client.CellTreeView.RefreshHandler;
22 import gr.ebs.gss.client.CellTreeViewModel.MyFolderDataProvider;
23 import gr.ebs.gss.client.rest.resource.MyFolderResource;
24 import gr.ebs.gss.client.rest.resource.RestResource;
25 import gr.ebs.gss.client.rest.resource.RestResourceWrapper;
27 import com.google.gwt.core.client.GWT;
28 import com.google.gwt.user.cellview.client.CellTree;
29 import com.google.gwt.user.cellview.client.TreeNode;
36 public class CellTreeViewUtils {
41 public CellTreeViewUtils(CellTree tree) {
45 void refreshNodeContainingResource(RestResource r){
46 TreeNode node = tree.getRootTreeNode();
47 refreshNodeContainingResource(node,r);
50 void refreshNodeContainingResource(String uri){
51 TreeNode node = tree.getRootTreeNode();
52 refreshNodeContainingResource(node,uri);
55 private void refreshNodeContainingResource(TreeNode node, RestResource resource){
56 int count = node.getChildCount();
57 for(int i=0;i<count;i++){
58 if(node.getChildValue(i).equals(resource)){
59 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
61 node.setChildOpen(i, false, true);
62 node.setChildOpen(i, true, true);
65 else if(node.isChildOpen(i)){
66 TreeNode n = node.setChildOpen(i, true);
68 refreshNodeContainingResource(n,resource);
74 void refreshNodeContainingResource(TreeNode node, String uri){
75 int count = node.getChildCount();
76 for(int i=0;i<count;i++){
77 if(node.isChildOpen(i)){
78 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(uri)){
79 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
81 node.setChildOpen(i, false, true);
82 node.setChildOpen(i, true, true);
86 TreeNode n = node.setChildOpen(i, true);
88 refreshNodeContainingResource(n,uri);
93 public void openNodeContainingResource(RestResource resource){
94 TreeNode node = tree.getRootTreeNode();
95 openNodeContainingResource(node,resource);
97 private void openNodeContainingResource(TreeNode node, RestResource resource){
98 int count = node.getChildCount();
99 for(int i=0;i<count;i++){
101 if(node.getChildValue(i).equals(resource)){
102 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
104 node.setChildOpen(i, true, true);
108 if(node.isChildOpen(i)){
109 TreeNode n = node.setChildOpen(i, true);
111 openNodeContainingResource(n,resource);
118 public void openNodeContainingResource(RestResource resource, RefreshHandler handler){
119 TreeNode node = tree.getRootTreeNode();
120 openNodeContainingResource(node,resource,handler);
122 private void openNodeContainingResource(TreeNode node, RestResource resource, RefreshHandler handler){
123 int count = node.getChildCount();
124 for(int i=0;i<count;i++){
125 if(node.getChildValue(i).equals(resource)){
126 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
128 //node.setChildOpen(i, false, true);
129 node.setChildOpen(i, true, true);
134 if(node.isChildOpen(i)){
135 TreeNode n = node.setChildOpen(i, true);
137 openNodeContainingResource(n,resource, handler);
146 public boolean doesNodeContainsResource(TreeNode node, RestResource resource){
147 int count = node.getChildCount();
148 for(int i=0;i<count;i++){
149 if(node.isChildOpen(i)){
150 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).equals(resource)){
153 else if(node.isChildOpen(i)){
154 TreeNode n = node.setChildOpen(i, true);
156 return doesNodeContainsResource(n,resource);
163 public boolean doesNodeContainsResource(TreeNode node, String resource){
164 int count = node.getChildCount();
165 for(int i=0;i<count;i++){
167 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
170 else if(node.isChildOpen(i)){
171 TreeNode n = node.setChildOpen(i, true);
173 return doesNodeContainsResource(n,resource);
180 public TreeNode getNodeContainingResource(TreeNode node, RestResource resource){
181 int count = node.getChildCount();
182 for(int i=0;i<count;i++){
184 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource.getUri())){
187 else if(node.isChildOpen(i)){
188 TreeNode n = node.setChildOpen(i, true);
190 return getNodeContainingResource(n,resource);
197 public TreeNode getNodeContainingResource(TreeNode node, String resource){
200 int count = node.getChildCount();
201 for(int i=0;i<count;i++){
203 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
206 else if(node.isChildOpen(i)){
207 TreeNode n = node.setChildOpen(i, true);
209 TreeNode result = getNodeContainingResource2(n,resource);
219 public TreeNode getNodeContainingResource2(TreeNode node, String resource){
222 int count = node.getChildCount();
223 for(int i=0;i<count;i++){
224 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
225 return node.setChildOpen(i, node.isChildOpen(i));
227 else if(node.isChildOpen(i)){
228 TreeNode n = node.setChildOpen(i, true);
230 TreeNode result = getNodeContainingResource2(n,resource);
239 public boolean doesSharedNodeContainsResource( String resource){
240 if(tree.getRootTreeNode().isChildOpen(2)){
241 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
242 return doesNodeContainsResource(node, resource);
247 public boolean doesSharedNodeContainsResourceIn1stLevel( String resource){
248 if(tree.getRootTreeNode().isChildOpen(2)){
249 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
250 int count = node.getChildCount();
251 for(int i=0;i<count;i++){
253 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
263 public boolean doesSharedNodeContainsResourceIn2ndLevel( String resource){
264 if(tree.getRootTreeNode().isChildOpen(2)){
265 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
266 int count = node.getChildCount();
267 for(int i=0;i<count;i++){
268 if(node.isChildOpen(i)){
269 TreeNode child = node.setChildOpen(i, true);
270 for(int j=0;j<child.getChildCount();j++){
271 if(child.getChildValue(j) instanceof RestResource && ((RestResource)child.getChildValue(j)).getUri().equals(resource)){
284 public boolean doesRootNodeContainsResource( String resource){
285 if(tree.getRootTreeNode().isChildOpen(0)){
286 TreeNode node = tree.getRootTreeNode().setChildOpen(0, true);
287 return doesNodeContainsResource(node, resource);
292 public boolean doesSharedNodeContainsResource( RestResource resource){
293 if(tree.getRootTreeNode().isChildOpen(2)){
294 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
295 return doesNodeContainsResource(node, resource);
300 public boolean doesRootNodeContainsResource( RestResource resource){
301 if(tree.getRootTreeNode().isChildOpen(0)){
302 TreeNode node = tree.getRootTreeNode().setChildOpen(0, true);
303 return doesNodeContainsResource(node, resource);