setFormat(theOwner.getCommentFormat());
}
void saveControllerAndGenerateDoc() {
final XJFileChooser fileChooser = MainFrame.getFileChooser();
ExtensionFileFilter filter = new ExtensionFileFilter(
"GATE Application files", "gapp");
fileChooser.addChoosableFileFilter(filter);
fileChooser.setDialogTitle("Select a file where to save the application "
+ ((theTarget instanceof CorpusController
&& ((CorpusController)theTarget).getCorpus() != null) ?
"WITH" : "WITHOUT") + " corpus.");
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setResource("application." + theTarget.getName());
if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
final File gappFile = fileChooser.getSelectedFile();
final JPanel parentPanel = this;
Runnable runnable = new Runnable() {
public void run() {
try {
// Relativize the directory paths with relation to the gappFile path
// before storing
owner.setTemplateDirName(owner.getTemplateDirName(), gappFile.getAbsolutePath());
owner.setOutputDirName(owner.getOutputDirName(), gappFile.getAbsolutePath());
Iterator it = ((Controller)theTarget).getPRs().iterator();
while(it.hasNext()) {
ProcessingResource pr = (ProcessingResource)it.next();
String resourceClassName = pr.getClass().getName();
ResourceData rd = Gate.getCreoleRegister().get(resourceClassName);
String helpURL = rd.getHelpURL();
if(helpURL != null) {
if(!helpURL.startsWith("http://") && !helpURL.startsWith("file:")) {
helpURL = "http://gate.ac.uk/userguide/" + helpURL;
}
pr.getFeatures().put("%@helpURL", helpURL);
}
}
Map<String, String> locations = fileChooser.getLocations();
// When saving an application state, use paths relative to
// GATE HOME for resources inside GATE HOME and warn about them.
gate.util.persistence.PersistenceManager
.saveObjectToFile(theTarget, gappFile, true, true);
// save also the location of the application as last application
locations.put("lastapplication", gappFile.getCanonicalPath());
// add this application to the list of recent applications
String list = locations.get("applications");
if (list == null) { list = ""; }
list = list.replaceFirst("\\Q"+theTarget.getName()+"\\E(;|$)", "");
list = theTarget.getName() + ";" + list;
locations.put("applications", list);
fileChooser.setLocations(locations);
// after the pipeline has been saved, generate the documentation
DocGenerator.generateDoc(gappFile, owner.getTemplateDirName(), owner.getOutputDirName());
}
catch(Exception e) {
JOptionPane.showMessageDialog(parentPanel, "Error!\n"