7 import java.io.OutputStreamWriter;
8 import java.io.PrintWriter;
9 import java.util.Hashtable;
10 import java.util.IdentityHashMap;
11 import java.util.Vector;
12 import java.util.jar.JarOutputStream;
14 import javax.swing.JInternalFrame;
16 import jalview.bin.Cache;
17 import jalview.io.VamsasDatastore;
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.Entry;
24 import org.vamsas.objects.core.VamsasDocument;
25 import org.vamsas.test.simpleclient.ArchiveClient;
26 import org.vamsas.test.simpleclient.ClientDoc;
32 public class VamsasClient
35 // Cache.preferences for vamsas client session arena
36 // preferences for check for default session at startup.
37 // user and organisation stuff.
38 public VamsasClient(Desktop jdesktop,
41 super(System.getProperty("user.name"), System.getProperty("host.name"),
46 public void initial_update()
48 Cache.log.info("Jalview loading the Vamsas Session.");
49 // load in the vamsas archive for the first time
50 ClientDoc cdoc = this.getUpdateable();
52 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
62 for (int i = frames.length - 1; i > -1; i--)
64 if (frames[i] instanceof AlignFrame)
66 AlignFrame af = (AlignFrame) frames[i];
67 af.alignPanel.alignmentChanged();
74 "Exception whilst refreshing jalview windows after a vamsas document update.",
82 * this will close all windows currently in Jalview.
85 protected void closeWindows() {
86 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
95 for (int i = frames.length - 1; i > -1; i--) {
98 } catch (Exception e) {
99 Cache.log.error("Whilst closing windows",e);
104 public void get_update(VamsasArchive doc) {
105 // Close windows - load update.
106 Cache.log.info("Jalview updating from Vamsas Session.");
109 VamsasClientWatcher watcher = null;
110 public void push_update()
112 watchForChange = false;
115 Thread.sleep(WATCH_SLEEP);
122 ClientDoc cdoc = getUpdateable();
123 updateVamsasDocument(cdoc);
127 watchForChange = true;
132 // collect all uncached alignments and put them into the vamsas dataset.
134 Cache.log.info("Jalview updating the Vamsas Session.");
137 public void end_session()
139 // stop any update/watcher thread.
140 watchForChange = false; // this makes any watch(long) loops return.
141 // we should also wait arount for this.WATCH_SLEEP to really make sure the watcher thread has stopped.
144 Thread.sleep(WATCH_SLEEP);
151 Cache.log.info("Jalview disconnecting from the Vamsas Session.");
154 public void updateJalview(ClientDoc cdoc)
157 VamsasDatastore vds = new VamsasDatastore(cdoc, vobj2jv, jv2vobj,
159 vds.updateToJalview();
162 private void ensureJvVamsas()
166 jv2vobj = new IdentityHashMap();
167 vobj2jv = new Hashtable();
172 * jalview object binding to VorbaIds
174 IdentityHashMap jv2vobj = null;
175 Hashtable vobj2jv = null;
176 public void updateVamsasDocument(ClientDoc doc)
179 VamsasDatastore vds = new VamsasDatastore(doc, vobj2jv, jv2vobj,
181 // wander through frames
182 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
192 for (int i = frames.length - 1; i > -1; i--)
194 if (frames[i] instanceof AlignFrame)
196 AlignFrame af = (AlignFrame) frames[i];
198 // update alignment and root from frame.
199 vds.storeVAMSAS(af.getViewport(), af.getTitle());
205 Cache.log.error("Vamsas Document store exception", e);
209 private Entry baseProvEntry()
211 org.vamsas.objects.core.Entry pentry = new org.vamsas.objects.core.Entry();
212 pentry.setUser(this.getProvenanceUser());
213 pentry.setApp(this.getClientHandle().getClientName());
214 pentry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));
215 pentry.setAction("created");
219 protected class VamsasClientWatcher
223 * @see java.lang.Thread#run()
225 VamsasClient client = null;
226 VamsasClientWatcher(VamsasClient client)
228 this.client = client;
231 boolean running = false;
235 while (client.watchForChange)
237 ClientDoc docio = client.watch(0);
240 client.disableGui(true);
241 Cache.log.debug("Updating jalview from changed vamsas document.");
242 client.updateJalview(docio);
243 Cache.log.debug("Finished updating from document change.");
246 client.disableGui(false);
255 public void disableGui(boolean b)
257 Desktop.instance.setVamsasUpdate(b);
260 public void startWatcher()
264 watcher = new VamsasClientWatcher(this);
266 Thread thr = new Thread()