|
1 /******************************************************************************* |
|
2 * Copyright (c) 2000, 2009 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; |
|
14 import org.eclipse.core.filesystem.*; |
|
15 import org.eclipse.core.internal.resources.Resource; |
|
16 import org.eclipse.core.resources.IResource; |
|
17 |
|
18 /** |
|
19 * A node in a {@link UnifiedTree}. A node usually represents a file/folder |
|
20 * in the workspace, the file system, or both. There are also special node |
|
21 * instances to act as child and level markers in the tree. |
|
22 */ |
|
23 public class UnifiedTreeNode implements ILocalStoreConstants { |
|
24 protected UnifiedTreeNode child; |
|
25 protected boolean existsWorkspace; |
|
26 protected IFileInfo fileInfo; |
|
27 protected IResource resource; |
|
28 protected IFileStore store; |
|
29 protected UnifiedTree tree; |
|
30 |
|
31 public UnifiedTreeNode(UnifiedTree tree, IResource resource, IFileStore store, IFileInfo fileInfo, boolean existsWorkspace) { |
|
32 this.tree = tree; |
|
33 this.resource = resource; |
|
34 this.store = store; |
|
35 this.fileInfo = fileInfo; |
|
36 this.existsWorkspace = existsWorkspace; |
|
37 } |
|
38 |
|
39 public boolean existsInFileSystem() { |
|
40 return fileInfo != null && fileInfo.exists(); |
|
41 } |
|
42 |
|
43 public boolean existsInWorkspace() { |
|
44 return existsWorkspace; |
|
45 } |
|
46 |
|
47 /** |
|
48 * Returns an Iterator of UnifiedTreeNode. |
|
49 */ |
|
50 public Iterator getChildren() { |
|
51 return tree.getChildren(this); |
|
52 } |
|
53 |
|
54 protected UnifiedTreeNode getFirstChild() { |
|
55 return child; |
|
56 } |
|
57 |
|
58 public long getLastModified() { |
|
59 return fileInfo == null ? 0 : fileInfo.getLastModified(); |
|
60 } |
|
61 |
|
62 public int getLevel() { |
|
63 return tree.getLevel(); |
|
64 } |
|
65 |
|
66 /** |
|
67 * Gets the name of this node in the local file system. |
|
68 * @return Returns a String |
|
69 */ |
|
70 public String getLocalName() { |
|
71 return fileInfo == null ? null : fileInfo.getName(); |
|
72 } |
|
73 |
|
74 public IResource getResource() { |
|
75 return resource; |
|
76 } |
|
77 |
|
78 /** |
|
79 * Returns the local store of this resource. May be null. |
|
80 */ |
|
81 public IFileStore getStore() { |
|
82 //initialize store lazily, because it is not always needed |
|
83 if (store == null) |
|
84 store = ((Resource) resource).getStore(); |
|
85 return store; |
|
86 } |
|
87 |
|
88 public boolean isFolder() { |
|
89 return fileInfo == null ? false : fileInfo.isDirectory(); |
|
90 } |
|
91 |
|
92 public boolean isSymbolicLink() { |
|
93 return fileInfo == null ? false : fileInfo.getAttribute(EFS.ATTRIBUTE_SYMLINK); |
|
94 } |
|
95 |
|
96 public void removeChildrenFromTree() { |
|
97 tree.removeNodeChildrenFromQueue(this); |
|
98 } |
|
99 |
|
100 /** |
|
101 * Reuses this object by assigning all new values for the fields. |
|
102 */ |
|
103 public void reuse(UnifiedTree aTree, IResource aResource, IFileStore aStore, IFileInfo info, boolean existsInWorkspace) { |
|
104 this.tree = aTree; |
|
105 this.child = null; |
|
106 this.resource = aResource; |
|
107 this.store = aStore; |
|
108 this.fileInfo = info; |
|
109 this.existsWorkspace = existsInWorkspace; |
|
110 } |
|
111 |
|
112 public void setExistsWorkspace(boolean exists) { |
|
113 this.existsWorkspace = exists; |
|
114 } |
|
115 |
|
116 protected void setFirstChild(UnifiedTreeNode child) { |
|
117 this.child = child; |
|
118 } |
|
119 |
|
120 public void setResource(IResource resource) { |
|
121 this.resource = resource; |
|
122 } |
|
123 |
|
124 public String toString() { |
|
125 String s = resource == null ? "null" : resource.getFullPath().toString(); //$NON-NLS-1$ |
|
126 return "Node: " + s; //$NON-NLS-1$ |
|
127 } |
|
128 } |