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.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);
114 Thread wthread = new Thread() {
122 // collect all uncached alignments and put them into the vamsas dataset.
124 Cache.log.info("Jalview updating the Vamsas Session.");
126 public void end_session() {
127 // stop any update/watcher thread.
128 watchForChange=false; // this makes any watch(long) loops return.
129 // we should also wait arount for this.WATCH_SLEEP to really make sure the watcher thread has stopped.
131 Thread.sleep(WATCH_SLEEP);
132 } catch (Exception e) {
135 Cache.log.info("Jalview disconnecting from the Vamsas Session.");
137 public void updateJalview(ClientDoc cdoc) {
139 VamsasDatastore vds = new VamsasDatastore(cdoc, vobj2jv, jv2vobj, baseProvEntry());
140 vds.updateToJalview();
142 private void ensureJvVamsas() {
144 jv2vobj = new IdentityHashMap();
145 vobj2jv = new Hashtable();
149 * jalview object binding to VorbaIds
151 IdentityHashMap jv2vobj = null;
152 Hashtable vobj2jv = null;
153 public void updateVamsasDocument(ClientDoc doc) {
155 VamsasDatastore vds = new VamsasDatastore(doc, vobj2jv, jv2vobj, baseProvEntry());
156 // wander through frames
157 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
167 for (int i = frames.length - 1; i > -1; i--)
169 if (frames[i] instanceof AlignFrame)
171 AlignFrame af = (AlignFrame) frames[i];
173 // update alignment and root from frame.
174 vds.storeVAMSAS(af.getViewport(), af.getTitle());
178 catch (Exception e) {
179 Cache.log.error("Vamsas Document store exception",e);
182 private Entry baseProvEntry() {
183 org.vamsas.objects.core.Entry pentry = new org.vamsas.objects.core.Entry();
184 pentry.setUser(this.getProvenanceUser());
185 pentry.setApp(this.getClientHandle().getClientName());
186 pentry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));
187 pentry.setAction("created");
190 protected class VamsasClientWatcher extends Thread implements Runnable {
192 * @see java.lang.Thread#run()
194 VamsasClient client=null;
195 VamsasClientWatcher(VamsasClient client) {
196 this.client = client;
198 boolean running=false;
201 while (client.watchForChange) {
202 ClientDoc docio = client.watch(0);
204 client.disableGui(true);
205 Cache.log.debug("Updating jalview from changed vamsas document.");
206 client.updateJalview(docio);
207 Cache.log.debug("Finished updating from document change.");
210 client.disableGui(false);
218 public void disableGui(boolean b) {
219 Desktop.instance.setVamsasUpdate(b);
221 public void startWatcher() {
223 watcher=new VamsasClientWatcher(this);
224 Thread thr = new Thread() {