source: main/trunk/gli/src/org/greenstone/gatherer/file/FileJob.java@ 36272

Last change on this file since 36272 was 11313, checked in by kjdon, 18 years ago

added two new job types - COPY_FILE_ONLY, which copies without trying to find metadata, and replace, which will move metadata from one file to another, and delete teh original file

  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.file;
28
29import javax.swing.tree.*;
30import org.greenstone.gatherer.util.DragComponent;
31
32/** This object encapsulates all the information about a certain file movement job. This job be to create a copy of a file from one place to another, or to simply delete a file.
33 * @author John Thompson
34 * @version 2.3c
35 */
36public class FileJob {
37 /** true to mark that this file has already been copied, false otherwise. */
38 public boolean done = false;
39
40 /** The type of this movement as an byte. */
41 public byte type = 0;
42 /** The DragComponent source of this file, most likely a GTree. */
43 public DragComponent source = null;
44 /** The DragComponent to move the file to, again most likely a GTree. */
45 public DragComponent target = null;
46 /** The unique identifier shared by all jobs created by the same action. */
47 private long id = 0;
48 /** The path to the destination node as a string. Used because any reference based path or variables quickly becomes obsolete. */
49 private TreePath destination_path = null;
50 /** The path to the origin node as a string. Used because any reference based path or variables quickly becomes obsolete. */
51 private TreePath origin_path = null;
52 /** An element of the job type enumeration indicating a copy action. */
53 static final public byte COPY = 1;
54 /** An element of the job type enumeration indicating a delete action. */
55 static final public byte DELETE = 2;
56 /** An element of the job type enumeration indicating a move action. */
57 static final public byte MOVE = 3;
58 /** An element of the job type enumeration indicating a new folder action. */
59 static final public byte NEW_FOLDER = 4;
60 /** An element of the job type enumeration indicating an empty folder delete action. */
61 static final public byte DELETE_EMPTY_DIRECTORY = 5;
62 /** An element of the job type enumeration indicating a rename action. */
63 static final public byte RENAME = 6;
64 /** An element of the job type enumeration indicating a replace action. */
65 static final public byte REPLACE = 7;
66 /** An element of the job type enumeration indicating a copy action (but don't look for metadata. */
67 static final public byte COPY_FILE_ONLY = 8;
68
69 /** Constructor.
70 * @param id A unique identifier for this job (and others created with a single gesture) as a long.
71 * @param source The DragComponent source of this file, most likely a GTree.
72 * @param orig The FileNode you wish to mode.
73 * @param target The DragComponent to move the file to, again most likely a GTree.
74 * @param dest The files new FileNode parent within the target.
75 * @param type The type of this movement as an int, either COPY or DELETE.
76 */
77 public FileJob(long id, DragComponent source, FileNode orig, DragComponent target, FileNode dest, byte type) {
78 this.id = id;
79 this.source = source;
80 this.target = target;
81 this.type = type;
82 ///ystem.err.println("New Job: " + type + ", " + source + ", " + target);
83 // Dont store FileNodes which can go stale. Store paths instead, which are used to locate current 'fresh' versions of nodes.
84 if(dest != null) {
85 this.destination_path = new TreePath(dest.getPath());
86 ///ystem.err.println("Destination Path: " + destination_path);
87 }
88 if(orig != null) {
89 this.origin_path = new TreePath(orig.getPath());
90 ///atherer.println("Origin Path: " + origin_path);
91 }
92 }
93
94 /** Retrieve the destination node. Watch out for stale versions by always attempting to load the node at destination_path first. */
95 public FileNode getDestination() {
96 FileNode destination = null;
97 if(destination_path != null) {
98 if(target != null) {
99 FileSystemModel model = (FileSystemModel)target.getTreeModel();
100 destination = model.getNode(destination_path);
101 }
102 // If the above fails, a stale copy may be better than nothing.
103 else {
104 destination = (FileNode) destination_path.getLastPathComponent();
105 }
106 }
107 return destination;
108 }
109
110 /** Retrieve the origin node. Watch out for stale versions by always attempting to load the node at origin_path first. */
111 public FileNode getOrigin() {
112 FileNode origin = null;
113 if(origin_path != null) {
114 if(source != null) {
115 FileSystemModel model = (FileSystemModel)source.getTreeModel();
116 origin = model.getNode(origin_path);
117 }
118 // If the above fails, a stale copy may be better than nothing.
119 else {
120 origin = (FileNode) origin_path.getLastPathComponent();
121 }
122 }
123 return origin;
124 }
125
126 /** Retrieve the id for this job. */
127 public long ID() {
128 return id;
129 }
130
131 public String toString() {
132 StringBuffer text = new StringBuffer("");
133 switch(type) {
134 case COPY:
135 text.append("copy ");
136 break;
137 case DELETE:
138 text.append("delete ");
139 break;
140 case MOVE:
141 text.append("move ");
142 break;
143 case DELETE_EMPTY_DIRECTORY:
144 text.append("empty directory delete ");
145 break;
146 default:
147 text.append("unknown ");
148 }
149 FileNode origin = getOrigin();
150 if(origin != null) {
151 text.append(origin.getFile().getAbsolutePath());
152 }
153 else {
154 text.append("ERROR!");
155 }
156 if (type != DELETE && type != DELETE_EMPTY_DIRECTORY) {
157 text.append(" -> ");
158 FileNode destination = getDestination();
159 if(destination != null) {
160 text.append(destination.getFile().getAbsolutePath());
161 }
162 else {
163 text.append("Recycle Bin");
164 }
165 }
166 return text.toString();
167 }
168}
Note: See TracBrowser for help on using the repository browser.