2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
35 package gr.grnet.pithos.web.client;
37 import gr.grnet.pithos.web.client.CellTreeView.RefreshHandler;
38 import gr.grnet.pithos.web.client.rest.resource.RestResource;
39 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
41 import com.google.gwt.user.cellview.client.CellTree;
42 import com.google.gwt.user.cellview.client.TreeNode;
45 public class CellTreeViewUtils {
50 public CellTreeViewUtils(CellTree tree) {
54 void refreshNodeContainingResource(RestResource r){
55 TreeNode node = tree.getRootTreeNode();
56 refreshNodeContainingResource(node,r);
59 void refreshNodeContainingResource(String uri){
60 TreeNode node = tree.getRootTreeNode();
61 refreshNodeContainingResource(node,uri);
64 private void refreshNodeContainingResource(TreeNode node, RestResource resource){
65 int count = node.getChildCount();
66 for(int i=0;i<count;i++){
67 if(node.getChildValue(i).equals(resource)){
68 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
70 node.setChildOpen(i, false, true);
71 node.setChildOpen(i, true, true);
74 else if(node.isChildOpen(i)){
75 TreeNode n = node.setChildOpen(i, true);
77 refreshNodeContainingResource(n,resource);
83 void refreshNodeContainingResource(TreeNode node, String uri){
84 int count = node.getChildCount();
85 for(int i=0;i<count;i++){
86 if(node.isChildOpen(i)){
87 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(uri)){
88 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
90 node.setChildOpen(i, false, true);
91 node.setChildOpen(i, true, true);
95 TreeNode n = node.setChildOpen(i, true);
97 refreshNodeContainingResource(n,uri);
102 public void openNodeContainingResource(RestResource resource){
103 TreeNode node = tree.getRootTreeNode();
104 openNodeContainingResource(node,resource);
106 private void openNodeContainingResource(TreeNode node, RestResource resource){
107 int count = node.getChildCount();
108 for(int i=0;i<count;i++){
110 if(node.getChildValue(i).equals(resource)){
111 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
113 node.setChildOpen(i, true, true);
117 if(node.isChildOpen(i)){
118 TreeNode n = node.setChildOpen(i, true);
120 openNodeContainingResource(n,resource);
127 public void openNodeContainingResource(RestResource resource, RefreshHandler handler){
128 TreeNode node = tree.getRootTreeNode();
129 openNodeContainingResource(node,resource,handler);
131 private void openNodeContainingResource(TreeNode node, RestResource resource, RefreshHandler handler){
132 int count = node.getChildCount();
133 for(int i=0;i<count;i++){
134 if(node.getChildValue(i).equals(resource)){
135 if(node.getChildValue(i) instanceof RestResourceWrapper && ((RestResourceWrapper)node.getChildValue(i)).getResource().getFolders().size()==0)
137 //node.setChildOpen(i, false, true);
138 node.setChildOpen(i, true, true);
143 if(node.isChildOpen(i)){
144 TreeNode n = node.setChildOpen(i, true);
146 openNodeContainingResource(n,resource, handler);
155 public boolean doesNodeContainsResource(TreeNode node, RestResource resource){
156 int count = node.getChildCount();
157 for(int i=0;i<count;i++){
158 if(node.isChildOpen(i)){
159 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).equals(resource)){
162 else if(node.isChildOpen(i)){
163 TreeNode n = node.setChildOpen(i, true);
165 return doesNodeContainsResource(n,resource);
172 public boolean doesNodeContainsResource(TreeNode node, String 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)){
179 else if(node.isChildOpen(i)){
180 TreeNode n = node.setChildOpen(i, true);
182 return doesNodeContainsResource(n,resource);
189 public TreeNode getNodeContainingResource(TreeNode node, RestResource resource){
190 int count = node.getChildCount();
191 for(int i=0;i<count;i++){
193 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource.getUri())){
196 else if(node.isChildOpen(i)){
197 TreeNode n = node.setChildOpen(i, true);
199 return getNodeContainingResource(n,resource);
206 public TreeNode getNodeContainingResource(TreeNode node, String resource){
209 int count = node.getChildCount();
210 for(int i=0;i<count;i++){
212 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
215 else if(node.isChildOpen(i)){
216 TreeNode n = node.setChildOpen(i, true);
218 TreeNode result = getNodeContainingResource2(n,resource);
228 public TreeNode getNodeContainingResource2(TreeNode node, String resource){
231 int count = node.getChildCount();
232 for(int i=0;i<count;i++){
233 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
234 return node.setChildOpen(i, node.isChildOpen(i));
236 else if(node.isChildOpen(i)){
237 TreeNode n = node.setChildOpen(i, true);
239 TreeNode result = getNodeContainingResource2(n,resource);
248 public boolean doesSharedNodeContainsResource( String resource){
249 if(tree.getRootTreeNode().isChildOpen(2)){
250 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
251 return doesNodeContainsResource(node, resource);
256 public boolean doesSharedNodeContainsResourceIn1stLevel( String resource){
257 if(tree.getRootTreeNode().isChildOpen(2)){
258 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
259 int count = node.getChildCount();
260 for(int i=0;i<count;i++){
262 if(node.getChildValue(i) instanceof RestResource && ((RestResource)node.getChildValue(i)).getUri().equals(resource)){
272 public boolean doesSharedNodeContainsResourceIn2ndLevel( String resource){
273 if(tree.getRootTreeNode().isChildOpen(2)){
274 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
275 int count = node.getChildCount();
276 for(int i=0;i<count;i++){
277 if(node.isChildOpen(i)){
278 TreeNode child = node.setChildOpen(i, true);
279 for(int j=0;j<child.getChildCount();j++){
280 if(child.getChildValue(j) instanceof RestResource && ((RestResource)child.getChildValue(j)).getUri().equals(resource)){
293 public boolean doesRootNodeContainsResource( String resource){
294 if(tree.getRootTreeNode().isChildOpen(0)){
295 TreeNode node = tree.getRootTreeNode().setChildOpen(0, true);
296 return doesNodeContainsResource(node, resource);
301 public boolean doesSharedNodeContainsResource( RestResource resource){
302 if(tree.getRootTreeNode().isChildOpen(2)){
303 TreeNode node = tree.getRootTreeNode().setChildOpen(2, true);
304 return doesNodeContainsResource(node, resource);
309 public boolean doesRootNodeContainsResource( RestResource resource){
310 if(tree.getRootTreeNode().isChildOpen(0)){
311 TreeNode node = tree.getRootTreeNode().setChildOpen(0, true);
312 return doesNodeContainsResource(node, resource);