1 19 20 package org.netbeans.modules.tasklist.usertasks.translators; 21 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import java.util.logging.Level ; 28 import javax.xml.transform.Transformer ; 29 import javax.xml.transform.TransformerConfigurationException ; 30 import javax.xml.transform.TransformerException ; 31 import javax.xml.transform.TransformerFactory ; 32 import javax.xml.transform.stream.StreamSource ; 33 34 import org.netbeans.modules.tasklist.core.export.ExportImportProvider; 35 import org.netbeans.modules.tasklist.core.export.SaveFilePanel; 36 import org.netbeans.modules.tasklist.core.util.ExtensionFileFilter; 37 import org.netbeans.modules.tasklist.core.util.SimpleWizardPanel; 38 import org.netbeans.modules.tasklist.usertasks.options.Settings; 39 import org.netbeans.modules.tasklist.usertasks.util.UTUtils; 40 import org.openide.DialogDisplayer; 41 import org.openide.NotifyDescriptor; 42 import org.openide.WizardDescriptor; 43 import org.openide.cookies.OpenCookie; 44 import org.openide.filesystems.FileObject; 45 import org.openide.filesystems.FileUtil; 46 import org.openide.loaders.DataObject; 47 import org.openide.loaders.DataObjectNotFoundException; 48 import org.openide.util.NbBundle; 49 50 55 public class TextExportFormat extends XmlExportFormat { 56 private String res = "usertasks-effort-text.xsl"; 58 61 public TextExportFormat() { 62 } 63 64 public String getName() { 65 return NbBundle.getMessage(TextExportFormat.class, "Text"); } 67 68 public org.openide.WizardDescriptor getWizard() { 69 SaveFilePanel chooseFilePanel = new SaveFilePanel(); 70 SimpleWizardPanel chooseFileWP = new SimpleWizardPanel(chooseFilePanel); 71 chooseFilePanel.setWizardPanel(chooseFileWP); 72 chooseFilePanel.getFileChooser().addChoosableFileFilter( 73 new ExtensionFileFilter( 74 NbBundle.getMessage(XmlExportFormat.class, 75 "TextFilter"), new String [] {".txt"})); chooseFilePanel.setFile(new File ( 78 Settings.getDefault().getLastUsedExportFolder(), 79 "tasklist.txt")); chooseFileWP.setContentHighlightedIndex(0); 81 chooseFilePanel.setOpenFileCheckBoxVisible(true); 82 83 WizardDescriptor.Iterator iterator = 85 new WizardDescriptor.ArrayIterator( 86 new WizardDescriptor.Panel[] {chooseFileWP}); 87 WizardDescriptor wd = new WizardDescriptor(iterator); 88 wd.putProperty("WizardPanel_contentData", new String [] { 90 NbBundle.getMessage( 91 TextExportFormat.class, "TextChooseDestination"), } 93 ); wd.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); wd.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); wd.putProperty("WizardPanel_contentNumbered", Boolean.TRUE); wd.setTitle(NbBundle.getMessage(TextExportFormat.class, 98 "ExportText")); wd.putProperty(CHOOSE_FILE_PANEL_PROP, chooseFilePanel); 100 wd.setTitleFormat(new java.text.MessageFormat ("{0}")); 102 return wd; 103 } 104 105 110 private static void openFileInIde(File file) { 111 try { 112 FileObject fo = FileUtil.toFileObject(file); 113 if (fo != null) { 114 DataObject do_ = DataObject.find(fo); 115 OpenCookie oc = (OpenCookie) do_.getCookie(OpenCookie.class); 116 if (oc != null) { 117 oc.open(); 118 } else { 119 String msg = NbBundle.getMessage(TextExportFormat.class, 120 "CannotOpenFile"); NotifyDescriptor nd = new NotifyDescriptor.Message( 122 msg, NotifyDescriptor.ERROR_MESSAGE); 123 DialogDisplayer.getDefault().notify(nd); 124 } 125 } else { 126 String msg = NbBundle.getMessage(TextExportFormat.class, 127 "CannotFindFile"); NotifyDescriptor nd = new NotifyDescriptor.Message( 129 msg, NotifyDescriptor.ERROR_MESSAGE); 130 DialogDisplayer.getDefault().notify(nd); 131 } 132 } catch (DataObjectNotFoundException e) { 133 UTUtils.LOGGER.log(Level.WARNING, "", e); } 135 } 136 137 protected Transformer createTransformer() { 138 TransformerFactory tf = TransformerFactory.newInstance(); 139 try { 140 InputStream xsl = TextExportFormat.class. 141 getResourceAsStream(res); 142 return tf.newTransformer(new StreamSource (xsl)); 143 } catch (TransformerConfigurationException e) { 144 UTUtils.LOGGER.log(Level.WARNING, 145 "XSL-Transformer not found", e); return null; 147 } catch (TransformerException e) { 148 UTUtils.LOGGER.log(Level.WARNING, 149 "XSL-Transformer cannot be created", e); return null; 151 } 152 } 153 154 public void doExportImport(ExportImportProvider provider, 155 WizardDescriptor wd) { 156 SaveFilePanel panel = (SaveFilePanel) 157 wd.getProperty(CHOOSE_FILE_PANEL_PROP); 158 super.doExportImport(provider, wd); 159 File dir = panel.getFile().getParentFile(); 160 Settings.getDefault().setLastUsedExportFolder(dir); 161 if (panel.getOpenExportedFile()) { 162 openFileInIde(panel.getFile()); 163 } 164 } 165 166 } 167 | Popular Tags |