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

Last change on this file since 5581 was 5581, checked in by mdewsnip, 21 years ago

Many formatting, structural and code improvements.

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