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

Last change on this file since 11082 was 11081, checked in by mdewsnip, 18 years ago

Added new DELETE_EMPTY_DIRECTORY job type, as part of the FileQueue rewrite.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 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 public boolean folder_level = false;
41 /** The type of this movement as an byte. */
42 public byte type = 0;
43 /** The DragComponent source of this file, most likely a GTree. */
44 public DragComponent source = null;
45 /** The DragComponent to move the file to, again most likely a GTree. */
46 public DragComponent target = null;
47 /** The unique identifier shared by all jobs created by the same action. */
48 private long id = 0;
49 /** The path to the destination node as a string. Used because any reference based path or variables quickly becomes obsolete. */
50 private TreePath destination_path = null;
51 /** The path to the origin node as a string. Used because any reference based path or variables quickly becomes obsolete. */
52 private TreePath origin_path = null;
53 /** An element of the job type enumeration indicating a copy action. */
54 static final public byte COPY = 1;
55 /** An element of the job type enumeration indicating a delete action. */
56 static final public byte DELETE = 2;
57 /** An element of the job type enumeration indicating a move action. */
58 static final public byte MOVE = 3;
59 /** An element of the job type enumeration indicating a new folder action. */
60 static final public byte NEW_FOLDER = 4;
61 /** An element of the job type enumeration indicating an empty folder delete action. */
62 static final public byte DELETE_EMPTY_DIRECTORY = 5;
63
64 /** Constructor.
65 * @param id A unique identifier for this job (and others created with a single gesture) as a long.
66 * @param source The DragComponent source of this file, most likely a GTree.
67 * @param orig The FileNode you wish to mode.
68 * @param target The DragComponent to move the file to, again most likely a GTree.
69 * @param dest The files new FileNode parent within the target.
70 * @param type The type of this movement as an int, either COPY or DELETE.
71 */
72 public FileJob(long id, DragComponent source, FileNode orig, DragComponent target, FileNode dest, byte type) {
73 this.id = id;
74 this.source = source;
75 this.target = target;
76 this.type = type;
77 ///ystem.err.println("New Job: " + type + ", " + source + ", " + target);
78 // Dont store FileNodes which can go stale. Store paths instead, which are used to locate current 'fresh' versions of nodes.
79 if(dest != null) {
80 this.destination_path = new TreePath(dest.getPath());
81 ///ystem.err.println("Destination Path: " + destination_path);
82 }
83 if(orig != null) {
84 this.origin_path = new TreePath(orig.getPath());
85 ///atherer.println("Origin Path: " + origin_path);
86 }
87 }
88
89 /** Retrieve the destination node. Watch out for stale versions by always attempting to load the node at destination_path first. */
90 public FileNode getDestination() {
91 FileNode destination = null;
92 if(destination_path != null) {
93 if(target != null) {
94 FileSystemModel model = (FileSystemModel)target.getTreeModel();
95 destination = model.getNode(destination_path);
96 }
97 // If the above fails, a stale copy may be better than nothing.
98 else {
99 destination = (FileNode) destination_path.getLastPathComponent();
100 }
101 }
102 return destination;
103 }
104
105 /** Retrieve the origin node. Watch out for stale versions by always attempting to load the node at origin_path first. */
106 public FileNode getOrigin() {
107 FileNode origin = null;
108 if(origin_path != null) {
109 if(source != null) {
110 FileSystemModel model = (FileSystemModel)source.getTreeModel();
111 origin = model.getNode(origin_path);
112 }
113 // If the above fails, a stale copy may be better than nothing.
114 else {
115 origin = (FileNode) origin_path.getLastPathComponent();
116 }
117 }
118 return origin;
119 }
120
121 /** Retrieve the id for this job. */
122 public long ID() {
123 return id;
124 }
125
126 public String toString() {
127 StringBuffer text = new StringBuffer("");
128 switch(type) {
129 case COPY:
130 text.append("copy ");
131 break;
132 case DELETE:
133 text.append("delete ");
134 break;
135 case MOVE:
136 text.append("move ");
137 break;
138 case DELETE_EMPTY_DIRECTORY:
139 text.append("empty directory delete ");
140 break;
141 default:
142 text.append("unknown ");
143 }
144 FileNode origin = getOrigin();
145 if(origin != null) {
146 text.append(origin.getFile().getAbsolutePath());
147 }
148 else {
149 text.append("ERROR!");
150 }
151 if (type != DELETE && type != DELETE_EMPTY_DIRECTORY) {
152 text.append(" -> ");
153 FileNode destination = getDestination();
154 if(destination != null) {
155 text.append(destination.getFile().getAbsolutePath());
156 }
157 else {
158 text.append("Recycle Bin");
159 }
160 }
161 return text.toString();
162 }
163}
Note: See TracBrowser for help on using the repository browser.