Search in sources :

Example 1 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class DefaultGridLayer method init.

protected void init(IUniqueIndexLayer bodyDataLayer, IUniqueIndexLayer columnHeaderDataLayer, IUniqueIndexLayer rowHeaderDataLayer, IUniqueIndexLayer cornerDataLayer) {
    // Body
    this.bodyDataLayer = bodyDataLayer;
    DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(bodyDataLayer);
    SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    // Column header
    this.columnHeaderDataLayer = columnHeaderDataLayer;
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, selectionLayer);
    // Row header
    this.rowHeaderDataLayer = rowHeaderDataLayer;
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, selectionLayer);
    // Corner
    this.cornerDataLayer = cornerDataLayer;
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
    setBodyLayer(bodyLayer);
    setColumnHeaderLayer(columnHeaderLayer);
    setRowHeaderLayer(rowHeaderLayer);
    setCornerLayer(cornerLayer);
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) ILayer(net.sourceforge.nattable.layer.ILayer) DefaultBodyLayerStack(net.sourceforge.nattable.layer.stack.DefaultBodyLayerStack)

Example 2 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class SelectionSearchStrategy method executeSearch.

public PositionCoordinate executeSearch(Object valueToMatch) {
    ILayer contextLayer = getContextLayer();
    if (!(contextLayer instanceof SelectionLayer)) {
        throw new RuntimeException("For the GridSearchStrategy to work it needs the selectionLayer to be passed as the contextLayer.");
    }
    SelectionLayer selectionLayer = (SelectionLayer) contextLayer;
    PositionCoordinate coordinate = CellDisplayValueSearchUtil.findCell(selectionLayer, configRegistry, getSelectedCells(selectionLayer), valueToMatch, getComparator(), isCaseSensitive());
    return coordinate;
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) ILayer(net.sourceforge.nattable.layer.ILayer) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 3 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class PopupMenuAction method run.

@Override
public void run(NatTable natTable, MouseEvent event) {
    //		ActiveCellEditor.commit(); // 执行弹出菜单前先关闭编辑模式的单元格
    super.run(natTable, event);
    if (selectionLayer == null) {
        selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
    }
    int rowIndex = natTable.getRowIndexByPosition(getGridRowPosition());
    XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
    if (!editor.isHorizontalLayout()) {
        rowIndex = rowIndex / 2;
    }
    // 如果该行已经选中的了,直接显示出右键菜单。
    if (!isSelected(rowIndex)) {
        HsMultiActiveCellEditor.commit(true);
        natTable.doCommand(new SelectCellCommand(natTable, getGridColumnPosition(), getGridRowPosition(), isWithShiftMask(), isWithControlMask()));
        HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
    }
    menu.setData(event.data);
    menu.setVisible(true);
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand)

Example 4 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class MergePreviousHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
    if (selectedRowIds.size() < 1) {
        return null;
    }
    String rowId = selectedRowIds.get(0);
    XLFHandler handler = xliffEditor.getXLFHandler();
    int rowIndex = handler.getRowIndex(rowId);
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    if (rowIndex == 0) {
        // 是第一行
        MessageDialog.openWarning(window.getShell(), "", "不存在上一文本段,不能合并。");
        return null;
    }
    String rowId2 = handler.getRowId(rowIndex - 1);
    if (handler.isApproved(rowId) || handler.isApproved(rowId2)) {
        MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。");
        return null;
    }
    String fileName1 = RowIdUtil.getFileNameByRowId(rowId);
    String fileName2 = RowIdUtil.getFileNameByRowId(rowId2);
    if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) {
        MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。");
        return null;
    }
    //		IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    //		try {
    //			operationHistory.execute(new MergeSegmentOperation("Merge Segment", xliffEditor, handler,
    //					rowIndex - 1), null, null);
    //		} catch (ExecutionException e) {
    //			e.printStackTrace();
    //		}
    // 选中上一行
    SelectionLayer selectionLayer = LayerUtil.getLayer(xliffEditor.getTable(), SelectionLayer.class);
    selectionLayer.selectRow(0, rowIndex - 1, false, false);
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 5 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method updateStatusLine.

/**
	 * 在状态栏上显示被编辑文件的信息。
	 */
public void updateStatusLine() {
    if (table == null || table.isDisposed()) {
        return;
    }
    SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    ViewportLayer viewportLayer = bodyLayer.getViewportLayer();
    PositionCoordinate cellPosition = selectionLayer.getLastSelectedCellPosition();
    if (cellPosition == null) {
        return;
    }
    // int order = LayerUtil.convertRowPosition(selectionLayer, cellPosition.rowPosition, viewportLayer);
    // Bug #2317:选中文本段后排序,不会刷新状态栏中的序号
    int[] selectedRowPostions = selectionLayer.getFullySelectedRowPositions();
    if (selectedRowPostions.length <= 0) {
        return;
    }
    // 刷新选中行的术语,使其排序后保持高亮显示
    // if (!isHorizontalLayout()) {
    // int rowPosition = selectedRowPostions[0];
    // rowPosition *= VerticalNatTableConfig.ROW_SPAN;
    // cellPosition.set(rowPosition, cellPosition.getColumnPosition());
    // } else {
    // cellPosition.set(selectedRowPostions[0], cellPosition.getColumnPosition());
    // }
    // if (!FindReplaceDialog.isOpen) {
    // CellRegion cellRegion = new CellRegion(cellPosition, new Region(0, selectionLayer.getWidth()));
    // ActiveCellRegion.setActiveCellRegion(cellRegion);
    // }
    int order = LayerUtil.convertRowPosition(selectionLayer, selectedRowPostions[0], viewportLayer);
    order += viewportLayer.getOriginRowPosition() + 1;
    // 垂直布局时order需要进行两行递增的处理
    if (!isHorizontalLayout) {
        order = (int) Math.ceil(order / 2.0);
    }
    MessageFormat messageFormat = null;
    if (order > 0) {
        /* 一个Xliff文件,可能有多个File节点,这里使用File结点的original属性 */
        /* 当前文件:{0} | 顺序号:{1} | 可见文本段数:{2} | 文本段总数:{3} | 当前用户名" */
        messageFormat = new MessageFormat(Messages.getString("editor.XLIFFEditorImplWithNatTable.messageFormat1"));
    } else {
        messageFormat = new MessageFormat(Messages.getString("editor.XLIFFEditorImplWithNatTable.messageFormat2"));
    }
    String fileName = "";
    // 添加 Project Name
    IEditorInput editorInput = getEditorInput();
    String filePath = "";
    if (isMultiFile()) {
        if (getSelectedRowIds().size() > 0) {
            filePath = RowIdUtil.getFileNameByRowId(getSelectedRowIds().get(0));
            fileName = ResourceUtils.toWorkspacePath(filePath);
        }
    } else {
        fileName = getEditorInput().getName();
        if (editorInput instanceof FileEditorInput) {
            FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
            filePath = fileEditorInput.getFile().getLocation().toOSString();
            fileName = fileEditorInput.getFile().getFullPath().toOSString();
        }
    }
    String systemUser = Activator.getDefault().getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
    int editableTuSum = handler.countEditableTransUnit();
    int tuSum = handler.countTransUnit();
    // int translatedSum1 = handler
    // .getNodeCount(filePath,
    // "/xliff/file/body/trans-unit[@approved = 'yes' and target/@state != 'translated' and target/@state != 'signed-off']");
    // int translatedSum2 = handler.getNodeCount(filePath,
    // "/xliff/file/body/trans-unit/target[@state = 'translated' or @state = 'signed-off']");
    // int approveSum1 = handler.getNodeCount(filePath,
    // "/xliff/file/body/trans-unit[not(@approved='yes') and target/@state='signed-off']");
    // int approveSum2 = handler.getNodeCount(filePath, "/xliff/file/body/trans-unit[@approved = 'yes']");
    int translatedSum = handler.getTranslatedCount();
    int approveedSum = handler.getApprovedCount();
    int approveP = (int) Math.floor(approveedSum / (double) tuSum * 100.00);
    int translatedP = (int) Math.floor(translatedSum / (double) tuSum * 100.00);
    translationItem.setProgressValue(translatedP);
    approveItem.setProgressValue(approveP);
    // 将信息显示在状态栏
    String message = messageFormat.format(new String[] { fileName, String.valueOf(order), String.valueOf(editableTuSum), String.valueOf(tuSum), systemUser });
    statusLineManager.setMessage(statusLineImage, message);
}
Also used : MessageFormat(java.text.MessageFormat) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) FileEditorInput(org.eclipse.ui.part.FileEditorInput) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) HorizontalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) VerticalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer) Point(org.eclipse.swt.graphics.Point) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput)

Aggregations

SelectionLayer (net.sourceforge.nattable.selection.SelectionLayer)11 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)5 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)3 ILayer (net.sourceforge.nattable.layer.ILayer)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)2 ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)2 MessageFormat (java.text.MessageFormat)1 ArrayList (java.util.ArrayList)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)1 HorizontalViewportLayer (net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer)1 VerticalViewportLayer (net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 DefaultBodyLayerStack (net.sourceforge.nattable.layer.stack.DefaultBodyLayerStack)1 ICellPainter (net.sourceforge.nattable.painter.cell.ICellPainter)1 RowSelectionEvent (net.sourceforge.nattable.selection.event.RowSelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IURIEditorInput (org.eclipse.ui.IURIEditorInput)1