[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu May 13 15:56:38 UTC 2010


gordonp
Thu May 13 11:56:37 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/util
In directory dev.open-bio.org:/tmp/cvs-serv28229/src/main/ca/ucalgary/services/util

Modified Files:
	PBERecorder.java 
Log Message:
Support for multiple paste format choices, better paste noted detection and message to include data type
moby-live/Java/src/main/ca/ucalgary/services/util PBERecorder.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/util/PBERecorder.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/util/PBERecorder.java	2010/04/23 05:15:41	1.5
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/util/PBERecorder.java	2010/05/13 15:56:37	1.6
@@ -49,6 +49,7 @@
     private Map<HttpServletRequest,Map<String,String>> params; // shared internal temp params used while processing a request
     private Map<String,Map<String,String>> sessionId2FieldTransformMap; //field->ruleURI map for pasted data
     private Map<String,Map<String,MobyDataInstance>> sessionId2MobySrcs; //field->dragged Moby data map 
+    private int lastChoice = -1; // GUI selection
     private String lastPastedSessionId = null; //use to unify the session receiving pasted data with the copied Seahawk data in PBE
     private MobyDataInstance lastCopiedSource = null; //see above
     private String lastCopiedValue = null; 
@@ -84,6 +85,7 @@
 
     public static final String RESOURCE_FILE_PARAM = "_resource"; // cgi key to retrieve a file such as a CSS
     public static final String AUTOCOMPLETE_PARAM = "autocomplete";  // ajax param
+    public static final String LIST_CHOICE_PARAM = "choice";  // ajax param
     public static final String RETURN_XPATH_PARAM = "ret"; // selection of nodes of interest
     public static final String VALUE_XPATH_PARAM = "val";  // scalars within selection to use in Moby obj construction
     public static final String CONTEXT_XPTR_PARAM = "contextXPtr";  // context for ns prefix:uri resolution
@@ -117,6 +119,11 @@
     private static final String inputEventAttributeValue = "pasteEvent(this)";
     private static final String submitEventAttributeName = "onsubmit";
     private static final String submitEventAttributeValue = "submit(this)";
+
+    private static final String choiceEventAttributeName = "onclick";
+    private static final String choiceEventSubstitutionSentinel = "INDEX";
+    private static final String choiceEventAttributeValue = "choiceEvent("+choiceEventSubstitutionSentinel+"); return false";
+    private static final String choiceScriptURL = "?"+RESOURCE_FILE_PARAM+"=list_choice.js";
     
     private static final String grayOutScriptURL = "?"+RESOURCE_FILE_PARAM+"=grayOut.js";
 
@@ -351,6 +358,9 @@
 	if(action.equals("pasteEvent")){
 	    dataPasted(request);
 	}
+	else if(action.equals("choiceEvent")){
+	    setChoice(request);
+	}
 	else{ //should be "hint"
 	    getStatus(request, response);
 	}
@@ -368,17 +378,73 @@
 
     public void getStatus(HttpServletRequest request,
 			  HttpServletResponse response){
-	response.setContentType("text/plain");
+	synchronized(statusMessage){
+	    response.setContentType("text/plain");
+	    try{
+		response.getOutputStream().write(statusMessage.getBytes());
+	    } catch(Exception e){
+		logger.log(Level.SEVERE, "Cannot write the response to a " + 
+			   DataRecorder.PASSTHROUGH_ACTION + " request", e);
+	    }
+	}
+    }
+
+    /**
+     * Show the user a set of choices in the browser window, 
+     * and waits until they pick one before returning.  
+     * Return -1 if canceled.
+     */
+    public int getChoice(String statusMsg, String[] choices){
+	if(choices == null || choices.length == 0){
+	    return -1;
+	}
+	synchronized(statusMessage){
+	    StringBuilder sb = new StringBuilder();
+	    sb.append("<table bgcolor='#EEEE00'><tr><td>"+statusMsg+"\n<ul>");
+	    for(int i = 0; i < choices.length; i++){		
+		sb.append("<li><a href=\"\" "+choiceEventAttributeName+"=\""+
+			  choiceEventAttributeValue.replaceAll(choiceEventSubstitutionSentinel,""+i)+
+			  "\">"+choices[i]+"</a></li>");
+	    }
+	    sb.append("</ul></td></tr></table>");
+	    statusMessage = sb.toString();
+	}
+
+	// Wait for the user click
+	int choice = -1;
+	for(;;){
+	    try{
+		Thread.sleep(500);
+	    } catch(Exception e){
+		logger.log(Level.WARNING, "Got exception while sleeping between polls for choice response", e);
+		break;
+	    }
+	    if(lastChoice != -1){		
+		choice = lastChoice;
+		lastChoice = -1;
+		return choice;
+	    }
+	}
+	return choice;
+    }
+
+    private void setChoice(HttpServletRequest request){
+	String choiceString = request.getParameter(LIST_CHOICE_PARAM);
+	int choice;
 	try{
-	    response.getOutputStream().write(statusMessage.getBytes());
+	    lastChoice = Integer.parseInt(choiceString);
 	} catch(Exception e){
-	    logger.log(Level.SEVERE, "Cannot write the response to a " + 
-		       DataRecorder.PASSTHROUGH_ACTION + " request", e);
+	    logger.log(Level.WARNING, "Could not parse integer response from "+choiceString, e);
+	    lastChoice = -1; //error
+	    return;
 	}
+	//setStatus("Choice being applied...");
     }
 
     public void setStatus(String statusMsg){
-	statusMessage = statusMsg;
+	synchronized(statusMessage){
+	    statusMessage = statusMsg;
+	}
     }
 
     /**
@@ -440,7 +506,7 @@
 
     public String getBody(HttpServletRequest request){
 	// Creates a floating frame
-	return
+	return "<script src=\""+request.getRequestURL()+choiceScriptURL+"\" type=\"text/javascript\"></script>\n"+
 	    "<script>\n"+divScriptText+"</script>\n\n"+
 	    "<layer id=\""+layerId+" class=\""+layerClass +"\"></layer>\n\n"+
 	    "<script src=\""+request.getRequestURL()+layerScriptURL+"\" type=\"text/javascript\"></script>\n";
@@ -2362,7 +2428,6 @@
 	    return;
 	}
 	lastPastedSessionId = session.getId();
-	setStatus("Paste noted");
 	doUnificationIfPossible();
     }
 
@@ -2386,6 +2451,25 @@
 	System.err.println("Pasted " + lastCopiedValue + " using transform " + 
 			   lastCopiedRuleURI + " from Seahawk source " + lastCopiedSource.toXML());
 	
+	if(lastCopiedSource instanceof MobyPrimaryData){
+	    MobyNamespace[] nss = ((MobyPrimaryData) lastCopiedSource).getNamespaces();
+	    if(MobyTags.MOBYOBJECT.equals(((MobyPrimaryData) lastCopiedSource).getDataType().getName()) &&
+	       nss != null && nss.length > 0){
+		setStatus("Paste of "+nss[0].getName()+ " type ID noted");
+	    }
+	    else{
+		setStatus("Paste of "+((MobyPrimaryData) lastCopiedSource).getDataType().getName()+" object noted");
+	    }
+	}
+	else if(lastCopiedSource instanceof MobySecondaryData){
+	    setStatus("Paste of secondary param "+((MobyPrimaryData) lastCopiedSource).getDataType()+" noted");
+	}
+	else{
+	    logger.log(Level.WARNING, "Got unexpected type (not MobyPrimaryData or MobySecondaryData) in paste: "+
+		       lastCopiedSource.getClass().getName());
+	    setStatus("Paste of "+lastCopiedSource.getClass().getName()+" noted");
+	}
+
 	// Now reset the variables so both dataCopied anmd dataPasted need to be called again
 	// during the next drag 'n' drop op between Seahawk and the browser.
 	lastPastedSessionId = null;




More information about the MOBY-guts mailing list