// $Id: StructureDocument.java,v 1.14 2007/02/05 04:11:33 Sasha Buzko Exp $ // // Copyright (c) 2000-2002 San Diego Supercomputer Center (SDSC), // a facility operated jointly by the University of California, // San Diego (UCSD) and General Atomics, San Diego, California, USA. // // Users and possessors of this source code are hereby granted a // nonexclusive, royalty-free copyright and design patent license to // use this code in individual software. License is not granted for // commercial resale, in whole or in part, without prior written // permission from SDSC. This source is provided "AS IS" without express // or implied warranty of any kind. // // For further information, please see: http://mbt.sdsc.edu // // History: // $Log: StructureDocument.java,v $ // Revision 1.14 2007/02/05 04:11:33 Sasha Buzko // *** empty log message *** // // Revision 1.13 2007/01/29 02:01:03 Sasha Buzko // *** empty log message *** // // Revision 1.12 2007/01/22 22:36:31 Sasha Buzko // Added tree viewer // // Revision 1.11 2006/12/23 06:18:55 Sasha Buzko // md // // Revision 1.10 2006/10/21 18:41:25 Sasha Buzko // *** empty log message *** // // Revision 1.9 2006/10/21 17:52:16 Sasha Buzko // Refactored the project to move all new code to edu.sdsc.sirius package. // // Revision 1.8 2006/09/12 06:33:34 Sasha Buzko // *** empty log message *** // // Revision 1.7 2006/09/12 04:21:15 Sasha Buzko // *** empty log message *** // // Revision 1.6 2006/08/09 22:38:00 Sasha Buzko // *** empty log message *** // // Revision 1.5 2006/08/03 06:21:22 Sasha Buzko // *** empty log message *** // // Revision 1.4 2006/07/31 05:34:30 Sasha Buzko // Fixed independent structure motion // // Revision 1.3 2006/07/25 04:08:04 Sasha Buzko // *** empty log message *** // // Revision 1.2 2006/05/21 04:31:08 Sasha Buzko // *** empty log message *** // // Revision 1.1 2006/05/20 17:02:02 Sasha Buzko // Updated version // // Revision 1.2 2006/05/17 07:06:17 Sasha Buzko // *** empty log message *** // // Revision 1.1 2006/04/30 20:13:57 Sasha Buzko // New version of the app // // Revision 1.1 2006/04/15 19:42:20 Sasha Buzko // Initial commit // // Revision 1.2 2005/12/25 04:44:45 Administrator // *** empty log message *** // // Revision 1.1 2005/11/13 04:35:11 Administrator // *** empty log message *** // // Revision 1.6 2003/04/23 23:22:11 moreland // Generarally implemented the code that was previously stubbed out. // // Revision 1.5 2002/12/20 22:43:50 moreland // Temporarily disabled generation of viewable objects for new geomtry engine testing. // // Revision 1.4 2002/12/16 06:42:41 moreland // Changed "fire" methods from private to public so that Viewers can // trigger an event to be propagated. This may be undone at some point // because a cleaner mechanism may be created to trigger an event after // batch modifications are applied to a StructureDocument. // // Revision 1.3 2002/11/14 18:47:33 moreland // Corrected "see" document reference. // // Revision 1.2 2002/11/14 18:30:54 moreland // First implementation of the StructureDocument class to encapsulate properties. // // Revision 1.1 2002/10/24 18:06:54 moreland // Added the beginnings of a StructureDocument and Viewable object API. // // Revision 1.1.1.1 2002/07/16 18:00:18 moreland // Imported sources // package edu.sdsc.mbt.viewables; import edu.sdsc.sirius.io.*; import edu.sdsc.sirius.util.Manager; import edu.sdsc.sirius.viewers.*; import edu.sdsc.mbt.*; import java.util.*; /** * This class implements the top-level container document for one or more * Structure objects. *
* @see edu.sdsc.mbt.viewables.StructureDocumentEvent *
* @author John L. Moreland
*/
public class StructureDocument implements java.io.Serializable
{
//
// Private variables.
//
/**
* List of Entry objects currently contained in the StructureDocument
*/
private ArrayList entries = new ArrayList();//for referencing by index
/**
* The repository of Viewers viewing this StructureDocument.
*/
private ArrayList viewers = new ArrayList( );
public Manager parent;
//
// Constructors.
//
/**
* Constructs a StructureDocument object with no initial Structure objects.
*/
public StructureDocument(Manager c )
{
parent = c;
}
//
// Structure management methods.
//
/**
* Add an Entry
to the list of managed/viewed structures,
* then send an event to inform all registered Viewer objects.
* Reference hash is created only for database-loaded entries that have both sequence and structure
* otherwise, it's left as null.
*/
public void addEntry( Entry entry )
throws IllegalArgumentException
{
if ( entry == null )
throw new IllegalArgumentException( "null entry" );
if ( entries.contains( entry ) )
throw new IllegalArgumentException( "entry already added" );
entries.add(entry);
// Fire a StructureDocumentEvent to all Viewer objects.
StructureDocumentEvent sde = new StructureDocumentEvent( );
sde.structureDocument = this;
sde.entry = entry;
sde.viewer = null;
sde.type = StructureDocumentEvent.TYPE_DATA;
sde.change = StructureDocumentEvent.CHANGE_ADDED;
fireStructureDocumentEvent( sde );
}
/**
* Remove an Entry
from this StructureDocument.
*/
public void removeEntry( Entry entry )
throws IllegalArgumentException
{
try{
if ( entry == null )
throw new IllegalArgumentException( "null entry" );
if ( ! entries.contains( entry ) )
throw new IllegalArgumentException( "entry not found" );
entries.remove( entry );
//check whether md dialog needs to be notified of removal of this Entry
if (parent.getDataListerDialog() != null) parent.getDataListerDialog().removeEntry(entry);
// Fire a StructureDocumentEvent to all Viewer objects.
StructureDocumentEvent sde = new StructureDocumentEvent( );
sde.structureDocument = this;
sde.entry = entry;
sde.viewer = null;
sde.type = StructureDocumentEvent.TYPE_DATA;
sde.change = StructureDocumentEvent.CHANGE_REMOVED;
fireStructureDocumentEvent( sde );
sde = null;
if (parent.getWBManager() != null) parent.getWBManager().unregisterEntry(entry);//even if it fails, it won't cause any side effects
}
catch (Exception ex){
parent.displayExceptionMessage("Exception removing " + entry.getName(), ex);
}
parent.getWBManager().unregisterEntry(entry);
entry = null;
}
/**
* Remove an Entry
from this StructureDocument.
*/
public void removeEntry( String entryId )
throws IllegalArgumentException
{
Entry entry = null;
try{
entry = getEntryById(entryId);
if ( entry == null )
throw new IllegalArgumentException( "null entry" );
if ( ! entries.contains( entry ) )
throw new IllegalArgumentException( "entry not found" );
entries.remove( entry );
//check if this entry has a structure, and if so, whether a Ramachandran plot is open
if (entry.TYPE == Entry.STRUCTURE_ENTRY){
parent.removeRamachandranDialog(((StructureEntry)entry).getStructure());
}
// Fire a StructureDocumentEvent to all Viewer objects.
StructureDocumentEvent sde = new StructureDocumentEvent( );
sde.structureDocument = this;
sde.entry = entry;
sde.viewer = null;
sde.type = StructureDocumentEvent.TYPE_DATA;
sde.change = StructureDocumentEvent.CHANGE_REMOVED;
fireStructureDocumentEvent( sde );
}
catch (Exception ex){
parent.displayExceptionMessage("Exception removing entry", ex);
}
}
public void removeEntryByName( String name )
throws IllegalArgumentException
{
Entry entry = null;
try{
for (int i = 0; i < entries.size(); i++){
Entry e = (Entry)entries.get(i);
if (e.getName().equals(name)){
entry = e;
break;
}
}
if ( entry == null )
throw new IllegalArgumentException( "null entry" );
if ( ! entries.contains( entry ) )
throw new IllegalArgumentException( "entry not found" );
entries.remove( entry );
//check if this entry has a structure, and if so, whether a Ramachandran plot is open
if (entry.TYPE == Entry.STRUCTURE_ENTRY || entry.TYPE == Entry.FRAGMENT_ENTRY){
parent.removeRamachandranDialog(((StructureEntry)entry).getStructure());
if (this.parent.getDataListerDialog() != null) parent.getDataListerDialog().removeEntry(entry);
}
// Fire a StructureDocumentEvent to all Viewer objects.
StructureDocumentEvent sde = new StructureDocumentEvent( );
sde.structureDocument = this;
sde.entry = entry;
sde.viewer = null;
sde.type = StructureDocumentEvent.TYPE_DATA;
sde.change = StructureDocumentEvent.CHANGE_REMOVED;
fireStructureDocumentEvent( sde );
}
catch (Exception ex){
parent.displayExceptionMessage("Exception removing entry", ex);
}
}
/**
* Returns count of Entries
currently in the application
* @return
*/
public int getEntryCount( ){
return entries.size( );
}
/**
* This method returns a list of currently loaded entry names and is used by the entry loading
* mechanism to check ahead of time whether a particular entry has been loaded.
*/
public Vector getEntryNames(){
Vector out = new Vector();
for (int i = 0; i < entries.size(); i++){
out.add(((Entry)entries.get(i)).getName());
}
return out;
}
/**
* Returns one of the loaded Entries
by index
* @param index integer index of the Entry
*/
public Entry getEntry (int index){
return (Entry) entries.get(index);
}
/**
* Returns a reference to an Entry by its name.
* @param name Entry name as a String
* @return Entry object reference
*/
public Entry getEntryByName(String name){
for (int i = 0; i < entries.size(); i++){
Entry e = (Entry)entries.get(i);
if (e.getName().equals(name)){
return e;
}
}
return null;//nothing was found
}
/**
* Returns a reference to an Entry by its id.
* @param name Entry id as a String
* @return Entry object reference
*/
public Entry getEntryById(String id){
for (int i = 0; i < entries.size(); i++){
Entry e = (Entry)entries.get(i);
if (e.getId().equals(id)){
return e;
}
}
return null;//nothing was found
}
//
// Viewer management methods.
//
/**
* Add a Viewer to the list of viewers.
*/
public void addViewer( Viewer viewer )
throws IllegalArgumentException
{
if ( viewer == null ){
throw new IllegalArgumentException( "null viewer" );
}
if ( viewers.contains( viewer ) ){
throw new IllegalArgumentException( "viewer " + viewer + " already added" );
}
viewers.add( viewer );
// Fire a StructureDocumentEvent to the new Viewer object.
// It should generate/render a new view of the document.
StructureDocumentEvent sde = new StructureDocumentEvent( );
sde.structureDocument = this;
sde.entry = null;
sde.viewer = viewer;
sde.type = StructureDocumentEvent.TYPE_VIEWER;
sde.change = StructureDocumentEvent.CHANGE_ADDED;
viewer.processStructureDocumentEvent( sde );
}
/**
* Remove a Viewer from the list of viewers.
*/
public void removeViewer( Viewer viewer )
throws IllegalArgumentException
{
if ( viewer == null )
throw new IllegalArgumentException( "null viewer" );
if ( ! viewers.contains( viewer ) )
throw new IllegalArgumentException( "viewer not found" );
viewers.remove( viewer );
if (viewer instanceof RamachandranViewer){
parent.removeRamachandranDialog(viewer);
}
// Fire a StructureDocumentEvent to the new Viewer object.
// It should clean up/remove its view of the document.
StructureDocumentEvent sde = new StructureDocumentEvent( );
sde.structureDocument = this;
sde.entry = null;
sde.viewer = viewer;
sde.type = StructureDocumentEvent.TYPE_VIEWER;
sde.change = StructureDocumentEvent.CHANGE_REMOVED;
viewer.processStructureDocumentEvent( sde );
sde = null;
}
//
// Outgoing Event methods.
//
/**
* A StructureDocumentEvent needs to be propagated to all Viewer objects.
*/
private void fireStructureDocumentEvent( StructureDocumentEvent structureDocumentEvent )
{
for ( int i=0; i