IEditorPart editorPart = getSite().getWorkbenchWindow().getActivePage().getActiveEditor(); if(editorPart != null) { IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ; IFile file = input.getFile(); IProject activeProject = file.getProject(); String activeProjectName = activeProject.getName(); //... use activeProjectName }
public void setActiveEditor(IAction action, IEditorPart editor) { if (editor != null && editor.getEditorInput() instanceof IFileEditorInput) { fEditor= editor; } else { fEditor= null; } super.setActiveEditor(action, editor); }
private IFile getFile() { if (fEditor != null) { IEditorInput ei= fEditor.getEditorInput(); if (ei instanceof IFileEditorInput) { return ((IFileEditorInput) ei).getFile(); } } return null; }
private IFile getFile() { if (fEditor != null) { IEditorInput ei= fEditor.getEditorInput(); if (ei instanceof IFileEditorInput) { return ((IFileEditorInput) ei).getFile(); } } return null; }
@Override public boolean isShownInEditor(Match match, IEditorPart editor) { Object element= match.getElement(); if (element instanceof IJavaElement) { element= ((IJavaElement) element).getOpenable(); // class file or compilation unit return element != null && element.equals(editor.getEditorInput().getAdapter(IJavaElement.class)); } else if (element instanceof IFile) { return element.equals(editor.getEditorInput().getAdapter(IFile.class)); } return false; }
@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; }
@Override public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) { IEditorInput editorInput = editor.getEditorInput(); IJavaElement element = editorInput.getAdapter(IJavaElement.class); if (element != null) { Set<Match> matches = new HashSet<>(); collectMatches(matches, element); return matches.toArray(new Match[matches.size()]); } return super.computeContainedMatches(result, editor); }
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) { IEditorInput ei= editor.getEditorInput(); if (ei instanceof IFileEditorInput) { IFileEditorInput fi= (IFileEditorInput) ei; return getMatches(fi.getFile()); } return EMPTY_ARR; }
protected IProject getCurrentProject() { if (fEditor != null) { IEditorInput ei= fEditor.getEditorInput(); if (ei instanceof IFileEditorInput) { return ((IFileEditorInput) ei).getFile().getProject(); } } return null; }
protected void handleInputChanged(IEditorPart editor) { IEditorInput newInput = editor.getEditorInput(); if (!Util.equals(newInput, lastEditorInput)) { fireSourceChanged(ISources.ACTIVE_EDITOR, ISources.ACTIVE_EDITOR_INPUT_NAME, newInput == null ? IEvaluationContext.UNDEFINED_VARIABLE : newInput); lastEditorInput = newInput; } }
public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (part instanceof IEditorPart) { IEditorInput input = ((IEditorPart) part).getEditorInput(); if (input instanceof IFileEditorInput) reactOnSelection(new StructuredSelection( ((IFileEditorInput) input).getFile())); } else reactOnSelection(selection); } };
/** * Returns the compilation unit that content assist is invoked in, <code>null</code> if there * is none. * * @return the compilation unit that content assist is invoked in, possibly <code>null</code> */ public ICompilationUnit getCompilationUnit() { return JavaUI.getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); }
private IResource getEditorInputResource(ExecutionEvent event) { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (!(activePart instanceof IEditorPart)) { return null; } IEditorInput input = ((IEditorPart)activePart).getEditorInput(); if (input instanceof IFileEditorInput) { return ((IFileEditorInput)input).getFile(); } return Adapters.adapt(input, IResource.class); }
public void launch(IEditorPart editor, String mode) { IEditorInput input = editor.getEditorInput(); IJavaElement je = (IJavaElement) input.getAdapter(IJavaElement.class); if (je != null) { IJavaProject jproject = je.getJavaProject(); if (jproject != null) { launch(jproject, mode); } } }
IWorkbench workbench = PlatformUI.getWorkbench(); IEditorPart editorPart = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor(); CompareEditorInput compareEditorInput = (CompareEditorInput) editorPart.getEditorInput(); ICompareInput compareInput = (ICompareInput) compareEditorInput.getCompareResult(); ITypedElement leftTypedElement = compareInput.getLeft(); ITypedElement rightTypedElement = compareInput.getRight(); IDocument leftDocument = CompareUI.getDocument(leftTypedElement); IDocument rightDocument = CompareUI.getDocument(rightTypedElement); String left = leftDocument.get(); String right = rightDocument.get();
/** * @see ILaunchShortcut#launch(IEditorPart, String) */ public void launch(IEditorPart editor, String mode) { IEditorInput input = editor.getEditorInput(); IJavaElement je = (IJavaElement) input.getAdapter(IJavaElement.class); if (je != null) { searchAndLaunch(new Object[] {je}, mode, getTypeSelectionTitle(), getEditorEmptyMessage()); } }
public void launch(IEditorPart editor, String mode) { ITypeRoot root = JavaUI.getEditorInputTypeRoot(editor.getEditorInput()); if (root != null) { IMethod method = resolveSelectedMethod(editor, root); if (method != null) { run(method, mode); } else if (root instanceof IJavaElement){ run(root, mode); } } }
/** * Saves the multi-page editor's document as another file. Also updates the * text for page 0's tab, and updates this multi-page editor's input to * correspond to the nested editor's. */ public void doSaveAs() { IEditorPart editor = getEditor(0); editor.doSaveAs(); setPageText(0, editor.getTitle()); setInput(editor.getEditorInput()); }
/** * Saves the multi-page editor's document as another file. Also updates the * text for page 0's tab, and updates this multi-page editor's input to * correspond to the nested editor's. */ public void doSaveAs() { IEditorPart editor = getEditor(0); editor.doSaveAs(); setPageText(0, editor.getTitle()); setInput(editor.getEditorInput()); }
private PropertiesAssistContext createAssistContext(IQuickAssistInvocationContext invocationContext) { IEditorPart editorPart= fAssistant.getEditor(); IFile file= editorPart.getEditorInput().getAdapter(IFile.class); ISourceViewer sourceViewer= invocationContext.getSourceViewer(); IType accessorType= ((PropertiesFileEditor) editorPart).getAccessorType(); return new PropertiesAssistContext(sourceViewer, invocationContext.getOffset(), invocationContext.getLength(), file, sourceViewer.getDocument(), accessorType); } }