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

Last change on this file since 11242 was 11242, checked in by mdewsnip, 18 years ago

Added the back-end code for supporting file/folder renames in the collection tree (Gather pane). Renaming is done almost exactly the same as moving.

  • 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 /** The type of this movement as an byte. */
41 public byte type = 0;
42 /** The DragComponent source of this file, most likely a GTree. */
43 public DragComponent source = null;
44 /** The DragComponent to move the file to, again most likely a GTree. */
45 public DragComponent target = null;
46 /** The unique identifier shared by all jobs created by the same action. */
47 private long id = 0;
48 /** The path to the destination node as a string. Used because any reference based path or variables quickly becomes obsolete. */
49 private TreePath destination_path = null;
50 /** The path to the origin node as a string. Used because any reference based path or variables quickly becomes obsolete. */
51 private TreePath origin_path = null;
52 /** An element of the job type enumeration indicating a copy action. */
53 static final public byte COPY = 1;
54 /** An element of the job type enumeration indicating a delete action. */
55 static final public byte DELETE = 2;
56 /** An element of the job type enumeration indicating a move action. */
57 static final public byte MOVE = 3;
58 /** An element of the job type enumeration indicating a new folder action. */
59 static final public byte NEW_FOLDER = 4;
60 /** An element of the job type enumeration indicating an empty folder delete action. */
61 static final public byte DELETE_EMPTY_DIRECTORY = 5;
62 /** An element of the job type enumeration indicating a rename action. */
63 static final public byte RENAME = 6;
64
65 /** Constructor.
66 * @param id A unique identifier for this job (and others created with a single gesture) as a long.
67 * @param source The DragComponent source of this file, most likely a GTree.
68 * @param orig The FileNode you wish to mode.
69 * @param target The DragComponent to move the file to, again most likely a GTree.
70 * @param dest The files new FileNode parent within the target.
71 * @param type The type of this movement as an int, either COPY or DELETE.
72 */
73 public FileJob(long id, DragComponent source, FileNode orig, DragComponent target, FileNode dest, byte type) {
74 this.id = id;
75 this.source = source;
76 this.target = target;
77 this.type = type;
78 ///ystem.err.println("New Job: " + type + ", " + source + ", " + target);
79 // Dont store FileNodes which can go stale. Store paths instead, which are used to locate current 'fresh' versions of nodes.
80 if(dest != null) {
81 this.destination_path = new TreePath(dest.getPath());
82 ///ystem.err.println("Destination Path: " + destination_path);
83 }
84 if(orig != null) {
85 this.origin_path = new TreePath(orig.getPath());
86 ///atherer.println("Origin Path: " + origin_path);
87 }
88 }
89
90 /** Retrieve the destination node. Watch out for stale versions by always attempting to load the node at destination_path first. */
91 public FileNode getDestination() {
92 FileNode destination = null;
93 if(destination_path != null) {
94 if(target != null) {
95 FileSystemModel model = (FileSystemModel)target.getTreeModel();
96 destination = model.getNode(destination_path);
97 }
98 // If the above fails, a stale copy may be better than nothing.
99 else {
100 destination = (FileNode) destination_path.getLastPathComponent();
101 }
102 }
103 return destination;
104 }
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
122 /** Retrieve the id for this job. */
123 public long ID() {
124 return id;
125 }
126
127 public String toString() {
128 StringBuffer text = new StringBuffer("");
129 switch(type) {
130 case COPY:
131 text.append("copy ");
132 break;
133 case DELETE:
134 text.append("delete ");
135 break;
136 case MOVE:
137 text.append("move ");
138 break;
139 case DELETE_EMPTY_DIRECTORY:
140 text.append("empty directory delete ");
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 if (type != DELETE && type != DELETE_EMPTY_DIRECTORY) {
153 text.append(" -> ");
154 FileNode destination = getDestination();
155 if(destination != null) {
156 text.append(destination.getFile().getAbsolutePath());
157 }
158 else {
159 text.append("Recycle Bin");
160 }
161 }
162 return text.toString();
163 }
164}
Note: See TracBrowser for help on using the repository browser.