2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.rest;
23 import jalview.bin.Cache;
24 import jalview.datamodel.AlignmentView;
25 import jalview.gui.AlignFrame;
26 import jalview.gui.AlignViewport;
27 import jalview.gui.AlignmentPanel;
28 import jalview.gui.Desktop;
29 import jalview.gui.WebserviceInfo;
30 import jalview.util.MessageManager;
31 import jalview.ws.WSClient;
32 import jalview.ws.WSClientI;
33 import jalview.ws.WSMenuEntryProviderI;
34 import jalview.ws.rest.clientdefs.ShmrRestClient;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.util.Vector;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuItem;
42 import javax.swing.JOptionPane;
43 import javax.swing.event.MenuEvent;
44 import javax.swing.event.MenuListener;
50 public class RestClient extends WSClient implements WSClientI,
53 RestServiceDescription service;
55 public RestClient(RestServiceDescription rsd)
61 * parent alignframe for this job
66 * alignment view which provides data for job.
71 * get the alignFrame for the associated input data if it exists.
75 protected AlignFrame recoverAlignFrameForView()
77 return jalview.gui.Desktop.getAlignFrameFor(av);
80 public RestClient(RestServiceDescription service2, AlignFrame alignFrame)
82 this(service2, alignFrame, false);
85 boolean headless = false;
87 public RestClient(RestServiceDescription service2, AlignFrame alignFrame,
92 av = alignFrame.getViewport();
97 public void setWebserviceInfo(boolean headless)
99 WebServiceJobTitle = MessageManager.formatMessage(
100 "label.webservice_job_title", new String[] {
101 service.details.Action, service.details.Name });
102 WebServiceName = service.details.Name;
103 WebServiceReference = "No reference - go to url for more info";
104 if (service.details.description != null)
106 WebServiceReference = service.details.description;
110 wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceName + "\n"
111 + WebServiceReference, true);
112 wsInfo.setRenderAsHtml(true);
118 public boolean isCancellable()
120 // TODO define process for cancelling rsbws jobs
125 public boolean canMergeResults()
127 // TODO process service definition to identify if the results might be
129 // TODO: change comparison for annotation merge
134 public void cancelJob()
136 System.err.println("Cannot cancel this job type: " + service);
140 public void attachWSMenuEntry(final JMenu wsmenu,
141 final AlignFrame alignFrame)
143 JMenuItem submit = new JMenuItem(service.details.Name);
144 submit.setToolTipText(MessageManager.formatMessage(
145 "label.rest_client_submit", new String[] {
146 service.details.Action, service.details.Name }));
147 submit.addActionListener(new ActionListener()
151 public void actionPerformed(ActionEvent e)
153 new RestClient(service, alignFrame);
158 // TODO: menu listener should enable/disable entry depending upon selection
159 // state of the alignment
160 wsmenu.addMenuListener(new MenuListener()
164 public void menuSelected(MenuEvent e)
166 // TODO Auto-generated method stub
171 public void menuDeselected(MenuEvent e)
173 // TODO Auto-generated method stub
178 public void menuCanceled(MenuEvent e)
180 // TODO Auto-generated method stub
189 * record of initial undoredo hash for the alignFrame providing data for this
192 long[] undoredo = null;
195 * Compare the original input data to the data currently presented to the
196 * user. // LOGIC: compare undo/redo - if same, merge regardless (coping with
197 * any changes in hidden columns as normal) // if different undo/redo then
198 * compare region that was submitted // if same, then merge as before, if
199 * different then prompt user to open a new window.
203 protected boolean isAlignmentModified()
205 if (undoredo == null || av == null || av.getAlignment() == null)
207 // always return modified if we don't have access to live GUI elements
211 if (av.isUndoRedoHashModified(undoredo))
213 // alignment has been modified in some way.
216 // TODO: look deeper into modification of selection state, etc that may
217 // affect RestJobThread.realiseResults(boolean merge);
223 * TODO: combine to form a dataset+alignment+annotation context
225 AlignmentView _input;
230 jalview.io.packed.JalviewDataset jds;
233 * informative name for results
235 public String viewTitle;
237 protected void constructJob()
239 service.setInvolvesFlags();
240 // record all aspects of alignment view so we can merge back or recreate
242 undoredo = av.getUndoRedoHash();
244 * delete ? Vector sgs = av.getAlignment().getGroups(); if (sgs!=null) {
245 * _sgs = new SequenceGroup[sgs.size()]; sgs.copyInto(_sgs); } else { _sgs =
246 * new SequenceGroup[0]; }
248 boolean selExists = (av.getSelectionGroup() != null)
249 && (av.getSelectionGroup().getSize() > 1);
250 // TODO: JAL-715: refactor to alignViewport methods and revise to full
251 // focus+context+dataset input data staging model
254 if (service.partitiondata)
256 if (av.getAlignment().getGroups() != null
257 && av.getAlignment().getGroups().size() > 0)
259 // intersect groups with selected region
260 _input = new AlignmentView(av.getAlignment(),
261 av.getColumnSelection(), av.getSelectionGroup(),
262 av.hasHiddenColumns(), true, true);
263 viewTitle = MessageManager.formatMessage(
264 "label.select_visible_region_of",
266 (av.hasHiddenColumns() ? MessageManager
267 .getString("label.visible") : ""),
272 // use selected region to partition alignment
273 _input = new AlignmentView(av.getAlignment(),
274 av.getColumnSelection(), av.getSelectionGroup(),
275 av.hasHiddenColumns(), false, true);
277 viewTitle = MessageManager.formatMessage(
278 "label.select_unselect_visible_regions_from",
280 (av.hasHiddenColumns() ? MessageManager
281 .getString("label.visible") : ""),
286 // just take selected region intersection
287 _input = new AlignmentView(av.getAlignment(),
288 av.getColumnSelection(), av.getSelectionGroup(),
289 av.hasHiddenColumns(), true, true);
290 viewTitle = MessageManager.formatMessage(
291 "label.select_visible_region_of",
293 (av.hasHiddenColumns() ? MessageManager
294 .getString("label.visible") : ""),
300 // standard alignment view without selection present
301 _input = new AlignmentView(av.getAlignment(),
302 av.getColumnSelection(), null, av.hasHiddenColumns(), false,
305 + (av.hasHiddenColumns() ? (new StringBuffer(" ")
306 .append(MessageManager
307 .getString("label.visible_region_of"))
308 .toString()) : "") + af.getTitle();
311 RestJobThread jobsthread = new RestJobThread(this);
313 if (jobsthread.isValid())
315 setWebserviceInfo(headless);
318 wsInfo.setthisService(this);
319 jobsthread.setWebServiceInfo(wsInfo);
325 // TODO: try to tell the user why the job couldn't be started.
329 (jobsthread.hasWarnings() ? jobsthread.getWarnings()
331 .getString("label.job_couldnt_be_started_check_input")),
333 .getString("label.unable_start_web_service_analysis"),
334 JOptionPane.WARNING_MESSAGE);
338 public AlignmentPanel recoverAlignPanelForView()
340 AlignmentPanel[] aps = Desktop
341 .getAlignmentPanels(av.getSequenceSetId());
342 for (AlignmentPanel alp : aps)
352 public boolean isShowResultsInNewView()
354 // TODO make this a property of the service
358 protected static Vector<String> services = null;
360 public static final String RSBS_SERVICES = "RSBS_SERVICES";
362 public static RestClient[] getRestClients()
364 if (services == null)
366 services = new Vector<String>();
369 for (RestServiceDescription descr : RestServiceDescription
370 .parseDescriptions(jalview.bin.Cache.getDefault(
372 ShmrRestClient.makeShmmrRestClient().service.toString())))
374 services.add(descr.toString());
376 } catch (Exception ex)
379 .println("Serious - RSBS descriptions in user preferences are corrupt!");
380 ex.printStackTrace();
384 RestClient[] lst = new RestClient[services.size()];
386 for (String svc : services)
388 lst[i++] = new RestClient(new RestServiceDescription(svc));
393 public String getAction()
395 return service.details.Action;
398 public RestServiceDescription getRestDescription()
403 public static Vector<String> getRsbsDescriptions()
405 Vector<String> rsbsDescrs = new Vector<String>();
406 for (RestClient rsbs : getRestClients())
408 rsbsDescrs.add(rsbs.getRestDescription().toString());
413 public static void setRsbsServices(Vector<String> rsbsUrls)
415 if (rsbsUrls != null)
417 // TODO: consider validating services ?
418 services = new Vector<String>(rsbsUrls);
419 StringBuffer sprop = new StringBuffer();
420 for (String s : services)
424 Cache.setProperty(RSBS_SERVICES, sprop.toString());
428 Cache.removeProperty(RSBS_SERVICES);