part finished (still finishing the updateJalview method of VamsasDatastore)
[jalview.git] / src / jalview / gui / VamsasClient.java
1 /**
2  * 
3  */
4 package jalview.gui;
5
6 import java.io.File;
7 import java.io.FileOutputStream;
8 import java.io.OutputStreamWriter;
9 import java.io.PrintWriter;
10 import java.util.Hashtable;
11 import java.util.IdentityHashMap;
12 import java.util.Vector;
13 import java.util.jar.JarOutputStream;
14
15 import javax.swing.JInternalFrame;
16
17 import jalview.bin.Cache;
18
19 import org.vamsas.client.UserHandle;
20 import org.vamsas.client.simpleclient.FileWatcher;
21 import org.vamsas.client.simpleclient.VamsasArchive;
22 import org.vamsas.client.simpleclient.VamsasFile;
23 import org.vamsas.objects.core.VamsasDocument;
24 import org.vamsas.test.simpleclient.ArchiveClient;
25 import org.vamsas.test.simpleclient.ClientDoc;
26
27 /**
28  * @author jimp
29  *
30  */
31 public class VamsasClient extends ArchiveClient {
32         Desktop us;
33         // Cache.preferences for vamsas client session arena
34         // preferences for check for default session at startup.
35         // user and organisation stuff.
36         public VamsasClient(Desktop jdesktop,
37                         File sessionPath) {
38                 super(System.getProperty("user.name"),System.getProperty("host.name"), "jalview","2.7",
39                                 sessionPath);
40                 us=jdesktop;
41         }
42         public void initial_update() {
43                 Cache.log.info("Jalview loading the Vamsas Session.");
44                 // load in the vamsas archive for the first time
45                 ClientDoc cdoc = this.getUpdateable();
46                 updateJalview(cdoc);
47                 
48         }
49         /**
50          * this will close all windows currently in Jalview.
51          *
52          */
53         protected void closeWindows() {
54                 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
55
56         if (frames == null)
57         {
58             return;
59         }
60
61         try
62         {       
63             for (int i = frames.length - 1; i > -1; i--) {
64                 frames[i].dispose();    
65             }
66         } catch (Exception e) {
67                 Cache.log.error("Whilst closing windows",e);
68         }
69                 
70         }
71         public void get_update(VamsasArchive doc) {
72                 // Close windows - load update.
73                 Cache.log.info("Jalview updating from Vamsas Session.");
74         }
75         public void push_update() {
76                 // collect all uncached alignments and put them into the vamsas dataset.
77                 // store them.
78                 Cache.log.info("Jalview updating the Vamsas Session.");
79         }
80         public void end_session() {
81                 // stop any update/watcher thread.
82                 Cache.log.info("Jalview disconnecting from the Vamsas Session.");
83         }
84         public void updateJalview(ClientDoc cdoc) {
85                 
86         }
87         protected void _updateAlignFrame(ClientDoc cdoc, AlignFrame av) {
88                 
89         }
90         /**
91          * jalview object binding to VorbaIds
92          */
93         IdentityHashMap jv2vobj = null;
94         Hashtable vobj2jv = null;
95         public void updateVamsasDocument(ClientDoc doc) {
96                 if (jv2vobj==null) {
97                         jv2vobj = new IdentityHashMap();
98                         vobj2jv = new Hashtable();
99                 }
100                 // wander through frames 
101                 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
102
103         if (frames == null)
104         {
105             return;
106         }
107
108         try
109         {       
110                 // Mapping
111                 // Alignframe.alignment (non-null dataset)==alignment
112                 // alignframe .alignment (dataset==null) = VAMAS[]
113                 // Tree.alignment = vamsas[].tree (vamsas[] given by dataset, alignment given by local ref]
114                 
115                 Vector shortNames = new Vector();
116                 
117                 //REVERSE ORDER
118             for (int i = frames.length - 1; i > -1; i--)
119             {
120                 if (frames[i] instanceof AlignFrame)
121                 {
122                         AlignFrame af = (AlignFrame) frames[i];
123                         
124                         // check if this frame has an associated alignment object ?
125                         
126                         // update alignment and root from frame.
127
128                 }
129             }
130         }
131         catch (Exception e) {
132                 Cache.log.error("Vamsas Document store exception",e);
133         }
134         }
135         protected class VamsasClientWatcher extends Thread implements Runnable {
136                 /* (non-Javadoc)
137                  * @see java.lang.Thread#run()
138                  */
139                 VamsasClient client=null;
140                 VamsasClientWatcher(VamsasClient client) {
141                         this.client = client;
142                 }
143                 public void run() {
144                         ClientDoc docio = client.watch(0);
145                         
146                 }
147                 
148         }
149         /**
150          * @param args
151          */
152         public static void main(String[] args) {
153                 // TODO Auto-generated method stub
154
155         }
156
157 }