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