Search in sources :

Example 1 with TransUnitBean

use of net.heartsome.cat.ts.core.bean.TransUnitBean in project translationstudio8 by heartsome.

the class StyledTextCellEditor method isApprovedOrLocked.

/**
	 * 是否批准或者锁定
	 * @return ;
	 */
public boolean isApprovedOrLocked() {
    int rowIndex = hsCellEditor.getRowIndex();
    if (rowIndex == -1) {
        return true;
    }
    if (!xliffEditor.isHorizontalLayout()) {
        // 是垂直布局
        // 得到实际的行索引
        rowIndex = rowIndex / VerticalNatTableConfig.ROW_SPAN;
    }
    TransUnitBean tu = xliffEditor.getRowTransUnitBean(rowIndex);
    String translate = tu.getTuProps().get("translate");
    if (translate != null && "no".equalsIgnoreCase(translate)) {
        return true;
    }
    return false;
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean)

Example 2 with TransUnitBean

use of net.heartsome.cat.ts.core.bean.TransUnitBean in project translationstudio8 by heartsome.

the class MatchViewPart method selectionChanged.

/**
	 * 监听XLFEditor的选择事件
	 */
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
    if (part == null || selection == null) {
        return;
    }
    if (!(part instanceof IEditorPart)) {
        updateActionState();
        return;
    }
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        updateActionState();
        return;
    }
    IXliffEditor editor = (IXliffEditor) part;
    IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
    final Object object = structuredSelecion.getFirstElement();
    if (object instanceof Integer) {
        int rowIndex = -1;
        int selRowIndex = (Integer) object;
        if (rowIndex == selRowIndex) {
            if (gridTable.getItemCount() != 0) {
                updateActionState();
            }
            return;
        } else {
            rowIndex = selRowIndex;
        }
        XLFHandler handler = editor.getXLFHandler();
        String rowId = handler.getRowId(rowIndex);
        // handler.getTransUnit(rowId);
        TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
        if (transUnit == null) {
            updateActionState();
            return;
        }
        TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
        FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
        IProject currentProject = input.getFile().getProject();
        copyEnable.resetSelection();
        gridTable.removeAll();
        altTransCacheList.clear();
        menuMgr.setEditor(editor);
        menuMgr.setRowIndex(rowIndex);
        executeMatch(editor, rowId, transUnit, tuInfoBean, currentProject);
    }
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Point(org.eclipse.swt.graphics.Point) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean) IProject(org.eclipse.core.resources.IProject)

Example 3 with TransUnitBean

use of net.heartsome.cat.ts.core.bean.TransUnitBean in project translationstudio8 by heartsome.

the class TerminologyViewPart method createAction.

/**
	 * 创建视图工具栏的按钮。
	 */
private void createAction() {
    firstAction = new Action() {

        @Override
        public void run() {
            if (rowIndex < 0) {
                return;
            }
            if (tempEditor == null || rowIndex < 0) {
                return;
            }
            TransUnitBean transUnit = tempEditor.getRowTransUnitBean(rowIndex);
            Hashtable<String, String> tuProp = transUnit.getTuProps();
            if (tuProp != null) {
                String translate = tuProp.get("translate");
                if (translate != null && translate.equalsIgnoreCase("no")) {
                    MessageDialog.openInformation(getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg1"));
                    return;
                }
            }
            String tarTerm = "";
            GridItem[] items = gridTable.getSelection();
            if (items.length <= 0) {
                return;
            } else {
                tarTerm = items[0].getText(2);
            }
            try {
                tempEditor.insertCell(rowIndex, tempEditor.getTgtColumnIndex(), tarTerm);
            // tempEditor.setFocus(); // 焦点给回编辑器
            } catch (ExecutionException e) {
                if (Constant.RUNNING_MODE == Constant.MODE_DEBUG) {
                    e.printStackTrace();
                }
                MessageDialog.openInformation(parent.getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg2") + e.getMessage());
            }
        }
    };
    firstAction.setText(Messages.getString("view.TerminologyViewPart.menu.inserttermtarget"));
    firstAction.setImageDescriptor(Activator.getIconDescriptor(ImageConstants.ACCPTE_TERM));
    firstAction.setToolTipText(Messages.getString("view.TerminologyViewPart.firstAction"));
    firstAction.setEnabled(false);
//getViewSite().getActionBars().getToolBarManager().add(firstAction);
}
Also used : Action(org.eclipse.jface.action.Action) TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) Hashtable(java.util.Hashtable) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with TransUnitBean

use of net.heartsome.cat.ts.core.bean.TransUnitBean in project translationstudio8 by heartsome.

the class TerminologyViewPart method selectionChanged.

/**
	 * 监听来自IHSEditor的选中改变事件。
	 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
	 *      org.eclipse.jface.viewers.ISelection)
	 */
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    // UNDO 每次启动程序后,术语匹配面板无法识别出术语。 2012-06-21
    if (part == null || selection == null) {
        return;
    }
    if (part instanceof IXliffEditor) {
        if (!part.equals(tempEditor)) {
            IXliffEditor editor = (IXliffEditor) part;
            tempEditor = editor;
            tempEditor = (IXliffEditor) part;
            FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
            IProject currProject = input.getFile().getProject();
            matcher.setCurrentProject(currProject);
        }
    } else {
        firstAction.setEnabled(false);
        return;
    }
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        firstAction.setEnabled(false);
        return;
    }
    IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
    Object object = structuredSelecion.getFirstElement();
    if (object instanceof Integer) {
        rowIndex = (Integer) object;
        IXliffEditor editor = (IXliffEditor) part;
        // handler.getTransUnit(rowId);
        TransUnitBean bean = editor.getRowTransUnitBean(rowIndex);
        String pureText = bean.getSrcText();
        srcLang = bean.getSrcLang();
        tgtLang = bean.getTgtLang();
        tgtLang = tgtLang == null || tgtLang.equals("") ? editor.getTgtColumnName() : tgtLang;
        srcLang = srcLang == null || "".equals(srcLang) ? editor.getSrcColumnName() : srcLang;
        if (srcLang == null || "".equals(srcLang) || tgtLang == null || "".equals(tgtLang)) {
            return;
        }
        Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
        Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
        if (srcLangL.isBidi() || tgtLangL.isBidi()) {
            gridTable.setOrientation(SWT.RIGHT_TO_LEFT);
        } else {
            gridTable.setOrientation(SWT.LEFT_TO_RIGHT);
        }
        srcTableColumn.setText(srcLang);
        tgtTableColumn.setText(tgtLang);
        loadData(pureText, srcLang, tgtLang, true);
    }
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) Language(net.heartsome.cat.common.locale.Language) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IProject(org.eclipse.core.resources.IProject)

Example 5 with TransUnitBean

use of net.heartsome.cat.ts.core.bean.TransUnitBean in project translationstudio8 by heartsome.

the class StatusPainter method getImages.

/**
	 * 通过LayerCell得到行号确定所要得到的TU对象,通过TU对象的各种属性确定其状态图片
	 * @param cell
	 * @param configRegistry
	 * @return ;
	 */
protected List<Map<Integer, Image>> getImages(LayerCell cell, IConfigRegistry configRegistry) {
    List<Map<Integer, Image>> images = new ArrayList<Map<Integer, Image>>();
    int index = cell.getLayer().getRowIndexByPosition(cell.getRowPosition());
    TransUnitBean tu = bodyDataProvider.getRowObject(index);
    String matchType = tu.getTgtProps().get("hs:matchType");
    machQuality = tu.getTgtProps().get("hs:quality");
    if (matchType != null && machQuality != null) {
        if (machQuality.endsWith("%")) {
            machQuality = machQuality.substring(0, machQuality.lastIndexOf("%"));
        }
        cellBackground = TmUtils.getMatchTypeColor(matchType, machQuality);
    }
    String approved = null;
    String translate = null;
    String state = null;
    String sendToTm = null;
    String needReview = null;
    int noteSize = 0;
    if (tu != null && tu.getTuProps() != null) {
        approved = tu.getTuProps().get("approved");
        sendToTm = tu.getTuProps().get("hs:send-to-tm");
        translate = tu.getTuProps().get("translate");
        needReview = tu.getTuProps().get("hs:needs-review");
        if (tu.getTgtProps() != null) {
            state = tu.getTgtProps().get("state");
        }
        if (tu.getNotes() != null) {
            noteSize = tu.getNotes().size();
        }
    }
    if (translate != null && "no".equals(translate)) {
        // 已锁定
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.LOCKED), 1);
    } else if (state != null && "signed-off".equals(state)) {
        // 已签发
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.SINGED_OFF), 1);
    } else if (approved != null && "yes".equals(approved)) {
        // 已批准
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.APPROVE), 1);
    } else if (state != null && "translated".equals(state)) {
        // 已翻译
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.TRANSLATED), 1);
    } else if (state != null && "new".equals(state)) {
        // 草稿
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.DRAFT), 1);
    } else {
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.EMPTY), 1);
    }
    if (sendToTm != null && ("no").equals(sendToTm)) {
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.DONT_ADDDB), 2);
    }
    if (needReview != null && "yes".equals(needReview)) {
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.HAS_QUESTION), 3);
    }
    if (noteSize > 0) {
        addImage(images, XliffEditorGUIHelper.getImage(ImageName.HAS_NOTE), 4);
    }
    return images;
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TransUnitBean (net.heartsome.cat.ts.core.bean.TransUnitBean)13 IProject (org.eclipse.core.resources.IProject)5 IEditorPart (org.eclipse.ui.IEditorPart)5 FileEditorInput (org.eclipse.ui.part.FileEditorInput)5 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)4 TransUnitInfo2TranslationBean (net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)4 Hashtable (java.util.Hashtable)3 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 Point (org.eclipse.swt.graphics.Point)3 AutoPilot (com.ximpleware.AutoPilot)2 NavException (com.ximpleware.NavException)2 VTDNav (com.ximpleware.VTDNav)2 XPathEvalException (com.ximpleware.XPathEvalException)2 XPathParseException (com.ximpleware.XPathParseException)2 HashMap (java.util.HashMap)2 AltTransBean (net.heartsome.cat.ts.core.bean.AltTransBean)2 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ModifyException (com.ximpleware.ModifyException)1