/**
*#########################################################################
*
* A component of the Gatherer application, part of the Greenstone digital
* library suite from the New Zealand Digital Library Project at the
* University of Waikato, New Zealand.
*
*
*
* Author: John Thompson, Greenstone Digital Library, University of Waikato
*
*
*
* Copyright (C) 1999 New Zealand Digital Library Project
*
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*########################################################################
*/
package org.greenstone.gatherer.msm;
/**
* Title: The Gatherer
* Description: The Gatherer: a tool for gathering and enriching digital collections.
* Copyright: Copyright (c) 2001
* Company: The University of Waikato
* @author John Thompson, Greenstone Digital Libraries
* @version 2.1
*/
import java.awt.AWTEvent;
import java.io.*;
import org.greenstone.gatherer.file.FileNode;
import org.greenstone.gatherer.msm.ElementWrapper;
import org.greenstone.gatherer.msm.Metadata;
import org.greenstone.gatherer.msm.MSMAction;
import org.greenstone.gatherer.valuetree.GValueModel;
/** 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). */
public class MSMEvent
extends AWTEvent {
/** The element associated with this event. */
private ElementWrapper element = null;
/** The file associated with this event. */
private File file = null;
/** The record associated with this event. */
private FileNode record = null;
/** The value tree model after adding a new value. */
private GValueModel new_model = null;
/** The value tree model prior to adding a new value. */
private GValueModel old_model = null;
/** A unique id given to any file or metadata task so it can be undone in its entirity. */
private long id;
/** The new metadata associated with this event. */
private Metadata new_metadata = null;
/** The old metadata associated with this event. */
private Metadata old_metadata = null;
/** The profile associated with this event. */
private MSMAction profile = null;
/** The value associated with this event. */
private String value = null;
/** The message counter. */
static private int count = 0;
/** Constructor.
* @param source The Object that caused this event.
* @param id An long identifier.
* @param element The ElementWrapper affected.
*/
public MSMEvent(Object source, long id, ElementWrapper element, GValueModel old_model, GValueModel new_model) {
super(source, 0);
this.element = element;
this.id = id;
this.new_model = new_model;
this.old_model = old_model;
this.profile = null;
this.record = null;
}
/** Constructor for a metadata change event involving a file. */
public MSMEvent(Object source, long id, File file, Metadata old_metadata, Metadata new_metadata) {
super(source, 0);
this.element = null;
this.file = file;
this.id = id;
this.new_metadata = new_metadata;
this.old_metadata = old_metadata;
this.profile = null;
}
/** Constructor for a metadata change event involving a filenode. */
public MSMEvent(Object source, long id, FileNode record, Metadata old_metadata, Metadata new_metadata) {
super(source, 0);
this.element = null;
this.id = id;
this.new_metadata = new_metadata;
this.old_metadata = old_metadata;
this.record = record;
this.profile = null;
}
/** Constructor.
* @param source The Object that caused this event.
* @param id An long identifier.
* @param profile The MSMAction profile if one is applicable.
*/
public MSMEvent(Object source, long id, MSMAction profile) {
super(source, 00);
this.element = null;
this.id = id;
this.record = null;
this.profile = profile;
}
/** Constructor for a metadata element changed event.
* @param source The Object that caused this event.
* @param element A reference to the effected metadata ElementWrapper, or null if element no longer exists.
* @param value The old name of the element (if its name has changed). If null old name defaults to element.toString().
*/
public MSMEvent(Object source, ElementWrapper element, String value) {
super(source, count++);
this.element = element;
this.value = value;
}
/** Method to retrieve of the element associated with this event.
* @return A ElementWrapper, or null if there is none.
*/
public ElementWrapper getElement() {
return element;
}
public File getFile() {
return file;
}
/** Method to retrieve the new metadata associated with this event.
* @return A Metadata, or null if there is none.
*/
public Metadata getNewMetadata() {
return new_metadata;
}
public GValueModel getNewModel() {
return new_model;
}
/** Method to retrieve the old metadata associated with this event.
* @return A Metadata, or null if there is none.
*/
public Metadata getOldMetadata() {
return old_metadata;
}
public GValueModel getOldModel() {
return old_model;
}
/** Method to retrieve of the profile associated with this event.
* @return A MSMAction which details the action profile, or null if no profile exists.
*/
public MSMAction getProfile() {
return profile;
}
/** Retrieve the record associated with this event. */
public FileNode getRecord() {
return record;
}
/** Retrieve the associated with this event.
* @return A String.
*/
public String getValue() {
String result = null;
if(value != null) {
result = value;
}
else if(element != null) {
result = element.toString();
}
return result;
}
public long ID() {
return id;
}
public String toString() {
StringBuffer text = new StringBuffer("");
if(old_metadata != null) {
text.append(old_metadata.toString());
}
text.append(" => ");
if(new_metadata != null) {
text.append(new_metadata.toString());
}
return text.toString();
}
}