Java Code Examples for org.eclipse.ui.ide.IDE#getDefaultEditor()

The following examples show how to use org.eclipse.ui.ide.IDE#getDefaultEditor() . 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: GWTDebugModelPresentation.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String getEditorId(IEditorInput input, Object inputObject) {
  IFileEditorInput fileEditorInput = AdapterUtilities.getAdapter(input,
      IFileEditorInput.class);
  if (fileEditorInput != null) {
    IEditorDescriptor editor = IDE.getDefaultEditor(fileEditorInput.getFile());
    if (editor != null) {
      return editor.getId();
    }
  }

  // If editor input isn't pointing to a file, we can't properly determine
  // the content type so delegate to the default implementation.
  return super.getEditorId(input, inputObject);
}
 
Example 2
Source File: OpenFileWithValidAction.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 验证是否已经被打开
 * @param iFile
 * @return 如果当前要打开的文件未被打开,那么验证通过,返回true,否则返回false。
 */
private boolean validIsopened(IFile iFile) throws Exception{
	String extention = iFile.getFileExtension();

	if (IDE.getDefaultEditor(iFile, true) != null
			&& XLIFF_EDITOR_ID.equals(IDE.getDefaultEditor(iFile, true).getId())
			&& CommonFunction.validXlfExtension(extention)) {
		IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getEditorReferences();
		IEditorPart editor = null;
		IFile openIFile = null;
		String needOpenIfileLc = iFile.getLocation().toOSString();
		for (int i = 0; i < editorRes.length; i++) {
			if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
				// 备注:这里的两行代码已经被注释了,原因是因为 getEditor 方法会让每一个 editor 都初始一次,这并不是本次需求所要的。注意。	2013-01-04
				//editor = editorRes[i].getEditor(true);
				//openIFile = ((IFileEditorInput) editor.getEditorInput()).getFile();
				openIFile = ((IFileEditorInput) editorRes[i].getEditorInput()).getFile();
				// 判断是否是合并打开,后缀名为xlp为合并打开,后缀名为xlf为单一打开
				if ("xlp".equals(openIFile.getFileExtension())) {
					// 开始解析这个合并打开临时文件,获取合并打开的文件。
					VTDGen vg = new VTDGen();
					if (vg.parseFile(openIFile.getLocation().toOSString(), 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)) {
									if (fileLC.equals(needOpenIfileLc)) {
										editor = editorRes[i].getEditor(true);
										page.activate(editor);
										return false;
									}
								}
							}
						} catch (Exception e) {
							e.printStackTrace();
						}
					} else {
						return false;
					}
				}
			}
		}
	}
	return true;
}
 
Example 3
Source File: OpenFileWithValidAction.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 验证是否已经被打开
 * @param iFile
 * @return 如果当前要打开的文件未被打开,那么验证通过,返回true,否则返回false。
 */
private boolean validIsopened(IFile iFile) throws Exception{
	String extention = iFile.getFileExtension();

	if (IDE.getDefaultEditor(iFile, true) != null
			&& XLIFF_EDITOR_ID.equals(IDE.getDefaultEditor(iFile, true).getId())
			&& CommonFunction.validXlfExtension(extention)) {
		IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getEditorReferences();
		IEditorPart editor = null;
		IFile openIFile = null;
		String needOpenIfileLc = iFile.getLocation().toOSString();
		for (int i = 0; i < editorRes.length; i++) {
			if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
				// 备注:这里的两行代码已经被注释了,原因是因为 getEditor 方法会让每一个 editor 都初始一次,这并不是本次需求所要的。注意。	2013-01-04
				//editor = editorRes[i].getEditor(true);
				//openIFile = ((IFileEditorInput) editor.getEditorInput()).getFile();
				openIFile = ((IFileEditorInput) editorRes[i].getEditorInput()).getFile();
				// 判断是否是合并打开,后缀名为xlp为合并打开,后缀名为xlf为单一打开
				if ("xlp".equals(openIFile.getFileExtension())) {
					// 开始解析这个合并打开临时文件,获取合并打开的文件。
					VTDGen vg = new VTDGen();
					if (vg.parseFile(openIFile.getLocation().toOSString(), 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)) {
									if (fileLC.equals(needOpenIfileLc)) {
										editor = editorRes[i].getEditor(true);
										page.activate(editor);
										return false;
									}
								}
							}
						} catch (Exception e) {
							e.printStackTrace();
						}
					} else {
						return false;
					}
				}
			}
		}
	}
	return true;
}