[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Fri Jan 30 14:44:19 UTC 2009


kawas
Fri Jan 30 09:44:18 EST 2009
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/data
In directory dev.open-bio.org:/tmp/cvs-serv16535/src/main/org/biomoby/service/dashboard/data

Modified Files:
	ServiceInputPanel.java DataTypeTreeTable.java 
Log Message:
added 2 methods that populate the table when given a moby XML message
moby-live/Java/src/main/org/biomoby/service/dashboard/data ServiceInputPanel.java,1.3,1.4 DataTypeTreeTable.java,1.12,1.13
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/data/ServiceInputPanel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/data/ServiceInputPanel.java	2006/02/20 05:51:10	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/data/ServiceInputPanel.java	2009/01/30 14:44:18	1.4
@@ -9,12 +9,15 @@
 package org.biomoby.service.dashboard.data;
 
 import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyException;
 import org.biomoby.shared.MobyService;
 import org.biomoby.shared.MobyData;
 import org.biomoby.shared.MobyPrimaryData;
 import org.biomoby.shared.MobyPrimaryDataSimple;
 import org.biomoby.shared.MobyPrimaryDataSet;
 import org.biomoby.shared.MobySecondaryData;
+import org.biomoby.shared.datatypes.MobyObject;
+import org.biomoby.shared.parser.MobyParameter;
 import org.biomoby.shared.parser.MobySimple;
 import org.biomoby.shared.parser.MobyCollection;
 import org.biomoby.shared.parser.MobyJob;
@@ -23,6 +26,7 @@
 import org.biomoby.service.dashboard.data.ParametersTable;
 import org.biomoby.service.dashboard.Dashboard;
 
+import org.tulsoft.shared.UUtils;
 import org.tulsoft.tools.gui.SwingUtils;
 
 import javax.swing.JPanel;
@@ -166,7 +170,6 @@
      * service given in the constructor of this class.
      *************************************************************************/
     public Document getXMLDocument() {
-
 	Vector v = new Vector();
 	for (int i = 0; i < inputTables.size(); i = i+2) {
 	    MobyData data = (MobyData)inputTables.elementAt (i);
@@ -198,6 +201,50 @@
 	    (new Element[] { MobyJob.toXML ("sip_1_", allData) });
 	return doc;
     }
+    
+    /**
+     * 
+     * @param xml
+     *                an XML file containing a full biomoby message that we
+     *                would like to parse and display as input to our service
+     * @throws MobyException if there is a problem parsing the XML or populating our table
+     */
+    public void setValues(String xml) throws MobyException {
+	// create the MobyPackage
+	MobyPackage pack = MobyPackage.createFromXML(xml);
+	// get our job
+	MobyJob job = null;
+	if (pack != null && pack.getJobs().length > 0)
+	    job = pack.getJob(0);
+	if (job == null)
+	    return;
+	for (int i = 0; i < inputTables.size(); i = i+2) {
+	    MobyData data = (MobyData)inputTables.elementAt (i);
+	    DataTypeTreeTable table = (DataTypeTreeTable)inputTables.elementAt (i+1);
+	    String articleName = data.getName();
+	    Object object = job.getData(articleName);
+	    // datatype not existent in this message
+	    if (object == null)
+		continue;
+	    table.populateData((MobyObject)object);
+	}
+	
+	// update secondary params
+	if (paramsTable != null) {
+	    Object[] values = paramsTable.tableModel.getData();
+	    for (int i = 0; i < values.length; i++) {
+		if (!"".equals(values[i])) {
+		    String name = paramsTable.paramDefs[i].getName();
+		    String secondary = job.getParameter(name);
+		    // set the secondary param
+		    if (secondary != null)
+			values[i] = (UUtils.isEmpty (secondary) ? "" : secondary);
+		}
+	    }
+	}
+	// update graphics
+	updateUI();
+    }
 
     /*************************************************************************
      * Return an XML string representing complete input for a service

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/data/DataTypeTreeTable.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/data/DataTypeTreeTable.java	2006/04/28 00:13:41	1.12
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/data/DataTypeTreeTable.java	2009/01/30 14:44:18	1.13
@@ -8,33 +8,35 @@
 
 package org.biomoby.service.dashboard.data;
 
-import org.biomoby.shared.MobyDataType;
-import org.biomoby.service.dashboard.Dashboard;
-import org.biomoby.service.dashboard.treetable.JTreeTable;
-import org.biomoby.service.dashboard.treetable.TreeTableModelAdapter;
-
-import org.tulsoft.tools.gui.SwingUtils;
-
-import org.jdom.Document;
-import org.jdom.Element;
+import java.awt.Component;
+import java.awt.event.MouseEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.EventObject;
 
-import javax.swing.JTable;
-import javax.swing.JComponent;
-import javax.swing.JButton;
-import javax.swing.Icon;
 import javax.swing.AbstractCellEditor;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JTable;
+import javax.swing.event.CellEditorListener;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.JTableHeader;
 import javax.swing.table.TableCellEditor;
 import javax.swing.table.TableCellRenderer;
-import javax.swing.table.DefaultTableCellRenderer;
-import javax.swing.table.TableModel;
 import javax.swing.table.TableColumn;
-import javax.swing.table.JTableHeader;
-import javax.swing.event.CellEditorListener;
-
-import java.awt.Component;
+import javax.swing.table.TableModel;
 
-import java.util.EventObject;
-import java.awt.event.MouseEvent;
+import org.biomoby.service.dashboard.Dashboard;
+import org.biomoby.service.dashboard.treetable.JTreeTable;
+import org.biomoby.service.dashboard.treetable.TreeTableModelAdapter;
+import org.biomoby.shared.Central;
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.Utils;
+import org.biomoby.shared.datatypes.MobyObject;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.tulsoft.tools.gui.SwingUtils;
 
 /**
  * A tree-table representing one BioMoby data type (with all its
@@ -155,6 +157,104 @@
     public Element toXML() {
 	return ((DataTypeNode)getInnerModel().getRoot()).toXML();
     }
+    
+    /**
+     * 
+     * @param mobyObject
+     *                a MobyObject that we would like to use as a template to
+     *                populate ourselves with actual data
+     */
+    public void populateData(MobyObject mobyObject) {
+	// TODO clear old data
+	DataTypeNode node = ((DataTypeNode)getInnerModel().getRoot());
+	// clear out 'extra' nodes
+	node.children = null;
+	node.loadChildren();
+	// set id/ns for this node
+	node.setId(mobyObject.getId());
+	node.setNamespace(mobyObject.getNamespace());
+	// set a value if applicable
+	if (node.isPrimitive) {
+	    node.setValue(mobyObject.getValue());
+	}
+	// fill any children present
+	if (!node.isPrimitive())
+	    populate_children(mobyObject, node);
+	// show our changes
+	updateUI();
+    }
+
+    /*
+     * @param mobyObject the object with children
+     * @param node the DataTypeNode to populate
+     */
+    private void populate_children(MobyObject mobyObject, DataTypeNode node) {
+	// no children
+	if (node.children == null)
+	   return;
+	// iterate over the children
+	for (DataTypeNode n : node.children) {
+	    // stolen from MobyParser maybe this should be made 'public'
+	    String methodName = "getMoby_"
+		    + Utils.mobyEscape(Utils.javaEscape(Utils
+			    .checkOrCreateArticleName(n.getMemberName(),
+				    mobyObject.getClass().getName())));
+	    // use reflection to get the datatype from this object
+	    Method method;
+	    try {
+		method = mobyObject.getClass().getMethod (methodName, new Class[] { });
+		Object o = method.invoke(mobyObject, new Object[] {});
+		if (o == null)
+		    continue;
+		if (o.getClass().isArray()) {
+		    // probably a has relationship
+		    if (n.isHAS()) {
+			Object[] os = (Object[])o;
+			// here we iterate over all of the nodes but the first one
+			// we do this because i need to populate the actual node 'n' as well
+			for (int x =1; x < os.length; x++) {
+			    DataTypeNode newNode = DataTypeNode.createNode(n.getDataType(), n.getMemberName(), Central.iHAS, n.getParentNode(), n.dtTable, n.model);
+			    newNode.loadChildren();
+			    newNode.setId(((MobyObject) os[x]).getId());
+			    newNode.setNamespace(((MobyObject) os[x]).getNamespace());
+			    if (newNode.isPrimitive)
+				newNode.setValue(((MobyObject) os[x]).getValue());
+			    n.getParentNode().addChild(newNode, n.getParentNode().getChildCount());
+			    if (!newNode.isPrimitive())
+				populate_children((MobyObject) os[x], newNode);
+			}
+			// now we populate the first one
+			if (os.length > 0) {
+			    n.setId(((MobyObject) os[0]).getId());
+			    n.setNamespace(((MobyObject) os[0]).getNamespace());
+			    if (n.isPrimitive)
+				n.setValue(((MobyObject) os[0]).getValue());
+			    if (!n.isPrimitive())
+				populate_children((MobyObject) os[0], n);
+			}
+		    }
+		} else {
+		    // not a has relationship, so populate it
+		    n.setId(((MobyObject) o).getId());
+		    n.setNamespace(((MobyObject) o).getNamespace());
+		    if (n.isPrimitive)
+			n.setValue(((MobyObject) o).getValue());
+		    if (!n.isPrimitive())
+			populate_children((MobyObject) o, n);
+		}
+	    } catch (SecurityException e) {
+		
+	    } catch (NoSuchMethodException e) {
+		
+	    } catch (IllegalAccessException e) {
+		
+	    } catch (IllegalArgumentException e) {
+		
+	    } catch (InvocationTargetException e) {
+		
+	    }
+	}
+    }
 
     /*********************************************************************
      * Load shared icons.




More information about the MOBY-guts mailing list