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

Last change on this file since 10260 was 10260, checked in by mdewsnip, 19 years ago

Added a "NEW_FOLDER" constant to indicate new folder actions.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 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
62 /** Constructor.
63 * @param id A unique identifier for this job (and others created with a single gesture) as a long.
64 * @param source The DragComponent source of this file, most likely a GTree.
65 * @param orig The FileNode you wish to mode.
66 * @param target The DragComponent to move the file to, again most likely a GTree.
67 * @param dest The files new FileNode parent within the target.
68 * @param type The type of this movement as an int, either COPY or DELETE.
69 */
70 public FileJob(long id, DragComponent source, FileNode orig, DragComponent target, FileNode dest, byte type) {
71 this.id = id;
72 this.source = source;
73 this.target = target;
74 this.type = type;
75 ///ystem.err.println("New Job: " + type + ", " + source + ", " + target);
76 // Dont store FileNodes which can go stale. Store paths instead, which are used to locate current 'fresh' versions of nodes.
77 if(dest != null) {
78 this.destination_path = new TreePath(dest.getPath());
79 ///ystem.err.println("Destination Path: " + destination_path);
80 }
81 if(orig != null) {
82 this.origin_path = new TreePath(orig.getPath());
83 ///atherer.println("Origin Path: " + origin_path);
84 }
85 }
86
87 /** Retrieve the destination node. Watch out for stale versions by always attempting to load the node at destination_path first. */
88 public FileNode getDestination() {
89 FileNode destination = null;
90 if(destination_path != null) {
91 if(target != null) {
92 FileSystemModel model = (FileSystemModel)target.getTreeModel();
93 destination = model.getNode(destination_path);
94 }
95 // If the above fails, a stale copy may be better than nothing.
96 else {
97 destination = (FileNode) destination_path.getLastPathComponent();
98 }
99 }
100 return destination;
101 }
102
103 /** Retrieve the origin node. Watch out for stale versions by always attempting to load the node at origin_path first. */
104 public FileNode getOrigin() {
105 FileNode origin = null;
106 if(origin_path != null) {
107 if(source != null) {
108 FileSystemModel model = (FileSystemModel)source.getTreeModel();
109 origin = model.getNode(origin_path);
110 }
111 // If the above fails, a stale copy may be better than nothing.
112 else {
113 origin = (FileNode) origin_path.getLastPathComponent();
114 }
115 }
116 return origin;
117 }
118
119 /** Retrieve the id for this job. */
120 public long ID() {
121 return id;
122 }
123
124 public String toString() {
125 StringBuffer text = new StringBuffer("");
126 switch(type) {
127 case COPY:
128 text.append("copy ");
129 break;
130 case DELETE:
131 text.append("delete ");
132 break;
133 case MOVE:
134 text.append("move ");
135 break;
136 default:
137 text.append("unknown ");
138 }
139 FileNode origin = getOrigin();
140 if(origin != null) {
141 text.append(origin.getFile().getAbsolutePath());
142 }
143 else {
144 text.append("ERROR!");
145 }
146 text.append(" -> ");
147 FileNode destination = getDestination();
148 if(destination != null) {
149 text.append(destination.getFile().getAbsolutePath());
150 }
151 else {
152 text.append("Recycle Bin");
153 }
154 return text.toString();
155 }
156}
Note: See TracBrowser for help on using the repository browser.