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.rest.resource.RestResource;
23 import gr.ebs.gss.client.rest.resource.RestResourceWrapper;
25 import com.google.gwt.user.cellview.client.CellTree;
26 import com.google.gwt.user.cellview.client.TreeNode;
33 public class CellTreeViewUtils {
38 public CellTreeViewUtils(CellTree tree) {
42 void refreshNodeContainingResource(RestResource r){
43 TreeNode node = tree.getRootTreeNode();
44 refreshNodeContainingResource(node,r);
47 void refreshNodeContainingResource(String uri){
48 TreeNode node = tree.getRootTreeNode();
49 refreshNodeContainingResource(node,uri);
52 private void refreshNodeContainingResource(TreeNode node, RestResource resource){
53 int count = node.getChildCount();
54 for(int i=0;i<count;i++){
55 if(node.isChildOpen(i)){
56 if(node.getChildValue(i).equals(resource)){
57 node.setChildOpen(i, false, true);
58 node.setChildOpen(i, true, true);
62 TreeNode n = node.setChildOpen(i, true);
64 refreshNodeContainingResource(n,resource);
70 private void refreshNodeContainingResource(TreeNode node, String uri){
71 int count = node.getChildCount();
72 for(int i=0;i<count;i++){
73 if(node.isChildOpen(i)){
74 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(uri)){
75 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
77 node.setChildOpen(i, false, true);
78 node.setChildOpen(i, true, true);
82 TreeNode n = node.setChildOpen(i, true);
84 refreshNodeContainingResource(n,uri);
89 public void openNodeContainingResource(RestResource resource){
90 TreeNode node = tree.getRootTreeNode();
91 openNodeContainingResource(node,resource);
93 private void openNodeContainingResource(TreeNode node, RestResource resource){
94 int count = node.getChildCount();
95 for(int i=0;i<count;i++){
96 if(node.getChildValue(i).equals(resource)){
97 //node.setChildOpen(i, false, true);
98 node.setChildOpen(i, true, true);
102 if(node.isChildOpen(i)){
103 TreeNode n = node.setChildOpen(i, true);
105 openNodeContainingResource(n,resource);
112 public void openNodeContainingResource(RestResource resource, RefreshHandler handler){
113 TreeNode node = tree.getRootTreeNode();
114 openNodeContainingResource(node,resource,handler);
116 private void openNodeContainingResource(TreeNode node, RestResource resource, RefreshHandler handler){
117 int count = node.getChildCount();
118 for(int i=0;i<count;i++){
119 if(node.getChildValue(i).equals(resource)){
120 //node.setChildOpen(i, false, true);
121 node.setChildOpen(i, true, true);
126 if(node.isChildOpen(i)){
127 TreeNode n = node.setChildOpen(i, true);
129 openNodeContainingResource(n,resource, handler);
138 public boolean doesNodeContainsResource(TreeNode node, RestResource resource){
139 int count = node.getChildCount();
140 for(int i=0;i<count;i++){
141 if(node.isChildOpen(i)){
142 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).equals(resource)){
145 else if(node.isChildOpen(i)){
146 TreeNode n = node.setChildOpen(i, true);
148 return doesNodeContainsResource(n,resource);
155 public boolean doesNodeContainsResource(TreeNode node, String resource){
156 int count = node.getChildCount();
157 for(int i=0;i<count;i++){
159 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
162 else if(node.isChildOpen(i)){
163 TreeNode n = node.setChildOpen(i, true);
165 return doesNodeContainsResource(n,resource);
172 public TreeNode getNodeContainingResource(TreeNode node, RestResource resource){
173 int count = node.getChildCount();
174 for(int i=0;i<count;i++){
176 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource.getUri())){
179 else if(node.isChildOpen(i)){
180 TreeNode n = node.setChildOpen(i, true);
182 return getNodeContainingResource(n,resource);
189 public TreeNode getNodeContainingResource(TreeNode node, String resource){
192 int count = node.getChildCount();
193 for(int i=0;i<count;i++){
195 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
198 else if(node.isChildOpen(i)){
199 TreeNode n = node.setChildOpen(i, true);
201 return getNodeContainingResource(n,resource);
208 public TreeNode getNodeContainingResource2(TreeNode node, String resource){
211 int count = node.getChildCount();
212 for(int i=0;i<count;i++){
214 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
215 return node.setChildOpen(i, node.isChildOpen(i));
217 else if(node.isChildOpen(i)){
218 TreeNode n = node.setChildOpen(i, true);
220 return getNodeContainingResource2(n,resource);
226 public boolean doesSharedNodeContainsResource( String resource){
227 if(tree.getRootTreeNode().isChildOpen(2)){
228 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
229 return doesNodeContainsResource(node, resource);
234 public boolean doesSharedNodeContainsResourceIn1stLevel( String resource){
235 if(tree.getRootTreeNode().isChildOpen(2)){
236 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
237 int count = node.getChildCount();
238 for(int i=0;i<count;i++){
240 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
250 public boolean doesRootNodeContainsResource( String resource){
251 if(tree.getRootTreeNode().isChildOpen(0)){
252 TreeNode node = tree.getRootTreeNode().setChildOpen(0, true);
253 return doesNodeContainsResource(node, resource);
258 public boolean doesSharedNodeContainsResource( RestResource resource){
259 if(tree.getRootTreeNode().isChildOpen(2)){
260 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
261 return doesNodeContainsResource(node, resource);
266 public boolean doesRootNodeContainsResource( RestResource resource){
267 if(tree.getRootTreeNode().isChildOpen(0)){
268 TreeNode node = tree.getRootTreeNode().setChildOpen(0, true);
269 return doesNodeContainsResource(node, resource);