[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Sat Apr 24 17:23:27 UTC 2010


gordonp
Sat Apr 24 13:23:27 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv7331/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobySecondaryInputGUI.java MobyServicesGUI.java 
Added Files:
	ServiceChoiceListener.java ServiceSearchDialog.java 
Log Message:
Initial commit of service search dialog
moby-live/Java/src/main/ca/ucalgary/seahawk/gui ServiceChoiceListener.java,NONE,1.1 ServiceSearchDialog.java,NONE,1.1 MobySecondaryInputGUI.java,1.7,1.8 MobyServicesGUI.java,1.22,1.23
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobySecondaryInputGUI.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobySecondaryInputGUI.java	2007/12/06 17:32:32	1.7
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobySecondaryInputGUI.java	2010/04/24 17:23:26	1.8
@@ -1,4 +1,3 @@
-
 package ca.ucalgary.seahawk.gui;
 
 import ca.ucalgary.seahawk.services.MobyClient;

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java	2010/04/23 05:18:13	1.22
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java	2010/04/24 17:23:26	1.23
@@ -27,7 +27,7 @@
  * Implementation of the actually popup menu that lists services available, and invokes them.
  */
 
-public class MobyServicesGUI implements ActionListener, Comparator<MobyService>, PopupMenuListener{
+public class MobyServicesGUI implements ActionListener, Comparator<MobyService>, PopupMenuListener, ServiceChoiceListener{
     public final static int MAX_ID_LEN = 30;
     public final static String SERVICE_SUBMENU_NAME = "seahawkPopupSubMenuName";
 
@@ -35,6 +35,10 @@
     public final static int MAX_SERVICES_PER_SUBMENU = 12;  
     public final static int MAX_SERVICE_DESC_LEN = 50;
     public final static String CLIPBOARD_CMD = "clipboard";
+    public final static String SERVICESEARCH_CMD = "service_search";
+    public final static String SEARCH_LABEL = "Find service by keyword...";
+    public final static String CLIPBOARD_LABEL = "Add to clipboard";
+
     /** Always spring MOBY response in a new window if this modifier is present for a click */
     public final static int USE_DEFAULT_HANDLER_MASK  = ActionEvent.SHIFT_MASK;
     public final static int USE_DEFAULT_SECONDARIES_MASK  = ActionEvent.CTRL_MASK;
@@ -57,6 +61,7 @@
     int maxDataDesc = 22;
     // tracks nested submenus to root submenus of choices popup
     private Map<JMenu, JMenu> service2submenu; 
+    private Map<JMenuItem, JMenu> search2submenu; 
     private Map<JComponent,Integer> submenu2msIndex;
     private Map<JMenu,JMenuItem> submenu2waitItem;
     // for storing callbacks to other than the default response handler
@@ -75,6 +80,7 @@
 	submenu2msIndex = new HashMap<JComponent,Integer>();
 	submenu2waitItem = new HashMap<JMenu,JMenuItem>();
 	service2submenu = new HashMap<JMenu,JMenu>();
+	search2submenu = new HashMap<JMenuItem,JMenu>();
 	specificHandlers = new HashMap<Integer,WeakReference<MobyRequestEventHandler>>();
     }
 
@@ -124,6 +130,20 @@
 		}
 		return;
 	    }
+	    if(service.equals(SERVICESEARCH_CMD)){
+		synchronized(ms){
+		    if(ms[which_data] == null){
+			logger.warn("Ignoring searvice search in " + getClass().getName() +
+				    ", the data to add is currently null (index "+which_data+")"+
+				    ", from source " + e.getSource());
+			removePopupOptions(e.getSource());
+			return;
+		    }
+		    setupSearchData(search2submenu.get((JMenuItem) e.getSource()), ms[which_data]);
+		    removePopupOptions(e.getSource());
+		}
+		return;   
+	    }
 	    // Otherwise call a remote service
 	    int which_service = Integer.parseInt(service);
 
@@ -322,7 +342,7 @@
     }
 
     /**
-     * If the popup is cancelled, we want to remove any data we've stored, and kill any 
+     * If the popup is canceled, we want to remove any data we've stored, and kill any 
      * requests to MOBYCentral.
      */
     public void popupMenuCanceled(PopupMenuEvent e){
@@ -533,6 +553,7 @@
 	
 	for(int i = 0; i < submenus.length; i++){
 	    addServicesToSubMenu(submenus[i], serviceAssocObjects[i], handler);
+	    addSearchItem(submenus[i], 1);
 	}
     }
 
@@ -595,6 +616,7 @@
 		    //}}.start();
 	    }
 	    service2submenu.clear();
+	    search2submenu.clear();
 	    submenu2msIndex.clear();
 	    submenu2waitItem.clear();
 	    ms = new MobyDataServiceAssocInstance[0];
@@ -732,6 +754,7 @@
 	}
 
 	addServicesToSubMenu(submenu, serviceAssocObject, handler);
+        addSearchItem(submenu, 0);
     }
 
     protected synchronized void addServicesToSubMenu(JMenu submenu, MobyDataServiceAssocInstance msadi){
@@ -1333,6 +1356,15 @@
 	return submenu;
     }
 
+    public void serviceSelected(ServiceSearchDialog dialog, javax.swing.JMenuItem selectedServiceItem){
+	actionPerformed(new ActionEvent(selectedServiceItem, 1, selectedServiceItem.getActionCommand()));
+	removePopupOptions();
+    }
+
+    public void selectionCanceled(ServiceSearchDialog dialog){
+	removePopupOptions();  //cleanup stored data
+    }
+
     private synchronized int assignMenuDataIndex(JMenu submenu){
 	// Make the services array bigger, then copy over existing data, 
 	// leaving a blank at the end to be filled in by addServicesToSubMenu
@@ -1370,6 +1402,64 @@
 	}
     }
 
+    /**
+     * Removes the popup menu and replaces it with a window that has a filter widget
+     * over the list of services from the original popup.
+     */
+    protected void setupSearchData(JMenu objectMenu, MobyDataInstance mobyData){
+	// Setup the chooser dialog
+	ServiceSearchDialog searchDialog = new ServiceSearchDialog(null, 
+								   objectMenu.getText().replaceFirst("Services for", "Run "), 
+								   this);
+	addMenuOptionsToSearch(searchDialog, objectMenu);
+
+	searchDialog.initializeList();
+	searchDialog.pack();
+	searchDialog.setVisible(true);
+    }
+
+    private void addMenuOptionsToSearch(ServiceSearchDialog searchDialog, MenuElement menuElement){
+	if(menuElement instanceof JPopupMenu || menuElement instanceof JMenu){
+	    for(MenuElement subMenuElement: menuElement.getSubElements()){
+		addMenuOptionsToSearch(searchDialog, subMenuElement);
+	    }
+	}
+	else if(menuElement instanceof JMenuItem){ // leaf defining a service
+	    JMenuItem serviceItem = (JMenuItem) menuElement;
+	    String label = serviceItem.getText();
+	    if(label.equals(SEARCH_LABEL) || label.equals(CLIPBOARD_LABEL)){
+		return; // not real services
+	    }
+	    serviceItem.setText(label.replaceFirst("Run ", ""));
+	    searchDialog.addOption(serviceItem, false);
+	}
+	else{
+	    System.err.println("Got dead end with "+menuElement.getClass().getName());
+	}
+    }
+
+    public void addSearchItem(JMenu menu, int location){
+	if(menu == null){
+	    logger.warn("Cannot add service search option, menu reference passed in was null");
+	    return;
+	}
+
+	if(!submenu2msIndex.containsKey(menu)){
+	    logger.warn("Cannot add service search option, cannot find " +
+			"moby object list index for menu " + 
+			menu.getText());
+	    return;
+	}
+
+
+	int dataIndex = ((Integer) submenu2msIndex.get(menu)).intValue();
+	JMenuItem searchItem = new JMenuItem(SEARCH_LABEL);
+	searchItem.setActionCommand("MOBY:"+dataIndex+":"+SERVICESEARCH_CMD);
+	searchItem.addActionListener(this);
+	menu.add(searchItem, location);	
+	search2submenu.put(searchItem, menu);
+    }
+
     public void addClipboardItem(JMenu menu, MobyDataInstance mobyData){
 	if(menu == null){
 	    logger.warn("Cannot add clipboard option, menu reference passed in was null");
@@ -1408,11 +1498,11 @@
 	}
 	else{
 	    logger.warn("Clipboard option for objects other than MobyDataObject " +
-			       "and MobyDataObjectSet are not yet supported:"+mobyData);
+			"and MobyDataObjectSet are not yet supported:"+mobyData);
 	    return;
 	}
 
-	JMenuItem clipItem = new JMenuItem("Add to clipboard");
+	JMenuItem clipItem = new JMenuItem(CLIPBOARD_LABEL);
 	clipItem.setActionCommand("MOBY:"+dataIndex+":"+CLIPBOARD_CMD);
 	clipItem.addActionListener(this);
 	menu.add(clipItem);




More information about the MOBY-guts mailing list