ptolemy.domains.space
Class Occupants

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.Sink
                              extended by ptolemy.actor.lib.database.ArrayOfRecordsRecorder
                                  extended by ptolemy.domains.space.Occupants
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class Occupants
extends ArrayOfRecordsRecorder

A Occupants display actor. This actor specializes its superclass for use with a space database. It provides a customized editor that supports modifying the space database in the following ways:

FIXME: When adding or editing a person, method _editPersonQuery, we should use Java code to tolerate more formats for the date, or better yet to bring up a calendar!

Since:
Ptolemy II 8.0
Version:
$Id: Occupants.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (eal)

Nested Class Summary
 class Occupants.OccupantsConfigureFactory
          An interactive editor that configures the occupants.
private  class Occupants.RowListener
          If a row is selected, then record which row is selected.
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private static int _ADD_NEW
          Indicator that a move to a new location should add a new space.
private  java.lang.String[] _classes
          The set of values of the classcd field found in the database.
private  java.util.Set<java.lang.String> _occupantFields
          A set of names of fields that remain with the occupant rather the space.
private  java.util.Set<java.lang.String> _occupantInSpaceFields
          The fields that can be edited for a person in a space.
private static int _REPLACE
          Indicator that a move to a new location should add a new space.
private  int _selectedRow
          The selected row.
private  java.util.Set<java.lang.String> _spaceFields
          A set of names of fields that remain with the space rather the occupant.
private static int _SWAP
          Indicator that a move to a new location should add a new space.
private  javax.swing.JTable _table
          The table.
 StringParameter databaseManager
          Name of the DatabaseManager to use.
 StringParameter table
          Table to use within the database.
 
Fields inherited from class ptolemy.actor.lib.database.ArrayOfRecordsRecorder
colorKey, columns, iconColumns, records
 
Fields inherited from class ptolemy.actor.lib.Sink
input
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
Occupants(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
private  void _addNewShared(DatabaseManager database, java.lang.String sourceSpaceID, RecordToken sourceRecord, RecordToken destinationRecord)
          Add a new occupant to share an existing space by creating a new space.
private  java.lang.String[] _classes(DatabaseManager database)
          Return an array of the names of classes in the database.
private  RecordToken _editPersonQuery(RecordToken person, java.lang.String room, DatabaseManager database, NamedObj object, java.awt.Frame parent)
          Construct a query for assigning an existing person to a space.
private  java.lang.String _getField(RecordToken record, java.lang.String field)
          Given a record and a string, return the entry in the record if there is one and it is a StringToken, and otherwise, return an empty string.
private  boolean _move(DatabaseManager database, java.lang.String sourceSpaceID, java.lang.String destinationSpaceID, int mode)
          Using the specified database, move the contents of sourceSpaceID to the destinationSpaceID, either adding to what is there, overwriting it, or swapping with it.
private  java.lang.String _occupants(ArrayToken records)
          Return the name of the first found occupant in the specified records, or null if there is no such occupant.
private  ArrayToken _priorOccupants(DatabaseManager database, java.lang.String building, java.lang.String room, java.lang.String deskno)
          Return the prior occupants of the specified space.
private  java.lang.String _quotedString(java.lang.String string)
          Return the specified string surrounded by single quotes with any internal single quotes escaped.
private  java.util.Map<java.lang.String,Token> _recordAsMap(RecordToken record)
          Return a map representing the specified record token.
private  RecordToken _searchForPerson(java.lang.String lname, java.lang.String fnames, java.lang.String classcd, java.lang.String email, java.lang.String sponsorlname, java.awt.Frame parent, NamedObj object, DatabaseManager database, RecordToken sponsor, java.lang.String message)
          Open a dialog to search for a person.
 
Methods inherited from class ptolemy.actor.lib.database.ArrayOfRecordsRecorder
clone, fire
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

databaseManager

public StringParameter databaseManager
Name of the DatabaseManager to use. This defaults to "DatabaseManager".


table

public StringParameter table
Table to use within the database. This is a string that defaults to "v_spaces".


_classes

private java.lang.String[] _classes
The set of values of the classcd field found in the database.


_occupantInSpaceFields

private java.util.Set<java.lang.String> _occupantInSpaceFields
The fields that can be edited for a person in a space.


_occupantFields

private java.util.Set<java.lang.String> _occupantFields
A set of names of fields that remain with the occupant rather the space.


_selectedRow

private int _selectedRow
The selected row.


_spaceFields

private java.util.Set<java.lang.String> _spaceFields
A set of names of fields that remain with the space rather the occupant.


_table

private javax.swing.JTable _table
The table.


_ADD_NEW

private static int _ADD_NEW
Indicator that a move to a new location should add a new space.


_REPLACE

private static int _REPLACE
Indicator that a move to a new location should add a new space.


_SWAP

private static int _SWAP
Indicator that a move to a new location should add a new space.

Constructor Detail

Occupants

public Occupants(CompositeEntity container,
                 java.lang.String name)
          throws NameDuplicationException,
                 IllegalActionException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

_addNewShared

private void _addNewShared(DatabaseManager database,
                           java.lang.String sourceSpaceID,
                           RecordToken sourceRecord,
                           RecordToken destinationRecord)
                    throws IllegalActionException
Add a new occupant to share an existing space by creating a new space. This method will optionally clear a specified space as well, which is useful if the sourceRecord is being moved from somewhere.

Parameters:
database - The database manager.
sourceSpaceID - The space to be cleared, or null to not clear it.
sourceRecord - A record containing information about the space to be shared.
destinationRecord - A record containing information about the new occupant.
Throws:
IllegalActionException

_classes

private java.lang.String[] _classes(DatabaseManager database)
                             throws IllegalActionException,
                                    CancelException
Return an array of the names of classes in the database.

Parameters:
database - The database manager.
Returns:
An array of class names found in the database.
Throws:
IllegalActionException - If the table parameter is not valid.
CancelException - If database access is canceled or denied.

_editPersonQuery

private RecordToken _editPersonQuery(RecordToken person,
                                     java.lang.String room,
                                     DatabaseManager database,
                                     NamedObj object,
                                     java.awt.Frame parent)
                              throws CancelException,
                                     IllegalActionException
Construct a query for assigning an existing person to a space.

Parameters:
person - A record with person information.
room - The room to assign the person to.
database - The database manager to use.
object - The Ptolemy II object for which this is an editor.
parent - The owning frame.
Returns:
A record for a person to assign.
Throws:
CancelException
IllegalActionException

_getField

private java.lang.String _getField(RecordToken record,
                                   java.lang.String field)
Given a record and a string, return the entry in the record if there is one and it is a StringToken, and otherwise, return an empty string.

Parameters:
record - The record.
field - The field name.

_move

private boolean _move(DatabaseManager database,
                      java.lang.String sourceSpaceID,
                      java.lang.String destinationSpaceID,
                      int mode)
               throws KernelException
Using the specified database, move the contents of sourceSpaceID to the destinationSpaceID, either adding to what is there, overwriting it, or swapping with it. In the latter two cases, if there is more than one occupant in the destination, this implementation simply works with the first one returned by the database.

Parameters:
database - The database manager.
sourceSpaceID - The spaceid of the source.
destinationSpaceID - The spaceid of the destination.
mode - One of _ADD_NEW, _REPLACE, or _SWAP.
Returns:
False if the user cancels, true otherwise.
Throws:
KernelException - If the table parameter can't be evaluated or if executing the database query throws it, or if re-executing the model throws it.

_occupants

private java.lang.String _occupants(ArrayToken records)
Return the name of the first found occupant in the specified records, or null if there is no such occupant.


_priorOccupants

private ArrayToken _priorOccupants(DatabaseManager database,
                                   java.lang.String building,
                                   java.lang.String room,
                                   java.lang.String deskno)
                            throws IllegalActionException
Return the prior occupants of the specified space.

Parameters:
database - The database manager.
building - The building name.
room - The room number.
deskno - The desk number.
Returns:
An array of RecortToken for prior occupants, which may be empty if there are no prior occupants, or null if the database access is canceled or denied.
Throws:
IllegalActionException

_quotedString

private java.lang.String _quotedString(java.lang.String string)
Return the specified string surrounded by single quotes with any internal single quotes escaped. If the string is empty, return instead the string "NULL".

Parameters:
string - The string to quote.
Returns:
A quoted string.

_recordAsMap

private java.util.Map<java.lang.String,Token> _recordAsMap(RecordToken record)
Return a map representing the specified record token.

Parameters:
record - The record token.
Returns:
A map with the contents of the record.

_searchForPerson

private RecordToken _searchForPerson(java.lang.String lname,
                                     java.lang.String fnames,
                                     java.lang.String classcd,
                                     java.lang.String email,
                                     java.lang.String sponsorlname,
                                     java.awt.Frame parent,
                                     NamedObj object,
                                     DatabaseManager database,
                                     RecordToken sponsor,
                                     java.lang.String message)
                              throws CancelException,
                                     IllegalActionException
Open a dialog to search for a person.

Parameters:
lname - Initial entry for the last name.
fnames - Initial entry for the first names.
classcd - Initial entry for the class.
email - Initial entry for the email.
sponsorlname - Initial entry for the sponsor last name.
parent - The parent frame for dialogs.
object - The Ptolemy object owning the dialog.
database - The database manager.
sponsor - If non-null, then a record specifying a sponsor. When this is non-null, a match is not required. If it is null, and no match is found, the user will be given the option of creating a new person.
message - A text message to include in the dialog, or null to not specify one.
Returns:
A record for a person.
Throws:
CancelException
IllegalActionException