source: trunk/gli/src/org/greenstone/gatherer/msm/MSMEvent.java@ 5990

Last change on this file since 5990 was 5990, checked in by jmt12, 20 years ago

Added a new attribute to these events, an integer describing the user action which caused them, if any

  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 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 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.msm;
38
39/**
40 * Title: The Gatherer<br>
41 * Description: The Gatherer: a tool for gathering and enriching digital collections.<br>
42 * Copyright: Copyright (c) 2001<br>
43 * Company: The University of Waikato<br>
44 * @author John Thompson, Greenstone Digital Libraries
45 * @version 2.1
46 */
47import java.awt.AWTEvent;
48import java.io.*;
49import org.greenstone.gatherer.file.FileNode;
50import org.greenstone.gatherer.msm.ElementWrapper;
51import org.greenstone.gatherer.msm.Metadata;
52import org.greenstone.gatherer.msm.MSMAction;
53import org.greenstone.gatherer.valuetree.GValueModel;
54/** An event object which contains useful information about the event that generated it, which in this case is probably an element update (this means a MSMAction object should be provided). */
55public class MSMEvent
56 extends AWTEvent {
57 /** The element associated with this event. */
58 private ElementWrapper element = null;
59 /** The file associated with this event. */
60 private File file = null;
61 /** The record associated with this event. */
62 private FileNode record = null;
63 /** The value tree model after adding a new value. */
64 private GValueModel new_model = null;
65 /** The value tree model prior to adding a new value. */
66 private GValueModel old_model = null;
67 /** The action initiated by the user which caused this event, if any */
68 private int action = -1;
69 /** A unique id given to any file or metadata task so it can be undone in its entirity. */
70 private long id;
71 /** The new metadata associated with this event. */
72 private Metadata new_metadata = null;
73 /** The old metadata associated with this event. */
74 private Metadata old_metadata = null;
75 /** The profile associated with this event. */
76 private MSMAction profile = null;
77 /** The value associated with this event. */
78 private String value = null;
79 /** The message counter. */
80 static private int count = 0;
81 /** Constructor.
82 * @param source The <strong>Object</strong> that caused this event.
83 * @param id An <i>long</i> identifier.
84 * @param element The <strong>ElementWrapper</strong> affected.
85 */
86 public MSMEvent(Object source, long id, ElementWrapper element, GValueModel old_model, GValueModel new_model) {
87 super(source, 0);
88 this.element = element;
89 this.id = id;
90 this.new_model = new_model;
91 this.old_model = old_model;
92 this.profile = null;
93 this.record = null;
94 }
95 /** Constructor for a metadata change event involving a file. */
96 public MSMEvent(Object source, long id, File file, Metadata old_metadata, Metadata new_metadata) {
97 super(source, 0);
98 this.element = null;
99 this.file = file;
100 this.id = id;
101 this.new_metadata = new_metadata;
102 this.old_metadata = old_metadata;
103 this.profile = null;
104 }
105 /** Constructor for a metadata change event involving a filenode. */
106 public MSMEvent(Object source, long id, FileNode record, Metadata old_metadata, Metadata new_metadata, int action) {
107 super(source, 0);
108 this.action = action;
109 this.element = null;
110 this.id = id;
111 this.new_metadata = new_metadata;
112 this.old_metadata = old_metadata;
113 this.record = record;
114 this.profile = null;
115 }
116 /** Constructor.
117 * @param source The <strong>Object</strong> that caused this event.
118 * @param id An <i>long</i> identifier.
119 * @param profile The <strong>MSMAction</strong> profile if one is applicable.
120 */
121 public MSMEvent(Object source, long id, MSMAction profile) {
122 super(source, 00);
123 this.element = null;
124 this.id = id;
125 this.record = null;
126 this.profile = profile;
127 }
128 /** Constructor for a metadata element changed event.
129 * @param source The <strong>Object</strong> that caused this event.
130 * @param element A reference to the effected metadata <strong>ElementWrapper</strong>, or <i>null</i> if element no longer exists.
131 * @param value The old name of the element (if its name has changed). If <i>null</i> old name defaults to element.toString().
132 */
133 public MSMEvent(Object source, ElementWrapper element, String value) {
134 super(source, count++);
135 this.element = element;
136 this.value = value;
137 }
138
139 /** Retrieve the code of the user action that fired this event.
140 * @return the action as an int
141 */
142 public int getAction() {
143 return action;
144 }
145
146 /** Method to retrieve of the element associated with this event.
147 * @return A <strong>ElementWrapper</strong>, or <i>null</i> if there is none.
148 */
149 public ElementWrapper getElement() {
150 return element;
151 }
152
153 public File getFile() {
154 return file;
155 }
156 /** Method to retrieve the new metadata associated with this event.
157 * @return A <strong>Metadata</strong>, or <i>null</i> if there is none.
158 */
159 public Metadata getNewMetadata() {
160 return new_metadata;
161 }
162 /* private GValueModel getNewModel() {
163 return new_model;
164 } */
165 /** Method to retrieve the old metadata associated with this event.
166 * @return A <strong>Metadata</strong>, or <i>null</i> if there is none.
167 */
168 public Metadata getOldMetadata() {
169 return old_metadata;
170 }
171 /* private GValueModel getOldModel() {
172 return old_model;
173 } */
174 /** Method to retrieve of the profile associated with this event.
175 * @return A <strong>MSMAction</strong> which details the action profile, or <i>null</i> if no profile exists.
176 */
177 /* private MSMAction getProfile() {
178 return profile;
179 } */
180 /** Retrieve the record associated with this event. */
181 public FileNode getRecord() {
182 return record;
183 }
184 /** Retrieve the associated with this event.
185 * @return A <strong>String</strong>.
186 */
187 public String getValue() {
188 String result = null;
189 if(value != null) {
190 result = value;
191 }
192 else if(element != null) {
193 result = element.toString();
194 }
195 return result;
196 }
197 public long ID() {
198 return id;
199 }
200
201 public String toString() {
202 StringBuffer text = new StringBuffer("");
203 if(old_metadata != null) {
204 text.append(old_metadata.toString());
205 }
206 text.append(" => ");
207 if(new_metadata != null) {
208 text.append(new_metadata.toString());
209 }
210 return text.toString();
211 }
212}
Note: See TracBrowser for help on using the repository browser.