org.eclipse.jdt.internal.ui.javaeditor.EditorUtility Java Examples
The following examples show how to use
org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.
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: JavaLaunchingCodeMiningProvider.java From jdt-codemining with Eclipse Public License 1.0 | 6 votes |
@Override public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) { return CompletableFuture.supplyAsync(() -> { monitor.isCanceled(); ITextEditor textEditor = super.getAdapter(ITextEditor.class); ITypeRoot unit = EditorUtility.getEditorInputJavaElement(textEditor, true); if (unit == null) { return Collections.emptyList(); } try { IJavaElement[] elements = unit.getChildren(); List<ICodeMining> minings = new ArrayList<>(elements.length); collectMinings(unit, textEditor, unit.getChildren(), minings, viewer, monitor); monitor.isCanceled(); return minings; } catch (JavaModelException e) { // Should never occur } return Collections.emptyList(); }); }
Example #2
Source File: PropertyKeyHyperlink.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void open(KeyReference keyReference) { if (keyReference == null) return; try { IEditorPart part= keyReference.element != null ? EditorUtility.openInEditor(keyReference.element, true) : EditorUtility.openInEditor(keyReference.resource, true); if (part != null) EditorUtility.revealInEditor(part, keyReference.offset, keyReference.length); } catch (PartInitException x) { String message= null; IWorkbenchAdapter wbAdapter= (IWorkbenchAdapter)((IAdaptable)keyReference).getAdapter(IWorkbenchAdapter.class); if (wbAdapter != null) message= Messages.format(PropertiesFileEditorMessages.OpenAction_error_messageArgs, new String[] { wbAdapter.getLabel(keyReference), x.getLocalizedMessage() } ); if (message == null) message= Messages.format(PropertiesFileEditorMessages.OpenAction_error_message, x.getLocalizedMessage()); MessageDialog.openError(fShell, PropertiesFileEditorMessages.OpenAction_error_messageProblems, message); } }
Example #3
Source File: JavadocWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void init(IWorkbench workbench, IStructuredSelection structuredSelection) { IWorkbenchWindow window= workbench.getActiveWorkbenchWindow(); List<?> selected= Collections.EMPTY_LIST; if (window != null) { ISelection selection= window.getSelectionService().getSelection(); if (selection instanceof IStructuredSelection) { selected= ((IStructuredSelection) selection).toList(); } else { IJavaElement element= EditorUtility.getActiveEditorJavaInput(); if (element != null) { selected= Arrays.asList(element); } } } fStore= new JavadocOptionsManager(fXmlJavadocFile, getDialogSettings(), selected); }
Example #4
Source File: TypeHierarchyViewPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void revealElementInEditor(Object elem, StructuredViewer originViewer) { // only allow revealing when the type hierarchy is the active page // no revealing after selection events due to model changes if (getSite().getPage().getActivePart() != this) { return; } if (fSelectionProviderMediator.getViewerInFocus() != originViewer) { return; } IEditorPart editorPart= EditorUtility.isOpenInEditor(elem); if (editorPart != null && (elem instanceof IJavaElement)) { getSite().getPage().removePartListener(fPartListener); getSite().getPage().bringToTop(editorPart); EditorUtility.revealInEditor(editorPart, (IJavaElement) elem); getSite().getPage().addPartListener(fPartListener); } }
Example #5
Source File: JavaEditorTextHoverDescriptor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Computes the state mask for the given modifier string. * * @param modifiers the string with the modifiers, separated by '+', '-', ';', ',' or '.' * @return the state mask or -1 if the input is invalid */ public static int computeStateMask(String modifiers) { if (modifiers == null) return -1; if (modifiers.length() == 0) return SWT.NONE; int stateMask= 0; StringTokenizer modifierTokenizer= new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$ while (modifierTokenizer.hasMoreTokens()) { int modifier= EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken()); if (modifier == 0 || (stateMask & modifier) == modifier) return -1; stateMask= stateMask | modifier; } return stateMask; }
Example #6
Source File: AddJavaDocStubAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public void run(IStructuredSelection selection) { IMember[] members= getSelectedMembers(selection); if (members == null || members.length == 0) { return; } try { ICompilationUnit cu= members[0].getCompilationUnit(); if (!ActionUtil.isEditable(getShell(), cu)) { return; } // open the editor, forces the creation of a working copy IEditorPart editor= JavaUI.openInEditor(cu); if (ElementValidator.check(members, getShell(), getDialogTitle(), false)) run(members); JavaModelUtil.reconcile(cu); EditorUtility.revealInEditor(editor, members[0]); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.AddJavaDocStubsAction_error_actionFailed); } }
Example #7
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 #8
Source File: NewSourceFolderWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private String getProjectPath(IStructuredSelection selection) { Object selectedElement= null; if (selection == null || selection.isEmpty()) { selectedElement= EditorUtility.getActiveEditorJavaInput(); } else if (selection.size() == 1) { selectedElement= selection.getFirstElement(); } if (selectedElement instanceof IResource) { IProject proj= ((IResource)selectedElement).getProject(); if (proj != null) { return proj.getFullPath().makeRelative().toString(); } } else if (selectedElement instanceof IJavaElement) { IJavaProject jproject= ((IJavaElement)selectedElement).getJavaProject(); if (jproject != null) { return jproject.getProject().getFullPath().makeRelative().toString(); } } return null; }
Example #9
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 #10
Source File: BugResolution.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
/** * This method is used by the test-framework, to catch the thrown exceptions * and report it to the user. * * @see #run(IMarker) */ private void runInternal(IMarker marker) throws CoreException { Assert.isNotNull(marker); PendingRewrite pending = resolveWithoutWriting(marker); if (pending == null) { return; } try { IRegion region = completeRewrite(pending); if (region == null) { return; } IEditorPart part = EditorUtility.isOpenInEditor(pending.originalUnit); if (part instanceof ITextEditor) { ((ITextEditor) part).selectAndReveal(region.getOffset(), region.getLength()); } } finally { pending.originalUnit.discardWorkingCopy(); } }
Example #11
Source File: JavaElementCodeMiningProvider.java From jdt-codemining with Eclipse Public License 1.0 | 6 votes |
@Override public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) { return CompletableFuture.supplyAsync(() -> { monitor.isCanceled(); ITextEditor textEditor = super.getAdapter(ITextEditor.class); ITypeRoot unit = EditorUtility.getEditorInputJavaElement(textEditor, true); if (unit == null) { return Collections.emptyList(); } fViewer = viewer; fUnit = unit; try { List<ICodeMining> minings = new ArrayList<>(); collectMinings(unit, textEditor, unit.getChildren(), minings, viewer, monitor); monitor.isCanceled(); return minings; } catch (JavaModelException e) { // TODO: what should we done when there are some errors? } return Collections.emptyList(); }); }
Example #12
Source File: JavaASTCodeMiningProvider.java From jdt-codemining with Eclipse Public License 1.0 | 6 votes |
@Override public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) { return CompletableFuture.supplyAsync(() -> { monitor.isCanceled(); ITextEditor textEditor = super.getAdapter(ITextEditor.class); ITypeRoot unit = EditorUtility.getEditorInputJavaElement(textEditor, true); if (unit == null) { return null; } List<ICodeMining> minings = new ArrayList<>(); collectCodeMinings(unit, textEditor, viewer, minings); monitor.isCanceled(); return minings; }); }
Example #13
Source File: JUnitCodeMiningProvider.java From jdt-codemining with Eclipse Public License 1.0 | 6 votes |
@Override public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) { this.viewer = viewer; return CompletableFuture.supplyAsync(() -> { monitor.isCanceled(); ITextEditor textEditor = super.getAdapter(ITextEditor.class); ITypeRoot unit = EditorUtility.getEditorInputJavaElement(textEditor, true); if (unit == null) { return null; } try { IJavaElement[] elements = unit.getChildren(); List<ICodeMining> minings = new ArrayList<>(elements.length); collectCodeMinings(unit, elements, minings, viewer, monitor); monitor.isCanceled(); return minings; } catch (JavaModelException e) { // TODO: what should we done when there are some errors? } return null; }); }
Example #14
Source File: JavaFileLinkHelper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) { if (selection == null || selection.isEmpty()) return; Object element= selection.getFirstElement(); IEditorPart part= EditorUtility.isOpenInEditor(element); if (part != null) { page.bringToTop(part); if (element instanceof IJavaElement) EditorUtility.revealInEditor(part, (IJavaElement) element); } }
Example #15
Source File: CorrectionMarkerResolutionGenerator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IMarkerResolution[] internalGetResolutions(IMarker marker) { if (!internalHasResolutions(marker)) { return NO_RESOLUTIONS; } ICompilationUnit cu= getCompilationUnit(marker); if (cu != null) { IEditorInput input= EditorUtility.getEditorInput(cu); if (input != null) { IProblemLocation location= findProblemLocation(input, marker); if (location != null) { IInvocationContext context= new AssistContext(cu, location.getOffset(), location.getLength()); if (!hasProblem (context.getASTRoot().getProblems(), location)) return NO_RESOLUTIONS; ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>(); JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals); Collections.sort(proposals, new CompletionProposalComparator()); int nProposals= proposals.size(); IMarkerResolution[] resolutions= new IMarkerResolution[nProposals]; for (int i= 0; i < nProposals; i++) { resolutions[i]= new CorrectionMarkerResolution(context.getCompilationUnit(), location.getOffset(), location.getLength(), proposals.get(i), marker); } return resolutions; } } } return NO_RESOLUTIONS; }
Example #16
Source File: AbstractInformationControl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void gotoSelectedElement() { Object selectedElement= getSelectedElement(); if (selectedElement != null) { try { dispose(); IEditorPart part= EditorUtility.openInEditor(selectedElement, true); if (part != null && selectedElement instanceof IJavaElement) EditorUtility.revealInEditor(part, (IJavaElement) selectedElement); } catch (CoreException ex) { JavaPlugin.log(ex); } } }
Example #17
Source File: JavaReconciler.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void install(ITextViewer textViewer) { super.install(textViewer); fPartListener= new PartListener(); IWorkbenchPartSite site= fTextEditor.getSite(); IWorkbenchWindow window= site.getWorkbenchWindow(); window.getPartService().addPartListener(fPartListener); fActivationListener= new ActivationListener(textViewer.getTextWidget()); Shell shell= window.getShell(); shell.addShellListener(fActivationListener); fJavaElementChangedListener= new ElementChangedListener(); JavaCore.addElementChangedListener(fJavaElementChangedListener); fResourceChangeListener= new ResourceChangeListener(); IWorkspace workspace= JavaPlugin.getWorkspace(); workspace.addResourceChangeListener(fResourceChangeListener); fPropertyChangeListener= new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (SpellingService.PREFERENCE_SPELLING_ENABLED.equals(event.getProperty()) || SpellingService.PREFERENCE_SPELLING_ENGINE.equals(event.getProperty())) forceReconciling(); } }; JavaPlugin.getDefault().getCombinedPreferenceStore().addPropertyChangeListener(fPropertyChangeListener); fReconciledElement= EditorUtility.getEditorInputJavaElement(fTextEditor, false); }
Example #18
Source File: JavadocHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static IEditorPart openDeclaration(IJavaElement element) throws PartInitException, JavaModelException { if (!(element instanceof IPackageFragment)) { return JavaUI.openInEditor(element); } IPackageFragment packageFragment= (IPackageFragment) element; ITypeRoot typeRoot; IPackageFragmentRoot root= (IPackageFragmentRoot) packageFragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root.getKind() == IPackageFragmentRoot.K_BINARY) { typeRoot= packageFragment.getClassFile(JavaModelUtil.PACKAGE_INFO_CLASS); } else { typeRoot= packageFragment.getCompilationUnit(JavaModelUtil.PACKAGE_INFO_JAVA); } // open the package-info file in editor if one exists if (typeRoot.exists()) return JavaUI.openInEditor(typeRoot); // open the package.html file in editor if one exists Object[] nonJavaResources= packageFragment.getNonJavaResources(); for (Object nonJavaResource : nonJavaResources) { if (nonJavaResource instanceof IFile) { IFile file= (IFile) nonJavaResource; if (file.exists() && JavaModelUtil.PACKAGE_HTML.equals(file.getName())) { return EditorUtility.openInEditor(file, true); } } } // select the package in the Package Explorer if there is no associated package Javadoc file PackageExplorerPart view= (PackageExplorerPart) JavaPlugin.getActivePage().showView(JavaUI.ID_PACKAGES); view.tryToReveal(packageFragment); return null; }
Example #19
Source File: StructureSelectionAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public final void run() { IJavaElement inputElement= EditorUtility.getEditorInputJavaElement(fEditor, false); if (!(inputElement instanceof ITypeRoot && inputElement.exists())) return; ITypeRoot typeRoot= (ITypeRoot) inputElement; ISourceRange sourceRange; try { sourceRange= typeRoot.getSourceRange(); if (sourceRange == null || sourceRange.getLength() == 0) { MessageDialog.openInformation(fEditor.getEditorSite().getShell(), SelectionActionMessages.StructureSelect_error_title, SelectionActionMessages.StructureSelect_error_message); return; } } catch (JavaModelException e) { } ITextSelection selection= getTextSelection(); ISourceRange newRange= getNewSelectionRange(createSourceRange(selection), typeRoot); // Check if new selection differs from current selection if (selection.getOffset() == newRange.getOffset() && selection.getLength() == newRange.getLength()) return; fSelectionHistory.remember(new SourceRange(selection.getOffset(), selection.getLength())); try { fSelectionHistory.ignoreSelectionChanges(); fEditor.selectAndReveal(newRange.getOffset(), newRange.getLength()); } finally { fSelectionHistory.listenToSelectionChanges(); } }
Example #20
Source File: JavaSearchEditorOpener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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); }
Example #21
Source File: JavaSearchEditorOpener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IEditorPart showWithoutReuse(Object element) throws PartInitException { try { return EditorUtility.openInEditor(element, false); } catch (PartInitException e) { if (e.getStatus().getCode() != IJavaStatusConstants.EDITOR_NO_EDITOR_INPUT) { throw e; } } return null; }
Example #22
Source File: JavaSearchEditorOpener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public IEditorPart openElement(Object element) throws PartInitException { IWorkbenchPage wbPage= JavaPlugin.getActivePage(); IEditorPart editor; if (NewSearchUI.reuseEditor()) editor= showWithReuse(element, wbPage); else editor= showWithoutReuse(element); if (element instanceof IJavaElement) EditorUtility.revealInEditor(editor, (IJavaElement) element); return editor; }
Example #23
Source File: JavaBrowsingPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Links to editor (if option enabled) * @param selection the selection */ private void linkToEditor(ISelection selection) { Object obj= SelectionUtil.getSingleElement(selection); if (obj != null) { IEditorPart part= EditorUtility.isOpenInEditor(obj); if (part != null) { IWorkbenchPage page= getSite().getPage(); page.bringToTop(part); if (obj instanceof IJavaElement) EditorUtility.revealInEditor(part, (IJavaElement) obj); } } }
Example #24
Source File: CallHierarchyUI.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static IEditorPart isOpenInEditor(Object elem) { IJavaElement javaElement= null; if (elem instanceof MethodWrapper) { javaElement= ((MethodWrapper) elem).getMember(); } else if (elem instanceof CallLocation) { javaElement= ((CallLocation) elem).getMember(); } if (javaElement != null) { return EditorUtility.isOpenInEditor(javaElement); } return null; }
Example #25
Source File: JavaDebugElementCodeMiningProvider.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
@Override protected List provideCodeMinings(ITextViewer viewer, IJavaStackFrame frame, IProgressMonitor monitor) { List<ICodeMining> minings = new ArrayList<>(); ITextEditor textEditor = super.getAdapter(ITextEditor.class); ITypeRoot unit = EditorUtility.getEditorInputJavaElement(textEditor, true); if (unit == null) { return minings; } CompilationUnit cu = SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_YES, null); JavaDebugElementCodeMiningASTVisitor visitor = new JavaDebugElementCodeMiningASTVisitor(frame, cu, viewer, minings, this); cu.accept(visitor); return minings; }
Example #26
Source File: GWTProjectPropertyPage.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public static IEditorReference[] getOpenJavaEditors(IProject project) { List<IEditorReference> projectOpenJavaEditors = new ArrayList<IEditorReference>(); try { IWorkbenchPage page = JavaPlugin.getActivePage(); if (page != null) { // Iterate through all the open editors IEditorReference[] openEditors = page.getEditorReferences(); for (IEditorReference openEditor : openEditors) { IEditorPart editor = openEditor.getEditor(false); // Only look for Java Editor and subclasses if (editor instanceof CompilationUnitEditor) { IEditorInput input = openEditor.getEditorInput(); IJavaProject inputProject = EditorUtility.getJavaProject(input); // See if the editor is editing a file in this project if (inputProject != null && inputProject.getProject().equals(project)) { projectOpenJavaEditors.add(openEditor); } } } } } catch (PartInitException e) { GWTPluginLog.logError(e); } return projectOpenJavaEditors.toArray(new IEditorReference[0]); }
Example #27
Source File: GWTJavaEditor.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
@Override protected void doSetInput(IEditorInput input) throws CoreException { IJavaProject javaProject = EditorUtility.getJavaProject(input); if (javaProject != null && GWTNature.isGWTProject(javaProject.getProject())) { // Use GWT partitioning if the compilation unit is in a GWT project inputPartitioning = GWTPartitions.GWT_PARTITIONING; } else { // Otherwise, use Java partitioning to emulate the Java editor inputPartitioning = IJavaPartitions.JAVA_PARTITIONING; } super.doSetInput(input); }
Example #28
Source File: OpenAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Note: This constructor is for internal use only. Clients should not call this constructor. * @param editor the Java editor * * @noreference This constructor is not intended to be referenced by clients. */ public OpenAction(JavaEditor editor) { this(editor.getEditorSite()); fEditor= editor; setText(ActionMessages.OpenAction_declaration_label); setEnabled(EditorUtility.getEditorInputJavaElement(fEditor, false) != null); }
Example #29
Source File: CUCorrectionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void apply(IDocument document) { try { ICompilationUnit unit= getCompilationUnit(); IEditorPart part= null; if (unit.getResource().exists()) { boolean canEdit= performValidateEdit(unit); if (!canEdit) { return; } part= EditorUtility.isOpenInEditor(unit); if (part == null) { part= JavaUI.openInEditor(unit); if (part != null) { fSwitchedEditor= true; document= JavaUI.getDocumentProvider().getDocument(part.getEditorInput()); } } IWorkbenchPage page= JavaPlugin.getActivePage(); if (page != null && part != null) { page.bringToTop(part); } if (part != null) { part.setFocus(); } } performChange(part, document); } catch (CoreException e) { ExceptionHandler.handle(e, CorrectionMessages.CUCorrectionProposal_error_title, CorrectionMessages.CUCorrectionProposal_error_message); } }
Example #30
Source File: PackageExplorerPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Links to editor (if option enabled) * @param selection the selection */ private void linkToEditor(ISelection selection) { Object obj= SelectionUtil.getSingleElement(selection); if (obj != null) { IEditorPart part= EditorUtility.isOpenInEditor(obj); if (part != null) { IWorkbenchPage page= getSite().getPage(); page.bringToTop(part); if (obj instanceof IJavaElement) EditorUtility.revealInEditor(part, (IJavaElement)obj); } } }