[8783] | 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 |
|
---|
| 27 | package org.greenstone.gatherer.file;
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | import java.io.*;
|
---|
| 31 | import java.util.*;
|
---|
[8787] | 32 | import javax.swing.filechooser.FileSystemView;
|
---|
[8783] | 33 | import org.greenstone.gatherer.Configuration;
|
---|
| 34 | import org.greenstone.gatherer.Dictionary;
|
---|
| 35 | import org.greenstone.gatherer.Gatherer;
|
---|
| 36 | import org.greenstone.gatherer.collection.BasicCollectionConfiguration; // !!! Don't like this here
|
---|
[13595] | 37 | import org.greenstone.gatherer.collection.CollectionManager; // !!! Don't like this here
|
---|
[8783] | 38 | import org.greenstone.gatherer.util.ArrayTools;
|
---|
| 39 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
| 40 | import org.greenstone.gatherer.util.Utility;
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | /** This class represents one node in the workspace tree. */
|
---|
| 44 | public class WorkspaceTreeNode
|
---|
| 45 | extends FileNode
|
---|
| 46 | {
|
---|
| 47 | private boolean is_gs3_site_node = false;
|
---|
[19226] | 48 | private boolean is_group_node = false;
|
---|
[8784] | 49 | private boolean is_in_loaded_collection = false;
|
---|
[8783] | 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 |
|
---|
[8784] | 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 |
|
---|
[8783] | 91 | public boolean isReadOnly()
|
---|
| 92 | {
|
---|
| 93 | // The workspace tree is read only
|
---|
| 94 | return true;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | public void map()
|
---|
| 99 | {
|
---|
[8787] | 100 | // Special Case: "Documents in Greenstone Collections" -- map the collections installed in Greenstone
|
---|
[9458] | 101 | if (file == null) { // a special mapping folder
|
---|
[8783] | 102 | if (child_nodes != null) {
|
---|
[9458] | 103 | // don't bother mapping again if we already have children
|
---|
[8783] | 104 | return;
|
---|
| 105 | }
|
---|
| 106 | child_nodes = new ArrayList();
|
---|
[9458] | 107 | if (title.equals(Dictionary.get("Tree.World")) && Gatherer.GS3) {
|
---|
[8783] | 108 | // the Greenstone collections folder for GS3 - this contains a
|
---|
| 109 | // folder for each site
|
---|
[9458] | 110 |
|
---|
[8783] | 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++) {
|
---|
[10342] | 115 | File collect_dir = new File(sites[i], "collect");
|
---|
[8783] | 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;
|
---|
[9458] | 122 | child.unmap();
|
---|
[8783] | 123 | child.setModel(model);
|
---|
| 124 | child.setParent(this);
|
---|
[9458] | 125 | child.map();
|
---|
[8783] | 126 | child_nodes.add(child);
|
---|
| 127 | }
|
---|
[9458] | 128 | model.nodeStructureChanged(this);
|
---|
| 129 |
|
---|
[19226] | 130 | } else if (title.equals(Dictionary.get("Tree.World")) || is_gs3_site_node || is_group_node) {
|
---|
[8783] | 131 | // For each of the children directories, which are collections...
|
---|
| 132 | File start;
|
---|
[19226] | 133 | if (is_gs3_site_node ) {
|
---|
[9045] | 134 | start = new File(Gatherer.getSitesDirectoryPath() + title + File.separator + "collect" + File.separator);
|
---|
[19226] | 135 | }
|
---|
| 136 | else if (is_group_node) {
|
---|
| 137 | start = new File(Gatherer.getCollectDirectoryPath() + title);
|
---|
| 138 | }
|
---|
| 139 | else {
|
---|
[9045] | 140 | start = new File(Gatherer.getCollectDirectoryPath());
|
---|
[8783] | 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)) {
|
---|
[19226] | 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()) {
|
---|
[8783] | 162 | continue;
|
---|
[19226] | 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
|
---|
[22410] | 170 | // Now made to work with collection groups
|
---|
| 171 | String groupQualifiedColName = cols[i].getName();
|
---|
| 172 | if(is_group_node) { // then title would have stored the colgroup name
|
---|
| 173 | groupQualifiedColName = title + File.separator + cols[i].getName();
|
---|
| 174 | }
|
---|
| 175 | collection_root.is_in_loaded_collection = groupQualifiedColName.equals(CollectionManager.getLoadedCollectionName());
|
---|
[19226] | 176 | child_nodes.add(collection_root);
|
---|
[8783] | 177 | }
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 | model.nodeStructureChanged(this);
|
---|
| 181 | }
|
---|
[9458] | 182 | else if (title.equals(Dictionary.get("Tree.Root"))) {
|
---|
| 183 | // Special Case: "Local Filespace" on Windows -- create a node for each filesystem root (drive letter)
|
---|
| 184 |
|
---|
| 185 | // Sort the roots into alphabetical order
|
---|
| 186 | File[] roots = File.listRoots();
|
---|
| 187 | ArrayTools.sort(roots);
|
---|
| 188 | for (int i = 0; i < roots.length; i++) {
|
---|
| 189 | // Only add root if it isn't a floppy drive
|
---|
[10632] | 190 | // this used to cause problems, I don't think it does now...
|
---|
| 191 | //if (!FileSystemView.getFileSystemView().isFloppyDrive(roots[i])) {
|
---|
| 192 | child_nodes.add(addChildNode(roots[i]));
|
---|
| 193 | // }
|
---|
[8787] | 194 | }
|
---|
| 195 | }
|
---|
[9458] | 196 | } // if file == null
|
---|
| 197 |
|
---|
[8783] | 198 | // General case
|
---|
| 199 | else {
|
---|
| 200 | super.map();
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | public String toString()
|
---|
| 206 | {
|
---|
| 207 | if (title != null) {
|
---|
| 208 | return title;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | return super.toString();
|
---|
| 212 | }
|
---|
[9458] | 213 |
|
---|
[8783] | 214 | }
|
---|