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;
15 import javax.swing.JInternalFrame;
17 import jalview.bin.Cache;
18 import jalview.io.VamsasDatastore;
20 import org.vamsas.client.UserHandle;
21 import org.vamsas.client.simpleclient.FileWatcher;
22 import org.vamsas.client.simpleclient.VamsasArchive;
23 import org.vamsas.client.simpleclient.VamsasFile;
24 import org.vamsas.objects.core.Entry;
25 import org.vamsas.objects.core.VamsasDocument;
26 import org.vamsas.test.simpleclient.ArchiveClient;
27 import org.vamsas.test.simpleclient.ClientDoc;
33 public class VamsasClient extends ArchiveClient {
34 // Cache.preferences for vamsas client session arena
35 // preferences for check for default session at startup.
36 // user and organisation stuff.
37 public VamsasClient(Desktop jdesktop,
39 super(System.getProperty("user.name"),System.getProperty("host.name"), "jalview","2.7",
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();
47 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
57 for (int i = frames.length - 1; i > -1; i--)
59 if (frames[i] instanceof AlignFrame)
61 AlignFrame af = (AlignFrame) frames[i];
62 af.alignPanel.alignmentChanged();
65 } catch (Exception e) {
66 Cache.log.warn("Exception whilst refreshing jalview windows after a vamsas document update.", e);
72 * this will close all windows currently in Jalview.
75 protected void closeWindows() {
76 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
85 for (int i = frames.length - 1; i > -1; i--) {
88 } catch (Exception e) {
89 Cache.log.error("Whilst closing windows",e);
94 public void get_update(VamsasArchive doc) {
95 // Close windows - load update.
96 Cache.log.info("Jalview updating from Vamsas Session.");
99 VamsasClientWatcher watcher=null;
100 public void push_update() {
101 watchForChange=false;
103 Thread.sleep(WATCH_SLEEP);
104 } catch (Exception e) {
107 ClientDoc cdoc = getUpdateable();
108 updateVamsasDocument(cdoc);
116 // collect all uncached alignments and put them into the vamsas dataset.
118 Cache.log.info("Jalview updating the Vamsas Session.");
120 public void end_session() {
121 // stop any update/watcher thread.
122 watchForChange=false; // this makes any watch(long) loops return.
123 // we should also wait arount for this.WATCH_SLEEP to really make sure the watcher thread has stopped.
125 Thread.sleep(WATCH_SLEEP);
126 } catch (Exception e) {
129 Cache.log.info("Jalview disconnecting from the Vamsas Session.");
131 public void updateJalview(ClientDoc cdoc) {
133 VamsasDatastore vds = new VamsasDatastore(cdoc, vobj2jv, jv2vobj, baseProvEntry());
134 vds.updateToJalview();
136 private void ensureJvVamsas() {
138 jv2vobj = new IdentityHashMap();
139 vobj2jv = new Hashtable();
143 * jalview object binding to VorbaIds
145 IdentityHashMap jv2vobj = null;
146 Hashtable vobj2jv = null;
147 public void updateVamsasDocument(ClientDoc doc) {
149 VamsasDatastore vds = new VamsasDatastore(doc, vobj2jv, jv2vobj, baseProvEntry());
150 // wander through frames
151 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
161 for (int i = frames.length - 1; i > -1; i--)
163 if (frames[i] instanceof AlignFrame)
165 AlignFrame af = (AlignFrame) frames[i];
167 // update alignment and root from frame.
168 vds.storeVAMSAS(af.getViewport(), af.getTitle());
172 catch (Exception e) {
173 Cache.log.error("Vamsas Document store exception",e);
176 private Entry baseProvEntry() {
177 org.vamsas.objects.core.Entry pentry = new org.vamsas.objects.core.Entry();
178 pentry.setUser(this.getProvenanceUser());
179 pentry.setApp(this.getClientHandle().getClientName());
180 pentry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));
181 pentry.setAction("created");
184 protected class VamsasClientWatcher extends Thread {
186 * @see java.lang.Thread#run()
188 VamsasClient client=null;
189 VamsasClientWatcher(VamsasClient client) {
190 this.client = client;
192 boolean running=false;
195 while (client.watchForChange) {
196 ClientDoc docio = client.watch(0);
198 client.disableGui(true);
199 Cache.log.debug("Updating jalview from changed vamsas document.");
200 client.updateJalview(docio);
201 Cache.log.debug("Finished updating from document change.");
204 client.disableGui(false);
212 public void disableGui(boolean b) {
213 Desktop.instance.setVamsasUpdate(b);
215 public void startWatcher() {
217 watcher=new VamsasClientWatcher(this);
218 Thread thr = new Thread() {