Search in sources :

Example 1 with TbImporter

use of net.heartsome.cat.ts.tb.importer.TbImporter 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();
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) Language(net.heartsome.cat.common.locale.Language) CoreException(org.eclipse.core.runtime.CoreException) TbImporter(net.heartsome.cat.ts.tb.importer.TbImporter) ITbImporter(net.heartsome.cat.ts.tb.importer.extension.ITbImporter) TerminologyViewPart(net.heartsome.cat.ts.ui.term.view.TerminologyViewPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

ImportException (net.heartsome.cat.common.core.exception.ImportException)1 Language (net.heartsome.cat.common.locale.Language)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 TbImporter (net.heartsome.cat.ts.tb.importer.TbImporter)1 ITbImporter (net.heartsome.cat.ts.tb.importer.extension.ITbImporter)1 TerminologyViewPart (net.heartsome.cat.ts.ui.term.view.TerminologyViewPart)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1