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

Last change on this file since 14048 was 14048, checked in by xiao, 17 years ago

Changes made to look for collectionConfig.xml in gs3 mode and collect.cfg in gs2 mode, rather than presumably only for the file collect.cfg.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 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_in_loaded_collection = false;
49 private String title = null;
50
51
52 public WorkspaceTreeNode(File file)
53 {
54 super(file);
55 }
56
57
58 public WorkspaceTreeNode(File file, String title)
59 {
60 this(file);
61 this.title = title;
62 }
63
64
65 public FileNode addChildNode(File file)
66 {
67 WorkspaceTreeNode child_node = new WorkspaceTreeNode(file);
68 child_node.setModel(model);
69 child_node.setParent(this);
70 return child_node;
71 }
72
73
74 /** Is this file node within the currently loaded collection? */
75 public boolean isInLoadedCollection()
76 {
77 if (is_in_loaded_collection) {
78 return true;
79 }
80 else {
81 FileNode parent = (FileNode) getParent();
82 if (parent != null) {
83 return parent.isInLoadedCollection();
84 }
85 }
86 return false;
87 }
88
89
90 public boolean isReadOnly()
91 {
92 // The workspace tree is read only
93 return true;
94 }
95
96
97 public void map()
98 {
99 // Special Case: "Documents in Greenstone Collections" -- map the collections installed in Greenstone
100 if (file == null) { // a special mapping folder
101 if (child_nodes != null) {
102 // don't bother mapping again if we already have children
103 return;
104 }
105 child_nodes = new ArrayList();
106 if (title.equals(Dictionary.get("Tree.World")) && Gatherer.GS3) {
107 // the Greenstone collections folder for GS3 - this contains a
108 // folder for each site
109
110 File start = new File(Utility.getSitesDir(Configuration.gsdl3_path));
111 File sites[] = start.listFiles();
112 ArrayTools.sort(sites);
113 for (int i = 0; sites != null && i < sites.length; i++) {
114 File collect_dir = new File(sites[i], "collect");
115 if (!collect_dir.exists()) {
116 continue;
117 }
118
119 WorkspaceTreeNode child = new WorkspaceTreeNode(null, sites[i].getName());
120 child.is_gs3_site_node = true;
121 child.unmap();
122 child.setModel(model);
123 child.setParent(this);
124 child.map();
125 child_nodes.add(child);
126 }
127 model.nodeStructureChanged(this);
128
129 } else if (title.equals(Dictionary.get("Tree.World")) || is_gs3_site_node) {
130 // For each of the children directories, which are collections...
131 File start;
132 if (is_gs3_site_node) {
133 start = new File(Gatherer.getSitesDirectoryPath() + title + File.separator + "collect" + File.separator);
134 } else {
135 start = new File(Gatherer.getCollectDirectoryPath());
136 }
137 File cols[] = start.listFiles();
138 ArrayTools.sort(cols);
139
140 // We add their import directories, except for the model collection
141 for (int i = 0; cols != null && i < cols.length; i++) {
142 if (!cols[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
143 File import_dir = new File(cols[i], "import");
144 if (!import_dir.exists()) {
145 continue;
146 }
147
148 // we don't care if there is no config file
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 WorkspaceTreeNode collection_root = new WorkspaceTreeNode(import_dir, collect_cfg.toString());
152 collection_root.setParent(this);
153 collection_root.setModel(model);
154
155 // One last piece of magic so we can determine the current collection
156 collection_root.is_in_loaded_collection = cols[i].getName().equals(CollectionManager.getLoadedCollectionName());
157 child_nodes.add(collection_root);
158 }
159 }
160 model.nodeStructureChanged(this);
161 }
162 else if (title.equals(Dictionary.get("Tree.Root"))) {
163 // Special Case: "Local Filespace" on Windows -- create a node for each filesystem root (drive letter)
164
165 // Sort the roots into alphabetical order
166 File[] roots = File.listRoots();
167 ArrayTools.sort(roots);
168 for (int i = 0; i < roots.length; i++) {
169 // Only add root if it isn't a floppy drive
170 // this used to cause problems, I don't think it does now...
171 //if (!FileSystemView.getFileSystemView().isFloppyDrive(roots[i])) {
172 child_nodes.add(addChildNode(roots[i]));
173 // }
174 }
175 }
176 } // if file == null
177
178 // General case
179 else {
180 super.map();
181 }
182 }
183
184
185 public String toString()
186 {
187 if (title != null) {
188 return title;
189 }
190
191 return super.toString();
192 }
193
194}
Note: See TracBrowser for help on using the repository browser.