Esempio n. 1
0
 /**
  * Adds an undone NullOperation (i.e. has no effects on executing, undoing or redoing) to the
  * Eclipse IOperationHistory to be sure that redoing is possible. This is necessary for the UI
  * Redo possibility being activated.
  */
 protected void simulateUndo() {
   IUndoableOperation auxOp = new NullOperation();
   try {
     auxOp.addContext(context);
     eclipseHistory.execute(auxOp, null, null);
     eclipseHistory.undo(context, null, null);
     if (!eclipseHistory.canRedo(context)) log.error("Simulating Undo failed");
   } catch (ExecutionException e) {
     log.error("Simulating Undo failed");
   }
 }
Esempio n. 2
0
 /**
  * Execute the passed Runnable within a command
  *
  * @param label
  * @param command
  */
 public static void exec(TransactionalEditingDomain domain, String label, final Runnable command) {
   // do works, undo does not (but is selectable in Papyrus Model explorer)
   IOperationHistory history = OperationHistoryFactory.getOperationHistory();
   try {
     history.execute(
         new AbstractTransactionalCommand(domain, label, Collections.EMPTY_LIST) {
           @Override
           public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) {
             command.run();
             return CommandResult.newOKCommandResult();
           }
         },
         null,
         null);
   } catch (ExecutionException e) {
     e.printStackTrace();
   }
 }
Esempio n. 3
0
 @Test
 public void testBug357516_bookmark() throws Exception {
   IResource resource = editor.getResource();
   HashMap<String, Object> attributes = new HashMap<String, Object>();
   attributes.put(IMarker.MESSAGE, CUSTOM_MARKER_TEST_MESSAGE);
   attributes.put(IMarker.LINE_NUMBER, 1);
   attributes.put(IMarker.LOCATION, resource.getFullPath().toPortableString());
   IUndoableOperation operation =
       new CreateMarkersOperation(
           IMarker.BOOKMARK, attributes, resource, CUSTOM_MARKER_TEST_MESSAGE);
   IOperationHistory operationHistory =
       PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
   try {
     operationHistory.execute(operation, null, null);
   } catch (ExecutionException x) {
     fail(x.getMessage());
   }
   String hoverInfo = hover.getHoverInfo(editor.getInternalSourceViewer(), 0);
   assertNotNull(hoverInfo);
   assertTrue(hoverInfo.contains(CUSTOM_MARKER_TEST_MESSAGE));
 }
Esempio n. 4
0
 /**
  * 设置是否添加到记忆库
  *
  * @param selectedRowIds
  * @param state "yes" or "no";
  */
 public void changeSendToTmState(List<String> selectedRowIds, String state) {
   IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
   try {
     operationHistory.execute(
         new SendTOTmOperation(
             "send-to-tm",
             xliffEditor.getTable(),
             selectedRowIds,
             xliffEditor.getXLFHandler(),
             state),
         null,
         null);
   } catch (ExecutionException e) {
     LOGGER.error("", e);
     MessageDialog.openError(
         xliffEditor.getSite().getShell(),
         Messages.getString("utils.NattableUtil.msgTitle2"),
         e.getMessage());
     e.printStackTrace();
   }
 }
Esempio n. 5
0
  /** 合并文本段 ; */
  public void mergeSegment() {
    XLFHandler handler = xliffEditor.getXLFHandler();
    List<String> lstRowId = xliffEditor.getSelectedRowIds();
    List<String> lstAllRowId = xliffEditor.getXLFHandler().getAllRowIds();
    Shell shell = xliffEditor.getSite().getShell();
    if (lstRowId.size() < 2) {
      MessageDialog.openInformation(
          shell,
          Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"),
          Messages.getString("utils.NattableUtil.mergeSegment.msg1"));
      return;
    }
    Collections.sort(lstRowId, new SortRowIdComparator());
    Collections.sort(lstAllRowId, new SortRowIdComparator());
    String rowId1 = lstRowId.get(0);
    String fileName = RowIdUtil.getFileNameByRowId(rowId1);
    if (fileName == null) {
      return;
    }
    if (handler.isLocked(rowId1)) {
      MessageDialog.openInformation(
          shell,
          Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"),
          Messages.getString("utils.NattableUtil.mergeSegment.msg3"));
      return;
    }
    for (int i = 1; i < lstRowId.size(); i++) {
      String rowId = lstRowId.get(i);
      if (handler.isLocked(rowId)) {
        MessageDialog.openInformation(
            shell,
            Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"),
            Messages.getString("utils.NattableUtil.mergeSegment.msg3"));
        return;
      }
      String fileName2 = RowIdUtil.getFileNameByRowId(rowId);
      // 数组集合必须在一个文件中才能合并
      if (fileName2 == null || !fileName.equals(fileName2)) {
        MessageDialog.openInformation(
            shell,
            Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"),
            Messages.getString("utils.NattableUtil.mergeSegment.msg4"));
        return;
      }
      // 判断所选文本段是否连续
      String strCurTuId = RowIdUtil.getTUIdByRowId(rowId);
      String strPreTuId = RowIdUtil.getTUIdByRowId(lstRowId.get(i - 1));
      if (strCurTuId == null || strPreTuId == null) {
        return;
      }

      if ((lstAllRowId.indexOf(rowId) - lstAllRowId.indexOf(lstRowId.get(i - 1))) != 1) {
        MessageDialog.openInformation(
            shell,
            Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"),
            Messages.getString("utils.NattableUtil.mergeSegment.msg5"));
        return;
      } else {
        String curOriginal = RowIdUtil.getOriginalByRowId(rowId);
        String preOriginal = RowIdUtil.getOriginalByRowId(lstRowId.get(i - 1));
        if (!curOriginal.equals(preOriginal)) {
          MessageDialog.openInformation(
              shell,
              Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"),
              Messages.getString("utils.NattableUtil.mergeSegment.msg5"));
          return;
        }
      }
    }

    // Bug #2373:选择全部文本段合并后,无显示内容
    if (lstRowId.size() == xliffEditor.getXLFHandler().getRowIds().size()) {
      xliffEditor.jumpToRow(0);
    }

    MergeSegmentOperation mergeOper =
        new MergeSegmentOperation("merge segment", xliffEditor, handler, lstRowId);
    IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    try {
      operationHistory.execute(mergeOper, null, null);
    } catch (Exception e) {
      LOGGER.error("", e);
    }
  }