[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Sun Apr 11 02:25:03 UTC 2010


gordonp
Sat Apr 10 22:25:03 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv20173/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobyContentClipboard.java 
Added Files:
	DataImportChoiceDialog.java DataImportChoiceListener.java 
Log Message:
Improved data import to clipboard UI
moby-live/Java/src/main/ca/ucalgary/seahawk/gui DataImportChoiceDialog.java,NONE,1.1 DataImportChoiceListener.java,NONE,1.1 MobyContentClipboard.java,1.9,1.10
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentClipboard.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentClipboard.java	2010/04/09 15:51:53	1.9
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentClipboard.java	2010/04/11 02:25:03	1.10
@@ -6,6 +6,7 @@
 
 import org.biomoby.client.MobyRequestEventHandler;
 import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyNamespace;
 import org.biomoby.shared.data.*;
 import org.biomoby.shared.parser.MobyTags;
 
@@ -20,12 +21,13 @@
 import java.io.FileOutputStream;
 import java.net.URL;
 import java.util.*;
+import java.util.regex.Pattern;
 
 /**
  * The clipboard is a special tab that holds a query with a MOBY Collection
  * that the user can add and subtract MobyDataInstances from.
  */
-public class MobyContentClipboard extends MobyContentPane{
+public class MobyContentClipboard extends MobyContentPane implements DataImportChoiceListener{
     public final static String CLEAR_CLIPBOARD_OPTION = "Clear Clipboard";
     public final static String CLIPBOARD_FILE_NAME = "SeaHawkClipboard";
     public final static String CLIPBOARD_COLLECTION_NAME = "Clipboard Collection";
@@ -41,7 +43,13 @@
     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;
+    private MobyDataType previousImportDataType = null;
+    private MobyNamespace previousImportNS = null;
+
+    private Pattern commentRegex;
+    private Pattern scriptRegex;
+    private Pattern styleRegex;
+    private Pattern tagRegex;
 
     // Clipboard editing variables
     private JMenuItem deleteDataPopupItem;
@@ -88,6 +96,12 @@
 	setTransferHandler(new FileAndTextTransferHandler(cGUI, false)); // false = open data in current tab
 	editorPane.setTransferHandler(getTransferHandler());
 
+	// Setup regexes used for stripping HTML docs of their markup (for data pasting ops)
+	commentRegex = Pattern.compile("<!--.*?-->", Pattern.MULTILINE | Pattern.DOTALL);
+	scriptRegex = Pattern.compile("<script.*?</script>",  Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
+	styleRegex = Pattern.compile("<style.*?</style>",  Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
+	tagRegex = Pattern.compile("<.*?>", Pattern.MULTILINE | Pattern.DOTALL);
+
 	sGUI.setClipboard(this);	
     }
 
@@ -248,7 +262,11 @@
 	    logger.warn("Could not read contents of the URL to import to the clipboard ("+u+"):" +e);
 	    return;
 	}
-	
+	if(urlContents.indexOf("<html") != -1 || urlContents.indexOf("<HTML") != -1){
+	    urlContents = tagRegex.matcher(commentRegex.matcher(styleRegex.matcher(scriptRegex.matcher(urlContents).replaceAll("")).replaceAll("")).replaceAll("")).replaceAll("");
+	}
+	System.err.println(urlContents);
+
 	MobyDataType targetDataType = null;
 	if(collection != null){
 	    targetDataType = collection.getDataType();
@@ -277,47 +295,28 @@
 		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");
+
+	// Otherwise we need the user to choose
+	new DataImportChoiceDialog(contentGUI, mobyDataFound, previousImportDataType, previousImportNS, this);
+    }
+
+    // Callback once user has selected the data to import from the DataImportChoiceDialog
+    public void importConfirmed(DataImportChoiceDialog dialog, MobyDataObject[] selectedData){	
+	if(selectedData == null){
+	    logger.warn("Got null for import selection, abandoning import");
 	    return;
 	}
-	for(int i = 0; i < selectionValues.length; i++){
-	    if(selection.equals(selectionValues[i])){
-		addCollectionData(mobyDataFound[i]);
-		previousImportDataType = selection;
-		return;
+	for(int i = 0; i < selectedData.length; i++){
+	    addCollectionData(selectedData[i], i == selectedData.length-1); // only update display on last import
+	    previousImportDataType = selectedData[i].getDataType();
+	    if(selectedData[i].getPrimaryNamespace() != null){
+		previousImportNS = selectedData[i].getPrimaryNamespace();
 	    }
 	}
     }
 
+    public void importCanceled(DataImportChoiceDialog dialog){}
+
     public boolean hasXMLSource(){
 	return true;
     }




More information about the MOBY-guts mailing list