Java Code Examples for org.eclipse.jdt.internal.ui.javaeditor.EditorUtility#isOpenInEditor()
The following examples show how to use
org.eclipse.jdt.internal.ui.javaeditor.EditorUtility#isOpenInEditor() .
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: 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 2
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 3
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 4
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 5
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 6
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); } } }
Example 7
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 8
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 9
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 10
Source File: PackageExplorerPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public void createPartControl(Composite parent) { final PerformanceStats stats= PerformanceStats.getStats(PERF_CREATE_PART_CONTROL, this); stats.startRun(); fViewer= createViewer(parent); fViewer.setUseHashlookup(true); initDragAndDrop(); setProviders(); JavaPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); MenuManager menuMgr= new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(this); fContextMenu= menuMgr.createContextMenu(fViewer.getTree()); fViewer.getTree().setMenu(fContextMenu); // Register viewer with site. This must be done before making the actions. IWorkbenchPartSite site= getSite(); site.registerContextMenu(menuMgr, fViewer); site.setSelectionProvider(fViewer); makeActions(); // call before registering for selection changes // Set input after filter and sorter has been set. This avoids resorting and refiltering. restoreFilterAndSorter(); fViewer.setInput(findInputElement()); initFrameActions(); initKeyListener(); fViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { fActionSet.handleDoubleClick(event); } }); fOpenAndLinkWithEditorHelper= new OpenAndLinkWithEditorHelper(fViewer) { @Override protected void activate(ISelection selection) { try { final Object selectedElement= SelectionUtil.getSingleElement(selection); if (EditorUtility.isOpenInEditor(selectedElement) != null) EditorUtility.openInEditor(selectedElement, true); } catch (PartInitException ex) { // ignore if no editor input can be found } } @Override protected void linkToEditor(ISelection selection) { PackageExplorerPart.this.linkToEditor(selection); } @Override protected void open(ISelection selection, boolean activate) { fActionSet.handleOpen(selection, activate); } }; IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager(); fViewer.addSelectionChangedListener(new StatusBarUpdater(slManager)); fViewer.addTreeListener(fExpansionListener); // Set help for the view JavaUIHelp.setHelp(fViewer, IJavaHelpContextIds.PACKAGES_VIEW); fillActionBars(); updateTitle(); fFilterUpdater= new FilterUpdater(fViewer); ResourcesPlugin.getWorkspace().addResourceChangeListener(fFilterUpdater); // Sync'ing the package explorer has to be done here. It can't be done // when restoring the link state since the package explorers input isn't // set yet. setLinkingEnabled(isLinkingEnabled()); stats.endRun(); }
Example 11
Source File: TypeHierarchyViewPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void setHierarchyMode(int viewerIndex) { Assert.isNotNull(fAllViewers); if (viewerIndex < fAllViewers.length && fCurrentViewerIndex != viewerIndex) { fCurrentViewerIndex= viewerIndex; updateHierarchyViewer(true); if (fInputElements != null) { ISelection currSelection= getCurrentViewer().getSelection(); if (currSelection == null || currSelection.isEmpty()) { internalSelectType(getSelectableType(fInputElements), false); currSelection= getCurrentViewer().getSelection(); } if (!fIsEnableMemberFilter) { typeSelectionChanged(currSelection); } } updateToolTipAndDescription(); fDialogSettings.put(DIALOGSTORE_HIERARCHYVIEW, viewerIndex); getCurrentViewer().getTree().setFocus(); if (fTypeOpenAndLinkWithEditorHelper != null) fTypeOpenAndLinkWithEditorHelper.dispose(); fTypeOpenAndLinkWithEditorHelper= new OpenAndLinkWithEditorHelper(getCurrentViewer()) { @Override protected void activate(ISelection selection) { try { final Object selectedElement= SelectionUtil.getSingleElement(selection); if (EditorUtility.isOpenInEditor(selectedElement) != null) EditorUtility.openInEditor(selectedElement, true); } catch (PartInitException ex) { // ignore if no editor input can be found } } @Override protected void linkToEditor(ISelection selection) { // do nothing: this is handled in more detailed by the part itself } @Override protected void open(ISelection selection, boolean activate) { if (selection instanceof IStructuredSelection) fOpenAction.run((IStructuredSelection)selection); } }; } for (int i= 0; i < fViewActions.length; i++) { ToggleViewAction action= fViewActions[i]; action.setChecked(fCurrentViewerIndex == action.getViewerIndex()); } }
Example 12
Source File: JavaBrowsingPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Adds additional listeners to this view. * This method can be overridden but should * call super. */ protected void hookViewerListeners() { fOpenAndLinkWithEditorHelper= new OpenAndLinkWithEditorHelper(fViewer) { @Override protected void activate(ISelection selection) { try { final Object selectedElement= SelectionUtil.getSingleElement(selection); if (EditorUtility.isOpenInEditor(selectedElement) != null) EditorUtility.openInEditor(selectedElement, true); } catch (PartInitException ex) { // ignore if no editor input can be found } } @Override protected void linkToEditor(ISelection selection) { if (!fProcessSelectionEvents) return; fPreviousSelectedElement= getSingleElementFromSelection(selection); IWorkbenchPage page= getSite().getPage(); if (page == null) return; if (page.equals(JavaPlugin.getActivePage()) && JavaBrowsingPart.this.equals(page.getActivePart())) { JavaBrowsingPart.this.linkToEditor(selection); } } @Override protected void open(ISelection selection, boolean activate) { IAction open= fOpenEditorGroup.getOpenAction(); if (open.isEnabled()) { open.run(); restoreSelection(); } } }; fOpenAndLinkWithEditorHelper.setLinkWithEditor(fLinkingEnabled); }