public abstract class DocumentFileExporter extends Object
GeneiousPlugin.getDocumentFileExporters().
The following example shows how to create a DocumentFileExporter as an anonymous inner class. In this
example, the exporter takes a number of sequences and exports their sequence strings to a txt file.
new DocumentFileExporter(){
public String getFileTypeDescription(){
return "Export sequence as string";
}
public String getDefaultExtension(){
return ".txt";
}
//DocumentFileExporters tell Geneious what types of documents they can accept with a list of DocumentSelectionSignature objects.
//This particular exporter accepts sequence documents (in a list containing one or more documents)
public DocumentSelectionSignature[] getSelectionSignatures(){
return new DocumentSelectionSignature[] {new DocumentSelectionSignature(SequenceDocument.class,1,Integer.MAX_VALUE)};
}
//This is where the work is done. Geneious gives us the File to write to, the list of AnnotatedPluginDocument objects to export, and a ProgressListener.
public void export(File file, AnnotatedPluginDocument[] docs, ProgressListener progress) throws IOException{
//First we create a writer using the supplied file handle.
PrintWriter out = new PrintWriter(new FileWriter(file));
//Lets give the ProgressListener an informative message.
progress.setMessage("Exporting sequences...");
//loop through all the documents in the list.
int count = docs.length;
for(int i=0; i < count; i++){
//update the ProgressListener
progress.setProgress(((double)i)/count);
//Geneious stores documents as AnnotatedPluginDocument objects, which
//contain an internal PluginDocument, as well as extra information (eg annotations).
//in this case we need the internal document, so we extract it using the AnnotatedPluginDocument.getDocumentOrThrow(Class) ()}
//which throws the exception class given when the document cannot be loaded.
PluginDocument internalDoc = docs[i].getDocumentOrThrow(IOException.class);
//since we specified that only SequenceDocuments be passed to our exporter in the getSelectionSignatures() method,we can be sure that the document is a SequenceDocument.
//so we can cast it without worrying about exceptions.
String residues = ((SequenceDocument)internalDoc).getSequenceString();
//write the sequence string to the file.
out.println(residues);
}
//its always good to perform housekeeping when we're done.
out.close();
}
}
| Constructor and Description |
|---|
DocumentFileExporter() |
| Modifier and Type | Method and Description |
|---|---|
void |
export(File file,
AnnotatedPluginDocument[] documents,
ProgressListener progressListener,
Options options)
Do the actual exporting.
|
void |
export(File file,
PluginDocument[] documents,
ProgressListener progressListener,
Options options)
Do the actual exporting from PluginDocuments.
|
abstract String |
getDefaultExtension()
Default extension for file.
|
abstract String |
getFileTypeDescription() |
Options |
getOptions()
Provides all possible options that can be displayed to the user when exporting.
|
Options |
getOptions(AnnotatedPluginDocument[] documentsToExport)
Provide some options to display to the user when exporting.
|
Options |
getOptionsForBatchExport(AnnotatedPluginDocument[] documentsToExport)
Provide some options to display to the user when batch exporting.
|
abstract DocumentSelectionSignature[] |
getSelectionSignatures()
Specifies the document selections that can be exported.
|
String |
getUniqueId()
Get a unique identifier for this DocumentFileExporter.
|
boolean |
isProOnly()
Deprecated.
Importers and exporters should not be restricted, all though this method still functions.
|
boolean |
mayDiscardInformation()
Return true if exporter does not preserve the complete geneious document, i.e if an export and a subsequent
import may result in a loss of some data items (say annotations, notes etc).
|
public abstract String getFileTypeDescription()
public abstract String getDefaultExtension()
public abstract DocumentSelectionSignature[] getSelectionSignatures()
public void export(File file, PluginDocument[] documents, ProgressListener progressListener, Options options) throws IOException
export(java.io.File, com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument[], jebl.util.ProgressListener, Options)
must be implemented. If both are implemented the other method will be used.
The default implementation of this method throws an UnsupportedOperationException.
Therefore any client of this class should call export(java.io.File, com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument[], jebl.util.ProgressListener, Options) instead
which will delegate back to this method if the exporter implementation only implements this method.file - File to write to. This file may exist so it should be overwritten. If canceled, this file should be deleted by the exporter.documents - to be exportedprogressListener - call setProgress or similar to report progress for the export. This may be ignored but is not recommended if
the import may take more than a second or so.options - the options previously returned from getOptions(com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument[])IOException - if it fails to write the file to disk.public void export(File file, AnnotatedPluginDocument[] documents, ProgressListener progressListener, Options options) throws IOException
export(java.io.File, com.biomatters.geneious.publicapi.documents.PluginDocument[], jebl.util.ProgressListener, Options)
must be implemented. If both are implemented this method will be used.
The default implementation of this method
loads the internal PluginDocument for each AnnotatedPluginDocument and then delegates to
export(java.io.File, com.biomatters.geneious.publicapi.documents.PluginDocument[], jebl.util.ProgressListener, Options).
Therefore any client of this class can always safely call this method to export documents.file - write contents to file.documents - to be exportedprogressListener - call setProgress or similar to report progress for the export. This may be ignored but is not recommended if
the import may take more than a second or so.options - the options previously returned from getOptions(com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument[])IOException - if it fails to write the file to disk.public Options getOptions()
getOptions(AnnotatedPluginDocument[]) should also implement this methodpublic Options getOptions(AnnotatedPluginDocument[] documentsToExport)
getOptions(), which is sufficient if the options displayed to the user do not depend on the documents being exporteddocumentsToExport - the documents to export.public Options getOptionsForBatchExport(AnnotatedPluginDocument[] documentsToExport)
documentsToExport - the documents to export.public boolean mayDiscardInformation()
public String getUniqueId()
PluginUtilities.getDocumentFileExporter(String)
can be used to find this DocumentFileExporter.
A unique identifier may consist of any valid Java indentifier characters (see Character.isJavaIdentifierPart(char) as well as to the space character.@Deprecated public boolean isProOnly()