/** * Opens a Java editor for the given element if the element is a Java compilation unit or a Java * class file. * * @return the IEditorPart or null if wrong element type or opening failed */ public static IEditorPart openInEditor(ICompilationUnit aCompilationUnit, String editorId) throws JavaModelException, PartInitException { return openInEditor(EditorUtility.getEditorInput(aCompilationUnit), editorId); }
private IEditorPart showWithReuse(Object element, IWorkbenchPage wbPage) throws PartInitException { IEditorInput input= EditorUtility.getEditorInput(element); if (input == null) return null; String editorID= EditorUtility.getEditorID(input); return showInEditor(wbPage, input, editorID); }
private IEditorPart showWithReuse(Object element, IWorkbenchPage wbPage) throws PartInitException { IEditorInput input= EditorUtility.getEditorInput(element); if (input == null) return null; String editorID= EditorUtility.getEditorID(input); return showInEditor(wbPage, input, editorID); }
private boolean inputIsSelected(IEditorInput input) { IStructuredSelection selection= (IStructuredSelection)fViewer.getSelection(); if (selection.size() != 1) return false; IEditorInput selectionAsInput= EditorUtility.getEditorInput(selection.getFirstElement()); return input.equals(selectionAsInput); }
public static IFile getFile(JavaClass javaClass) { ICompilationUnit comp = getCompilationUnit(javaClass); if (comp == null) return null; IEditorInput input = null; try { input = EditorUtility.getEditorInput(comp); } catch (JavaModelException ex) { return null; } if (input != null) { return (IFile) input.getAdapter(IFile.class); } return null; }
private boolean inputIsSelected(IEditorInput input) { IStructuredSelection selection= (IStructuredSelection)fViewer.getSelection(); if (selection.size() != 1) return false; IEditorInput selectionAsInput= null; try { selectionAsInput= EditorUtility.getEditorInput(selection.getFirstElement()); } catch (JavaModelException e1) { return false; } return input.equals(selectionAsInput); }
private boolean inputIsSelected(IEditorInput input) { IStructuredSelection selection= (IStructuredSelection)fViewer.getSelection(); if (selection.size() != 1) return false; IEditorInput selectionAsInput= EditorUtility.getEditorInput(selection.getFirstElement()); return input.equals(selectionAsInput); }
@Override public IEditorInput getEditorInput(SearchResultDoc doc) throws Exception { if( ! doc.isInJar() ) return super.getEditorInput(doc); if( "class".equals(doc.getFileExtension()) ) { IClassFile classFile = getClassFile(doc); if( classFile == null ) return null; return EditorUtility.getEditorInput(classFile); } IStorage storage = getNonJavaResource(doc); if( storage == null ) return null; return EditorUtility.getEditorInput(storage); }
public static IEditorInput getEditorInput(Object input) { if (input instanceof IJavaElement) return getEditorInput((IJavaElement) input); if (input instanceof IFile) return new FileEditorInput((IFile) input); if (JavaModelUtil.isOpenableStorage(input)) return new JarEntryEditorInput((IStorage)input); return null; }
public static IEditorInput getEditorInput(Object input) throws JavaModelException { if (input instanceof IJavaElement) return getEditorInput((IJavaElement) input); if (input instanceof IFile) return new FileEditorInput((IFile) input); if (JavaModelUtil.isOpenableStorage(input)) return new JarEntryEditorInput((IStorage)input); return null; }
public static IEditorInput getEditorInput(Object input) { if (input instanceof IJavaElement) return getEditorInput((IJavaElement) input); if (input instanceof IFile) return new FileEditorInput((IFile) input); if (JavaModelUtil.isOpenableStorage(input)) return new JarEntryEditorInput((IStorage)input); return null; }
/** * Tests if a CU is currently shown in an editor * * @param inputElement the input element * @return the IEditorPart if shown, null if element is not open in an editor */ public static IEditorPart isOpenInEditor(Object inputElement) { IEditorPart editor= findEditor(inputElement, false); if (editor != null) return editor; IEditorInput input= getEditorInput(inputElement); if (input != null) { IWorkbenchPage p= JavaPlugin.getActivePage(); if (p != null) { return p.findEditor(input); } } return null; }
/** * Tests if a CU is currently shown in an editor * * @param inputElement the input element * @return the IEditorPart if shown, null if element is not open in an editor */ public static IEditorPart isOpenInEditor(Object inputElement) { IEditorPart editor= findEditor(inputElement, false); if (editor != null) return editor; IEditorInput input= getEditorInput(inputElement); if (input != null) { IWorkbenchPage p= JavaPlugin.getActivePage(); if (p != null) { return p.findEditor(input); } } return null; }
/** * Tests if a CU is currently shown in an editor * * @return the IEditorPart if shown, null if element is not open in an editor */ public static IEditorPart isOpenInEditor(Object inputElement) { IEditorInput input= null; try { input= getEditorInput(inputElement); } catch (JavaModelException x) { JavaPlugin.log(x.getStatus()); } if (input != null) { IWorkbenchPage p= JavaPlugin.getActivePage(); if (p != null) { return p.findEditor(input); } } return null; }
@Override public void dragStart(DragSourceEvent event) { fEditorInputDatas= new ArrayList<>(); ISelection selection= fProvider.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection= (IStructuredSelection) selection; for (Iterator<?> iter= structuredSelection.iterator(); iter.hasNext();) { Object element= iter.next(); IEditorInput editorInput= EditorUtility.getEditorInput(element); if (editorInput != null && editorInput.getPersistable() != null) { try { String editorId= EditorUtility.getEditorID(editorInput); // see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..): IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor editorDesc= editorReg.findEditor(editorId); if (editorDesc != null && !editorDesc.isOpenExternal()) { fEditorInputDatas.add(EditorInputTransfer.createEditorInputData(editorId, editorInput)); } } catch (PartInitException e) { JavaPlugin.log(e); } } } } event.doit= fEditorInputDatas.size() > 0; }
private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) return NO_PROPOSALS; IMarker marker= markerAnnotation.getMarker(); ICompilationUnit cu= getCompilationUnit(marker); if (cu == null) return NO_PROPOSALS; IEditorInput input= EditorUtility.getEditorInput(cu); if (input == null) return NO_PROPOSALS; IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); if (model == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) return NO_PROPOSALS; IMarker marker= markerAnnotation.getMarker(); ICompilationUnit cu= getCompilationUnit(marker); if (cu == null) return NO_PROPOSALS; IEditorInput input= EditorUtility.getEditorInput(cu); if (input == null) return NO_PROPOSALS; IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); if (model == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
/** * Opens the editor currently associated with the given element (IJavaElement, IFile, IStorage...) * * @param inputElement the input element * @param activate <code>true</code> if the editor should be activated * @return an open editor or <code>null</code> if an external editor was opened * @throws PartInitException if the editor could not be opened or the input element is not valid * Status code {@link IJavaStatusConstants#EDITOR_NO_EDITOR_INPUT} if opening the editor failed as * no editor input could be created for the given element. */ public static IEditorPart openInEditor(Object inputElement, boolean activate) throws PartInitException { if (inputElement instanceof IFile) { IFile file= (IFile) inputElement; if (!isClassFile(file)) return openInEditor(file, activate); inputElement= JavaCore.createClassFileFrom(file); } IEditorPart editor= findEditor(inputElement, activate); if (editor != null) return editor; IEditorInput input= getEditorInput(inputElement); if (input == null) throwPartInitException(JavaEditorMessages.EditorUtility_no_editorInput, IJavaStatusConstants.EDITOR_NO_EDITOR_INPUT); return openInEditor(input, getEditorID(input), activate); }
/** * Opens the editor currently associated with the given element (IJavaElement, IFile, IStorage...) * * @param inputElement the input element * @param activate <code>true</code> if the editor should be activated * @return an open editor or <code>null</code> if an external editor was opened * @throws PartInitException if the editor could not be opened or the input element is not valid * Status code {@link IJavaStatusConstants#EDITOR_NO_EDITOR_INPUT} if opening the editor failed as * no editor input could be created for the given element. */ public static IEditorPart openInEditor(Object inputElement, boolean activate) throws PartInitException { if (inputElement instanceof IFile) { IFile file= (IFile) inputElement; if (!isClassFile(file)) return openInEditor(file, activate); inputElement= JavaCore.createClassFileFrom(file); } IEditorPart editor= findEditor(inputElement, activate); if (editor != null) return editor; IEditorInput input= getEditorInput(inputElement); if (input == null) throwPartInitException(JavaEditorMessages.EditorUtility_no_editorInput, IJavaStatusConstants.EDITOR_NO_EDITOR_INPUT); return openInEditor(input, getEditorID(input), activate); }
@Override public IAdaptable createElement(IMemento memento) { String identifier= memento.getString(KEY); if (identifier == null) return null; IJavaElement element= JavaCore.create(identifier); try { if (!element.exists() && element instanceof IOrdinaryClassFile) { /* * Let's try to find the class file, * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=83221 */ IOrdinaryClassFile cf= (IOrdinaryClassFile)element; IType type= cf.getType(); IJavaProject project= element.getJavaProject(); if (project != null) { type= project.findType(type.getFullyQualifiedName()); if (type == null) return null; element= type.getParent(); } } return EditorUtility.getEditorInput(element); } catch (JavaModelException x) { // Don't report but simply return null return null; } }