KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > localstore > UnifiedTreeNode


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.localstore;
12
13 import java.util.Iterator JavaDoc;
14 import org.eclipse.core.filesystem.*;
15 import org.eclipse.core.internal.resources.Resource;
16 import org.eclipse.core.resources.IResource;
17
18 public class UnifiedTreeNode implements ILocalStoreConstants {
19     protected UnifiedTreeNode child;
20     protected boolean existsWorkspace;
21     protected IFileInfo fileInfo;
22     protected IResource resource;
23     protected IFileStore store;
24     protected UnifiedTree tree;
25
26     public UnifiedTreeNode(UnifiedTree tree, IResource resource, IFileStore store, IFileInfo fileInfo, boolean existsWorkspace) {
27         this.tree = tree;
28         this.resource = resource;
29         this.store = store;
30         this.fileInfo = fileInfo;
31         this.existsWorkspace = existsWorkspace;
32     }
33
34     public boolean existsInFileSystem() {
35         return fileInfo != null && fileInfo.exists();
36     }
37
38     public boolean existsInWorkspace() {
39         return existsWorkspace;
40     }
41
42     /**
43      * Returns an Enumeration of UnifiedResourceNode.
44      */

45     public Iterator JavaDoc getChildren() {
46         return tree.getChildren(this);
47     }
48
49     protected UnifiedTreeNode getFirstChild() {
50         return child;
51     }
52
53     public long getLastModified() {
54         return fileInfo == null ? 0 : fileInfo.getLastModified();
55     }
56
57     public int getLevel() {
58         return tree.getLevel();
59     }
60
61     /**
62      * Gets the name of this node in the local file system.
63      * @return Returns a String
64      */

65     public String JavaDoc getLocalName() {
66         return fileInfo == null ? null : fileInfo.getName();
67     }
68
69     public IResource getResource() {
70         return resource;
71     }
72
73     /**
74      * Returns the local store of this resource. May be null.
75      */

76     public IFileStore getStore() {
77         //initialize store lazily, because it is not always needed
78
if (store == null)
79             store = ((Resource) resource).getStore();
80         return store;
81     }
82
83     public boolean isFolder() {
84         return fileInfo == null ? false : fileInfo.isDirectory();
85     }
86     
87     public boolean isSymbolicLink() {
88         return fileInfo == null ? false : fileInfo.getAttribute(EFS.ATTRIBUTE_SYMLINK);
89     }
90
91     public void removeChildrenFromTree() {
92         tree.removeNodeChildrenFromQueue(this);
93     }
94
95     /**
96      * Reuses this object by assigning all new values for the fields.
97      */

98     public void reuse(UnifiedTree aTree, IResource aResource, IFileStore aStore, IFileInfo info, boolean existsInWorkspace) {
99         this.tree = aTree;
100         this.child = null;
101         this.resource = aResource;
102         this.store = aStore;
103         this.fileInfo = info;
104         this.existsWorkspace = existsInWorkspace;
105     }
106
107     public void setExistsWorkspace(boolean exists) {
108         this.existsWorkspace = exists;
109     }
110
111     protected void setFirstChild(UnifiedTreeNode child) {
112         this.child = child;
113     }
114
115     public void setResource(IResource resource) {
116         this.resource = resource;
117     }
118
119     public String JavaDoc toString() {
120         String JavaDoc s = resource == null ? "null" : resource.getFullPath().toString(); //$NON-NLS-1$
121
return "Node: " + s; //$NON-NLS-1$
122
}
123 }
124
Popular Tags