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

The following examples show how to use org.eclipse.ui.handlers.HandlerUtil#getActivePartChecked() . 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: AbstractExportHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
	config = new ExportConfig();
	Shell shell = HandlerUtil.getActiveShell(event);
	String partId = HandlerUtil.getActivePartId(event);

	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();
		if (selection != null && !selection.isEmpty()) {
			for (Object obj : selection.toList()) {
				if (obj instanceof IFile) {
					addXLFFile((IFile) obj);
				} else if (obj instanceof IFolder) {
					traversalFile((IFolder) obj);
				} else if (obj instanceof IProject) {
					IProject proj = (IProject) obj;
					traversalFile(proj.getFolder(XLF));
				}
			}
			if (config.getProjects() == null || config.getProjects().size() < 1) {
				MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
						Messages.getString("xlf2tmx.info.notfoundxlf"));
				return false;
			}
		}
	} 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 false;
		} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
			addXLFFile(iFile);
		}
	}

	return true;
}
 
Example 2
Source File: ImportExternal.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	XLIFFEditorImplWithNatTable xliffEditor = null;
	final Shell shell = HandlerUtil.getActiveShell(event);
	String partId = HandlerUtil.getActivePartId(event);
	IFile file = null;
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof XLIFFEditorImplWithNatTable) {
		xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	}
	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();
		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("ImportDocxHandler.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);

		if (xliffEditor.isMultiFile()) {
			MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
					Messages.getString("ImportDocxHandler.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();
	}

	final ImportConfig config = new ImportConfig();
	config.setShell(shell);
	config.set_xliff(file == null ? "" : file.getFullPath().toOSString());
	config.setXliffEditor(xliffEditor);
	config.setXliffFile(file == null ? "" : ResourceUtils.iFileToOSPath(file));
	HsMultiActiveCellEditor.commit(true);
	ImportExternalDialog dialog = new ImportExternalDialog(shell, xliffEditor, config);
	if (Dialog.OK == dialog.open()) {
		config.doImport();
		if (xliffEditor != null) {
			// reopen if need
			if (xliffEditor.getXLFHandler().getVnMap().get(config.getXliffFile()) != null) {
				Map<String, Object> resultMap = xliffEditor.getXLFHandler().openFile(config.getXliffFile());
				if (resultMap == null
						|| Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap
								.get(Constant.RETURNVALUE_RESULT)) {
					// 打开文件失败。
					MessageDialog.openWarning(
							shell,
							Messages.getString("all.dialog.warning"),
							MessageFormat.format(Messages.getString("ImportDocxDialog.ok.parseError"),
									config.get_xliff()));
					LOGGER.error(MessageFormat.format(Messages.getString("ImportDocxDialog.ok.parseError"),
							config.get_xliff()));
					return null;
				}
				xliffEditor.reloadData();
				HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
			}
		}
	}
	return null;
}
 
Example 3
Source File: ExportRTFHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	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(ExportRTFHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
		System.exit(0);
	}
	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("handler.ExportRTFHandler.msg.title"),
						Messages.getString("handler.ExportRTFHandler.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("handler.ExportRTFHandler.msg.title"),
					Messages.getString("handler.ExportRTFHandler.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();
	}

	ExportRTFDilaog dialog = new ExportRTFDilaog(shell, file == null ? "" : file.getFullPath().toOSString(),
			file == null ? "" : ResourceUtils.iFileToOSPath(file));
	dialog.open();
	return null;
}
 
Example 4
Source File: ImportRTFHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	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(ImportRTFHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
		System.exit(0);
	}
	XLIFFEditorImplWithNatTable xliffEditor = null;
	Shell shell = HandlerUtil.getActiveShell(event);
	String partId = HandlerUtil.getActivePartId(event);
	IFile file = null;
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof XLIFFEditorImplWithNatTable) {
		xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	}
	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("handler.ImportRTFHandler.msg.title"),
						Messages.getString("handler.ImportRTFHandler.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);
		
		if (xliffEditor.isMultiFile()) {
			MessageDialog.openInformation(shell, Messages.getString("handler.ImportRTFHandler.msg.title"),
					Messages.getString("handler.ImportRTFHandler.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();
	}
	ImportRTFDialog dialog = new ImportRTFDialog(shell, xliffEditor, file == null ? "" : file.getFullPath().toOSString(),
			file == null ? "" : ResourceUtils.iFileToOSPath(file));
	dialog.open();
	return null;
}
 
Example 5
Source File: ImportDocxHandler.java    From translationstudio8 with GNU General Public License v2.0 votes vote down vote up
@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		XLIFFEditorImplWithNatTable xliffEditor = null;
		Shell shell = HandlerUtil.getActiveShell(event);
		String partId = HandlerUtil.getActivePartId(event);
		IFile file = null;
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		if (editor instanceof XLIFFEditorImplWithNatTable) {
			xliffEditor = (XLIFFEditorImplWithNatTable) editor;
		}
		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();
			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("ImportDocxHandler.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);
			
			if (xliffEditor.isMultiFile()) {
				MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
						Messages.getString("ImportDocxHandler.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();
		}
		ImportDocxDialog dialog = new ImportDocxDialog(shell, xliffEditor, file == null ? "" : file.getFullPath().toOSString(),
				file == null ? "" : ResourceUtils.iFileToOSPath(file));
		dialog.open();
		return null;
	} 
Example 6
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;
		
	}