Java Code Examples for org.eclipse.ui.IEditorPart#getEditorInput()
The following examples show how to use
org.eclipse.ui.IEditorPart#getEditorInput() .
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: DockerBuildLaunchShortcut.java From doclipser with Eclipse Public License 1.0 | 6 votes |
@Override public void launch(IEditorPart editor, String mode) { IEditorInput input = editor.getEditorInput(); IFile dockerfile = (IFile) input.getAdapter(IFile.class); IPath dockerfilePath = null; if (dockerfile != null) { dockerfilePath = dockerfile.getLocation().removeLastSegments(1); } if (dockerfilePath == null) { ILocationProvider locationProvider = (ILocationProvider) input.getAdapter(ILocationProvider.class); if (locationProvider != null) { dockerfilePath = locationProvider.getPath(input); } } if (dockerfilePath != null) { launch(dockerfile, dockerfilePath); } }
Example 2
Source File: CoreEditorUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
public static List<IEditorPart> getDirtyEditors(boolean skipNonResourceEditors) { Set<IEditorInput> inputs= new HashSet<IEditorInput>(); List<IEditorPart> result= new ArrayList<IEditorPart>(0); IWorkbench workbench= PlatformUI.getWorkbench(); IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); for (int i= 0; i < windows.length; i++) { IWorkbenchPage[] pages= windows[i].getPages(); for (int x= 0; x < pages.length; x++) { IEditorPart[] editors= pages[x].getDirtyEditors(); for (int z= 0; z < editors.length; z++) { IEditorPart ep= editors[z]; IEditorInput input= ep.getEditorInput(); if (inputs.add(input)) { if (!skipNonResourceEditors || isResourceEditorInput(input)) { result.add(ep); } } } } } return result; }
Example 3
Source File: CorrectionMarkerResolutionGenerator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void run(IMarker marker) { try { IEditorPart part= EditorUtility.isOpenInEditor(fCompilationUnit); if (part == null) { part= JavaUI.openInEditor(fCompilationUnit, true, false); if (part instanceof ITextEditor) { ((ITextEditor) part).selectAndReveal(fOffset, fLength); } } if (part != null) { IEditorInput input= part.getEditorInput(); IDocument doc= JavaPlugin.getDefault().getCompilationUnitDocumentProvider().getDocument(input); fProposal.apply(doc); } } catch (CoreException e) { JavaPlugin.log(e); } }
Example 4
Source File: OccurrencesSearchResult.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) { //TODO same code in JavaSearchResult IEditorInput editorInput= editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput= (IFileEditorInput) editorInput; return computeContainedMatches(result, fileEditorInput.getFile()); } else if (editorInput instanceof IClassFileEditorInput) { IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) editorInput; IClassFile classFile= classFileEditorInput.getClassFile(); Object[] elements= getElements(); if (elements.length == 0) return NO_MATCHES; //all matches from same file: JavaElementLine jel= (JavaElementLine) elements[0]; if (jel.getJavaElement().equals(classFile)) return collectMatches(elements); } return NO_MATCHES; }
Example 5
Source File: QuickFixCompletionProposalWrapper.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
@Override public void run(IMarker marker) { try { IEditorPart part = EditorUtility.isOpenInEditor(cu); if (part == null) { part = JavaUI.openInEditor(cu, true, false); if (part instanceof ITextEditor) { ((ITextEditor) part).selectAndReveal(offset, length); } } if (part != null) { IEditorInput input = part.getEditorInput(); IDocument doc = JavaPlugin.getDefault().getCompilationUnitDocumentProvider().getDocument( input); proposal.apply(doc); } } catch (CoreException e) { CorePluginLog.logError(e); } }
Example 6
Source File: AbstractResourceSelectionJobCommand.java From cppcheclipse with Apache License 2.0 | 6 votes |
private IStructuredSelection getEditorFileSelection(IEditorPart editor) { if (editor == null) { return null; } IEditorInput input = editor.getEditorInput(); if (input == null) { return null; } IFileEditorInput fileInput = (IFileEditorInput) input .getAdapter(IFileEditorInput.class); if (fileInput == null) { return null; } List<IFile> fileList = new LinkedList<IFile>(); fileList.add(fileInput.getFile()); return new StructuredSelection(fileList); }
Example 7
Source File: TypeScriptSearchResult.java From typescript.java with MIT License | 5 votes |
@Override public boolean isShownInEditor(Match match, IEditorPart editor) { IEditorInput ei = editor.getEditorInput(); if (ei instanceof IFileEditorInput) { IFileEditorInput fi = (IFileEditorInput) ei; return match.getElement().equals(fi.getFile()); } return false; }
Example 8
Source File: SelectionUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public static IFile getSelectedFile(IEditorPart editor) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput; return fileEditorInput.getFile(); } return null; }
Example 9
Source File: WizardUtils.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
public static String getXPageFileName() { IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = win.getActivePage(); if (page != null) { IEditorPart editor = page.getActiveEditor(); if (editor != null) { IEditorInput input = editor.getEditorInput(); if (input instanceof IFileEditorInput) { return ((IFileEditorInput) input).getFile().getLocation().lastSegment(); } } } return null; }
Example 10
Source File: AddProjectToSessionWizard.java From saros with GNU General Public License v2.0 | 5 votes |
private Collection<IEditorPart> getOpenEditorsForSharedProjects(Collection<IProject> projects) { List<IEditorPart> openEditors = new ArrayList<IEditorPart>(); Set<IEditorPart> editors = EditorAPI.getOpenEditors(); for (IProject project : projects) { for (IEditorPart editor : editors) { if (editor.getEditorInput() instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile(); if (project.equals(file.getProject())) openEditors.add(editor); } } } return openEditors; }
Example 11
Source File: AnnotationModelHelper.java From saros with GNU General Public License v2.0 | 5 votes |
public IAnnotationModel retrieveAnnotationModel(IEditorPart editorPart) { IEditorInput input = editorPart.getEditorInput(); IDocumentProvider provider = DocumentProviderRegistry.getDefault().getDocumentProvider(input); IAnnotationModel model = provider.getAnnotationModel(input); return model; }
Example 12
Source File: GenerateXpectReportShortcut.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public void launch(IEditorPart editor, String mode) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFile selectObj = ((IFileEditorInput) editorInput).getFile(); generateBug(selectObj); } else { showDialogNotImplemented(editor.getClass().getName()); } }
Example 13
Source File: LaunchHelper.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** Check the project of the active editor. */ public IModule[] asModules(IEditorPart editor) throws CoreException { if (editor != null && editor.getEditorInput() instanceof IFileEditorInput) { IFileEditorInput input = (IFileEditorInput) editor.getEditorInput(); IProject project = input.getFile().getProject(); if (project != null) { return new IModule[] {asModule(project)}; } } throw new CoreException( StatusUtil.error(this, Messages.getString("CANNOT_DETERMINE_EXECUTION_CONTEXT"))); //$NON-NLS-1$ }
Example 14
Source File: PythonLinkHelper.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) { return; } Object firstElement = aSelection.getFirstElement(); //if it is a python element, let's first get the actual object for finding the editor if (firstElement instanceof IWrappedResource) { IWrappedResource resource = (IWrappedResource) firstElement; firstElement = resource.getActualObject(); } //and now, if it is really a file... if (firstElement instanceof IFile) { //ok, let's check if the active editor is already the selection, because although the findEditor(editorInput) method //may return an editor for the correct file, we may have multiple editors for the same file, and if the current //editor is already correct, we don't want to change it //@see bug: https://sourceforge.net/tracker/?func=detail&atid=577329&aid=2037682&group_id=85796 IEditorPart activeEditor = aPage.getActiveEditor(); if (activeEditor != null) { IEditorInput editorInput = activeEditor.getEditorInput(); IFile currFile = (IFile) editorInput.getAdapter(IFile.class); if (currFile != null && currFile.equals(firstElement)) { return; //the current editor is already the active editor. } } //if we got here, the active editor is not a match, so, let's find one and show it. IEditorPart editor = null; IEditorInput fileInput = new FileEditorInput((IFile) firstElement); if ((editor = aPage.findEditor(fileInput)) != null) { aPage.bringToTop(editor); } } }
Example 15
Source File: LapseView.java From lapse-plus with GNU General Public License v3.0 | 5 votes |
public static IOpenable getJavaInput(IEditorPart part) { IEditorInput editorInput= part.getEditorInput(); if (editorInput != null) { IJavaElement input= (IJavaElement)editorInput.getAdapter(IJavaElement.class); if (input instanceof IOpenable) { return (IOpenable) input; } } return null; }
Example 16
Source File: EditorUtil.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * Gets the URI associated with the editor. * * @param editor * @return */ public static URI getURI(IEditorPart editor) { // NOTE: Moved from CommonContentAssistProcessor if (editor != null) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IURIEditorInput) { IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput; return uriEditorInput.getURI(); } if (editorInput instanceof IPathEditorInput) { IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput; return URIUtil.toURI(pathEditorInput.getPath()); } if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput; return fileEditorInput.getFile().getLocationURI(); } try { if (editorInput instanceof IStorageEditorInput) { IStorageEditorInput storageEditorInput = (IStorageEditorInput) editorInput; IStorage storage = storageEditorInput.getStorage(); if (storage != null) { IPath path = storage.getFullPath(); if (path != null) { return URIUtil.toURI(path); } } } } catch (CoreException e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } if (editorInput instanceof ILocationProviderExtension) { ILocationProviderExtension lpe = (ILocationProviderExtension) editorInput; return lpe.getURI(null); } if (editorInput instanceof ILocationProvider) { ILocationProvider lp = (ILocationProvider) editorInput; return URIUtil.toURI(lp.getPath(null)); } } return null; }
Example 17
Source File: PreviewTranslationHandler.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
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(); 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(PreviewTranslationHandler.class).error("Exception:key hs008 is lost.(Can't find the key)"); System.exit(0); } if (file == null) { MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg1")); } else { String fileExtension = file.getFileExtension(); if (fileExtension != null && CommonFunction.validXlfExtension(fileExtension)) { ConverterViewModel model = getConverterViewModel(file); if (model != null) { // model.convert(); try { previewFiles(new ArrayList<IFile>(Arrays.asList(new IFile[] { file }))); } catch (Exception e) { // 修改 当异常没有消息,提示信息为空 MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg7")); LOGGER.error("", e); } } } else if (fileExtension != null && "xlp".equalsIgnoreCase(fileExtension)) { // UNDO 合并打开的预览翻译有问题,是针对合并打开的文件,而不是针对项目所有的文件 robert 2012-07-12 if (file.exists()) { // IFolder xliffFolder = file.getProject().getFolder(Constant.FOLDER_XLIFF); // Fixed Bug #2616 预览翻译--合并打开的文件不能进行预览翻译 by Jason XLFHandler hander = new XLFHandler(); List<String> files = hander.getMultiFiles(file); List<IFile> ifileList = new ArrayList<IFile>(); for (String tf : files) { ifileList.add(ResourceUtils.fileToIFile(tf)); } // if (xliffFolder.exists()) { // ArrayList<IFile> files = new ArrayList<IFile>(); // try { // ResourceUtils.getXliffs(xliffFolder, files); // } catch (CoreException e) { // throw new ExecutionException(e.getMessage(), e); // } previewFiles(ifileList); // } else { // MessageDialog // .openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), // Messages.getString("handler.PreviewTranslationHandler.msg2")); // } } } else { MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg3")); } } return null; }
Example 18
Source File: PreviewTranslationHandler.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
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, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg1")); } else { String fileExtension = file.getFileExtension(); if (fileExtension != null && CommonFunction.validXlfExtension(fileExtension)) { ConverterViewModel model = getConverterViewModel(file); if (model != null) { // model.convert(); try { previewFiles(new ArrayList<IFile>(Arrays.asList(new IFile[] { file }))); } catch (Exception e) { // 修改 当异常没有消息,提示信息为空 MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg7")); LOGGER.error("", e); } } } else if (fileExtension != null && "xlp".equalsIgnoreCase(fileExtension)) { // UNDO 合并打开的预览翻译有问题,是针对合并打开的文件,而不是针对项目所有的文件 robert 2012-07-12 if (file.exists()) { // IFolder xliffFolder = file.getProject().getFolder(Constant.FOLDER_XLIFF); // Fixed Bug #2616 预览翻译--合并打开的文件不能进行预览翻译 by Jason XLFHandler hander = new XLFHandler(); List<String> files = hander.getMultiFiles(file); List<IFile> ifileList = new ArrayList<IFile>(); for (String tf : files) { ifileList.add(ResourceUtils.fileToIFile(tf)); } // if (xliffFolder.exists()) { // ArrayList<IFile> files = new ArrayList<IFile>(); // try { // ResourceUtils.getXliffs(xliffFolder, files); // } catch (CoreException e) { // throw new ExecutionException(e.getMessage(), e); // } previewFiles(ifileList); // } else { // MessageDialog // .openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), // Messages.getString("handler.PreviewTranslationHandler.msg2")); // } } } else { MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg3")); } } return null; }
Example 19
Source File: DataSourceHelper.java From translationstudio8 with GNU General Public License v2.0 | 2 votes |
/** * 获取数据源 * @param editorPart * @return ; */ public T getDataSource(IEditorPart editorPart) { IEditorInput editorInput = editorPart.getEditorInput(); return this.getDataSource(editorInput); }
Example 20
Source File: DataSourceHelper.java From tmxeditor8 with GNU General Public License v2.0 | 2 votes |
/** * 获取数据源 * @param editorPart * @return ; */ public T getDataSource(IEditorPart editorPart) { IEditorInput editorInput = editorPart.getEditorInput(); return this.getDataSource(editorInput); }