예제 #1
0
 @Override
 public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
   if (oldState != null && oldState.size() > 0) {
     handler.changeTgtPropValue(oldState, "state");
     table.redraw();
   }
   return Status.OK_STATUS;
 }
예제 #2
0
 /**
  * “修改状态“操作
  *
  * @param label 操作名
  * @param natTable NatTable对象
  * @param rowIdList RowId集合
  * @param handler XLFHandler对象
  * @param state 状态值(Target节点的state属性的值)
  */
 public StateOperation(
     String label, NatTable natTable, List<String> rowIdList, XLFHandler handler, String state) {
   super(label);
   IUndoContext context = (IUndoContext) natTable.getData(IUndoContext.class.getName());
   addContext(context);
   this.table = natTable;
   this.rowIdList = rowIdList;
   this.handler = handler;
   this.state = state;
   this.oldState = handler.getTgtPropValue(rowIdList, "state");
 }
예제 #3
0
 @Override
 public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
   if (rowIdList != null && rowIdList.size() > 0) {
     handler.changeTgtPropValue(rowIdList, "state", state);
     if (state.equals("translated") || state.equals("new")) { // 切换到已翻译或草稿状态
       handler.deleteTuProp(rowIdList, "approved");
     }
     if (state.equals("signed-off")) {
       handler.changeTuPropValue(rowIdList, "approved", "yes");
     }
     table.redraw();
   }
   return Status.OK_STATUS;
 }
  public static void activeSourceAndTargetCell(XLIFFEditorImplWithNatTable xliffEditor) {
    if (xliffEditor == null) {
      return;
    }
    int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
      return;
    }
    Arrays.sort(selectedRowIndexs);
    int rowIndex = selectedRowIndexs[selectedRowIndexs.length - 1];
    if (!xliffEditor.isHorizontalLayout()) {
      rowIndex = rowIndex * 2; // source index
    }

    NatTable natTable = xliffEditor.getTable();
    IConfigRegistry configRegistry = natTable.getConfigRegistry();
    ViewportLayer vLayer = LayerUtil.getLayer(natTable, ViewportLayer.class);
    int rowPosition = vLayer.getRowPositionByIndex(rowIndex);
    rowPosition += 1;
    if (rowPosition < 1) {
      return;
    }

    int columnIndex = xliffEditor.getSrcColumnIndex();
    HsMultiCellEditor srcCellEditor =
        activeCell(
            vLayer,
            xliffEditor,
            configRegistry,
            columnIndex,
            rowIndex,
            rowPosition,
            NatTableConstant.SOURCE);
    if (srcCellEditor == null) {
      return;
    }

    if (!xliffEditor.isHorizontalLayout()) {
      rowIndex = rowIndex + 1; // target
      rowPosition = vLayer.getRowPositionByIndex(rowIndex);
      rowPosition += 1;
      if (rowPosition < 1) {
        return;
      }
    }
    columnIndex = xliffEditor.getTgtColumnIndex();
    HsMultiCellEditor tgtCellEditor =
        activeCell(
            vLayer,
            xliffEditor,
            configRegistry,
            columnIndex,
            rowIndex,
            rowPosition,
            NatTableConstant.TARGET);
    if (tgtCellEditor == null) {
      return;
    }
    HsMultiActiveCellEditor.activateCellEditors(srcCellEditor, tgtCellEditor, natTable);

    // 目标文本段一进入焦点就进行一次拼写检查 robert 2013-01-22
    // UNDO 这里错误单词提示并没有修改颜色。
    String tgtLang = xliffEditor.getTgtColumnName();
    spellTrigger = RealTimeSpellCheckTrigger.getInstance();
    if (spellTrigger != null && spellTrigger.checkSpellAvailable(tgtLang)) {
      tgtTextFirstRealTimeSpellCheck(tgtLang, tgtCellEditor);
      tgtTextRealTimeSpellCheck(tgtLang, tgtCellEditor);
    }
    List<String> terms = xliffEditor.getTermsCache().get(selectedRowIndexs[0]);
    if (terms != null && terms.size() > 0) {
      srcCellEditor.highlightedTerms(terms);
    }
  }
  private static HsMultiCellEditor activeCell(
      ViewportLayer vLayer,
      XLIFFEditorImplWithNatTable xliffEditor,
      IConfigRegistry configRegistry,
      int columnIndex,
      int rowIndex,
      int rowPosition,
      String cellType) {
    NatTable natTable = xliffEditor.getTable();
    int columnPosition = vLayer.getColumnPositionByIndex(columnIndex);

    LayerCell cell = natTable.getCellByPosition(columnPosition, rowPosition);
    if (cell == null) {
      return null;
    }
    Rectangle cellBounds = cell.getBounds();
    List<String> configLabels = cell.getConfigLabels().getLabels();
    if (!xliffEditor.isHorizontalLayout()) {
      if (cellType.equals(NatTableConstant.SOURCE)) {
        configLabels.remove(XLIFFEditorImplWithNatTable.TARGET_EDIT_CELL_LABEL);
      } else if (cellType.equals(NatTableConstant.TARGET)) {
        configLabels.remove(XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
      }
    }
    ILayer layer = cell.getLayer();
    Object originalCanonicalValue = cell.getDataValue();

    IDisplayConverter displayConverter =
        configRegistry.getConfigAttribute(
            CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels);
    IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels);
    IDataValidator dataValidator =
        configRegistry.getConfigAttribute(
            EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels);

    Rectangle editorBounds =
        layer
            .getLayerPainter()
            .adjustCellBounds(
                new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));

    int cellStartY = cellBounds.y;
    int cellEndY = cellStartY + cellBounds.height;
    Rectangle clientArea = natTable.getClientAreaProvider().getClientArea();
    int clientAreaEndY = clientArea.y + clientArea.height;
    if (cellEndY > clientAreaEndY) {
      editorBounds.height = clientAreaEndY - cellStartY;
    }

    StyledTextCellEditor cellEditor =
        (StyledTextCellEditor)
            configRegistry.getConfigAttribute(
                EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
    ICellEditHandler editHandler = new HsMultiCellEditorHandler(cellEditor, layer);

    HsMultiCellEditor hsCellEditor =
        new HsMultiCellEditor(
            cellType,
            cellEditor,
            editHandler,
            columnPosition,
            rowPosition,
            columnIndex,
            rowIndex,
            dataValidator,
            originalCanonicalValue,
            displayConverter,
            cellStyle,
            editorBounds);

    return hsCellEditor;
  }