Coverage Report - net.sf.jabref.external.PushToWinEdt
 
Classes in this File Line Coverage Branch Coverage Complexity
PushToWinEdt
57%
29/50
20%
2/10
1.636
 
 1  
 package net.sf.jabref.external;
 2  
 
 3  
 import java.io.IOException;
 4  
 
 5  
 import javax.swing.*;
 6  
 
 7  
 import net.sf.jabref.*;
 8  
 import com.jgoodies.forms.builder.DefaultFormBuilder;
 9  
 import com.jgoodies.forms.layout.FormLayout;
 10  
 
 11  3088196515
 public class PushToWinEdt implements PushToApplication {
 12  
 
 13  3088196515
     private boolean couldNotCall=false;
 14  3088196515
     private boolean notDefined=false;
 15  3088196515
     private JPanel settings = null;
 16  3088196515
     private JTextField winEdtPath = new JTextField(30),
 17  
         citeCommand = new JTextField(30);
 18  
 
 19  
     public String getName() {
 20  122291250
         return Globals.lang("Insert selected citations into WinEdt");
 21  
     }
 22  
 
 23  
     public String getApplicationName() {
 24  2965979861
         return "WinEdt";
 25  
     }
 26  
 
 27  
     public String getTooltip() {
 28  2965979861
         return Globals.lang("Push selection to WinEdt");
 29  
     }
 30  
 
 31  
     public Icon getIcon() {
 32  3088233813
         return GUIGlobals.getImage("winedt");
 33  
     }
 34  
 
 35  
     public String getKeyStrokeName() {
 36  0
         return "Push to WinEdt";
 37  
     }
 38  
 
 39  
     public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) {
 40  
 
 41  0
         couldNotCall = false;
 42  0
         notDefined = false;
 43  
 
 44  0
         String winEdt = Globals.prefs.get("winEdtPath");
 45  0
         if ((winEdt == null) || (winEdt.trim().length() == 0)) {
 46  0
             notDefined = true;
 47  0
             return;
 48  
         }
 49  
 
 50  
         try {
 51  0
             StringBuffer toSend = new StringBuffer("\"[InsText('")
 52  
                     .append(Globals.prefs.get("citeCommandWinEdt")).append("{")
 53  
                     .append(keyString.replaceAll("'", "''"))
 54  
                     .append("}');]\"");
 55  0
             Runtime.getRuntime().exec(winEdt + " " + toSend.toString());
 56  
 
 57  
         }
 58  
 
 59  0
         catch (IOException excep) {
 60  0
             couldNotCall = true;
 61  0
             excep.printStackTrace();
 62  0
         }
 63  
 
 64  
 
 65  0
     }
 66  
 
 67  
     public void operationCompleted(BasePanel panel) {
 68  0
         if (notDefined) {
 69  0
             panel.output(Globals.lang("Error") + ": "+
 70  
                     Globals.lang("Path to %0 not defined", getApplicationName())+".");
 71  
         }
 72  0
         else if (couldNotCall) {
 73  0
             panel.output(Globals.lang("Error") + ": " + Globals.lang("Could not call executable") + " '"
 74  
                     +Globals.prefs.get("winEdtPath") + "'.");
 75  
         }
 76  
         else
 77  0
             Globals.lang("Pushed citations to WinEdt");
 78  0
     }
 79  
 
 80  
     public boolean requiresBibtexKeys() {
 81  0
         return true;
 82  
     }
 83  
 
 84  
     public JPanel getSettingsPanel() {
 85  856876
         if (settings == null)
 86  855551
             initSettingsPanel();
 87  856876
         winEdtPath.setText(Globals.prefs.get("winEdtPath"));
 88  856876
         citeCommand.setText(Globals.prefs.get("citeCommandWinEdt"));
 89  856876
         return settings;
 90  
     }
 91  
 
 92  
     private void initSettingsPanel() {
 93  855551
         DefaultFormBuilder builder = new DefaultFormBuilder(
 94  
                 new FormLayout("left:pref, 4dlu, fill:pref, 4dlu, fill:pref", ""));
 95  855551
         builder.append(new JLabel(Globals.lang("Path to WinEdt.exe") + ":"));
 96  855551
         builder.append(winEdtPath);
 97  855551
         BrowseAction action = new BrowseAction(null, winEdtPath, false);
 98  855551
         JButton browse = new JButton(Globals.lang("Browse"));
 99  855551
         browse.addActionListener(action);
 100  855551
         builder.append(browse);
 101  855551
         builder.nextLine();
 102  855551
         builder.append(Globals.lang("Cite command") + ":");
 103  855551
         builder.append(citeCommand);
 104  855551
         settings = builder.getPanel();
 105  855551
     }
 106  
 
 107  
     public void storeSettings() {
 108  215547
         Globals.prefs.put("winEdtPath", winEdtPath.getText());
 109  215547
         Globals.prefs.put("citeCommandWinEdt", citeCommand.getText());
 110  215547
     }
 111  
 }