use of net.heartsome.cat.ts.ui.term.view.TerminologyViewPart in project translationstudio8 by heartsome.
the class AddTermToTBDialog method okPressed.
@Override
protected void okPressed() {
String srcTerm = cleanString(txtSrc.getText());
String tgtTerm = cleanString(txtTgt.getText());
if (srcTerm == null || srcTerm.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg1"));
return;
}
if (tgtTerm == null || tgtTerm.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg2"));
return;
}
// 添加空格不可入库的判断,--robert 2012-11-19
if (srcTerm.length() > 0 && srcTerm.trim().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.addTip1"));
return;
}
if (tgtTerm.length() > 0 && tgtTerm.trim().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.addTip2"));
return;
}
srcTerm = srcTerm.trim();
tgtTerm = tgtTerm.trim();
XLFHandler handler = new XLFHandler();
IStructuredSelection srcSelected = (IStructuredSelection) cmbSrcLang.getSelection();
Language srcSelectedLang = (Language) srcSelected.getFirstElement();
String srcLang = srcSelectedLang.getCode();
IStructuredSelection tgtSelection = (IStructuredSelection) cmbTgtLang.getSelection();
Language tgtSelectedLang = (Language) tgtSelection.getFirstElement();
String tgtLang = tgtSelectedLang.getCode();
String strTBX = handler.generateTBXWithString(srcLang, tgtLang, srcTerm, tgtTerm, txtProperty.getText());
TbImporter importer = TbImporter.getInstance();
importer.setProject(project);
int state = -1;
try {
if (TYPE == EDIT_TYPE) {
if (null != this.dbOperator) {
state = DatabaseService.importTbxWithString(strTBX, null, this.dbOperator, Constants.IMPORT_MODEL_ALWAYSADD, srcLang);
if (state != 1) {
return;
}
}
} else if (TYPE == ADD_TYPE) {
state = importer.executeImport(strTBX, srcLang, null);
if (state == ITbImporter.IMPORT_STATE_FAILED) {
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg3"));
importer.clearResources();
return;
}
}
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), msg);
}
});
return;
}
importer.clearResources();
TerminologyViewPart view = (TerminologyViewPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(TerminologyViewPart.ID);
if (view != null) {
view.refresh();
}
setReturnCode(OK);
if (TYPE == ADD_TYPE) {
try {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
LOGGER.error("", e);
}
}
close();
}
Aggregations