use OOMwarning to warn user when out of Memory occurs
[jalview.git] / src / jalview / io / vamsas / LocalDocSyncObject.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.io.vamsas;
20
21 import uk.ac.vamsas.client.Vobject;
22
23 /**
24  * Implement the basic logic for synchronising changes to or from the Vamsas Document
25  * @author JimP
26  */
27 public abstract class LocalDocSyncObject extends DatastoreItem
28 {
29   /**
30    * 
31    * @return null or the local object that is being worked on. 
32    */
33   public abstract Object getLObject();
34   /**
35    * 
36    * @return null or the document object that is being worked on
37    */
38   public abstract Vobject getVObject();
39   
40   /**
41    * endpoint for synchronize when all opreations are finished.
42    */
43   public abstract void nextObject();
44   /**
45    * called if the local object can be safely updated from the bound document object.
46    */
47   public abstract void updateFromDoc();
48   /**
49    * called if the associated document object can be safely updated with the local changes
50    */
51   public abstract void updateToDoc();
52   /**
53    * @return true if the local object is modified
54    */
55   public abstract boolean locallyModified();
56   /**
57    * 
58    * @return true if the bound document object is modified
59    */
60   public abstract boolean documentModified();
61   /**
62    * 
63    * @return true if the document object is locked  w.r.t. this object's update.
64    */
65   public abstract boolean documentObjectLocked();
66   /**
67    * 
68    * @return a new datastore item instance which binds the local object to a new document object 
69    */
70   public abstract LocalDocSyncObject newDocumentObject(); // could make this constructor(Lobject)
71   /**
72    * 
73    * @return a new datastore item instance which binds the document object to a new local object. 
74    */
75   public abstract LocalDocSyncObject newLocalObject(); // make this constructor(Vobject)
76   /**
77    * apply the update/commit logic as defined in the vamsas paper
78    * @param documentIsUpdated true if a document update event is being handled  
79    */
80   public void synchronize(boolean documentIsUpdated) {
81     Object Lobject = getLObject();
82     Vobject Vobject = getVObject();
83     if (Lobject==null)
84     {
85       // no local binding for document object
86       newLocalObject().synchronize(documentIsUpdated);
87       return;
88     }
89     if (Vobject==null)
90     {
91       // no document binding for local object
92       newDocumentObject().synchronize(documentIsUpdated);
93     }
94     // Check binding is valid
95     if (getjv2vObj(Lobject)!=Vobject)
96     {
97       // no local binding for document object
98       newLocalObject().synchronize(documentIsUpdated);
99       // no document binding for local object
100       newDocumentObject().synchronize(documentIsUpdated);
101     }
102   }
103 }