[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Sat Jul 28 03:42:00 UTC 2007
gordonp
Fri Jul 27 23:42:00 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv26828/src/main/ca/ucalgary/seahawk/gui
Modified Files:
MobyContentClipboard.java
Log Message:
Made the clipboard 'smart', pasted data is automatically converted to MOBY Objects and append to clipboard collection
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentClipboard.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentClipboard.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentClipboard.java 2007/06/08 14:04:27 1.4
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentClipboard.java 2007/07/28 03:42:00 1.5
@@ -1,16 +1,15 @@
package ca.ucalgary.seahawk.gui;
-import ca.ucalgary.seahawk.util.DataRecorder;
+import ca.ucalgary.seahawk.services.MobyClient;
+import ca.ucalgary.seahawk.util.*;
import org.biomoby.client.MobyRequestEventHandler;
+import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.data.*;
+import org.biomoby.shared.parser.MobyTags;
-import javax.swing.ImageIcon;
-import javax.swing.JLabel;
-import javax.swing.JMenuItem;
-import javax.swing.JPopupMenu;
-import javax.swing.JTabbedPane;
+import javax.swing.*;
import javax.xml.transform.Transformer;
import javax.xml.parsers.DocumentBuilder;
@@ -42,6 +41,7 @@
private File clipboardFile;
private MobyDataJob query; // lump all data into one query
private MobyDataObjectSet collection; // lump all data into one collection
+ private String previousImportDataType = null;
// Clipboard editing variables
private JMenuItem deleteDataPopupItem;
@@ -82,7 +82,12 @@
return;
}
clipboardFile.deleteOnExit();
-
+
+ // The dfeault is to open a new tab when contents is transfered (dropped/pasted) onto the tab,
+ // we want to override that behaviour to a collation for the clipboard
+ setTransferHandler(new FileAndTextTransferHandler(cGUI, false)); // false = open data in current tab
+ editorPane.setTransferHandler(getTransferHandler());
+
sGUI.setClipboard(this);
}
@@ -112,6 +117,9 @@
// Only process if the passed in data is one of the top level collection elements
// (i.e. don't delete subparts of object)
if(!(mdi instanceof MobyDataObject) || !collection.contains(mdi)){
+ mdi.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ System.err.println("Skipping " + mdi.toXML());
+ mdi.setXmlMode(MobyDataInstance.CENTRAL_XML_MODE);
return;
}
@@ -156,6 +164,10 @@
* @param mdi the data to be added to the main clipboard collection
*/
public void addCollectionData(MobyDataInstance mdi){
+ addCollectionData(mdi, true);
+ }
+
+ public void addCollectionData(MobyDataInstance mdi, boolean updateDisplay){
if(mdi == null){
logger.warn("Cannot add null object to the clipboard.");
return;
@@ -177,9 +189,125 @@
return;
}
+ if(updateDisplay){
+ updateDisplay();
+ }
+ }
+
+ /**
+ * Objects in the content instance will be flattened into a list
+ * and appended to the current contents of the collection.
+ */
+ public void addCollectionData(MobyContentInstance mci){
+ for(MobyDataJob job: mci.values()){
+ for(MobyDataInstance data: job.getPrimaryData()){
+ addCollectionData(data, false); //false == don't update display
+ }
+ }
updateDisplay();
}
+ /**
+ * Attempts to add data from the given URL as MOBY objects (converting if necessary).
+ * The conversion is "smart", and so if you have 2 DNASequences on the clipboard
+ * already, it will try to extract DNASequences from the URL data first, then other
+ * types.
+ */
+ public void addCollectionData(URL u){
+ try{
+ MobyContentInstance mobyContents =
+ MobyUtils.convertURLtoMobyBinaryData(servicesGUI.getMobyClient(), u);
+ if(mobyContents != null){
+ addCollectionData(mobyContents);
+ return;
+ }
+ } catch(Exception e){
+ logger.warn("Could not transform binary file ("+u+"): " + e);
+ }
+
+ // Not binary, see if it's text that's convertible to MOBY data
+ MobyClient client = servicesGUI.getMobyClient();
+ if(client == null){
+ logger.warn("Could not get MOBY client from MOBY services GUI, " +
+ "cannot transform incoming clipboard data to MOBY objects");
+ }
+ String urlContents = null;
+ try{
+ urlContents = HTMLUtils.getURLContents(u);
+ } catch(Exception e){
+ logger.warn("Could not read contents of the URL to import to the clipboard ("+u+"):" +e);
+ return;
+ }
+
+ MobyDataType targetDataType = null;
+ if(collection != null){
+ targetDataType = collection.getDataType();
+ }
+ MobyDataObject[] mobyDataFound = client.getMobyObjects(urlContents, targetDataType);
+ // If only one data available, use it
+ if(mobyDataFound.length == 1){
+ addCollectionData(mobyDataFound[0]);
+ return;
+ }
+ // If no data available, try a more general object finding query
+ else if(mobyDataFound.length == 0){
+ // If the previous transformation attempt was for the base Object, there's
+ // nothing more to search for, just treat the data as a string.
+ if(targetDataType == null || MobyTags.MOBYOBJECT.equals(targetDataType.getName())){
+ addCollectionData(new MobyDataString(urlContents));
+ return;
+ }
+ mobyDataFound = client.getMobyObjects(urlContents);
+ if(mobyDataFound.length == 1){
+ addCollectionData(mobyDataFound[0]);
+ return;
+ }
+ else if(mobyDataFound.length == 0){
+ addCollectionData(new MobyDataString(urlContents));
+ return;
+ }
+ }
+ // Otherwise we need to ask the user what data to import ("Paste as...")
+ // Implicitly...mobyDataFound.length > 1
+ String[] selectionValues = new String[mobyDataFound.length];
+ for(int i = 0; i < mobyDataFound.length; i++){
+ selectionValues[i] = mobyDataFound[i].getDataType().getName();
+ if(MobyTags.MOBYOBJECT.equals(selectionValues[i]) &&
+ mobyDataFound[i].getPrimaryNamespace() != null){
+ selectionValues[i] += " (" + mobyDataFound[i].getPrimaryNamespace().getName() + ")";
+ }
+ }
+ // Sort alphabetically
+ //Arrays.sort(selectionValues);
+ String initialSelectionValue = selectionValues[0];
+ if(previousImportDataType != null){
+ for(String selectionValue: selectionValues){
+ if(previousImportDataType.equals(selectionValue)){
+ initialSelectionValue = selectionValue;
+ break;
+ }
+ }
+ }
+ String selection = (String) JOptionPane.showInputDialog(this,
+ "Paste data as...",
+ "Data import choice",
+ JOptionPane.PLAIN_MESSAGE,
+ (Icon) null,
+ selectionValues,
+ initialSelectionValue);
+ if(selection == null){
+ logger.warn("No data type for import selected, abandoning import");
+ return;
+ }
+ for(int i = 0; i < selectionValues.length; i++){
+ if(selection.equals(selectionValues[i])){
+ addCollectionData(mobyDataFound[i]);
+ previousImportDataType = selection;
+ return;
+ }
+ }
+ }
+
public boolean hasXMLSource(){
return true;
}
More information about the MOBY-guts
mailing list