source: gli/trunk/src/org/greenstone/gatherer/file/WorkspaceTreeNode.java@ 19226

Last change on this file since 19226 was 19226, checked in by kjdon, 15 years ago

added code to handle collect groups

  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/**
2 *############################################################################
3 * A component of the Greenstone Librarian Interface, part of the Greenstone
4 * digital library suite from the New Zealand Digital Library Project at the
5 * University of Waikato, New Zealand.
6 *
7 * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
8 *
9 * Copyright (C) 2004 New Zealand Digital Library Project
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *############################################################################
25 */
26
27package org.greenstone.gatherer.file;
28
29
30import java.io.*;
31import java.util.*;
32import javax.swing.filechooser.FileSystemView;
33import org.greenstone.gatherer.Configuration;
34import org.greenstone.gatherer.Dictionary;
35import org.greenstone.gatherer.Gatherer;
36import org.greenstone.gatherer.collection.BasicCollectionConfiguration; // !!! Don't like this here
37import org.greenstone.gatherer.collection.CollectionManager; // !!! Don't like this here
38import org.greenstone.gatherer.util.ArrayTools;
39import org.greenstone.gatherer.util.StaticStrings;
40import org.greenstone.gatherer.util.Utility;
41
42
43/** This class represents one node in the workspace tree. */
44public class WorkspaceTreeNode
45 extends FileNode
46{
47 private boolean is_gs3_site_node = false;
48 private boolean is_group_node = false;
49 private boolean is_in_loaded_collection = false;
50 private String title = null;
51
52
53 public WorkspaceTreeNode(File file)
54 {
55 super(file);
56 }
57
58
59 public WorkspaceTreeNode(File file, String title)
60 {
61 this(file);
62 this.title = title;
63 }
64
65
66 public FileNode addChildNode(File file)
67 {
68 WorkspaceTreeNode child_node = new WorkspaceTreeNode(file);
69 child_node.setModel(model);
70 child_node.setParent(this);
71 return child_node;
72 }
73
74
75 /** Is this file node within the currently loaded collection? */
76 public boolean isInLoadedCollection()
77 {
78 if (is_in_loaded_collection) {
79 return true;
80 }
81 else {
82 FileNode parent = (FileNode) getParent();
83 if (parent != null) {
84 return parent.isInLoadedCollection();
85 }
86 }
87 return false;
88 }
89
90
91 public boolean isReadOnly()
92 {
93 // The workspace tree is read only
94 return true;
95 }
96
97
98 public void map()
99 {
100 // Special Case: "Documents in Greenstone Collections" -- map the collections installed in Greenstone
101 if (file == null) { // a special mapping folder
102 if (child_nodes != null) {
103 // don't bother mapping again if we already have children
104 return;
105 }
106 child_nodes = new ArrayList();
107 if (title.equals(Dictionary.get("Tree.World")) && Gatherer.GS3) {
108 // the Greenstone collections folder for GS3 - this contains a
109 // folder for each site
110
111 File start = new File(Utility.getSitesDir(Configuration.gsdl3_path));
112 File sites[] = start.listFiles();
113 ArrayTools.sort(sites);
114 for (int i = 0; sites != null && i < sites.length; i++) {
115 File collect_dir = new File(sites[i], "collect");
116 if (!collect_dir.exists()) {
117 continue;
118 }
119
120 WorkspaceTreeNode child = new WorkspaceTreeNode(null, sites[i].getName());
121 child.is_gs3_site_node = true;
122 child.unmap();
123 child.setModel(model);
124 child.setParent(this);
125 child.map();
126 child_nodes.add(child);
127 }
128 model.nodeStructureChanged(this);
129
130 } else if (title.equals(Dictionary.get("Tree.World")) || is_gs3_site_node || is_group_node) {
131 // For each of the children directories, which are collections...
132 File start;
133 if (is_gs3_site_node ) {
134 start = new File(Gatherer.getSitesDirectoryPath() + title + File.separator + "collect" + File.separator);
135 }
136 else if (is_group_node) {
137 start = new File(Gatherer.getCollectDirectoryPath() + title);
138 }
139 else {
140 start = new File(Gatherer.getCollectDirectoryPath());
141 }
142 File cols[] = start.listFiles();
143 ArrayTools.sort(cols);
144
145 // We add their import directories, except for the model collection
146 for (int i = 0; cols != null && i < cols.length; i++) {
147 if (!cols[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
148 // check for groups
149 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
150 BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(new File(cols[i], file_name));
151 if (collect_cfg.getCollectGroup().equals("true")) {
152 WorkspaceTreeNode child = new WorkspaceTreeNode(null, cols[i].getName());
153 child.is_group_node = true;
154 child.unmap();
155 child.setModel(model);
156 child.setParent(this);
157 child.map();
158 child_nodes.add(child);
159 } else {
160 File import_dir = new File(cols[i], "import");
161 if (!import_dir.exists()) {
162 continue;
163 }
164
165 WorkspaceTreeNode collection_root = new WorkspaceTreeNode(import_dir, collect_cfg.toString());
166 collection_root.setParent(this);
167 collection_root.setModel(model);
168
169 // One last piece of magic so we can determine the current collection
170 collection_root.is_in_loaded_collection = cols[i].getName().equals(CollectionManager.getLoadedCollectionName());
171 child_nodes.add(collection_root);
172 }
173 }
174 }
175 model.nodeStructureChanged(this);
176 }
177 else if (title.equals(Dictionary.get("Tree.Root"))) {
178 // Special Case: "Local Filespace" on Windows -- create a node for each filesystem root (drive letter)
179
180 // Sort the roots into alphabetical order
181 File[] roots = File.listRoots();
182 ArrayTools.sort(roots);
183 for (int i = 0; i < roots.length; i++) {
184 // Only add root if it isn't a floppy drive
185 // this used to cause problems, I don't think it does now...
186 //if (!FileSystemView.getFileSystemView().isFloppyDrive(roots[i])) {
187 child_nodes.add(addChildNode(roots[i]));
188 // }
189 }
190 }
191 } // if file == null
192
193 // General case
194 else {
195 super.map();
196 }
197 }
198
199
200 public String toString()
201 {
202 if (title != null) {
203 return title;
204 }
205
206 return super.toString();
207 }
208
209}
Note: See TracBrowser for help on using the repository browser.