Java Code Examples for org.eclipse.core.resources.IFile#getFileExtension()

The following examples show how to use org.eclipse.core.resources.IFile#getFileExtension() . These examples are extracted from open source projects. 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 Project: Pydev   File: PyDevBuilder.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param resourcesToParse the list where the resource may be added
 * @param member the resource we are adding
 * @param nature the nature associated to the resource
 */
private void addToResourcesToParse(List<IFile> resourcesToParse, IFile member, IPythonNature nature) {
    //analyze it only if it is a valid source file
    String fileExtension = member.getFileExtension();
    if (DEBUG) {
        System.out.println("Checking name:'" + member.getName() + "' projPath:'" + member.getProjectRelativePath()
                + "' ext:'" + fileExtension + "'");
        System.out.println("loc:'" + member.getLocation() + "' rawLoc:'" + member.getRawLocation() + "'");

    }
    if (fileExtension != null && PythonPathHelper.isValidSourceFile("." + fileExtension)) {
        if (DEBUG) {
            System.out.println("Adding resource to parse:" + member.getProjectRelativePath());
        }
        resourcesToParse.add(member);
    }
}
 
Example 2
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 3
/**
 * 初步验证所选的xliff文件是否能合并。
 */
private void validXlf() {
	if (model.getMergeXliffFile().size() < 2) {
		setErrorMessage(Messages.getString("wizard.MergeXliffWizardPage.msg2"));
		setPageComplete(false);
		return;
	} else {
		// 验证文件是否是同一类型
		String fileExtension = "";
		for (IFile iFIle : model.getMergeXliffFile()) {
			if (iFIle.getFileExtension() == null || "".equals(iFIle.getFileExtension())) {
				setErrorMessage(MessageFormat.format(Messages.getString("wizard.MergeXliffWizardPage.msg3"), model
						.getMergeXliffFile().indexOf(iFIle) + 1) + 1);
				setPageComplete(false);
				return;
			}
			String curExtenstion = iFIle.getFileExtension();
			if ("".equals(fileExtension)) {
				fileExtension = curExtenstion;
			} else if (!curExtenstion.equals(fileExtension)) {
				setErrorMessage(MessageFormat.format(Messages.getString("wizard.MergeXliffWizardPage.msg4"), model
						.getMergeXliffFile().indexOf(iFIle) + 1));
				setPageComplete(false);
				return;
			}
		}
	}
	setPageComplete(true);
	setErrorMessage(null);
}
 
Example 4
Source Project: eclipse.jdt.ls   File: JDTUtils.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static ICompilationUnit resolveCompilationUnit(IFile resource) {
	if(resource != null){
		if(!ProjectUtils.isJavaProject(resource.getProject())){
			return null;
		}
		if (resource.getFileExtension() != null) {
			String name = resource.getName();
			if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name)) {
				return JavaCore.createCompilationUnitFrom(resource);
			}
		}
	}

	return null;
}
 
Example 5
public static PropertyDocument<?> loadRegistryResourceDocument(IFile file) {
  String docExt = file.getFileExtension();
  ResourceDocumentConfig rsrcConfig =
      ResourceDocumentConfigRegistry.getRegistryDocumentConfig(docExt);
  AbstractDocXmlPersist<?> xmlPersist =
      rsrcConfig.getDocXmlPersist(file, true);
  return (PropertyDocument<?>) xmlPersist.load(file.getRawLocationURI());
}
 
Example 6
private boolean hasDefaultExtension(IFile file, IType resourceType) throws JavaModelException {
  String fileExtension = "." + file.getFileExtension();

  for (String defaultExtension : ResourceTypeDefaultExtensions.getDefaultExtensions(resourceType)) {
    if (ResourceUtils.areFilenamesEqual(fileExtension, defaultExtension)) {
      return true;
    }
  }
  return false;
}
 
Example 7
private GenericFileInfo createShapeFileSupportMetaData(final IFile file) {
	GenericFileInfo info = null;
	final IResource r = shapeFileSupportedBy(file);
	if (r == null) { return null; }
	final String ext = file.getFileExtension();
	final String type = longNames.containsKey(ext) ? longNames.get(ext) : "Data";
	info = new GenericFileInfo(file.getModificationStamp(), "" + type + " for '" + r.getName() + "'");
	return info;

}
 
Example 8
/**
 * 初步验证所选的xliff文件是否能合并。
 */
private void validXlf() {
	if (model.getMergeXliffFile().size() < 2) {
		setErrorMessage(Messages.getString("wizard.MergeXliffWizardPage.msg2"));
		setPageComplete(false);
		return;
	} else {
		// 验证文件是否是同一类型
		String fileExtension = "";
		for (IFile iFIle : model.getMergeXliffFile()) {
			if (iFIle.getFileExtension() == null || "".equals(iFIle.getFileExtension())) {
				setErrorMessage(MessageFormat.format(Messages.getString("wizard.MergeXliffWizardPage.msg3"), model
						.getMergeXliffFile().indexOf(iFIle) + 1) + 1);
				setPageComplete(false);
				return;
			}
			String curExtenstion = iFIle.getFileExtension();
			if ("".equals(fileExtension)) {
				fileExtension = curExtenstion;
			} else if (!curExtenstion.equals(fileExtension)) {
				setErrorMessage(MessageFormat.format(Messages.getString("wizard.MergeXliffWizardPage.msg4"), model
						.getMergeXliffFile().indexOf(iFIle) + 1));
				setPageComplete(false);
				return;
			}
		}
	}
	setPageComplete(true);
	setErrorMessage(null);
}
 
Example 9
public static IResource shapeFileSupportedBy(final IFile r) {
	String fileName = r.getName();
	// Special case for these odd files
	if (fileName.endsWith(".shp.xml")) {
		fileName = fileName.replace(".xml", "");
	} else {
		final String extension = r.getFileExtension();
		if (!longNames.containsKey(extension)) { return null; }
		fileName = fileName.replace(extension, "shp");
	}
	return r.getParent().findMember(fileName);
}
 
Example 10
Source Project: JDeodorant   File: ASTReader.java    License: MIT License 5 votes vote down vote up
private List<CommentObject> processComments(IFile iFile, IDocument iDocument,
		AbstractTypeDeclaration typeDeclaration, List<Comment> comments) {
	List<CommentObject> commentList = new ArrayList<CommentObject>();
	int typeDeclarationStartPosition = typeDeclaration.getStartPosition();
	int typeDeclarationEndPosition = typeDeclarationStartPosition + typeDeclaration.getLength();
	for(Comment comment : comments) {
		int commentStartPosition = comment.getStartPosition();
		int commentEndPosition = commentStartPosition + comment.getLength();
		int commentStartLine = 0;
		int commentEndLine = 0;
		String text = null;
		try {
			commentStartLine = iDocument.getLineOfOffset(commentStartPosition);
			commentEndLine = iDocument.getLineOfOffset(commentEndPosition);
			text = iDocument.get(commentStartPosition, comment.getLength());
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
		CommentType type = null;
		if(comment.isLineComment()) {
			type = CommentType.LINE;
		}
		else if(comment.isBlockComment()) {
			type = CommentType.BLOCK;
		}
		else if(comment.isDocComment()) {
			type = CommentType.JAVADOC;
		}
		CommentObject commentObject = new CommentObject(text, type, commentStartLine, commentEndLine);
		commentObject.setComment(comment);
		String fileExtension = iFile.getFileExtension() != null ? "." + iFile.getFileExtension() : "";
		if(typeDeclarationStartPosition <= commentStartPosition && typeDeclarationEndPosition >= commentEndPosition) {
			commentList.add(commentObject);
		}
		else if(iFile.getName().equals(typeDeclaration.getName().getIdentifier() + fileExtension)) {
			commentList.add(commentObject);
		}
	}
	return commentList;
}
 
Example 11
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 12
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
	final Shell shell = window.getShell();

	ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
	if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {

		IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;

		if (structuredSelection.size() < 2) {
			MessageDialog.openInformation(shell, Messages.getString("handler.MergeXliffHandler.msgTitle1"),
					Messages.getString("handler.MergeXliffHandler.msg1"));
			return null;
		}

		Vector<IFile> seleFiles = new Vector<IFile>();
		String notXlfFile = "";
		@SuppressWarnings("rawtypes")
		Iterator selectIt = structuredSelection.iterator();
		while (selectIt.hasNext()) {
			Object object = selectIt.next();
			if (object instanceof IFile) {
				IFile selectFile = (IFile) object;
				String fileExtension = selectFile.getFileExtension();

				// 如果后缀名不是xlf,那么就进行提示
				if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
					notXlfFile += selectFile.getFullPath().toOSString() + ",";
				}
				seleFiles.add(selectFile);
			}
		}

		if (notXlfFile.length() > 0) {
			notXlfFile = notXlfFile.substring(0, notXlfFile.length() - 1);
			boolean isSure = MessageDialog.openConfirm(shell, Messages
					.getString("handler.MergeXliffHandler.msgTitle2"), MessageFormat.format(
					Messages.getString("handler.MergeXliffHandler.msg2"), new Object[] { notXlfFile }));
			if (!isSure) {
				return null;
			}
		}
		
		List<IFile> lstFiles = new ArrayList<IFile>();
		XLFValidator.resetFlag();
		for (IFile iFile : seleFiles) {
			if (!XLFValidator.validateXliffFile(iFile)) {
				lstFiles.add(iFile);
			}
		}
		XLFValidator.resetFlag();
		seleFiles.removeAll(lstFiles);
		if (seleFiles.size() == 0) {
			return null;
		}
		
		if (seleFiles.size() > 0) {
			String projectPath = seleFiles.get(0).getProject().getFullPath().toOSString();
			for (int i = 1; i < seleFiles.size(); i++) {
				if (!projectPath.equals(seleFiles.get(i).getProject().getFullPath().toOSString())) {
					MessageDialog.openInformation(shell, Messages.getString("handler.MergeXliffHandler.msgTitle1"),
							Messages.getString("handler.MergeXliffHandler.msg3"));
					return null;
				}
			}
			SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
			model.setMergeXliffFile(seleFiles);
			MergeXliffWizard wizard = new MergeXliffWizard(model);
			TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
			dialog.open();
		}
	}
	return null;
}
 
Example 13
/**
 * 关闭指定文件的编辑器		-- robert 2013-04-01
 * 备注:这里面的方法,是不能获取 nattable 的实例,故,在处理 合并打开的情况时,是通过 vtd 进行解析 合并临时文件从而获取相关文件的
 * @param iFileList
 */
public static void closePointEditor(List<IFile> iFileList){
	Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>();
	IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
	for(IEditorReference reference : referenceArray){
		IEditorPart editor = reference.getEditor(true);
		IFile iFile = ((FileEditorInput)editor.getEditorInput()).getFile();
		// 如果这是一个 nattable 编辑器
		if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
			String iFilePath = iFile.getLocation().toOSString();
			String extension = iFile.getFileExtension();
			if ("hsxliff".equals(extension)) {
				openedIfileMap.put(iFile, editor);
			}else if ("xlp".equals(extension)) {
				// 这是合并打开的情况
				// 开始解析这个合并打开临时文件,获取合并打开的文件。
				VTDGen vg = new VTDGen();
				if (vg.parseFile(iFilePath, true)) {
					VTDNav vn = vg.getNav();
					AutoPilot ap = new AutoPilot(vn);
					try {
						ap.selectXPath("/mergerFiles/mergerFile/@filePath");
						int index = -1;
						while ((index = ap.evalXPath()) != -1) {
							String fileLC = vn.toString(index + 1);
							if (fileLC != null && !"".equals(fileLC)) {
								openedIfileMap.put(ResourceUtils.fileToIFile(fileLC), editor);
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}else {
			// 其他情况,直接将文件丢进去就行了
			openedIfileMap.put(iFile, editor);
		}
		
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		
		for(IFile curIfile : iFileList){
			if (openedIfileMap.containsKey(curIfile)) {
				page.closeEditor(openedIfileMap.get(curIfile), false);
			}
		}
	}
}
 
Example 14
Source Project: typescript.java   File: TypeScriptHover.java    License: MIT License 4 votes vote down vote up
protected String getFileExtension(IFile tsFile) {
	return tsFile.getFileExtension();
}
 
Example 15
public static String suggestResourceTypeName(IJavaProject javaProject,
    IFile file) {
  String ext = file.getFileExtension();
  if (ext == null) {
    return DATA_RESOURCE_TYPE_NAME;
  }

  // The @DefaultExtensions include the leading dot, so we need to as well
  ext = "." + ext;

  try {
    List<String> matchingResourceTypes = new ArrayList<String>();

    // Look for @DefaultExtensions on all ResourcePrototype subtypes
    IType[] resourceTypes = findResourcePrototypeSubtypes(javaProject);
    for (IType resourceType : resourceTypes) {
      String[] defaultExtensions = ResourceTypeDefaultExtensions.getDefaultExtensions(resourceType);
      for (String defaultExtension : defaultExtensions) {
        if (ResourceUtils.areFilenamesEqual(ext, defaultExtension)) {
          String resourceTypeName = resourceType.getFullyQualifiedName('.');
          matchingResourceTypes.add(resourceTypeName);
        }
      }
    }

    // Now see what we found
    if (matchingResourceTypes.size() > 0) {
      /*
       * If TextResource was a match, prefer it. This is necessary since it
       * and ExternalTextResource both declare .txt as their default
       * extension. Since TextResource (which inlines its content into the
       * compiled output) is the more commonly used variant, we want to use it
       * by default. If we're wrong, the user can always change it manually.
       */
      if (matchingResourceTypes.contains(TEXT_RESOURCE_TYPE_NAME)) {
        return TEXT_RESOURCE_TYPE_NAME;
      }

      /*
       * If we don't have TextResource in the mix, return the first matching
       * ResourcePrototype subtype we found. In the case of multiple resource
       * types that declare the same default file extensions, the order in
       * which they are found is undefined, so which one we return is
       * undefined as well. In general, multiple resource types will not have
       * the same default extensions, so this is probably good enough (that
       * is, it's not worth creating new UI/settings for this edge case).
       */
      return matchingResourceTypes.get(0);
    }

  } catch (JavaModelException e) {
    GWTPluginLog.logError(e, "Unable to suggest resource type for file "
        + file.getName());
  }

  return DATA_RESOURCE_TYPE_NAME;
}
 
Example 16
private GenericFileInfo createGenericFileMetaData(final IFile file) {
	String ext = file.getFileExtension();
	if (ext == null) { return new GenericFileInfo(file.getModificationStamp(), "Generic file"); }
	ext = ext.toUpperCase();
	return new GenericFileInfo(file.getModificationStamp(), "Generic " + ext + " file");
}
 
Example 17
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 18
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
	final Shell shell = window.getShell();

	ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
	if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {

		IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;

		if (structuredSelection.size() < 2) {
			MessageDialog.openInformation(shell, Messages.getString("handler.MergeXliffHandler.msgTitle1"),
					Messages.getString("handler.MergeXliffHandler.msg1"));
			return null;
		}

		Vector<IFile> seleFiles = new Vector<IFile>();
		String notXlfFile = "";
		@SuppressWarnings("rawtypes")
		Iterator selectIt = structuredSelection.iterator();
		while (selectIt.hasNext()) {
			Object object = selectIt.next();
			if (object instanceof IFile) {
				IFile selectFile = (IFile) object;
				String fileExtension = selectFile.getFileExtension();

				// 如果后缀名不是xlf,那么就进行提示
				if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
					notXlfFile += selectFile.getFullPath().toOSString() + ",";
				}
				seleFiles.add(selectFile);
			}
		}

		if (notXlfFile.length() > 0) {
			notXlfFile = notXlfFile.substring(0, notXlfFile.length() - 1);
			boolean isSure = MessageDialog.openConfirm(shell, Messages
					.getString("handler.MergeXliffHandler.msgTitle2"), MessageFormat.format(
					Messages.getString("handler.MergeXliffHandler.msg2"), new Object[] { notXlfFile }));
			if (!isSure) {
				return null;
			}
		}
		
		List<IFile> lstFiles = new ArrayList<IFile>();
		XLFValidator.resetFlag();
		for (IFile iFile : seleFiles) {
			if (!XLFValidator.validateXliffFile(iFile)) {
				lstFiles.add(iFile);
			}
		}
		XLFValidator.resetFlag();
		seleFiles.removeAll(lstFiles);
		if (seleFiles.size() == 0) {
			return null;
		}
		
		if (seleFiles.size() > 0) {
			String projectPath = seleFiles.get(0).getProject().getFullPath().toOSString();
			for (int i = 1; i < seleFiles.size(); i++) {
				if (!projectPath.equals(seleFiles.get(i).getProject().getFullPath().toOSString())) {
					MessageDialog.openInformation(shell, Messages.getString("handler.MergeXliffHandler.msgTitle1"),
							Messages.getString("handler.MergeXliffHandler.msg3"));
					return null;
				}
			}
			SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
			model.setMergeXliffFile(seleFiles);
			MergeXliffWizard wizard = new MergeXliffWizard(model);
			TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
			dialog.open();
		}
	}
	return null;
}
 
Example 19
/**
 * 关闭指定文件的编辑器		-- robert 2013-04-01
 * 备注:这里面的方法,是不能获取 nattable 的实例,故,在处理 合并打开的情况时,是通过 vtd 进行解析 合并临时文件从而获取相关文件的
 * @param iFileList
 */
public static void closePointEditor(List<IFile> iFileList){
	Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>();
	IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
	for(IEditorReference reference : referenceArray){
		IEditorPart editor = reference.getEditor(true);
		IFile iFile = ((FileEditorInput)editor.getEditorInput()).getFile();
		// 如果这是一个 nattable 编辑器
		if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
			String iFilePath = iFile.getLocation().toOSString();
			String extension = iFile.getFileExtension();
			if ("hsxliff".equals(extension)) {
				openedIfileMap.put(iFile, editor);
			}else if ("xlp".equals(extension)) {
				// 这是合并打开的情况
				// 开始解析这个合并打开临时文件,获取合并打开的文件。
				VTDGen vg = new VTDGen();
				if (vg.parseFile(iFilePath, true)) {
					VTDNav vn = vg.getNav();
					AutoPilot ap = new AutoPilot(vn);
					try {
						ap.selectXPath("/mergerFiles/mergerFile/@filePath");
						int index = -1;
						while ((index = ap.evalXPath()) != -1) {
							String fileLC = vn.toString(index + 1);
							if (fileLC != null && !"".equals(fileLC)) {
								openedIfileMap.put(ResourceUtils.fileToIFile(fileLC), editor);
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}else {
			// 其他情况,直接将文件丢进去就行了
			openedIfileMap.put(iFile, editor);
		}
		
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		
		for(IFile curIfile : iFileList){
			if (openedIfileMap.containsKey(curIfile)) {
				page.closeEditor(openedIfileMap.get(curIfile), false);
			}
		}
	}
}
 
Example 20
@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;
		
	}