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

Last change on this file since 8597 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

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