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 node.setChildOpen(i, false, true);
60 node.setChildOpen(i, true, true);
63 else if(node.isChildOpen(i)){
64 TreeNode n = node.setChildOpen(i, true);
66 refreshNodeContainingResource(n,resource);
72 private void refreshNodeContainingResource(TreeNode node, String uri){
73 int count = node.getChildCount();
74 for(int i=0;i<count;i++){
75 if(node.isChildOpen(i)){
76 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(uri)){
77 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
79 node.setChildOpen(i, false, true);
80 node.setChildOpen(i, true, true);
84 TreeNode n = node.setChildOpen(i, true);
86 refreshNodeContainingResource(n,uri);
91 public void openNodeContainingResource(RestResource resource){
92 TreeNode node = tree.getRootTreeNode();
93 openNodeContainingResource(node,resource);
95 private void openNodeContainingResource(TreeNode node, RestResource resource){
96 int count = node.getChildCount();
97 for(int i=0;i<count;i++){
98 if(node.getChildValue(i).equals(resource)){
99 //node.setChildOpen(i, false, true);
100 node.setChildOpen(i, true, true);
104 if(node.isChildOpen(i)){
105 TreeNode n = node.setChildOpen(i, true);
107 openNodeContainingResource(n,resource);
114 public void openNodeContainingResource(RestResource resource, RefreshHandler handler){
115 TreeNode node = tree.getRootTreeNode();
116 openNodeContainingResource(node,resource,handler);
118 private void openNodeContainingResource(TreeNode node, RestResource resource, RefreshHandler handler){
119 int count = node.getChildCount();
120 for(int i=0;i<count;i++){
121 if(node.getChildValue(i).equals(resource)){
122 //node.setChildOpen(i, false, true);
123 node.setChildOpen(i, true, true);
128 if(node.isChildOpen(i)){
129 TreeNode n = node.setChildOpen(i, true);
131 openNodeContainingResource(n,resource, handler);
140 public boolean doesNodeContainsResource(TreeNode node, RestResource resource){
141 int count = node.getChildCount();
142 for(int i=0;i<count;i++){
143 if(node.isChildOpen(i)){
144 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).equals(resource)){
147 else if(node.isChildOpen(i)){
148 TreeNode n = node.setChildOpen(i, true);
150 return doesNodeContainsResource(n,resource);
157 public boolean doesNodeContainsResource(TreeNode node, String resource){
158 int count = node.getChildCount();
159 for(int i=0;i<count;i++){
161 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
164 else if(node.isChildOpen(i)){
165 TreeNode n = node.setChildOpen(i, true);
167 return doesNodeContainsResource(n,resource);
174 public TreeNode getNodeContainingResource(TreeNode node, RestResource resource){
175 int count = node.getChildCount();
176 for(int i=0;i<count;i++){
178 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource.getUri())){
181 else if(node.isChildOpen(i)){
182 TreeNode n = node.setChildOpen(i, true);
184 return getNodeContainingResource(n,resource);
191 public TreeNode getNodeContainingResource(TreeNode node, String resource){
194 int count = node.getChildCount();
195 for(int i=0;i<count;i++){
197 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
200 else if(node.isChildOpen(i)){
201 TreeNode n = node.setChildOpen(i, true);
203 return getNodeContainingResource(n,resource);
210 public TreeNode getNodeContainingResource2(TreeNode node, String resource){
213 int count = node.getChildCount();
214 for(int i=0;i<count;i++){
216 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
217 return node.setChildOpen(i, node.isChildOpen(i));
219 else if(node.isChildOpen(i)){
220 TreeNode n = node.setChildOpen(i, true);
222 return getNodeContainingResource2(n,resource);
228 public boolean doesSharedNodeContainsResource( String resource){
229 if(tree.getRootTreeNode().isChildOpen(2)){
230 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
231 return doesNodeContainsResource(node, resource);
236 public boolean doesSharedNodeContainsResourceIn1stLevel( String resource){
237 if(tree.getRootTreeNode().isChildOpen(2)){
238 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
239 int count = node.getChildCount();
240 for(int i=0;i<count;i++){
242 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
252 public boolean doesRootNodeContainsResource( String resource){
253 if(tree.getRootTreeNode().isChildOpen(0)){
254 TreeNode node = tree.getRootTreeNode().setChildOpen(0, true);
255 return doesNodeContainsResource(node, resource);
260 public boolean doesSharedNodeContainsResource( RestResource resource){
261 if(tree.getRootTreeNode().isChildOpen(2)){
262 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
263 return doesNodeContainsResource(node, resource);
268 public boolean doesRootNodeContainsResource( RestResource resource){
269 if(tree.getRootTreeNode().isChildOpen(0)){
270 TreeNode node = tree.getRootTreeNode().setChildOpen(0, true);
271 return doesNodeContainsResource(node, resource);