[MOBY-guts] biomoby commit

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


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

Modified Files:
	MobySecondaryInputGUI.java 
Log Message:
Added proper multi-primary parameter support, and tooltip formatting for secondary parameters
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobySecondaryInputGUI.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobySecondaryInputGUI.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/seahawk/gui/MobySecondaryInputGUI.java	2007/04/12 01:03:14	1.5
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobySecondaryInputGUI.java	2007/04/26 15:25:13	1.6
@@ -1,21 +1,22 @@
 
 package ca.ucalgary.seahawk.gui;
 
-import org.biomoby.shared.data.MobyDataSecondaryInstance;
-import org.biomoby.shared.MobySecondaryData;
+import ca.ucalgary.seahawk.services.MobyClient;
+import ca.ucalgary.seahawk.util.HTMLUtils;
+import org.biomoby.shared.data.*;
+import org.biomoby.shared.*;
 import java.awt.*;
 import javax.swing.*;
 import javax.swing.text.JTextComponent;
 import java.awt.event.*;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
+import java.util.*;
 
 /**
  * A class that generates a GUI to fill in (instantiate or change) the values of Secondary Input to MOBY services.
  */
 
 public class MobySecondaryInputGUI extends JDialog implements ActionListener, Runnable {
+    public final static int MAX_TOOLTIP_WIDTH = 40;
     public final static int INT_CHOICE_MAX = 100;
     public final static int DEFAULT_TEXT_SIZE = 12;
     public final static String UNBOUNDED_INT_RANGE_DESC = "[integer]";
@@ -23,6 +24,7 @@
     public final static String TITLE = "Secondary Inputs for MOBY Service";
     public final static String OK_BUTTON_NAME = "MSIGexecuteButton";
 
+    private MobyPrimaryData[] inputsPrimary = null;
     private MobyDataSecondaryInstance[] inputs = null;
     private JButton cancelButton;
     private String cancelMessage = "Cancel";
@@ -34,35 +36,38 @@
     private ActionListener listener;
     private int handlerCode = 0;  // callback event ID provided by caller to c-tor
     private boolean showingNew = false;
+    private MobyClient mobyClient;
 
     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(MobySecondaryInputGUI.class);
 
-    public MobySecondaryInputGUI(ActionListener al, Frame owner, boolean modal){
-	this(al, owner, modal, 0);
+    public MobySecondaryInputGUI(ActionListener al, Frame owner, boolean modal, MobyClient client){
+	this(al, owner, modal, 0, client);
     }
 
     /**
      * @param al the object to receive the "all done" callback 
      * @param actionCommandID the id to give back as the event ID during callback 
      */
-    public MobySecondaryInputGUI(ActionListener al, Frame owner, boolean modal, int actionCommandID){
+    public MobySecondaryInputGUI(ActionListener al, Frame owner, boolean modal, int actionCommandID, MobyClient client){
 	super(owner, modal);
  	setup();
 	listener = al;
 	handlerCode = actionCommandID;
+	mobyClient = client;
 	setVisible(false);
         showingNew = false;
 	setName(TITLE);
     }
 
-    public MobySecondaryInputGUI(ActionListener al){
-	this(al, 0);
+    public MobySecondaryInputGUI(ActionListener al, MobyClient client){
+	this(al, 0, client);
     }
 
-    public MobySecondaryInputGUI(ActionListener al, int actionCommandID){
+    public MobySecondaryInputGUI(ActionListener al, int actionCommandID, MobyClient client){
 	super();
 	setup();
 	listener = al;
+	mobyClient = client;
 	handlerCode = actionCommandID;
 	setVisible(false);
     }
@@ -121,19 +126,24 @@
     }
 
     public void fillIn(MobyDataSecondaryInstance[] secondaryInputs, boolean showGUI){
-	if(secondaryInputs == null){
+	fillIn(null, secondaryInputs, showGUI);
+    }
+
+    public void fillIn(MobyPrimaryData[] primaryInputs, MobyDataSecondaryInstance[] secondaryInputs, boolean showGUI){
+	// If more than 1 primary input parameter, need to disable
+	// submission until these fields are filled in too.
+	if(!setupPrimaryInput(primaryInputs) && secondaryInputs == null){
 	    run();
 	    //should do callback
 	    return;
 	}
 
 	inputs = secondaryInputs;
-	java.util.Arrays.sort(inputs);
 
 	// Create a thread here to prevent possible AWT-EventQueue deadlock
 	// when widgets are added and the thread of caller of the method was
 	// the AWT-EventQueue.
-	WidgetCreatorThread widgetMaker = new WidgetCreatorThread(showGUI);
+	WidgetCreatorThread widgetMaker = new WidgetCreatorThread(showGUI, true);
 	if(!showGUI){
 	    // Call synchronous to ensure data is present before returning
 	    widgetMaker.run();
@@ -145,11 +155,31 @@
 	
     }
 
+    /**
+     * Is there more than one primary parameter?  Do we need to populate it?
+     * @return true if we can submit the job as is, otherwise false (data still needs to be filled in)
+     */
+    protected boolean setupPrimaryInput(MobyPrimaryData[] primaryInputs){
+	confirmButton.setEnabled(true);  //unless otherwise noted, we can submit
+	if(primaryInputs != null){
+	    inputsPrimary = primaryInputs;
+	    for(MobyPrimaryData primary: inputsPrimary){
+		if(!(primary instanceof MobyDataInstance)){
+		    // a primary parameter has not yet been instantiated
+		    confirmButton.setEnabled(false);
+		}
+	    }
+	}
+	return confirmButton.isEnabled();
+    }
+
     class WidgetCreatorThread extends Thread{
 	private boolean showGUI;
+	private boolean showSinglePrimaryInput;
 
-	public WidgetCreatorThread(boolean b){
-	    showGUI = b;
+	public WidgetCreatorThread(boolean gui, boolean single){
+	    showGUI = gui;
+	    showSinglePrimaryInput = single;
 	}
 
 	public void run(){
@@ -159,10 +189,24 @@
 		setVisible(true);
 	    }
 
-	    // Add a widget for each input value
-	    for(int i = 0; i < inputs.length; i++){
-		optionsPanel.add(makeWidget(inputs[i]));
+	    if(!confirmButton.isEnabled() || showSinglePrimaryInput){
+		//java.util.Arrays.sort(inputsPrimary);
+		for(MobyPrimaryData input: inputsPrimary){ 
+		    optionsPanel.add(makeWidget(input));
+		}
+
+		// Visually separate the primary and secondary inputs
+		optionsPanel.add(new JSeparator());
+	    }
+
+	    // Sort the parameters alphabetically
+	    Arrays.sort(inputs); // MobyDataSecondaryInstance implements Comparable
+
+	    // Add a widget for each secondary param
+	    for(MobyDataSecondaryInstance input: inputs){ 
+		optionsPanel.add(makeWidget(input));
 	    }
+
 	    // Make the window the preferred size of its widget contents
 	    if(showGUI){
 		pack();
@@ -182,6 +226,22 @@
 	return ret;
     }
 
+    public Component makeWidget(MobyPrimaryData data){
+	boolean DATA_EDITABLE = true;
+	MobyDataObjectWidget primaryDataWidget = null;
+	// Choose c-tor based on if param is instantiated or not
+	if(data instanceof MobyDataInstance){
+	    primaryDataWidget = new MobyDataObjectWidget(data.getName(), mobyClient, (MobyDataInstance) data, DATA_EDITABLE);
+	}
+	else{
+	    primaryDataWidget = new MobyDataObjectWidget(data.getName(), mobyClient, data);
+	}
+	// We want to get informed of updates to the data, as this
+	// may change whether the dialog should be submittable or not
+	primaryDataWidget.addActionListener(this);
+	return primaryDataWidget;
+    }
+
     public Component makeWidget(MobyDataSecondaryInstance msdi){
 	String dataType = msdi.getDataType();
 
@@ -410,7 +470,7 @@
 	if(desc == null || desc.length() == 0){
 	    desc = "Sorry, no description of this input is available from the service provider";
 	}
-	label.setToolTipText(desc);
+	label.setToolTipText(HTMLUtils.htmlifyToolTipText(desc, MAX_TOOLTIP_WIDTH));
 	return label;
     }
 
@@ -441,6 +501,25 @@
 	else if(source == cancelButton){
 	    dispose();
 	}
+	// Primary input data update
+	else if(source instanceof MobyDataObjectWidget){
+	    MobyPrimaryData newData = ((MobyDataObjectWidget) source).getData();
+	    String newDataName = ((MobyDataObjectWidget) source).getName();
+	    boolean enableSubmit = true;
+
+	    // Copy the new data value to the original array
+	    for(int i = 0; i < inputsPrimary.length; i++){
+		if(inputsPrimary[i].getName().equals(newDataName)){
+		    newData.setName(newDataName);
+		    inputsPrimary[i] = newData;
+		}
+		// Is there still some uninstantiated data?
+		if(enableSubmit && !(inputsPrimary[i] instanceof MobyDataInstance)){
+		    enableSubmit = false;
+		}
+	    }
+	    confirmButton.setEnabled(enableSubmit);
+	}
 	else{
 	    logger.warn("Unrecognized event source (" + source + ") in " + getClass());
 	}




More information about the MOBY-guts mailing list