Search in sources :

Example 1 with SegmentViewer

use of net.heartsome.cat.ts.ui.innertag.SegmentViewer in project translationstudio8 by heartsome.

the class DeleteToEndOrToTagHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        String deleteType = event.getParameter("DeleteContent");
        if (deleteType == null) {
            return null;
        }
        StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
        if (cellEditor == null || !cellEditor.getCellType().equals(NatTableConstant.TARGET)) {
            return null;
        }
        if (!cellEditor.isEditable()) {
            // cellEditor.showUneditableMessage();
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteToEndOrToTagHandler.msgTitle"), cellEditor.getEditableManager().getUneditableMessage());
            return null;
        }
        StyledText styledText = cellEditor.getSegmentViewer().getTextWidget();
        int offset = styledText.getCaretOffset();
        Point p = styledText.getSelection();
        if (p != null) {
            int len = styledText.getText().length();
            String preText = "";
            String nextText = "";
            SegmentViewer viewer = (SegmentViewer) cellEditor.getSegmentViewer();
            if (offset > 0) {
                preText = styledText.getText(0, offset - 1);
                preText = viewer.convertDisplayTextToOriginalText(preText);
            }
            // 删除标记前所有内容
            if (deleteType.equals("DeleteToTag") && offset < len) {
                nextText = styledText.getText(offset, len - 1);
                Matcher matcher = PATTERN.matcher(nextText);
                if (matcher.find()) {
                    int index = matcher.start();
                    nextText = nextText.substring(index);
                } else {
                    // 选择删除标记前所有内容时,如果当前光标之后没有标记,则删除光标之后的所有内容
                    nextText = "";
                }
            }
            nextText = viewer.convertDisplayTextToOriginalText(nextText);
            String newText = preText + nextText;
            Hashtable<String, String> map = new Hashtable<String, String>();
            // Fix Bug #2883 删除光标后内容--同时选择多个文本段进行操作时,界面出错 By Jason
            // for (String rowId : xliffEditor.getSelectedRowIds()) {
            // map.put(rowId, newText);
            // }
            int index = cellEditor.getRowIndex();
            String rowId = xliffEditor.getXLFHandler().getRowId(index);
            map.put(rowId, newText);
            xliffEditor.updateSegments(map, xliffEditor.getTgtColumnIndex(), null, null);
            // 定位光标
            styledText.setCaretOffset(offset);
        }
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) StyledText(org.eclipse.swt.custom.StyledText) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) Matcher(java.util.regex.Matcher) Hashtable(java.util.Hashtable) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) Point(org.eclipse.swt.graphics.Point)

Example 2 with SegmentViewer

use of net.heartsome.cat.ts.ui.innertag.SegmentViewer in project translationstudio8 by heartsome.

the class MatchViewPart method createPartControl.

@Override
public void createPartControl(Composite parent) {
    GridLayout parentGl = new GridLayout(1, false);
    parentGl.marginWidth = 0;
    parentGl.marginHeight = 0;
    parent.setLayout(parentGl);
    final Composite composite = new Composite(parent, SWT.NONE);
    GridLayout compositeGl = new GridLayout(1, false);
    compositeGl.marginBottom = -1;
    compositeGl.marginLeft = -1;
    compositeGl.marginRight = -1;
    compositeGl.marginTop = 0;
    compositeGl.marginWidth = 0;
    compositeGl.marginHeight = 0;
    compositeGl.verticalSpacing = 0;
    composite.setLayout(compositeGl);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    // sourceText = new StyledText(composite, SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY);
    // GridData sTextGd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    // Font f = JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT);
    // sourceText.setFont(f);
    // int lineH = sourceText.getLineHeight() * 3;
    // sTextGd.heightHint = lineH;
    // sTextGd.minimumHeight = lineH;
    // sourceText.setLayoutData(sTextGd);
    SashForm sashForm = new SashForm(composite, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    sourceText = new SegmentViewer(sashForm, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL, null);
    StyledText srcTextControl = sourceText.getTextWidget();
    srcTextControl.setLineSpacing(net.heartsome.cat.ts.ui.Constants.SEGMENT_LINE_SPACING);
    srcTextControl.setLeftMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_LEFT_MARGIN);
    srcTextControl.setRightMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_RIGHT_MARGIN);
    srcTextControl.setTopMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_TOP_MARGIN);
    srcTextControl.setBottomMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_TOP_MARGIN);
    srcTextControl.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
    sourceText.setSource("");
    sourceColunmCellRenderer.setSegmentViewer(sourceText);
    GridData sTextGd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    Font f = JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT);
    srcTextControl.setFont(f);
    int lineH = srcTextControl.getLineHeight() * 2;
    sTextGd.heightHint = lineH;
    sTextGd.minimumHeight = lineH;
    srcTextControl.setLayoutData(sTextGd);
    net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(sourceText);
    gridTable = new Grid(sashForm, SWT.BORDER | SWT.V_SCROLL);
    gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    gridTable.setHeaderVisible(false);
    gridTable.setAutoHeight(true);
    gridTable.setRowsResizeable(true);
    gridTable.setData("selectedBgColor", selectedBgColor);
    final GridColumn sourceCln = new GridColumn(gridTable, SWT.NONE);
    sourceColunmCellRenderer.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
    sourceCln.setCellRenderer(sourceColunmCellRenderer);
    sourceCln.setText(Messages.getString("view.MatchViewPart.sourceCln"));
    sourceCln.setWordWrap(true);
    sourceCln.setAlignment(SWT.CENTER);
    sourceCln.setResizeable(false);
    final GridColumn typeCln = new GridColumn(gridTable, SWT.NONE);
    typeColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
    typeCln.setCellRenderer(typeColumnCellRenderer);
    typeCln.setText(Messages.getString("view.MatchViewPart.typeCln"));
    typeCln.setWordWrap(true);
    typeCln.setAlignment(SWT.CENTER);
    typeCln.setResizeable(false);
    final GridColumn targetCln = new GridColumn(gridTable, SWT.NONE);
    targetColumnCellRenderer.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
    targetCln.setCellRenderer(targetColumnCellRenderer);
    targetCln.setText(Messages.getString("view.MatchViewPart.targetCln"));
    targetCln.setWordWrap(true);
    targetCln.setAlignment(SWT.CENTER);
    targetCln.setResizeable(false);
    // 设置可复制功能
    copyEnable = new GridCopyEnable(gridTable);
    sourceColunmCellRenderer.setCopyEnable(copyEnable);
    targetColumnCellRenderer.setCopyEnable(copyEnable);
    Composite statusComposite = new Composite(composite, SWT.NONE);
    GridLayout statusComptGridLayout = new GridLayout(2, false);
    statusComptGridLayout.marginBottom = -1;
    statusComptGridLayout.marginLeft = -1;
    statusComptGridLayout.marginRight = -1;
    statusComptGridLayout.marginTop = -1;
    statusComptGridLayout.marginWidth = 0;
    statusComptGridLayout.marginHeight = 0;
    statusComposite.setLayout(statusComptGridLayout);
    statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tipLabel = new CLabel(statusComposite, SWT.NONE);
    tipLabel.setAlignment(SWT.LEFT);
    infoLabel = new CLabel(statusComposite, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd.heightHint = 20;
    infoLabel.setLayoutData(gd);
    infoLabel.setAlignment(SWT.RIGHT);
    // 设置列宽按比例4.5:1:4.5
    composite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle area = composite.getClientArea();
            Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            // - 2 * gridTable.getBorderWidth();
            int width = area.width;
            if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
                Point vBarSize = gridTable.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            gridTable.setSize(area.width, area.height);
            width = width - 42;
            sourceCln.setWidth((int) (width * 0.5));
            typeCln.setWidth(42);
            targetCln.setWidth((int) (width * 0.5));
        }
    });
    gridTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            StyledText text = sourceText.getTextWidget();
            text.setText(text.getText());
            updateActionState();
            GridItem[] selItems = gridTable.getSelection();
            if (selItems.length != 1) {
                return;
            }
            GridItem item = selItems[0];
            setMatchMessage(infoLabelImage, item.getData("info").toString(), item.getData("infoTooltip").toString());
            composite.layout();
        }
    });
    gridTable.addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            menuMgr.acceptMatchAction.run();
        }
    });
    createActions();
    sashForm.setWeights(new int[] { 3, 8 });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) StyledText(org.eclipse.swt.custom.StyledText) ISelectionListener(org.eclipse.ui.ISelectionListener) Listener(org.eclipse.swt.widgets.Listener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Grid(org.eclipse.nebula.widgets.grid.Grid) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GridCopyEnable(net.heartsome.cat.ts.ui.grid.GridCopyEnable) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 3 with SegmentViewer

use of net.heartsome.cat.ts.ui.innertag.SegmentViewer in project translationstudio8 by heartsome.

the class TmMatchEditDialog method createDialogArea.

/**
	 * Create contents of the dialog.
	 * @param parent
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new GridLayout(1, false));
    Group srcGroup = new Group(container, SWT.NONE);
    srcGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    srcGroup.setLayout(new GridLayout(1, false));
    String srcGroupTile = Messages.getString("dialog.TmMatchEditDialog.component.src");
    srcGroupTile = MessageFormat.format(srcGroupTile, fuzzyResult.getTu().getSource().getLangCode());
    srcGroup.setText(srcGroupTile);
    srcSegmentViewer = new SegmentViewer(srcGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL, null);
    StyledText srcTextControl = srcSegmentViewer.getTextWidget();
    srcTextControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    srcTextControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING);
    srcTextControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN);
    srcTextControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN);
    srcTextControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN);
    srcTextControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN);
    srcTextControl.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    Group targetGroup = new Group(container, SWT.NONE);
    targetGroup.setLayout(new GridLayout(1, false));
    targetGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    String tgtGroupTile = Messages.getString("dialog.TmMatchEditDialog.component.tgt");
    tgtGroupTile = MessageFormat.format(tgtGroupTile, fuzzyResult.getTu().getSource().getLangCode());
    targetGroup.setText(tgtGroupTile);
    tgtSegmentViewer = new SegmentViewer(targetGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL, null);
    StyledText tgtTextControl = tgtSegmentViewer.getTextWidget();
    tgtTextControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tgtTextControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING);
    tgtTextControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN);
    tgtTextControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN);
    tgtTextControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN);
    tgtTextControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN);
    tgtTextControl.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(srcSegmentViewer);
    net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(tgtSegmentViewer);
    TmMatchEditorBodyMenu srcMenu = new TmMatchEditorBodyMenu(srcSegmentViewer);
    srcSegmentViewer.getTextWidget().setMenu(srcMenu.getBodyMenu());
    TmMatchEditorBodyMenu tgtMenu = new TmMatchEditorBodyMenu(tgtSegmentViewer);
    tgtSegmentViewer.getTextWidget().setMenu(tgtMenu.getBodyMenu());
    loadData();
    return container;
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData)

Example 4 with SegmentViewer

use of net.heartsome.cat.ts.ui.innertag.SegmentViewer in project translationstudio8 by heartsome.

the class StyledTextCellEditor method createTextControl.

protected StyledText createTextControl(Composite parent) {
    TagStyleManager tagStyleManager = xliffEditor.getTagStyleManager();
    IStyle cellStyle = this.hsCellEditor.getCellStyle();
    int styled = HorizontalAlignmentEnum.getSWTStyle(cellStyle);
    styled |= SWT.MULTI | SWT.WRAP;
    viewer = new SegmentViewer(parent, styled, tagStyleManager.getTagStyle());
    // 添加标记样式改变监听
    // addTagStyleChangeListener();
    // 注册标记样式调节器
    net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(viewer);
    // TagStyleConfigurator.configure(viewer);
    // 将原来直接创建StyledText的方式改为由TextViewer提供
    final StyledText textControl = viewer.getTextWidget();
    initStyle(textControl, cellStyle);
    textControl.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent e) {
        }

        public void focusGained(FocusEvent e) {
            getActionHandler().updateGlobalActionHandler();
        }
    });
    viewer.getDocument().addDocumentListener(new IDocumentListener() {

        public void documentChanged(DocumentEvent e) {
            // 自动行高
            autoResize();
        }

        public void documentAboutToBeChanged(DocumentEvent event) {
        }
    });
    // 实现编辑模式下添加右键菜单
    // dispose textControl前应去掉右键menu,因为右键menu是和nattable共享的,不能在这儿dispose,说见close()方法
    final Menu menu = (Menu) xliffEditor.getTable().getData(Menu.class.getName());
    textControl.setMenu(menu);
    return textControl;
}
Also used : IStyle(net.sourceforge.nattable.style.IStyle) ISegmentViewer(net.heartsome.cat.ts.ui.innertag.ISegmentViewer) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) StyledText(org.eclipse.swt.custom.StyledText) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Menu(org.eclipse.swt.widgets.Menu) DocumentEvent(org.eclipse.jface.text.DocumentEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

SegmentViewer (net.heartsome.cat.ts.ui.innertag.SegmentViewer)4 StyledText (org.eclipse.swt.custom.StyledText)4 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Hashtable (java.util.Hashtable)1 Matcher (java.util.regex.Matcher)1 GridCopyEnable (net.heartsome.cat.ts.ui.grid.GridCopyEnable)1 ISegmentViewer (net.heartsome.cat.ts.ui.innertag.ISegmentViewer)1 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)1 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)1 IStyle (net.sourceforge.nattable.style.IStyle)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IDocumentListener (org.eclipse.jface.text.IDocumentListener)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 Grid (org.eclipse.nebula.widgets.grid.Grid)1 GridColumn (org.eclipse.nebula.widgets.grid.GridColumn)1 GridItem (org.eclipse.nebula.widgets.grid.GridItem)1