[4293] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | *
|
---|
| 4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
| 5 | * library suite from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * <BR><BR>
|
---|
| 9 | *
|
---|
[10245] | 10 | * Author: John Thompson, NZDL Project, University of Waikato
|
---|
[4293] | 11 | *
|
---|
| 12 | * <BR><BR>
|
---|
| 13 | *
|
---|
[10245] | 14 | * Copyright (C) 2005 New Zealand Digital Library Project
|
---|
[4293] | 15 | *
|
---|
| 16 | * <BR><BR>
|
---|
| 17 | *
|
---|
| 18 | * This program is free software; you can redistribute it and/or modify
|
---|
| 19 | * it under the terms of the GNU General Public License as published by
|
---|
| 20 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 21 | * (at your option) any later version.
|
---|
| 22 | *
|
---|
| 23 | * <BR><BR>
|
---|
| 24 | *
|
---|
| 25 | * This program is distributed in the hope that it will be useful,
|
---|
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 28 | * GNU General Public License for more details.
|
---|
| 29 | *
|
---|
| 30 | * <BR><BR>
|
---|
| 31 | *
|
---|
| 32 | * You should have received a copy of the GNU General Public License
|
---|
| 33 | * along with this program; if not, write to the Free Software
|
---|
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 35 | *########################################################################
|
---|
| 36 | */
|
---|
[5564] | 37 | package org.greenstone.gatherer.file;
|
---|
| 38 |
|
---|
[4293] | 39 | import java.io.File;
|
---|
| 40 | import javax.swing.*;
|
---|
[5564] | 41 | import org.greenstone.gatherer.Dictionary;
|
---|
[4293] | 42 | import org.greenstone.gatherer.Gatherer;
|
---|
[13586] | 43 | import org.greenstone.gatherer.collection.CollectionManager;
|
---|
[11246] | 44 | import org.greenstone.gatherer.collection.CollectionTree;
|
---|
[8783] | 45 | import org.greenstone.gatherer.collection.CollectionTreeNode;
|
---|
[13455] | 46 | import org.greenstone.gatherer.gui.ExplodeMetadataDatabasePrompt;
|
---|
[15105] | 47 | import org.greenstone.gatherer.gui.ReplaceSrcDocWithHtmlPrompt;
|
---|
[11073] | 48 | import org.greenstone.gatherer.gui.GProgressBar;
|
---|
[9114] | 49 | import org.greenstone.gatherer.gui.NewFolderOrFilePrompt;
|
---|
[11246] | 50 | import org.greenstone.gatherer.gui.RenamePrompt;
|
---|
[4293] | 51 | import org.greenstone.gatherer.gui.tree.DragTree;
|
---|
[10376] | 52 | import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
|
---|
[4293] | 53 | import org.greenstone.gatherer.util.DragComponent;
|
---|
[7647] | 54 | import org.greenstone.gatherer.util.Utility;
|
---|
[5564] | 55 |
|
---|
[4675] | 56 | /** Manages the moving of files within a separate thread.
|
---|
[10245] | 57 | * @author John Thompson, NZDL Project, University of Waikato
|
---|
[4293] | 58 | */
|
---|
[10245] | 59 | public class FileManager
|
---|
| 60 | {
|
---|
| 61 | /** Not only the queue of files to be moved, but also the object that moves them. */
|
---|
| 62 | static private FileQueue file_queue = null;
|
---|
[6319] | 63 |
|
---|
[9114] | 64 | public static int FILE_TYPE = 0;
|
---|
| 65 | public static int FOLDER_TYPE = 1;
|
---|
[11440] | 66 | protected static File startup_directory = null;
|
---|
[9114] | 67 |
|
---|
[6319] | 68 |
|
---|
[4366] | 69 | /** Constructor.
|
---|
| 70 | * @see org.greenstone.gatherer.file.FileQueue
|
---|
| 71 | */
|
---|
[10245] | 72 | public FileManager()
|
---|
| 73 | {
|
---|
| 74 | file_queue = new FileQueue();
|
---|
| 75 | file_queue.start();
|
---|
[4366] | 76 | }
|
---|
[4293] | 77 |
|
---|
[10245] | 78 |
|
---|
| 79 | /** Determine what action should be carried out by the file queue, and add all of the necessary file jobs. */
|
---|
| 80 | public void action(DragComponent source, FileNode[] source_nodes, DragComponent target, FileNode target_node)
|
---|
| 81 | {
|
---|
[10246] | 82 | // Check there is something to do
|
---|
[10265] | 83 | if (source_nodes == null || source_nodes.length == 0) {
|
---|
[10246] | 84 | return;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | // We need a unique ID for each file task
|
---|
[10245] | 88 | long id = System.currentTimeMillis();
|
---|
| 89 |
|
---|
| 90 | // If source and target are the same we're moving
|
---|
| 91 | if (source == target) {
|
---|
| 92 | // Start a new move FileTask and we're done
|
---|
| 93 | (new FileTask(id, source, source_nodes, target, target_node, FileJob.MOVE)).start();
|
---|
| 94 | return;
|
---|
[4366] | 95 | }
|
---|
[7647] | 96 |
|
---|
[10245] | 97 | // If target isn't the RecycleBin, we're copying
|
---|
| 98 | if (!(target instanceof RecycleBin)) {
|
---|
| 99 | // Start a new copy FileTask and we're done
|
---|
| 100 | (new FileTask(id, source, source_nodes, target, target_node, FileJob.COPY)).start();
|
---|
| 101 | return;
|
---|
| 102 | }
|
---|
[8391] | 103 |
|
---|
[10245] | 104 | // We're deleting... but first make sure source isn't read-only
|
---|
| 105 | boolean read_only_source = false;
|
---|
| 106 |
|
---|
| 107 | // The workspace tree is read-only...
|
---|
| 108 | if (source.toString().equals("Workspace")) {
|
---|
| 109 | read_only_source = true;
|
---|
| 110 |
|
---|
| 111 | // ...except for files from the "Downloaded Files" folder
|
---|
[10342] | 112 | String downloaded_files_folder_path = Gatherer.getGLIUserCacheDirectoryPath();
|
---|
[10245] | 113 | for (int i = 0; i < source_nodes.length; i++) {
|
---|
| 114 | // Is this the "Downloaded Files" folder?
|
---|
| 115 | if (source_nodes[i].getFile().getAbsolutePath().startsWith(downloaded_files_folder_path)) {
|
---|
| 116 | read_only_source = false;
|
---|
[4366] | 117 | }
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
[10245] | 120 |
|
---|
| 121 | // The source is read-only, so tell the user and abort
|
---|
| 122 | if (read_only_source) {
|
---|
| 123 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Read_Only"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
|
---|
| 124 | return;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | // Start a new delete FileTask and we're done
|
---|
| 128 | (new FileTask(id, source, source_nodes, target, target_node, FileJob.DELETE)).start();
|
---|
[4366] | 129 | }
|
---|
[4293] | 130 |
|
---|
[10245] | 131 |
|
---|
[4366] | 132 | /** Retrieves the file queue object. */
|
---|
[10245] | 133 | public FileQueue getQueue()
|
---|
| 134 | {
|
---|
| 135 | return file_queue;
|
---|
[4366] | 136 | }
|
---|
[4293] | 137 |
|
---|
[10245] | 138 |
|
---|
| 139 | private class FileTask
|
---|
| 140 | extends Thread
|
---|
| 141 | {
|
---|
| 142 | private long id;
|
---|
| 143 | private DragComponent source;
|
---|
| 144 | private FileNode[] source_nodes;
|
---|
| 145 | private DragComponent target;
|
---|
| 146 | private FileNode target_node;
|
---|
| 147 | private byte type;
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | public FileTask(long id, DragComponent source, FileNode[] source_nodes, DragComponent target, FileNode target_node, byte type)
|
---|
| 151 | {
|
---|
| 152 | this.id = id;
|
---|
| 153 | this.source = source;
|
---|
| 154 | this.source_nodes = source_nodes;
|
---|
| 155 | this.target = target;
|
---|
| 156 | this.target_node = target_node;
|
---|
| 157 | this.type = type;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | public void run()
|
---|
| 162 | {
|
---|
| 163 | // Reset the progress bar and set it to indeterminate while calculating its size
|
---|
[11073] | 164 | GProgressBar progress_bar = file_queue.getProgressBar();
|
---|
[10245] | 165 | progress_bar.reset();
|
---|
| 166 | progress_bar.setIndeterminate(true);
|
---|
| 167 |
|
---|
| 168 | // Calculate the progress bar size
|
---|
| 169 | boolean cancelled = file_queue.calculateSize(source_nodes);
|
---|
| 170 | if (!cancelled) {
|
---|
[11241] | 171 | file_queue.addJob(id, source, source_nodes, target, target_node, type);
|
---|
[10248] | 172 | if (Gatherer.isGsdlRemote) {
|
---|
[22410] | 173 | String collection_name = CollectionManager.getLoadedCollectionName();
|
---|
[10561] | 174 |
|
---|
| 175 | // Perform the appropriate action based on the job type (RemoteGreenstoneServer will queue)
|
---|
| 176 | if (type == FileJob.COPY) {
|
---|
[10726] | 177 | // Copies: upload all the files at once in one zip file
|
---|
[10561] | 178 | File[] source_files = new File[source_nodes.length];
|
---|
| 179 | for (int i = 0; i < source_nodes.length; i++) {
|
---|
| 180 | source_files[i] = source_nodes[i].getFile();
|
---|
| 181 | }
|
---|
[17612] | 182 | Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, source_files, target_node.getFile());
|
---|
[10561] | 183 | }
|
---|
| 184 | else if (type == FileJob.DELETE) {
|
---|
[10726] | 185 | // Deletes: delete each top-level file/directory one at a time
|
---|
| 186 | for (int i = 0; i < source_nodes.length; i++) {
|
---|
[17612] | 187 | Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, source_nodes[i].getFile());
|
---|
[10726] | 188 | }
|
---|
[10561] | 189 | }
|
---|
| 190 | else if (type == FileJob.MOVE) {
|
---|
[10726] | 191 | // Moves: move each top-level file/directory one at a time
|
---|
| 192 | for (int i = 0; i < source_nodes.length; i++) {
|
---|
[17612] | 193 | Gatherer.remoteGreenstoneServer.moveCollectionFile(
|
---|
| 194 | collection_name, source_nodes[i].getFile(), target_node.getFile());
|
---|
[10726] | 195 | }
|
---|
[10561] | 196 | }
|
---|
[10248] | 197 | }
|
---|
[10245] | 198 | }
|
---|
| 199 |
|
---|
| 200 | progress_bar.setIndeterminate(false);
|
---|
| 201 | progress_bar.clear();
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[13455] | 205 | public void explodeMetadataDatabase(File file)
|
---|
| 206 | {
|
---|
| 207 | // This must go in a separate thread because we need the progress bar to work (remote Greenstone server)
|
---|
| 208 | new ExplodeMetadataDatabasePromptTask(file).start();
|
---|
| 209 | }
|
---|
| 210 |
|
---|
[15105] | 211 | // Works with replace_srcdoc_with_html.pl
|
---|
| 212 | public void replaceSrcDocWithHtml(File[] files)
|
---|
| 213 | {
|
---|
| 214 | // This must go in a separate thread because we need the progress bar to work (remote Greenstone server)
|
---|
| 215 | new ReplaceSrcDocWithHtmlPromptTask(files).start();
|
---|
| 216 | }
|
---|
[13455] | 217 |
|
---|
| 218 | private class ExplodeMetadataDatabasePromptTask
|
---|
| 219 | extends Thread
|
---|
| 220 | {
|
---|
| 221 | private File metadata_database_file = null;
|
---|
| 222 |
|
---|
| 223 | public ExplodeMetadataDatabasePromptTask(File metadata_database_file)
|
---|
| 224 | {
|
---|
| 225 | this.metadata_database_file = metadata_database_file;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | public void run()
|
---|
| 229 | {
|
---|
| 230 | ExplodeMetadataDatabasePrompt emp = new ExplodeMetadataDatabasePrompt(metadata_database_file);
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[15105] | 234 | // Works with replace_srcdoc_with_html.pl
|
---|
| 235 | private class ReplaceSrcDocWithHtmlPromptTask
|
---|
| 236 | extends Thread
|
---|
| 237 | {
|
---|
| 238 | private File[] replace_these_srcdoc_files = null;
|
---|
[13455] | 239 |
|
---|
[15105] | 240 | public ReplaceSrcDocWithHtmlPromptTask(File[] replace_these_srcdoc_files)
|
---|
| 241 | {
|
---|
| 242 | this.replace_these_srcdoc_files = replace_these_srcdoc_files;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | public void run()
|
---|
| 246 | {
|
---|
| 247 | ReplaceSrcDocWithHtmlPrompt prompt = new ReplaceSrcDocWithHtmlPrompt(replace_these_srcdoc_files);
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 |
|
---|
[10555] | 252 | public void openFileInExternalApplication(File file)
|
---|
| 253 | {
|
---|
| 254 | // This must go in a separate thread because we need the progress bar to work (remote Greenstone server)
|
---|
| 255 | new OpenFileInExternalApplicationTask(file).start();
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 | private class OpenFileInExternalApplicationTask
|
---|
| 260 | extends Thread
|
---|
| 261 | {
|
---|
| 262 | private File file = null;
|
---|
| 263 |
|
---|
| 264 | public OpenFileInExternalApplicationTask(File file)
|
---|
| 265 | {
|
---|
| 266 | this.file = file;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | public void run()
|
---|
| 270 | {
|
---|
| 271 | // If we're using a remote Greenstone server, we need to download the file before viewing it...
|
---|
| 272 | if (Gatherer.isGsdlRemote) {
|
---|
| 273 | // ... but only if it is inside the collection and we haven't already downloaded it
|
---|
| 274 | if (file.getAbsolutePath().startsWith(Gatherer.getCollectDirectoryPath()) && file.length() == 0) {
|
---|
[17612] | 275 | if (Gatherer.remoteGreenstoneServer.downloadCollectionFile(
|
---|
[22410] | 276 | CollectionManager.getLoadedCollectionName(), file).equals("")) {
|
---|
[10726] | 277 | // Something has gone wrong downloading the file
|
---|
| 278 | return;
|
---|
| 279 | }
|
---|
[10555] | 280 | }
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | // View the file in an external application
|
---|
| 284 | Gatherer.spawnApplication(file);
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 |
|
---|
[9114] | 289 | public void newDummyDoc(DragTree tree, CollectionTreeNode parent_node){
|
---|
| 290 | newFolderOrDummyDoc(tree, parent_node, FILE_TYPE);
|
---|
| 291 | }
|
---|
| 292 |
|
---|
[10245] | 293 |
|
---|
[8783] | 294 | public void newFolder(DragTree tree, CollectionTreeNode parent_node) {
|
---|
[9114] | 295 | newFolderOrDummyDoc(tree, parent_node, FOLDER_TYPE);
|
---|
| 296 | }
|
---|
[10245] | 297 |
|
---|
| 298 |
|
---|
[9114] | 299 | protected void newFolderOrDummyDoc(DragTree tree, CollectionTreeNode parent_node, int type) {
|
---|
[10726] | 300 | (new NewFolderOrDummyDocumentTask(tree, parent_node, type)).start();
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 |
|
---|
| 304 | private class NewFolderOrDummyDocumentTask
|
---|
| 305 | extends Thread
|
---|
| 306 | {
|
---|
| 307 | private DragTree tree = null;
|
---|
| 308 | private CollectionTreeNode parent_node = null;
|
---|
| 309 | private int type;
|
---|
| 310 |
|
---|
| 311 | public NewFolderOrDummyDocumentTask(DragTree tree, CollectionTreeNode parent_node, int type)
|
---|
| 312 | {
|
---|
| 313 | this.tree = tree;
|
---|
| 314 | this.parent_node = parent_node;
|
---|
| 315 | this.type = type;
|
---|
[9114] | 316 | }
|
---|
[10726] | 317 |
|
---|
| 318 | public void run()
|
---|
| 319 | {
|
---|
| 320 | // Ask the user for the directories name.
|
---|
| 321 | String extension = "";
|
---|
| 322 | if (type == FILE_TYPE) {
|
---|
| 323 | extension = ".nul";
|
---|
[4366] | 324 | }
|
---|
[10726] | 325 |
|
---|
| 326 | NewFolderOrFilePrompt new_folder_prompt = new NewFolderOrFilePrompt(parent_node, type, extension);
|
---|
| 327 | String name = new_folder_prompt.display();
|
---|
| 328 | new_folder_prompt.dispose();
|
---|
| 329 | new_folder_prompt = null;
|
---|
| 330 |
|
---|
| 331 | // And if the name is non-null...
|
---|
| 332 | if (name != null) {
|
---|
| 333 | FileSystemModel model = (FileSystemModel) tree.getModel();
|
---|
| 334 | File folder_file = new File(parent_node.getFile(), name);
|
---|
| 335 |
|
---|
| 336 | //... check if it already exists.
|
---|
| 337 | if (folder_file.exists()) {
|
---|
[9114] | 338 | if (type == FILE_TYPE) {
|
---|
[10726] | 339 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.File_Already_Exists_No_Create", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
|
---|
| 340 | }
|
---|
| 341 | else {
|
---|
| 342 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Folder_Already_Exists", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
|
---|
| 343 | }
|
---|
| 344 | }
|
---|
| 345 | // Otherwise create it.
|
---|
| 346 | else {
|
---|
| 347 | try {
|
---|
| 348 | if (type == FILE_TYPE) {
|
---|
| 349 | folder_file.createNewFile();
|
---|
[13300] | 350 | if (Gatherer.isGsdlRemote) {
|
---|
[17612] | 351 | Gatherer.remoteGreenstoneServer.uploadCollectionFile(
|
---|
[22410] | 352 | CollectionManager.getLoadedCollectionName(), folder_file);
|
---|
[13300] | 353 | }
|
---|
[10265] | 354 | }
|
---|
[10726] | 355 | else {
|
---|
| 356 | folder_file.mkdirs();
|
---|
| 357 | if (Gatherer.isGsdlRemote) {
|
---|
[17612] | 358 | Gatherer.remoteGreenstoneServer.newCollectionDirectory(
|
---|
[22410] | 359 | CollectionManager.getLoadedCollectionName(), folder_file);
|
---|
[10726] | 360 | }
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | // Update the parent node to show the new folder
|
---|
| 364 | parent_node.refresh();
|
---|
| 365 |
|
---|
| 366 | // Refresh workspace tree (collection tree is done automatically)
|
---|
| 367 | Gatherer.g_man.refreshWorkspaceTree(DragTree.COLLECTION_CONTENTS_CHANGED);
|
---|
[9114] | 368 | }
|
---|
[10726] | 369 | catch (Exception exception) {
|
---|
| 370 | if (type == FILE_TYPE) {
|
---|
| 371 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.File_Create_Error", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
|
---|
| 372 | }
|
---|
| 373 | else {
|
---|
| 374 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Folder_Create_Error", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
|
---|
| 375 | }
|
---|
[9114] | 376 | }
|
---|
| 377 | }
|
---|
[10726] | 378 |
|
---|
| 379 | folder_file = null;
|
---|
| 380 | model = null;
|
---|
[4366] | 381 | }
|
---|
[10726] | 382 | name = null;
|
---|
[4366] | 383 | }
|
---|
| 384 | }
|
---|
[11246] | 385 |
|
---|
| 386 |
|
---|
| 387 | public void renameCollectionFile(CollectionTree collection_tree, CollectionTreeNode collection_tree_node)
|
---|
| 388 | {
|
---|
| 389 | // This must go in a separate thread because we need the progress bar to work (remote Greenstone server)
|
---|
| 390 | new RenameTask(collection_tree, collection_tree_node).start();
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 |
|
---|
| 394 | private class RenameTask
|
---|
| 395 | extends Thread
|
---|
| 396 | {
|
---|
| 397 | private CollectionTree collection_tree = null;
|
---|
| 398 | private CollectionTreeNode collection_tree_node = null;
|
---|
| 399 |
|
---|
| 400 | public RenameTask(CollectionTree collection_tree, CollectionTreeNode collection_tree_node)
|
---|
| 401 | {
|
---|
| 402 | this.collection_tree = collection_tree;
|
---|
| 403 | this.collection_tree_node = collection_tree_node;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | public void run()
|
---|
| 407 | {
|
---|
| 408 | RenamePrompt rename_prompt = new RenamePrompt(collection_tree_node);
|
---|
| 409 | String new_collection_file_name = rename_prompt.display();
|
---|
| 410 | rename_prompt.dispose();
|
---|
| 411 | rename_prompt = null;
|
---|
| 412 |
|
---|
| 413 | if (new_collection_file_name != null) {
|
---|
| 414 | File collection_file = collection_tree_node.getFile();
|
---|
| 415 | File new_collection_file = new File(collection_file.getParentFile(), new_collection_file_name);
|
---|
| 416 | CollectionTreeNode new_collection_tree_node = new CollectionTreeNode(new_collection_file);
|
---|
| 417 | file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.RENAME);
|
---|
[13604] | 418 | if (Gatherer.isGsdlRemote) {
|
---|
[17612] | 419 | Gatherer.remoteGreenstoneServer.moveCollectionFile(
|
---|
[22410] | 420 | CollectionManager.getLoadedCollectionName(), collection_file, new_collection_file);
|
---|
[13604] | 421 | }
|
---|
[11246] | 422 | }
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
[11314] | 425 |
|
---|
| 426 | public void replaceCollectionFile(CollectionTree collection_tree, CollectionTreeNode collection_tree_node)
|
---|
| 427 | {
|
---|
| 428 | // This must go in a separate thread because we need the progress bar to work (remote Greenstone server)
|
---|
| 429 | new ReplaceTask(collection_tree, collection_tree_node).start();
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 |
|
---|
| 433 | private class ReplaceTask
|
---|
| 434 | extends Thread
|
---|
| 435 | {
|
---|
| 436 | private CollectionTree collection_tree = null;
|
---|
| 437 | private CollectionTreeNode collection_tree_node = null;
|
---|
| 438 |
|
---|
| 439 | public ReplaceTask(CollectionTree collection_tree, CollectionTreeNode collection_tree_node)
|
---|
| 440 | {
|
---|
| 441 | this.collection_tree = collection_tree;
|
---|
| 442 | this.collection_tree_node = collection_tree_node;
|
---|
| 443 | }
|
---|
| 444 |
|
---|
| 445 | public void run()
|
---|
| 446 | {
|
---|
[11440] | 447 | JFileChooser file_chooser = new JFileChooser(startup_directory);
|
---|
[11314] | 448 | file_chooser.setDialogTitle(Dictionary.get("ReplacePrompt.Title"));
|
---|
| 449 | File new_file = null;
|
---|
| 450 | int return_val = file_chooser.showOpenDialog(null);
|
---|
| 451 | if(return_val == JFileChooser.APPROVE_OPTION) {
|
---|
| 452 | new_file = file_chooser.getSelectedFile();
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | if (new_file == null) {
|
---|
| 456 | return;
|
---|
| 457 | }
|
---|
| 458 |
|
---|
[11440] | 459 | // save the search path for next time
|
---|
| 460 | startup_directory = new_file.getParentFile();
|
---|
[11314] | 461 | // make up a node for the file to bring in
|
---|
| 462 | WorkspaceTreeNode source_node = new WorkspaceTreeNode(new_file);
|
---|
| 463 |
|
---|
| 464 | File target_directory = collection_tree_node.getFile().getParentFile();
|
---|
| 465 | CollectionTreeNode new_collection_tree_node = new CollectionTreeNode(new File(target_directory, new_file.getName()));
|
---|
| 466 | // copy the new file in - but don't bring metadata
|
---|
| 467 | file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, (FileNode)collection_tree_node.getParent(), FileJob.COPY_FILE_ONLY);
|
---|
[13605] | 468 | if (Gatherer.isGsdlRemote) {
|
---|
[22410] | 469 | String collection_name = CollectionManager.getLoadedCollectionName();
|
---|
[19239] | 470 | Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, collection_tree_node.getFile());
|
---|
| 471 | Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, new File[] { new_file }, target_directory);
|
---|
[13605] | 472 | }
|
---|
[11314] | 473 | // do a replace of old file with new file
|
---|
| 474 | file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE);
|
---|
| 475 | }
|
---|
| 476 | }
|
---|
[4293] | 477 | }
|
---|