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 extends ArchiveClient {
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,
38 super(System.getProperty("user.name"),System.getProperty("host.name"), "jalview","2.7",
41 public void initial_update() {
42 Cache.log.info("Jalview loading the Vamsas Session.");
43 // load in the vamsas archive for the first time
44 ClientDoc cdoc = this.getUpdateable();
46 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
56 for (int i = frames.length - 1; i > -1; i--)
58 if (frames[i] instanceof AlignFrame)
60 AlignFrame af = (AlignFrame) frames[i];
61 af.alignPanel.alignmentChanged();
64 } catch (Exception e) {
65 Cache.log.warn("Exception whilst refreshing jalview windows after a vamsas document update.", e);
71 * this will close all windows currently in Jalview.
74 protected void closeWindows() {
75 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
84 for (int i = frames.length - 1; i > -1; i--) {
87 } catch (Exception e) {
88 Cache.log.error("Whilst closing windows",e);
93 public void get_update(VamsasArchive doc) {
94 // Close windows - load update.
95 Cache.log.info("Jalview updating from Vamsas Session.");
98 VamsasClientWatcher watcher=null;
99 public void push_update() {
100 watchForChange=false;
102 Thread.sleep(WATCH_SLEEP);
103 } catch (Exception e) {
106 ClientDoc cdoc = getUpdateable();
107 updateVamsasDocument(cdoc);
115 // collect all uncached alignments and put them into the vamsas dataset.
117 Cache.log.info("Jalview updating the Vamsas Session.");
119 public void end_session() {
120 // stop any update/watcher thread.
121 watchForChange=false; // this makes any watch(long) loops return.
122 // we should also wait arount for this.WATCH_SLEEP to really make sure the watcher thread has stopped.
124 Thread.sleep(WATCH_SLEEP);
125 } catch (Exception e) {
128 Cache.log.info("Jalview disconnecting from the Vamsas Session.");
130 public void updateJalview(ClientDoc cdoc) {
132 VamsasDatastore vds = new VamsasDatastore(cdoc, vobj2jv, jv2vobj, baseProvEntry());
133 vds.updateToJalview();
135 private void ensureJvVamsas() {
137 jv2vobj = new IdentityHashMap();
138 vobj2jv = new Hashtable();
142 * jalview object binding to VorbaIds
144 IdentityHashMap jv2vobj = null;
145 Hashtable vobj2jv = null;
146 public void updateVamsasDocument(ClientDoc doc) {
148 VamsasDatastore vds = new VamsasDatastore(doc, vobj2jv, jv2vobj, baseProvEntry());
149 // wander through frames
150 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
160 for (int i = frames.length - 1; i > -1; i--)
162 if (frames[i] instanceof AlignFrame)
164 AlignFrame af = (AlignFrame) frames[i];
166 // update alignment and root from frame.
167 vds.storeVAMSAS(af.getViewport(), af.getTitle());
171 catch (Exception e) {
172 Cache.log.error("Vamsas Document store exception",e);
175 private Entry baseProvEntry() {
176 org.vamsas.objects.core.Entry pentry = new org.vamsas.objects.core.Entry();
177 pentry.setUser(this.getProvenanceUser());
178 pentry.setApp(this.getClientHandle().getClientName());
179 pentry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));
180 pentry.setAction("created");
183 protected class VamsasClientWatcher extends Thread {
185 * @see java.lang.Thread#run()
187 VamsasClient client=null;
188 VamsasClientWatcher(VamsasClient client) {
189 this.client = client;
191 boolean running=false;
194 while (client.watchForChange) {
195 ClientDoc docio = client.watch(0);
197 client.disableGui(true);
198 Cache.log.debug("Updating jalview from changed vamsas document.");
199 client.updateJalview(docio);
200 Cache.log.debug("Finished updating from document change.");
203 client.disableGui(false);
211 public void disableGui(boolean b) {
212 Desktop.instance.setVamsasUpdate(b);
214 public void startWatcher() {
216 watcher=new VamsasClientWatcher(this);
217 Thread thr = new Thread() {