chooser.show();
String fname = chooser.getFile();
if (fname == null) return;
final File f = new File(chooser.getDirectory(), fname);
TaskWorker tworker = new TaskWorker(yoshikoder){
TM tmd;
protected void doWork() throws Exception {
tmd =
TokenizationService.getTokenizationService().addTokenizerPlugin(f);
log.info(tmd.name + "/" + tmd.description + "/" + tmd.classname + "/" + tmd.location);
}
protected void onError(){
if (e instanceof DuplicatePluginException){
int resp = DialogUtil.askYesNo(yoshikoder,
"Replace existing plugin with this name?",
"Replace Tokenizer Plugin");
if (resp == JOptionPane.YES_OPTION){
// replace on the dispatch thread - not ideal
try {
TM tm =
TokenizationService.getTokenizationService().replaceTokenizerPlugin(tmd,f);
listModel.removeElement(tmd);
listModel.addElement(tm);
list.setSelectedValue(tm, true);
return;
} catch (PluginException ple){
log.log(Level.WARNING, "Failed to replace tokenizer", ple);
}
} else {
// just leave things as they are
return;
}
}
String mess =
Messages.getString("TokenizerPluginsPanel.metadataExtractionFailure");
DialogUtil.yelp(yoshikoder, mess, new PluginException(mess));
}
protected void onSuccess() {
listModel.addElement(tmd);
list.setSelectedValue(tmd, true);
}
};
tworker.start();
}