Ignore:
Timestamp:
2024-03-18T20:37:34+13:00 (3 months ago)
Author:
anupama
Message:
  1. Running webswing-phind as an application instead of as an applet, so we can finally pass in the variable collection and library parameters. This required altering webswing.config.in (to launch JPhind as application instead of applet) and webswing-phind.xsl (to pass in the additional parameters). 2. When run as applet, clicking leaf nodes in the search results list opened the clicked url result in a browser window/tab but this wasn't happening when run as application. The easiest solution was to handle it when JPhind is run as a webswing application: in that case, it just requires registering a new eventhandler called openURL in the webswing-phind.xsl's JavaScript code, then calling this from the Java code. In JPhind.java, we now pass in a webswing command line parameter set to 1 to indicate JPhind is run as by webswing and as an application. (The webswing cmdline arg will default to 0 if not set, such as for applets or if run from the commandline without being set.) If run as an applet, JPhind uses the inherited AppletContext object as before to open a URL in the browser where the applet is being run. But now, if run as a webswing Application, it calls the new webswing custom eventhandler called openURL (for which JPhind needs to be compiled against the webswing-api.jar now) and passes the URL and any target window where the URL is to be opened. Finally, webswing.config.in passes in the new webswing parameter set to 1, since we're running the phind webswing as an application and also needs the webswing-api.jar in its classpath for phind.
Location:
main/trunk/greenstone3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/build.xml

    r38806 r38848  
    822822    <pathelement location="${lib.jni}/mg.jar"/>
    823823    <pathelement location="${lib.jni}/mgpp.jar"/>
     824
     825    <pathelement location="${web.writablehome}/ext/webswing/api/webswing-api.jar"/>   
    824826   
    825827    <!-- Include all elements that Tomcat exposes to applications -->
  • main/trunk/greenstone3/src/java/org/greenstone/applet/phind/JPhind.java

    r38817 r38848  
    9292package org.greenstone.applet.phind;
    9393
     94import org.webswing.toolkit.api.WebswingUtil;
     95
    9496import javax.swing.JApplet;
    9597import javax.swing.JComponent;
     
    136138    implements ActionListener {
    137139
     140    boolean isWebswingApplication = false; // if run as webswing *and* application (not applet)
     141   
    138142    boolean isRunAsApplet = true;
    139143    // set only if JPhind object is run as an application
     
    215219    // 1. The search button is easy to disable, and is disabled when a
    216220    //    socket connection is in progress.
    217     // 2. ResutCanvas widgets can'r be similarly disabled because the
     221    // 2. ResutCanvas widgets can't be similarly disabled because the
    218222    //    browser hides or wipes them, which looks very bad.
    219223    // 3. I cannot just ignore clicks on canvasses because the browser
     
    280284    }
    281285
     286    isWebswingApplication = appParams.getOrDefault("webswing", "0").equals("1") ? true : false;
     287   
    282288    // manually calling (J)Applet method init()
    283289    init();
     
    716722    try {
    717723        URL url= new URL(address);
    718         if (window.length() > 0) {
    719         getAppletContext().showDocument(url, window);
    720         } else {
    721         getAppletContext().showDocument(url);
     724        if(isRunAsApplet) {
     725        if (window.length() > 0) {
     726            getAppletContext().showDocument(url, window);
     727        } else {
     728            getAppletContext().showDocument(url);
     729        }
     730        } else if(isWebswingApplication) {
     731        if (window.length() > 0) {
     732            WebswingUtil.getWebswingApi().sendActionEvent("openURL",
     733                                  url.toString() + " - " +window,
     734                                  null);
     735        } else {
     736            WebswingUtil.getWebswingApi().sendActionEvent("openURL", url.toString(), null);
     737        }
     738        } else { // else application, but not webswing, TODO: open browser at the URL
     739        System.err.println("Phind.displayWebPage() for non-applet and non-webswing application is not yet implemented.");
    722740        }
    723741    } catch (Exception e) {
     
    11301148    public static void main(String args[]) {
    11311149    if(args.length < 9) {
    1132         System.err.println("Need minimum --params: <baseURL> --collection <collection> --classifier <classifier> --phindcgi <URL> --library <libURL> [--backdrop <ImgURL>] [--xtraParams <key1=value1&key2=value2&...]");
     1150        System.err.println("Need minimum --params: <baseURL> --collection <collection> --classifier <classifier> --phindcgi <URL> --library <libURL> [--webswing <1/0>] [--backdrop <ImgURL>] [--xtraParams <key1=value1&key2=value2&...]");
    11331151    }
    11341152    else { // collection fao.org, classifier 1, phindcgi url, library url, backdrop imgurl
  • main/trunk/greenstone3/web/WEB-INF/classes/interface_default.properties

    r38329 r38848  
    330330webswinggli.brief=Allows you to configure and build collections
    331331
     332webswing_glipage=The WebSwing GLI page
     333webswing_phindpage=The WebSwing Phind page
     334
    332335tabletopDL.title=Tabletop DL Interface
    333336tabletopDL.brief=An interactive experience for end-users based around a tabletop/desktop metaphor
  • main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-phind.xsl

    r38817 r38848  
    117117        customization: function(injector) {
    118118        injector.services.base.handleActionEvent = function(actionName, data, binaryData) {
    119                 console.log("WebSwing actionEvent callback handler: called with actionName = " + actionName);       
     119                //console.log("WebSwing actionEvent callback handler: called with actionName = " + actionName);
     120
     121            if (actionName === "openURL") {
     122              var url = data;
     123          // check if a target tab/window name has been specified
     124          // Any better way of passing more than 1 string between Java and JavaScript?
     125          var index = url.indexOf(" - ");
     126          if (index !== -1) {
     127             var target = url.substring(index+3); // skip past " - " to get target name
     128             window.open(url, target);               
     129          } else {
     130             window.open(url, '_blank');
     131          }
     132        }
     133       
    120134          }
    121135            }
     
    124138       }
    125139       };
     140
     141       
     142       // The applet jar files can just remain in web/applet where they are compiled up
     143       if(!webswingInstance0.options.args) {
     144       webswingInstance0.options.args="";       
     145       }
     146       
     147       //https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript
     148       var baseURL = window.location.origin+window.location.pathname;       
     149       // webswingInstance0.options.args += "\"" + baseURL+ "?a=a&amp;rt=d&amp;s=PhindApplet&amp;c="+gs.cgiParams.c + "\"";       
     150       webswingInstance0.options.args += "\"" + baseURL + "\"";
     151       
     152       webswingInstance0.options.args += " --collection=" + gs.cgiParams.c;
     153       webswingInstance0.options.args += " --library=" + gs.xsltParams.library_name;
     154       
     155       //console.log("args: " +  webswingInstance0.options.args);
     156       
     157       
    126158       /*
    127159       // Not yet working. Stick ${customArgs} at end of final param Value (BEFORE the value's closing double quote) in webswing.config.in
Note: See TracChangeset for help on using the changeset viewer.