[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Fri Apr 23 05:17:28 UTC 2010


gordonp
Fri Apr 23 01:17:28 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv24559/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	SeahawkTransferable.java 
Log Message:
Better complex object drag and drop export support
moby-live/Java/src/main/ca/ucalgary/seahawk/gui SeahawkTransferable.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/SeahawkTransferable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/SeahawkTransferable.java	2009/06/09 19:46:48	1.1
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/SeahawkTransferable.java	2010/04/23 05:17:28	1.2
@@ -1,9 +1,15 @@
 package ca.ucalgary.seahawk.gui;
 
+import ca.ucalgary.seahawk.util.SeahawkOptions;
+import ca.ucalgary.seahawk.services.TextClient;
+
+import org.biomoby.shared.MobyPrimaryData;
 import org.biomoby.shared.data.*;
 
 import java.awt.datatransfer.*;
+import javax.swing.JOptionPane;
 import java.util.*;
+import java.util.logging.*;
 
 /**
  * This class handles the export of data from the Seahawk interface into other applications,
@@ -16,9 +22,20 @@
     private String lastPastedValue;
     private String lastTransformRuleURI;
 
+    private static TextClient textClient;
+    private static Logger logger = Logger.getLogger(SeahawkTransferable.class.getName());
+
     public SeahawkTransferable(MobyContentPane p){
 	pane = p;
     }
+    
+    private synchronized TextClient getTextClient() throws Exception{
+	if(textClient == null){
+	    textClient = new TextClient(SeahawkOptions.getRegistry());
+	    //auto populate the rules
+	}
+	return textClient;
+    }
 
     public Object getTransferData(DataFlavor flavor) 
 	throws UnsupportedFlavorException, java.io.IOException{
@@ -28,7 +45,7 @@
 	Class clazz = flavor.getRepresentationClass();
 	
 	// Essentially, we let the user drag Moby objects or submembers rather than substrings of members' text
-	// so that we can make simple rules for decomposition in programming-by-example.  OR an XSLT "DEM" rulew
+	// so that we can make simple rules for decomposition in programming-by-example.  OR an XSLT "DEM" rules
 	// could be applied to provide a particular format e.g. DNASequence -> FastA
 	String fieldString = null;
 	String transformRuleURI = null;
@@ -54,12 +71,38 @@
 	    fieldString = ((MobyDataObject) field).getValue().toString();
 	    transformRuleURI = "urn:lsid:bioxml.info:mobyLoweringSchemaMapping:DateTime2String";
 	}
-	else if(field instanceof MobyDataObjectVector){	    
-	}
-	else if(field instanceof MobyDataObjectSet){
+	else if(field instanceof MobyDataObjectVector){	
+	    //todo?
 	}
 	else if(field instanceof MobyDataComposite){
-	    // todo: Is there a DEM rule we can use?
+	    try{
+		// Is there a DEM rule we can use?
+		boolean ONLY_IF_HAS_URN = true;
+		String[] formatChoices = getTextClient().getPossibleTextTypes((MobyPrimaryData) field, ONLY_IF_HAS_URN);
+		String targetTextType = null;
+		if(formatChoices != null && formatChoices.length != 0){
+		    if(formatChoices.length == 1){
+			targetTextType = formatChoices[0];
+		    }
+		    else{
+			// Give the user a choice
+			targetTextType = formatChoices[0];
+			logger.log(Level.INFO, "Chose "+formatChoices[0]+" instead of "+formatChoices[1]);
+// 			targetTextType = (String) JOptionPane.showInputDialog(pane
+// 									      "Please select a text format to convert to",
+// 									      "Format choices available",
+// 									      JOptionPane.QUESTION_MESSAGE,
+// 									      null,
+// 									      formatChoices,
+// 									      formatChoices[0]);
+		    }
+		}
+		fieldString = getTextClient().getText(field, targetTextType);
+		transformRuleURI = getTextClient().getTemplateURN(targetTextType);
+	    } catch(Exception e){
+		pane.setStatus("Could not transform Moby object to text: " + e.getMessage());
+		logger.log(Level.SEVERE, "Could not transform Moby object to text: ", e);
+	    }
 	}
 	else{
 	    // Must be just a base MobyDataObject




More information about the MOBY-guts mailing list