1 package org.columba.core.gui.externaltools; 2 3 import java.io.File ; 4 5 import org.columba.core.config.Config; 6 import org.columba.core.xml.XmlElement; 7 8 30 public class ExternalToolsManager { 31 32 private static ExternalToolsManager instance = new ExternalToolsManager(); 33 34 private ExternalToolsManager() { 35 } 36 37 public static ExternalToolsManager getInstance() { 38 return instance; 39 } 40 41 50 public File getLocationOfExternalTool(String toolID) { 51 52 XmlElement root = getConfiguration(toolID); 54 55 if (root == null) { 56 XmlElement parent = Config.getInstance().get("external_tools") 58 .getElement("tools"); 59 XmlElement child = new XmlElement("tool"); 60 child.addAttribute("first_time", "true"); 61 child.addAttribute("name", toolID); 62 parent.addElement(child); 63 64 root = child; 65 } 66 67 boolean firsttime = false; 68 69 if (root.getAttribute("first_time").equals("true")) { 70 firsttime = true; 71 } 72 73 if (firsttime) { 74 ExternalToolsWizardLauncher launcher = new ExternalToolsWizardLauncher(); 76 launcher.launchWizard(toolID, true); 77 78 if (launcher.isFinished()) { 79 XmlElement r = getConfiguration(toolID); 81 File file = new File (r.getAttribute("location")); 82 83 return file; 84 } 85 } else { 86 String location = root.getAttribute("location"); 87 88 File file = new File (location); 89 90 return file; 91 } 92 93 return null; 94 } 95 96 103 public XmlElement getConfiguration(String id) { 104 XmlElement root = Config.getInstance().get("external_tools") 105 .getElement("tools"); 106 for (int i = 0; i < root.count(); i++) { 107 XmlElement child = root.getElement(i); 108 109 if (child.getAttribute("name").equals(id)) { 110 return child; 111 } 112 } 113 114 return null; 115 } 116 } 117 | Popular Tags |