Search in sources :

Example 6 with NoteBean

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

the class XLFHandler method deleteNote.

/**
	 * 删除批注
	 * @param rowId
	 *            行的唯一标识
	 * @param note
	 *            批注;
	 */
public void deleteNote(final HashMap<String, Vector<NoteBean>> mapNote) {
    HashMap<String, List<String>> mapRowIdAndXpath = new HashMap<String, List<String>>();
    Iterator<Entry<String, Vector<NoteBean>>> it = mapNote.entrySet().iterator();
    List<String> lstRowId = new ArrayList<String>();
    while (it.hasNext()) {
        Entry<String, Vector<NoteBean>> entry = (Entry<String, Vector<NoteBean>>) it.next();
        String rowId = entry.getKey();
        String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
        for (NoteBean bean : entry.getValue()) {
            String from = bean.getFrom();
            String applyCurrent = bean.getApplyCurrent();
            StringBuffer subXPath = new StringBuffer();
            if (from != null && !from.equals("")) {
                subXPath.append("@from='").append(from).append("' and ");
            }
            // 只有是所有句段时才加该属性
            if (applyCurrent != null && applyCurrent.equalsIgnoreCase("No")) {
                subXPath.append("@hs:apply-current='").append(applyCurrent).append("' and ");
            }
            subXPath.insert(0, "/note[");
            subXPath.append("text()='");
            if (bean.getApplyCurrent().equals("Yes")) {
                List<String> lstXpath = mapRowIdAndXpath.get(rowId);
                if (lstXpath == null) {
                    lstXpath = new ArrayList<String>();
                    mapRowIdAndXpath.put(rowId, lstXpath);
                }
                subXPath.insert(0, tuXPath);
                subXPath.append(bean.getNoteText()).append("']");
                lstXpath.add(subXPath.toString());
                if (!lstRowId.contains(rowId)) {
                    lstRowId.add(rowId);
                }
            } else {
                // 删除所有句段的批注
                List<String> rowIds = getRowIds();
                if (!lstRowId.containsAll(rowIds)) {
                    lstRowId.clear();
                    lstRowId.addAll(rowIds);
                }
                for (String strRowId : rowIds) {
                    StringBuffer strTuXPath = new StringBuffer(RowIdUtil.parseRowIdToXPath(strRowId));
                    List<String> lstXpath = mapRowIdAndXpath.get(strRowId);
                    if (lstXpath == null) {
                        lstXpath = new ArrayList<String>();
                        mapRowIdAndXpath.put(strRowId, lstXpath);
                    }
                    lstXpath.add(strTuXPath.append(subXPath).append(bean.getNoteText()).append("']").toString());
                }
            }
        }
    }
    XMLModifier xm = new XMLModifier();
    VTDUtils vu = new VTDUtils();
    Map<String, List<String>> map = RowIdUtil.groupRowIdByFileName(lstRowId);
    Iterator<Entry<String, List<String>>> iterator = map.entrySet().iterator();
    try {
        while (iterator.hasNext()) {
            Entry<String, List<String>> entry = (Entry<String, List<String>>) iterator.next();
            String fileName = entry.getKey();
            VTDNav vn = vnMap.get(fileName);
            xm.bind(vn);
            vu.bind(vn);
            List<String> rowIdList = entry.getValue();
            for (String rowId : rowIdList) {
                List<String> lstXpath = mapRowIdAndXpath.get(rowId);
                if (lstXpath != null) {
                    AutoPilot ap = new AutoPilot(vu.getVTDNav());
                    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
                    for (String xpath : lstXpath) {
                        xm = vu.delete(ap, xm, xpath);
                    }
                }
            }
            saveAndReparse(xm, fileName);
        }
    } catch (ModifyException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) NavException(com.ximpleware.NavException) Entry(java.util.Map.Entry) NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) ModifyException(com.ximpleware.ModifyException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Vector(java.util.Vector) VTDNav(com.ximpleware.VTDNav)

Example 7 with NoteBean

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

the class DeleteSelectionSegmentNotesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg1"));
    if (res) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        XLFHandler handler = xliffEditor.getXLFHandler();
        List<String> lstRowId = xliffEditor.getSelectedRowIds();
        // 先将应用范围为当前文本段的批注删除
        handler.deleteEditableSegmentNote(lstRowId);
        try {
            HashMap<String, Vector<NoteBean>> mapNote = new HashMap<String, Vector<NoteBean>>();
            for (String rowId : lstRowId) {
                // 删除应用范围为所有文本段的批注
                Vector<NoteBean> noteBeans = xliffEditor.getXLFHandler().getNotes(rowId);
                if (noteBeans != null && noteBeans.size() > 0) {
                    mapNote.put(rowId, noteBeans);
                }
            }
            xliffEditor.getXLFHandler().deleteNote(mapNote);
        } catch (NavException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } catch (XPathParseException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } catch (XPathEvalException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } finally {
            xliffEditor.refresh();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) HashMap(java.util.HashMap) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) IEditorPart(org.eclipse.ui.IEditorPart) XPathParseException(com.ximpleware.XPathParseException) NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) Vector(java.util.Vector) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 8 with NoteBean

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

the class MouseEditAction method run.

public void run(NatTable natTable, MouseEvent event) {
    XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent();
    if (xliffEditor == null) {
        return;
    }
    int columnPosition = natTable.getColumnPositionByX(event.x);
    int rowPosition = natTable.getRowPositionByY(event.y);
    boolean withShiftMask = (event.stateMask & SWT.SHIFT) != 0;
    boolean withCtrlMask = (event.stateMask & SWT.CTRL) != 0;
    if (!xliffEditor.isHorizontalLayout() && rowPosition != HsMultiActiveCellEditor.targetRowPosition && (rowPosition != HsMultiActiveCellEditor.sourceRowPosition || columnPosition != xliffEditor.getSrcColumnIndex())) {
        HsMultiActiveCellEditor.commit(true);
        natTable.doCommand(new SelectCellCommand(natTable, columnPosition, rowPosition, withShiftMask, withCtrlMask));
        if (columnPosition == xliffEditor.getTgtColumnIndex()) {
            HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
        }
    } else if (rowPosition != HsMultiActiveCellEditor.targetRowPosition || columnPosition != xliffEditor.getSrcColumnIndex() || columnPosition != xliffEditor.getTgtColumnIndex()) {
        HsMultiActiveCellEditor.commit(true);
        natTable.doCommand(new SelectCellCommand(natTable, columnPosition, rowPosition, withShiftMask, withCtrlMask));
        if (columnPosition == xliffEditor.getSrcColumnIndex() || columnPosition == xliffEditor.getTgtColumnIndex()) {
            HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
        }
    }
    // 点击批注图片时打开编辑批注对话框
    Image image = XliffEditorGUIHelper.getImage(ImageName.HAS_NOTE);
    // int columnPosition = natTable.getColumnPositionByX(event.x);
    // int rowPosition = natTable.getRowPositionByY(event.y);
    LayerCell cell = natTable.getCellByPosition(columnPosition, rowPosition);
    Rectangle imageBounds = image.getBounds();
    if (cell == null) {
        return;
    }
    Rectangle cellBounds = cell.getBounds();
    int x = cellBounds.x + imageBounds.width * 3 + 20;
    int y = cellBounds.y + CellStyleUtil.getVerticalAlignmentPadding(CellStyleUtil.getCellStyle(cell, natTable.getConfigRegistry()), cellBounds, imageBounds.height);
    if (columnPosition == xliffEditor.getStatusColumnIndex() && event.x >= x && event.x <= (x + imageBounds.width) && event.y >= y && event.y <= (y + imageBounds.height)) {
        if ((xliffEditor.isHorizontalLayout() && columnPosition == 2) || (!xliffEditor.isHorizontalLayout() && columnPosition == 1)) {
            Vector<NoteBean> noteBeans = null;
            try {
                int rowIndex = natTable.getRowIndexByPosition(rowPosition);
                if (!xliffEditor.isHorizontalLayout()) {
                    rowIndex = rowIndex / VerticalNatTableConfig.ROW_SPAN;
                }
                noteBeans = xliffEditor.getXLFHandler().getNotes(xliffEditor.getXLFHandler().getRowId(rowIndex));
                if (noteBeans != null && noteBeans.size() > 0) {
                    UpdateNoteDialog dialog = new UpdateNoteDialog(xliffEditor.getSite().getShell(), xliffEditor, rowIndex);
                    dialog.open();
                }
            } catch (NavException e) {
                e.printStackTrace();
            } catch (XPathParseException e) {
                e.printStackTrace();
            } catch (XPathEvalException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) Image(org.eclipse.swt.graphics.Image) XPathParseException(com.ximpleware.XPathParseException) NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) UpdateNoteDialog(net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.UpdateNoteDialog)

Example 9 with NoteBean

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

the class UpdateNoteDialog method initListener.

private void initListener() {
    btnAdd.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            AddOrUpdateNoteDialog dialog = new AddOrUpdateNoteDialog(getShell(), xliffEditor, AddOrUpdateNoteDialog.DIALOG_ADD, null);
            if (dialog.open() == Window.OK) {
                initTable();
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnEdit.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (tableViewer.getTable().getSelectionCount() != 1) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateNoteDialog.msgTitle1"), Messages.getString("dialog.UpdateNoteDialog.msg2"));
                return;
            }
            TableItem item = tableViewer.getTable().getSelection()[0];
            String[] arrNoteItem = new String[] { item.getText(0), item.getText(1), item.getText(2), item.getText(3), item.getText(4) };
            AddOrUpdateNoteDialog dialog = new AddOrUpdateNoteDialog(getShell(), xliffEditor, AddOrUpdateNoteDialog.DIALOG_EDIT, arrNoteItem);
            if (dialog.open() == Window.OK) {
                initTable();
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnDelete.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = tableViewer.getTable().getSelection();
            if (items.length == 0) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateNoteDialog.msgTitle1"), Messages.getString("dialog.UpdateNoteDialog.msg3"));
                return;
            }
            if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.UpdateNoteDialog.msgTitle2"), Messages.getString("dialog.UpdateNoteDialog.msg4"))) {
                Vector<NoteBean> lstBeans = new Vector<NoteBean>();
                for (TableItem item : items) {
                    String date = item.getText(2);
                    String noteText = "";
                    if (date != null && !date.equals("")) {
                        noteText += date + ":";
                    }
                    NoteBean bean = new NoteBean(noteText + item.getText(3));
                    bean.setFrom(item.getText(1));
                    String strApplyCurrent = item.getText(4);
                    strApplyCurrent = strApplyCurrent.equals(NatTableConstant.CURRENT_TEXT) ? "Yes" : "No";
                    bean.setApplyCurrent(strApplyCurrent);
                    lstBeans.add(bean);
                }
                HashMap<String, Vector<NoteBean>> mapNote = new HashMap<String, Vector<NoteBean>>();
                mapNote.put(xliffEditor.getXLFHandler().getRowId(rowIndex), lstBeans);
                xliffEditor.getXLFHandler().deleteNote(mapNote);
                initTable();
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) HashMap(java.util.HashMap) TableItem(org.eclipse.swt.widgets.TableItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Vector(java.util.Vector) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

NoteBean (net.heartsome.cat.ts.core.bean.NoteBean)9 Vector (java.util.Vector)6 AutoPilot (com.ximpleware.AutoPilot)5 VTDNav (com.ximpleware.VTDNav)5 NavException (com.ximpleware.NavException)4 XPathEvalException (com.ximpleware.XPathEvalException)3 XPathParseException (com.ximpleware.XPathParseException)3 HashMap (java.util.HashMap)3 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)3 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)2 ModifyException (com.ximpleware.ModifyException)1 XMLModifier (com.ximpleware.XMLModifier)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 UpdateNoteDialog (net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.UpdateNoteDialog)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1