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

Last change on this file since 4366 was 4366, checked in by kjdon, 21 years ago

re-tabbed the code for java

  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1package org.greenstone.gatherer.file;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * Author: John Thompson, Greenstone Digital Library, University of Waikato
10 *
11 * Copyright (C) 1999 New Zealand Digital Library Project
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *########################################################################
27 */
28import javax.swing.tree.*;
29import org.greenstone.gatherer.file.FileNode;
30import org.greenstone.gatherer.file.FileSystemModel;
31import org.greenstone.gatherer.util.DragComponent;
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 /** Constructor.
64 * @param id A unique identifier for this job (and others created with a single gesture) as a long.
65 * @param source The DragComponent source of this file, most likely a GTree.
66 * @param orig The FileNode you wish to mode.
67 * @param target The DragComponent to move the file to, again most likely a GTree.
68 * @param dest The files new FileNode parent within the target.
69 * @param type The type of this movement as an int, either COPY or DELETE.
70 * @param undo true if this job some create an undo job when actioned, false for a redo job.
71 * @param undoable true if this job can generate undo or redo jobs, false otherwise.
72 */
73 public FileJob(long id, DragComponent source, FileNode orig, DragComponent target, FileNode dest, byte type, boolean undo, boolean undoable) {
74 this.id = id;
75 this.source = source;
76 this.target = target;
77 this.type = type;
78 this.undo = undo;
79 this.undoable = undoable;
80 ///ystem.err.println("New Job: " + type + ", " + source + ", " + target);
81 // Dont store FileNodes which can go stale. Store paths instead, which are used to locate current 'fresh' versions of nodes.
82 if(dest != null) {
83 this.destination_path = new TreePath(dest.getPath());
84 ///ystem.err.println("Destination Path: " + destination_path);
85 }
86 if(orig != null) {
87 this.origin_path = new TreePath(orig.getPath());
88 ///ystem.err.println("Origin Path: " + origin_path);
89 }
90 }
91 /** Retrieve the destination node. Watch out for stale versions by always attempting to load the node at destination_path first. */
92 public FileNode getDestination() {
93 FileNode destination = null;
94 if(destination_path != null) {
95 if(target != null) {
96 FileSystemModel model = (FileSystemModel)target.getTreeModel();
97 destination = model.getNode(destination_path);
98 }
99 // If the above fails, a stale copy may be better than nothing.
100 else {
101 destination = (FileNode) destination_path.getLastPathComponent();
102 }
103 }
104 return destination;
105 }
106 /** Retrieve the origin node. Watch out for stale versions by always attempting to load the node at origin_path first. */
107 public FileNode getOrigin() {
108 FileNode origin = null;
109 if(origin_path != null) {
110 if(source != null) {
111 FileSystemModel model = (FileSystemModel)source.getTreeModel();
112 origin = model.getNode(origin_path);
113 }
114 // If the above fails, a stale copy may be better than nothing.
115 else {
116 origin = (FileNode) origin_path.getLastPathComponent();
117 }
118 }
119 return origin;
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 default:
139 text.append("unknown ");
140 }
141 FileNode origin = getOrigin();
142 if(origin != null) {
143 text.append(origin.getFile().getAbsolutePath());
144 }
145 else {
146 text.append("ERROR!");
147 }
148 text.append(" -> ");
149 FileNode destination = getDestination();
150 if(destination != null) {
151 text.append(destination.getFile().getAbsolutePath());
152 }
153 else {
154 text.append("Recycle Bin");
155 }
156 return text.toString();
157 }
158}
Note: See TracBrowser for help on using the repository browser.