[4293] | 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 | */
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | package org.greenstone.gatherer.msm;
|
---|
| 44 | /**
|
---|
| 45 | * Title: The Gatherer<br>
|
---|
| 46 | * Description: The Gatherer: a tool for gathering and enriching digital collections.<br>
|
---|
| 47 | * Copyright: Copyright (c) 2001<br>
|
---|
| 48 | * Company: The University of Waikato<br>
|
---|
| 49 | * @author John Thompson, Greenstone Digital Libraries
|
---|
| 50 | * @version 2.1
|
---|
| 51 | */
|
---|
| 52 | import java.awt.AWTEvent;
|
---|
| 53 | import java.io.*;
|
---|
| 54 | import org.greenstone.gatherer.file.FileNode;
|
---|
| 55 | import org.greenstone.gatherer.msm.ElementWrapper;
|
---|
| 56 | import org.greenstone.gatherer.msm.Metadata;
|
---|
| 57 | import org.greenstone.gatherer.msm.MSMAction;
|
---|
| 58 | import org.greenstone.gatherer.valuetree.GValueModel;
|
---|
| 59 | /** 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). */
|
---|
| 60 | public class MSMEvent
|
---|
[4365] | 61 | extends AWTEvent {
|
---|
| 62 | /** The element associated with this event. */
|
---|
| 63 | private ElementWrapper element = null;
|
---|
| 64 | /** The file associated with this event. */
|
---|
| 65 | private File file = null;
|
---|
| 66 | /** The record associated with this event. */
|
---|
| 67 | private FileNode record = null;
|
---|
| 68 | /** The value tree model after adding a new value. */
|
---|
| 69 | private GValueModel new_model = null;
|
---|
| 70 | /** The value tree model prior to adding a new value. */
|
---|
| 71 | private GValueModel old_model = null;
|
---|
| 72 | /** A unique id given to any file or metadata task so it can be undone in its entirity. */
|
---|
| 73 | private long id;
|
---|
| 74 | /** The new metadata associated with this event. */
|
---|
| 75 | private Metadata new_metadata = null;
|
---|
| 76 | /** The old metadata associated with this event. */
|
---|
| 77 | private Metadata old_metadata = null;
|
---|
| 78 | /** The profile associated with this event. */
|
---|
| 79 | private MSMAction profile = null;
|
---|
| 80 | /** The value associated with this event. */
|
---|
| 81 | private String value = null;
|
---|
| 82 | /** The message counter. */
|
---|
| 83 | static private int count = 0;
|
---|
| 84 | /** Constructor.
|
---|
| 85 | * @param source The <strong>Object</strong> that caused this event.
|
---|
| 86 | * @param id An <i>long</i> identifier.
|
---|
| 87 | * @param element The <strong>ElementWrapper</strong> affected.
|
---|
[4293] | 88 | */
|
---|
[4365] | 89 | public MSMEvent(Object source, long id, ElementWrapper element, GValueModel old_model, GValueModel new_model) {
|
---|
| 90 | super(source, 0);
|
---|
| 91 | this.element = element;
|
---|
| 92 | this.id = id;
|
---|
| 93 | this.new_model = new_model;
|
---|
| 94 | this.old_model = old_model;
|
---|
| 95 | this.profile = null;
|
---|
| 96 | this.record = null;
|
---|
| 97 | }
|
---|
| 98 | /** Constructor for a metadata change event involving a file. */
|
---|
| 99 | public MSMEvent(Object source, long id, File file, Metadata old_metadata, Metadata new_metadata) {
|
---|
| 100 | super(source, 0);
|
---|
| 101 | this.element = null;
|
---|
| 102 | this.file = file;
|
---|
| 103 | this.id = id;
|
---|
| 104 | this.new_metadata = new_metadata;
|
---|
| 105 | this.old_metadata = old_metadata;
|
---|
| 106 | this.profile = null;
|
---|
| 107 | }
|
---|
| 108 | /** Constructor for a metadata change event involving a filenode. */
|
---|
| 109 | public MSMEvent(Object source, long id, FileNode record, Metadata old_metadata, Metadata new_metadata) {
|
---|
| 110 | super(source, 0);
|
---|
| 111 | this.element = null;
|
---|
| 112 | this.id = id;
|
---|
| 113 | this.new_metadata = new_metadata;
|
---|
| 114 | this.old_metadata = old_metadata;
|
---|
| 115 | this.record = record;
|
---|
| 116 | this.profile = null;
|
---|
| 117 | }
|
---|
| 118 | /** Constructor.
|
---|
[4293] | 119 | * @param source The <strong>Object</strong> that caused this event.
|
---|
| 120 | * @param id An <i>long</i> identifier.
|
---|
| 121 | * @param profile The <strong>MSMAction</strong> profile if one is applicable.
|
---|
| 122 | */
|
---|
[4365] | 123 | public MSMEvent(Object source, long id, MSMAction profile) {
|
---|
| 124 | super(source, 00);
|
---|
| 125 | this.element = null;
|
---|
| 126 | this.id = id;
|
---|
| 127 | this.record = null;
|
---|
| 128 | this.profile = profile;
|
---|
| 129 | }
|
---|
| 130 | /** Constructor for a metadata element changed event.
|
---|
[4293] | 131 | * @param source The <strong>Object</strong> that caused this event.
|
---|
| 132 | * @param element A reference to the effected metadata <strong>ElementWrapper</strong>, or <i>null</i> if element no longer exists.
|
---|
| 133 | * @param value The old name of the element (if its name has changed). If <i>null</i> old name defaults to element.toString().
|
---|
| 134 | */
|
---|
[4365] | 135 | public MSMEvent(Object source, ElementWrapper element, String value) {
|
---|
| 136 | super(source, count++);
|
---|
| 137 | this.element = element;
|
---|
| 138 | this.value = value;
|
---|
| 139 | }
|
---|
| 140 | /** Method to retrieve of the element associated with this event.
|
---|
[4293] | 141 | * @return A <strong>ElementWrapper</strong>, or <i>null</i> if there is none.
|
---|
| 142 | */
|
---|
[4365] | 143 | public ElementWrapper getElement() {
|
---|
| 144 | return element;
|
---|
| 145 | }
|
---|
[4293] | 146 |
|
---|
[4365] | 147 | public File getFile() {
|
---|
| 148 | return file;
|
---|
| 149 | }
|
---|
| 150 | /** Method to retrieve the new metadata associated with this event.
|
---|
[4293] | 151 | * @return A <strong>Metadata</strong>, or <i>null</i> if there is none.
|
---|
| 152 | */
|
---|
[4365] | 153 | public Metadata getNewMetadata() {
|
---|
| 154 | return new_metadata;
|
---|
| 155 | }
|
---|
| 156 | public GValueModel getNewModel() {
|
---|
| 157 | return new_model;
|
---|
| 158 | }
|
---|
| 159 | /** Method to retrieve the old metadata associated with this event.
|
---|
[4293] | 160 | * @return A <strong>Metadata</strong>, or <i>null</i> if there is none.
|
---|
| 161 | */
|
---|
[4365] | 162 | public Metadata getOldMetadata() {
|
---|
| 163 | return old_metadata;
|
---|
| 164 | }
|
---|
| 165 | public GValueModel getOldModel() {
|
---|
| 166 | return old_model;
|
---|
| 167 | }
|
---|
| 168 | /** Method to retrieve of the profile associated with this event.
|
---|
[4293] | 169 | * @return A <strong>MSMAction</strong> which details the action profile, or <i>null</i> if no profile exists.
|
---|
| 170 | */
|
---|
[4365] | 171 | public MSMAction getProfile() {
|
---|
| 172 | return profile;
|
---|
| 173 | }
|
---|
| 174 | /** Retrieve the record associated with this event. */
|
---|
| 175 | public FileNode getRecord() {
|
---|
| 176 | return record;
|
---|
| 177 | }
|
---|
| 178 | /** Retrieve the associated with this event.
|
---|
[4293] | 179 | * @return A <strong>String</strong>.
|
---|
| 180 | */
|
---|
[4365] | 181 | public String getValue() {
|
---|
| 182 | String result = null;
|
---|
| 183 | if(value != null) {
|
---|
| 184 | result = value;
|
---|
| 185 | }
|
---|
| 186 | else if(element != null) {
|
---|
| 187 | result = element.toString();
|
---|
| 188 | }
|
---|
| 189 | return result;
|
---|
| 190 | }
|
---|
| 191 | public long ID() {
|
---|
| 192 | return id;
|
---|
| 193 | }
|
---|
[4361] | 194 |
|
---|
[4365] | 195 | public String toString() {
|
---|
| 196 | StringBuffer text = new StringBuffer("");
|
---|
| 197 | if(old_metadata != null) {
|
---|
| 198 | text.append(old_metadata.toString());
|
---|
| 199 | }
|
---|
| 200 | text.append(" => ");
|
---|
| 201 | if(new_metadata != null) {
|
---|
| 202 | text.append(new_metadata.toString());
|
---|
| 203 | }
|
---|
| 204 | return text.toString();
|
---|
| 205 | }
|
---|
[4293] | 206 | }
|
---|