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

Last change on this file since 6169 was 6169, checked in by jmt12, 20 years ago

Added then removed debug comments only

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