From 58347e32c437d34bf07e516a1b4a74cd50088c70 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Thu, 1 Feb 2018 04:10:47 +0000 Subject: [PATCH] JAL-2890 cipres example query made functional --- src/jalview/ext/cipres/CipresExample.java | 108 ++++++++++++++++------------- 1 file changed, 60 insertions(+), 48 deletions(-) diff --git a/src/jalview/ext/cipres/CipresExample.java b/src/jalview/ext/cipres/CipresExample.java index 81497ab..4e6aa6a 100644 --- a/src/jalview/ext/cipres/CipresExample.java +++ b/src/jalview/ext/cipres/CipresExample.java @@ -1,9 +1,8 @@ package jalview.ext.cipres; -/** - * Example originally from cipres_java_client (Example.java there) - */ -import java.io.Console; +import jalview.bin.Cache; +import jalview.io.JalviewFileChooser; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -13,12 +12,13 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import javax.swing.JOptionPane; + import org.ngbw.directclient.CiApplication; import org.ngbw.directclient.CiCipresException; import org.ngbw.directclient.CiClient; import org.ngbw.directclient.CiJob; import org.ngbw.directclient.CiResultFile; -import org.ngbw.directclient.example.Example; import org.ngbw.restdatatypes.ErrorData; import org.ngbw.restdatatypes.LimitStatus; import org.ngbw.restdatatypes.ParamError; @@ -54,9 +54,7 @@ public class CipresExample { @SuppressWarnings("unused") private static final Logger log = LoggerFactory - .getLogger(Example.class.getName()); - - private static Console console = System.console(); + .getLogger(CipresExample.class.getName()); private static String entry; @@ -71,11 +69,6 @@ public class CipresExample public static void main(String[] args) throws Exception { - if (console == null) - { - System.out.println("No console"); - return; - } // If true, the example will use umbrella authentication if (args.length > 0 && args[0].equals("-u")) @@ -83,9 +76,20 @@ public class CipresExample umbrella = true; } - // Copy example fasta file from jar to temp file on disk - fastaFile = copyResource("ex1.fasta"); + JalviewFileChooser chooser = new JalviewFileChooser( + Cache.getProperty("LAST_DIRECTORY") + ); + int value = chooser.showOpenDialog(null); + if (value == JalviewFileChooser.APPROVE_OPTION) + { + fastaFile = chooser.getSelectedFile().getPath(); + } + else + { + System.exit(0); + } + // Get username, password, app name, app id, url from pycipes.conf CiApplication app = CiApplication.getInstance(); @@ -109,15 +113,16 @@ public class CipresExample { if (umbrella) { - System.out.println( - "\nEnter s(submit), v(validate), l(list), d(delete), j(job status), r(retrieve results), t(show tools), u(change end user) or q(quit):"); + command = JOptionPane.showInputDialog( + "\nEnter s(submit), v(validate), l(list), d(delete), j(job status), r(retrieve results), t(show tools), u(change end user) or q(quit):" + ); } else { - System.out.println( - "\nEnter s(submit), v(validate), l(list), d(delete), j(job status), r(retrieve results) or t(show tools) or q(quit):"); + command = JOptionPane.showInputDialog( + "\nEnter s(submit), v(validate), l(list), d(delete), j(job status), r(retrieve results) or t(show tools) or q(quit):" + ); } - command = console.readLine(); try { if (command.equals("q")) @@ -207,9 +212,10 @@ public class CipresExample private static void submitJob() throws CiCipresException { - System.out.println( - "Will submit an example clustalw job. Enter a name for the job or enter a single 'n' to cancel"); - entry = console.readLine(); + + entry = JOptionPane.showInputDialog( + "Will submit an example clustalw job. Enter a name for the job or enter a single 'n' to cancel" + ); if (entry.equals("n")) { return; @@ -263,8 +269,9 @@ public class CipresExample private static void deleteJob() throws CiCipresException { - System.out.println("Enter url of job to delete or n(no, cancel)"); - entry = console.readLine(); + entry = JOptionPane + .showInputDialog("Enter url of job to delete or n(no, cancel)" + ); if (!entry.startsWith("http")) { return; @@ -277,8 +284,9 @@ public class CipresExample throws CiCipresException, IOException { boolean finalResults = true; - System.out.println("Enter url of job or n(no, cancel)"); - entry = console.readLine(); + entry = JOptionPane + .showInputDialog("Enter url of job or n(no, cancel)" + ); if (!entry.startsWith("http")) { return; @@ -286,9 +294,9 @@ public class CipresExample CiJob job = myClient.getJob(entry); if (job.isDone() == false) { - System.out.println( - "Job is not finished. Enter y(yes, get working dir contents) or n(no, cancel)"); - entry = console.readLine(); + entry = JOptionPane.showInputDialog( + "Job is not finished. Enter y(yes, get working dir contents) or n(no, cancel)" + ); if (entry.equals("n")) { return; @@ -306,9 +314,9 @@ public class CipresExample System.out.println(count + ". " + file.getName() + " (" + file.getLength() + " bytes )"); } - System.out.println( - "Enter name of file to download or a(all) or n(no, cancel)"); - entry = console.readLine(); + entry = JOptionPane.showInputDialog( + "Enter name of file to download or a(all) or n(no, cancel)" + ); boolean all = false; if (entry.equals("a")) { @@ -338,8 +346,9 @@ public class CipresExample { if (!umbrella) { - System.out.println("Enter jobhandle or n(no, cancel)"); - entry = console.readLine(); + entry = JOptionPane + .showInputDialog("Enter jobhandle or n(no, cancel)" + ); if (!entry.startsWith("NGBW")) { return; @@ -359,9 +368,9 @@ public class CipresExample single job, using a CiClient configured for the owner of the job. */ - System.out.println( - "Enter comma separated list of jobhandles or n(no, cancel)"); - entry = console.readLine(); + entry = JOptionPane.showInputDialog( + "Enter comma separated list of jobhandles or n(no, cancel)" + ); if (!entry.startsWith("NGBW")) { return; @@ -404,7 +413,7 @@ public class CipresExample { InputStream is; - is = Example.class.getResourceAsStream("/" + name); + is = CipresExample.class.getResourceAsStream(name); File dest = File.createTempFile("Example", ".txt"); dest.deleteOnExit(); @@ -418,27 +427,30 @@ public class CipresExample System.out.println( "\nEnter information about the current end user of this application."); - System.out.println("Enter username or q(quit)"); - String username = console.readLine(); + String username = JOptionPane + .showInputDialog("Enter username or q(quit)" + ); if (username.equals("q")) { return null; } - System.out.println("Enter user's email address or q(quit)"); - String email = console.readLine(); + String email = JOptionPane + .showInputDialog("Enter user's email address or q(quit)" + ); if (email.equals("q")) { return null; } - System.out.println("Enter user's institution or q(quit)"); - String institution = console.readLine(); + String institution = JOptionPane + .showInputDialog("Enter user's institution or q(quit)" + ); if (institution.equals("q")) { return null; } - System.out.println( - "Enter user's country code (must be 2 letters, both uppercase) or q(quit)"); - String country = console.readLine(); + String country = JOptionPane.showInputDialog( + "Enter user's country code (must be 2 letters, both uppercase) or q(quit)" + ); if (country.equals("q")) { return null; -- 1.7.10.2