[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Apr 26 15:26:25 UTC 2007


gordonp
Thu Apr 26 11:26:24 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv912/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobyServicesGUI.java 
Log Message:
Added support for multiple primary input parameters to a service, and fixed up tooltip formatting
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyServicesGUI.java,1.9,1.10
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java	2007/04/18 16:08:15	1.9
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java	2007/04/26 15:26:24	1.10
@@ -1,6 +1,7 @@
 package ca.ucalgary.seahawk.gui;
 
 import ca.ucalgary.seahawk.services.MobyClient;
+import ca.ucalgary.seahawk.util.HTMLUtils;
 import javax.swing.*;
 import org.w3c.dom.*;
 import org.biomoby.shared.*;
@@ -13,6 +14,7 @@
 import java.awt.*;
 import java.io.*;
 import java.text.Collator;
+import java.net.URL;
 import java.util.*;
 import javax.swing.event.PopupMenuListener;
 import javax.swing.event.PopupMenuEvent;
@@ -47,6 +49,7 @@
     MobyDataServiceAssocInstance[] ms;
 
     MobyDataSecondaryInstance[] secondaryInputInstances = null;
+    MobyPrimaryData[] primaryInput = null;
     int maxDataDesc = 22;
     private HashMap<JMenu, JMenu> service2submenu; //tracks nested submenus to root submenus of choices popup
     private HashMap submenu2msIndex;
@@ -174,23 +177,50 @@
     }
 
     public void setupServiceSecondaryData(MobyRequestEventHandler handler){
+	MobyDataInstance[] castInputs = new MobyDataInstance[primaryInput.length];
+	System.err.println("Submitting job with " + primaryInput.length + " parameters");
+	for(int i = 0; i < primaryInput.length; i++){
+	    if(!(primaryInput[i] instanceof MobyDataInstance)){
+		logger.warn("Warning: setupServiceSecondaryData was called before the primary input" +
+			    " for the service was instantiated, ignoring the call.  Object found was" +
+			    " of class "+primaryInput[i].getClass().getName());
+		return;
+	    }
+	    castInputs[i] = (MobyDataInstance) primaryInput[i];
+	}
+
+	try{	    
+	    mobyRequest.setInput(castInputs);
+	} catch(MobyException me){
+	    me.printStackTrace();
+	    logger.warn("Error while trying to set service input: " + me);
+	}
 	mobyRequest.setSecondaryInput(secondaryInputInstances);
 	executeService(handler);
     }
 
     protected void setupService(MobyService mobyService, MobyDataInstance mdi, int handlerHashCode, boolean useDefaultSecondaries){
-	mobyRequest.setDebugMode(System.getProperty("moby.debug") != null);
-	mobyRequest.setService(mobyService);
-	// We only implement simple input for now (i.e. only one input argument)
-	try{
-	    mobyRequest.setInput(mdi, "");
-	}
-	catch(MobyException me){
-	    logger.error("Failure in MOBY input, was not acceptable:" + me);
+	if(!(mdi instanceof MobyPrimaryData)){
+	    logger.error("Failure in MOBY input, was not primary data as expected, but rather "+mdi.getClass().getName());
 	    return;
 	}
+	
+	mobyRequest.setDebugMode(System.getProperty("moby.debug") != null);
+	mobyRequest.setService(mobyService);
+	MobyPrimaryData[] primaryInputTemplate = mobyService.getPrimaryInputs();
+	primaryInput = new MobyPrimaryData[primaryInputTemplate.length];
+	System.arraycopy(primaryInputTemplate, 0, primaryInput, 0, primaryInput.length);
 
 	if(!hasSecondaryInput(mobyService)){
+	    try{
+		// Implement simple input (i.e. only one input argument)
+		mobyRequest.setInput(mdi, "");
+	    }
+	    catch(MobyException me){
+		logger.error("Failure in MOBY input, was not acceptable:" + me);
+		return;
+	    }
+
 	    // No need for further info, just launch the request
 	    removePopupOptions();
 	    executeService(getHandlerByHashCode(handlerHashCode));
@@ -198,14 +228,55 @@
 	else{
 	    // We need more info from the user to launch this service
 	    //logger.warn("Need to get secondary parameters: " + secondaryInputTemplate.getClass());
-	    MobyData[] secondaryInputTemplate = mobyService.getSecondaryInputs();
-	    getSecondaryInput((MobySecondaryData[]) secondaryInputTemplate, handlerHashCode, useDefaultSecondaries);
+	    MobyService metaDataMobyService = MobyService.getService(mobyService.getName(), mobyService.getAuthority());
+
+	    // We need to figure out where the provided data instance goes into the parameter list for the service
+	    Vector<String> paramMatch = new Vector<String>();
+	    int paramMatchDefault = 0;
+	    MobyDataType providedDataType = ((MobyPrimaryData) mdi).getDataType();
+	    for(MobyPrimaryData input: primaryInput){
+		if(providedDataType.inheritsFrom(input.getDataType())){
+		    paramMatch.add(input.getName());
+		}
+	    }
+	    if(paramMatch.size() == 0){
+		logger.error("Failure in MOBY input, could not match the input (" +providedDataType.getName() +
+			     ") to any service param for service "+mobyService.getName());
+		return;
+	    }
+
+	    String targetParamName = paramMatch.elementAt(0);
+	    // Need to choose among multiple parameters	    
+	    if(paramMatch.size() > 1){
+		targetParamName = (String) JOptionPane.showInputDialog(null,
+								       "Choose the service parameter the chosen " +
+								       "object represents", 
+								       "Service Parameter Choice",
+								       JOptionPane.QUESTION_MESSAGE, 
+								       null,
+								       paramMatch.toArray(), 
+								       paramMatch.elementAt(paramMatchDefault));
+	    }
+	    // Finds the matching param and set it
+	    for(int i = 0; i < primaryInput.length; i++){
+		if(targetParamName.equals(primaryInput[i].getName())){
+		    mdi.setName(targetParamName);
+		    primaryInput[i] = (MobyPrimaryData) mdi;
+		}
+	    }
+
+	    // We need to create the secondary parameters too, and launch the dialog to fill in the
+	    // uninstantiated data.
+	    getSecondaryInput(metaDataMobyService, handlerHashCode, useDefaultSecondaries);
 	}
     }
 
+    // True if there are secondaries, or more than one primary input 
+    // (which also needs the dialog for user data instantiation)
     private boolean hasSecondaryInput(MobyService mobyService){
 	MobyData[] secondaryInputTemplate = mobyService.getSecondaryInputs();
-	return secondaryInputTemplate != null && secondaryInputTemplate.length != 0;
+	return secondaryInputTemplate != null && secondaryInputTemplate.length != 0 ||
+	    mobyService.getPrimaryInputs().length > 1;
     }
 
     /**
@@ -233,11 +304,14 @@
      * Launches a dialog that the user can configure secondary parameters in,
      * or tries to fill in and use all defaults if valid and useDefaults is specified.
      */
-    protected void getSecondaryInput(MobySecondaryData[] secondaryInputTemplate, int handlerHashCode, boolean useDefaults){
+    protected void getSecondaryInput(MobyService mobyService, int handlerHashCode, boolean useDefaults){
+	MobySecondaryData[] secondaryInputTemplate = mobyService.getSecondaryInputs();
 	if(secondaryGUI == null){
-	    secondaryGUI = new MobySecondaryInputGUI(this, handlerHashCode);
+	    secondaryGUI = new MobySecondaryInputGUI(this, handlerHashCode, mobyClient);
 	}
 
+	// Create the param array that will be modified in the secondary dialog and used
+	// after the callback to run the service.
 	secondaryInputInstances = 
 		new MobyDataSecondaryInstance[secondaryInputTemplate.length];
 	for(int i = 0; i < secondaryInputInstances.length; i++){
@@ -249,7 +323,8 @@
 	    return;
 	}
 	// The GUI will perform a callback when the user is done the input
-	secondaryGUI.fillIn(secondaryInputInstances);
+	boolean SHOW_DIALOG = true;
+	secondaryGUI.fillIn(primaryInput, secondaryInputInstances, SHOW_DIALOG);
     }
 
     /**
@@ -943,19 +1018,12 @@
 	    String serviceDesc = service.getDescription();
 	    String serviceAuthority = service.getAuthority();
 	    if(serviceDesc != null && serviceDesc.length() > 0){
-		if(serviceDesc.length() > MAX_SERVICE_DESC_LEN){
-		    serviceDesc = htmlifyToolTipText(serviceDesc);
+		if(serviceAuthority != null && serviceAuthority.length() > 0){
+		    serviceDesc += " [" + serviceAuthority + "]";
 		}
+		serviceDesc = HTMLUtils.htmlifyToolTipText(serviceDesc, MAX_SERVICE_DESC_LEN);
 		sdesc = serviceDesc;
 	    }
-	    if(serviceAuthority != null && serviceAuthority.length() > 0){
-		if(sdesc == null){
-		    sdesc = serviceAuthority;
-		}
-		else{
-		    sdesc += " [" + serviceAuthority + "]";
-		}
-	    }
 	    if(sdesc != null){
 		mobyItem.setToolTipText(sdesc);
 	    }
@@ -987,10 +1055,7 @@
 	}
 
 	String menuToolTip = commonAncestorDesc + type.getDescription();
-	if(menuToolTip.length() > MAX_SERVICE_DESC_LEN){
-	    // Cut down really long ancestry descs to the last part (most precise)
-	    menuToolTip = htmlifyToolTipText(menuToolTip);
-	}
+	menuToolTip = HTMLUtils.htmlifyToolTipText(menuToolTip,  MAX_SERVICE_DESC_LEN);
 	menu.setToolTipText(menuToolTip);
 	parentMenu.add(menu);
 
@@ -1017,46 +1082,6 @@
 	}
     }
 
-    /**
-     * By turning the tool tip text into HTML, we can make it multiline
-     */
-    protected String htmlifyToolTipText(String text){
-	int maxLine = MAX_SERVICE_DESC_LEN;
-	StringBuffer result = null;
-
-	while(true){
-	    result = new StringBuffer("<html>");
-	    StringTokenizer st = new StringTokenizer(text, " \t\n");
-	    int lineCharCount = 0;
-	    
-	    if(st.hasMoreTokens()){
-		result.append(st.nextToken());
-		lineCharCount = result.length()-6;
-	    }
-	    while(st.hasMoreTokens()){
-		String word = st.nextToken();
-		if(lineCharCount != 0 && lineCharCount + word.length() >= maxLine){
-		    result.append("<br>" + word);
-		    lineCharCount = word.length();
-		    continue;
-		}
-		result.append(" " + word);
-		lineCharCount += word.length()+1;
-		
-		if(lineCharCount > maxLine){  //single word is bigger than preset width, redo layout
-		    maxLine = lineCharCount;
-		    break;
-		}
-	    }
-	    result.append("</html>");
-	    if(!st.hasMoreTokens()){  //used up all the text, didn't break previous loop abnormally
-		break;
-	    }
-        }  //end layout block
-
-	return result.toString();
-    }
-
     public JMenu addNameDivSubMenu(JMenu parentMenu, MobyService[] services){
 	if(services == null || services.length == 0){
 	    return null;
@@ -1097,10 +1122,7 @@
 	    desc = type.getComment();
 	}
 	String menuToolTip = commonAncestorDesc + desc;
-	if(menuToolTip.length() > MAX_SERVICE_DESC_LEN){
-	    // Cut down really long ancestry descs to the last part (most precise)
-	    menuToolTip = htmlifyToolTipText(menuToolTip);
-	}
+	menuToolTip = HTMLUtils.htmlifyToolTipText(menuToolTip, MAX_SERVICE_DESC_LEN);
 	menu.setToolTipText(menuToolTip);
 	parentMenu.add(menu);
 
@@ -1230,9 +1252,7 @@
 	    assignMenuDataIndex(submenu);
 	}
 	desc = "Input data: " + desc;
-	if(desc.length() > MAX_SERVICE_DESC_LEN){
-	    desc = htmlifyToolTipText(desc);
-	}
+	desc = HTMLUtils.htmlifyToolTipText(desc, MAX_SERVICE_DESC_LEN);
 	submenu.setToolTipText(desc);
 	submenu.setName(SERVICE_SUBMENU_NAME);
 	return submenu;




More information about the MOBY-guts mailing list