| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| BuddiImportPlugin |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Created on Sep 14, 2006 by wyatt | |
| 3 | * | |
| 4 | * The interface which can be extended to create import filters | |
| 5 | */ | |
| 6 | package org.homeunix.thecave.buddi.plugin.api; | |
| 7 | ||
| 8 | import java.io.File; | |
| 9 | ||
| 10 | import org.homeunix.thecave.buddi.i18n.BuddiKeys; | |
| 11 | import org.homeunix.thecave.buddi.plugin.api.exception.PluginException; | |
| 12 | import org.homeunix.thecave.buddi.plugin.api.exception.PluginMessage; | |
| 13 | import org.homeunix.thecave.buddi.plugin.api.model.MutableDocument; | |
| 14 | ||
| 15 | import ca.digitalcave.moss.application.plugin.MossPlugin; | |
| 16 | import ca.digitalcave.moss.swing.MossDocumentFrame; | |
| 17 | ||
| 18 | /** | |
| 19 | * The abstract class to extend when creating an import plugin. The method importData() | |
| 20 | * is the one which is called by Buddi when executing the plugin. In this method, | |
| 21 | * you have access to the main document object, the frame from which the plugin was | |
| 22 | * called, and the file to import from. | |
| 23 | * | |
| 24 | * @author wyatt | |
| 25 | * | |
| 26 | */ | |
| 27 | 0 | public abstract class BuddiImportPlugin extends MenuPlugin implements MossPlugin, FileAccess { |
| 28 | ||
| 29 | /** | |
| 30 | * Imports data as required. The plugin launch code will prompt for a file | |
| 31 | * and pass it in (unless you override the isPromptForFile() method to return false). | |
| 32 | * | |
| 33 | * This method is executed from the launch code within a SwingWorker thread. Once this | |
| 34 | * method is completed, the launch code will update all windows with any new information | |
| 35 | * which may have come from this plugin. Thus, it is not a good idea to use any threads | |
| 36 | * in this method, unless you can guarantee that this method will not complete until | |
| 37 | * all data processing is completed. | |
| 38 | * | |
| 39 | * As well, since this method is not run from the AWT Event thread, you should not display | |
| 40 | * any Swing objects here, as it can potentially cause deadlocks in some situations. This | |
| 41 | * should not be a problem for most plugins, as they just need a file (provided), and that is | |
| 42 | * all. If you do need to display some Swing objects, you can do so using the | |
| 43 | * SwingUtilities.invokeLater() method. | |
| 44 | */ | |
| 45 | public abstract void importData(MutableDocument model, MossDocumentFrame callingFrame, File file) throws PluginException, PluginMessage; | |
| 46 | ||
| 47 | @Override | |
| 48 | public void processData(MutableDocument model, MossDocumentFrame callingFrame, File file) throws PluginException, PluginMessage { | |
| 49 | 0 | importData(model, callingFrame, file); |
| 50 | 0 | } |
| 51 | ||
| 52 | public String getDescription() { | |
| 53 | 0 | return BuddiKeys.FILE_DESCRIPTION_BUDDI_IMPORT_FILES.toString(); |
| 54 | } | |
| 55 | ||
| 56 | public String getProcessingMessage() { | |
| 57 | 0 | return BuddiKeys.MESSAGE_IMPORTING_FILE.toString(); |
| 58 | } | |
| 59 | ||
| 60 | @Override | |
| 61 | public boolean isFileChooserSave() { | |
| 62 | 0 | return false; |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * If set to true, we will force the creation of a new file here. Most people will want to | |
| 67 | * leave this as false (the default); only people who are importing a complete file from | |
| 68 | * another source (e.g. Legacy Buddi files) will want to set it to true. | |
| 69 | * | |
| 70 | * @return | |
| 71 | */ | |
| 72 | public boolean isCreateNewFile(){ | |
| 73 | 0 | return false; |
| 74 | } | |
| 75 | } |