Java Code Examples for org.eclipse.ui.handlers.HandlerUtil#getActiveEditor()

The following examples show how to use org.eclipse.ui.handlers.HandlerUtil#getActiveEditor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShowPreviousUntranslatableHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int firstSelectedRow = selectedRows[0];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getPreviousUntranslatableSegmentIndex(firstSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在上一不可翻译文本段。");
	}

	return null;
}
 
Example 2
Source File: ShowPreviousUntranslatedHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int firstSelectedRow = selectedRows[0];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getPreviousUntranslatedSegmentIndex(firstSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在上一未翻译文本段。");
	}

	return null;
}
 
Example 3
Source File: OpenOppositeFileHandler.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	IWorkbenchPage page = editor.getSite().getPage();
	Collection<FileOpener> destinations = Lists.newArrayList();
	collectOpeners(editor, CollectionBasedAcceptor.of(destinations));
	switch (destinations.size()) {
		case 0:
			return null;
		case 1:
			destinations.iterator().next().open(page);
			return null;
		default:
			List<FileOpener> selected = selectOpeners(page, destinations);
			for (FileOpener sel : selected)
				sel.open(page);
			return null;
	}
}
 
Example 4
Source File: ShowNextUnapprovedHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int lastSelectedRow = selectedRows[selectedRows.length - 1];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getNextUnapprovedSegmentIndex(lastSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在下一个未批准文本段。");
	}

	return null;
}
 
Example 5
Source File: ApproveSegmentHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof XLIFFEditorImplWithNatTable) {
		final XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
		List<String> rowIds = xliffEditor.getSelectedRowIds();


		if (rowIds.size() == 0) {
			return null;
		}

		String parameter = event.getParameter("approveSegment");
		if (parameter != null) {
			HsMultiActiveCellEditor.commit(true);
			NattableUtil util = NattableUtil.getInstance(xliffEditor);
			util.approveTransUnits(parameter.equalsIgnoreCase("approveAndJumpNext")); // 执行批准
		}
	}
	return null;
}
 
Example 6
Source File: ShowPreviousNoteHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int firstSelectedRow = selectedRows[0];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getPreviousNoteSegmentIndex(firstSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在上一个带批注的文本段。");
	}

	return null;
}
 
Example 7
Source File: ShowPreviousSegmentHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int firstSelectedRow = selectedRows[0];
	if (firstSelectedRow == 0) {
		firstSelectedRow = 1;
	}
	xliffEditor.jumpToRow(firstSelectedRow - 1);
	return null;
}
 
Example 8
Source File: ShowNextNoteHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int lastSelectedRow = selectedRows[selectedRows.length - 1];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getNextNoteSegmentIndex(lastSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在下一个带批注的文本段。");
	}

	return null;
}
 
Example 9
Source File: ChangeSourceEditableHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
			XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
			ICellEditor cellEditor = xliffEditor.getTable().getConfigRegistry().getConfigAttribute(
					EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
			if (cellEditor == null || !(cellEditor instanceof StyledTextCellEditor)) {
				return null;
			}
			HsMultiActiveCellEditor.commit(false);
			StyledTextCellEditor sce = (StyledTextCellEditor) cellEditor;
			EditableManager editableManager = sce.getEditableManager();
//			SourceEditMode nextMode = editableManager.getSourceEditMode().getNextMode();
			SourceEditMode nextMode = getSourceEditMode(editableManager);
			editableManager.setSourceEditMode(nextMode);
//			element.setIcon(Activator.getImageDescriptor(nextMode.getImagePath()));
			if (!sce.isClosed()) {
				editableManager.judgeEditable();
//				更新全局 Action 的可用状态,主要是更新编辑-删除功能的可用状态。
				sce.getActionHandler().updateActionsEnableState();
			}
			
			sce.addClosingListener(listener);
		}
		return null;
	}
 
Example 10
Source File: ToggleTextNodesHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException
{
	Command command = event.getCommand();
	boolean oldValue = HandlerUtil.toggleCommandState(command);
	HTMLPreferenceUtil.setShowTextNodesInOutline(!oldValue);

	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof AbstractThemeableEditor)
	{
		CommonOutlinePage page = ((AbstractThemeableEditor) editor).getOutlinePage();
		page.refresh();
	}
	return null;
}
 
Example 11
Source File: ChangeEditorLayoutHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
	// 改为布局
	if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
		// ActiveCellRegion.setActiveCellRegion(null);
		((XLIFFEditorImplWithNatTable) editorPart).changeLayout();
	}
	return null;
}
 
Example 12
Source File: ShowLastSegmentHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	XLFHandler handler = xliffEditor.getXLFHandler();
	int lastRow = handler.countEditableTransUnit() - 1;
	xliffEditor.jumpToRow(lastRow);
	return null;
}
 
Example 13
Source File: ToggleWordWrapHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException
{
	// this applies to the specific editor, so no need to modify the global preference
	IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
	if (editorPart instanceof AbstractThemeableEditor)
	{
		AbstractThemeableEditor activeEditor = (AbstractThemeableEditor) editorPart;
		activeEditor.setWordWrapEnabled(!activeEditor.getWordWrapEnabled());
	}
	return null;
}
 
Example 14
Source File: AddTermToTBHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		if (editor instanceof IXliffEditor) {
			String tshelp = System.getProperties().getProperty("TSHelp");
			String tsstate = System.getProperties().getProperty("TSState");
			if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
				LoggerFactory.getLogger(AddTermToTBHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
				System.exit(0);
			}
			IXliffEditor xliffEditor = (IXliffEditor) editor;
			IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
//			ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
//			List<DatabaseModelBean> lstDatabase = projectConfig.getTermBaseDbs(true);
			TbImporter.getInstance().setProject(file.getProject());
			if (!TbImporter.getInstance().checkImporter()) {
				MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
						Messages.getString("handler.AddTermToTBHandler.msgTitle"),
						Messages.getString("handler.AddTermToTBHandler.msg"));
				return null;
			}

			StringBuffer srcTerm = new StringBuffer();
			StringBuffer tgtTerm = new StringBuffer();
			String srcAllText = xliffEditor.getRowTransUnitBean(xliffEditor.getSelectedRows()[0]).getSrcText();
			xliffEditor.getSelectSrcOrTgtPureText(srcTerm, tgtTerm);

			AddTermToTBDialog dialog = AddTermToTBDialog.getInstance(editor.getSite().getShell(), srcTerm.toString().trim(),
					tgtTerm.toString().trim());
			dialog.setProject(file.getProject());
			dialog.setSrcLang(xliffEditor.getSrcColumnName());
			dialog.setTgtLang(xliffEditor.getTgtColumnName());
			dialog.setSrcAllText(srcAllText);
			dialog.open();
		}
		return null;
	}
 
Example 15
Source File: MergeSegmentHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	NattableUtil util = NattableUtil.getInstance(xliffEditor);
	util.mergeSegment();
	return null;
}
 
Example 16
Source File: PreviewTranslationHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor == null) {
		return false;
	}
	IEditorInput input = editor.getEditorInput();
	IFile file = ResourceUtil.getFile(input);
	shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
	if (file == null) {
		MessageDialog.openInformation(shell, "提示", "未找当前编辑器打开的文件资源。");
	} else {
		String fileExtension = file.getFileExtension();
		if (fileExtension != null && "xlf".equalsIgnoreCase(fileExtension)) {
			ConverterViewModel model = getConverterViewModel(file);
			if (model != null) {
				model.convert();
			}
		} else if (fileExtension != null && "xlp".equalsIgnoreCase(fileExtension)) {
			if (file.exists()) {
				IFolder xliffFolder = file.getProject().getFolder(Constant.FOLDER_XLIFF);
				if (xliffFolder.exists()) {
					ArrayList<IFile> files = new ArrayList<IFile>();
					try {
						getChildFiles(xliffFolder, "xlf", files);
					} catch (CoreException e) {
						throw new ExecutionException(e.getMessage(), e);
					}
					previewFiles(files);
				} else {
					MessageDialog.openWarning(shell, "提示", "未找到系统默认的 XLIFF 文件夹!");
				}
			}
		} else {
			MessageDialog.openInformation(shell, "提示", "当前编辑器打开的文件不是一个合法的 XLIFF 文件。");
		}
	}
	return null;
}
 
Example 17
Source File: MergeNextHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
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(selectedRowIds.size() - 1);
		XLFHandler handler = xliffEditor.getXLFHandler();

		int rowIndex = handler.getRowIndex(rowId);

		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		if (rowIndex == handler.countEditableTransUnit() - 1) { // 是最后一行
			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), null, null);
//		} catch (ExecutionException e) {
//			e.printStackTrace();
//		}

		return null;
	}
 
Example 18
Source File: ExecuteBingTransHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
	public Object execute(ExecutionEvent event) throws ExecutionException {

		final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		if (!(editor instanceof IXliffEditor)) {
			return null;
		}

		// check the google translation state: check the key availability
		PrefrenceParameters ps = PrefrenceParameters.getInstance();
		if (!ps.getState()) {
			MessageDialog.openError(window.getShell(),
					Messages.getString("handler.ExecuteBingTransHandler.msgTitle"),
					Messages.getString("handler.ExecuteBingTransHandler.msg"));
			return null;
		}
		String tshelp = System.getProperties().getProperty("TSHelp");
		String tsstate = System.getProperties().getProperty("TSState");
		if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
			LoggerFactory.getLogger(ExecuteBingTransHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
			System.exit(0);
		}
		final IXliffEditor xliffEditor = (IXliffEditor) editor;

		final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
		if (selectedRowIndexs.length == 0) {
			return null;
		}
//		int currentRowIndex = selectedRowIndexs[0];
//		TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(currentRowIndex);
//		if (transUnitBean == null) {
//			return null;
//		}
//		String srcPureText = transUnitBean.getSrcText();
//		String tgtLanguage = xliffEditor.getTgtColumnName();
//		String srcLanguage = xliffEditor.getSrcColumnName();

//		TransUnitInfo2TranslationBean tuInfo2Trans = new TransUnitInfo2TranslationBean();
//		tuInfo2Trans.setSrcPureText(srcPureText);
//		tuInfo2Trans.setSrcLanguage(srcLanguage);
//		tuInfo2Trans.setTgtLangugage(tgtLanguage);

		ISimpleMatcher matcher = new SimpleMatcherBingImpl();
//		String tgtText = matcher.executeMatch(tuInfo2Trans);
//		if (tgtText.equals("")) {
//			return null;
//		}

//		AltTransBean bean = new AltTransBean(srcPureText, tgtText, srcLanguage, tgtLanguage,
//				matcher.getMathcerOrigin(), matcher.getMathcerToolId());
//		bean.getMatchProps().put("match-quality", "100");
//		bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
//		bean.setSrcContent(srcPureText);
//		bean.setTgtContent(tgtText);

//		List<AltTransBean> newAltTrans = new ArrayList<AltTransBean>();
//		newAltTrans.add(bean);
		
		// check if need save the AltTrans to file
//		if (CommonFunction.checkEdition("U") && matcher.isSuportPreTrans()) {
//			List<String> oldToolIds = new ArrayList<String>();
//			oldToolIds.add(matcher.getMathcerToolId());
//			xliffEditor.getXLFHandler().updateAltTrans(xliffEditor.getXLFHandler().getRowId(currentRowIndex), newAltTrans, oldToolIds);
//		}

		IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
		if (viewPart != null && viewPart instanceof MatchViewPart) {
			MatchViewPart matchView = (MatchViewPart) viewPart;
			//matchView.refreshView(xliffEditor, selectedRowIndexs[0]);
//			matchView.refreshViewByToolId(xliffEditor, newAltTrans, matcher.getMathcerToolId());
//			matchView.replaceMatchs(newAltTrans);
//			newAltTrans.clear();
			matchView.manualExecSimpleTranslation(matcher);
		}

		return null;
	}
 
Example 19
Source File: AbstractInsertTagHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
		this.event = event;
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
			return null; // 不是针对 XLIFFEditorImplWithNatTable 编辑器中的操作,则退出
		}
		cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
		if(cellEditor == null){
			return null;
		}
//		ICellEditor iCellEditor = HsMultiActiveCellEditor.getTargetEditor().getCellEditor();
//				//ActiveCellEditor.getCellEditor();
//		if (!(iCellEditor instanceof StyledTextCellEditor)) {
//			return null; // 不是 StyledTextCellEditor 实例,则退出
//		}
//
//		cellEditor = (StyledTextCellEditor) iCellEditor;
		if (!cellEditor.isEditable()) {
			cellEditor.showUneditableMessage(); // 显示不可编辑提示信息。
			return null; // 不可编辑,则退出
		}

		ISegmentViewer segmentViewer = cellEditor.getSegmentViewer();
		int caretOffset = segmentViewer.getTextWidget().getCaretOffset(); // 插入位置
		if (caretOffset < 0) {
			return null; // 文本框已经关闭,则退出
		}

		sourceMaxTagIndex = segmentViewer.getSourceMaxTagIndex(); // source 内部标记中的最大索引
		if (sourceMaxTagIndex <= 0) { // source 无内部标记。
			return null;
		}

		int num = getTagNum();
		if (num < 0 || num > sourceMaxTagIndex) {
			return null;
		}

		cellEditor.getSegmentViewer().insertInnerTag(num, caretOffset);
		return null;
	}
 
Example 20
Source File: ExportDocxHandler.java    From translationstudio8 with GNU General Public License v2.0 votes vote down vote up
@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Shell shell = HandlerUtil.getActiveShell(event);
		String partId = HandlerUtil.getActivePartId(event);
		IFile file = null;
		if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
			// 导航视图处于激活状态
			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
			IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
			StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider()
					.getSelection();
			// ISelection selection = HandlerUtil.getCurrentSelection(event);
			if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
				List<?> lstObj = ((IStructuredSelection) selection).toList();
				ArrayList<IFile> lstXliff = new ArrayList<IFile>();
				for (Object obj : lstObj) {
					if (obj instanceof IFile) {
						IFile tempFile = (IFile) obj;
						// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
						if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
							lstXliff.add(tempFile);
						}
					}
				}
				if (lstXliff.size() > 1) {
					MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
							Messages.getString("ExportDocxHandler.msg1"));
					return null;
				}
				if (lstXliff.size() == 1) {
					file = lstXliff.get(0);
				}
			}
		} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
			// nattable 处于激活状态
			IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
			IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
			IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
			IEditorPart editor = HandlerUtil.getActiveEditor(event);
			IXliffEditor xliffEditor = (IXliffEditor) editor;

			if (xliffEditor.isMultiFile()) {
				MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
						Messages.getString("ExportDocxHandler.msg2"));
				return null;
			} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
				file = iFile;
			}
		}

		if (file != null) {
			XLFValidator.resetFlag();
			if (!XLFValidator.validateXliffFile(file)) {
				return null;
			}
			XLFValidator.resetFlag();
		}

		ExportDocxDialog dialog = new ExportDocxDialog(shell, file == null ? "" : file.getFullPath().toOSString(),
				file == null ? "" : ResourceUtils.iFileToOSPath(file));
		dialog.open();
		return null;
		
	}