Java Code Examples for org.eclipse.ui.IWorkbenchPage#findEditor()
The following examples show how to use
org.eclipse.ui.IWorkbenchPage#findEditor() .
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: N4JSResourceLinkHelper.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public void activateEditor(final IWorkbenchPage page, final IStructuredSelection selection) { if (null != selection && !selection.isEmpty()) { final Object firstElement = selection.getFirstElement(); if (firstElement instanceof ResourceNode) { SafeURI<?> nodeLocation = ((ResourceNode) firstElement).getLocation(); if (nodeLocation.isFile()) { final URI uri = nodeLocation.toURI(); final IEditorInput editorInput = EditorUtils.createEditorInput(new URIBasedStorage(uri)); final IEditorPart editor = page.findEditor(editorInput); if (null != editor) { page.bringToTop(editor); } else { languageSpecificURIEditorOpener.open(uri, true); } return; } } } super.activateEditor(page, selection); }
Example 2
Source File: ReadCamelProcess.java From tesb-studio-se with Apache License 2.0 | 6 votes |
@Override protected void doRun() { final IRepositoryNode node = (IRepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement(); CamelProcessItem processItem = (CamelProcessItem) node.getObject().getProperty().getItem(); IWorkbenchPage page = getActivePage(); try { CamelProcessEditorInput fileEditorInput = new CamelProcessEditorInput(processItem, true, null, true); checkUnLoadedNodeForProcess(fileEditorInput); IEditorPart editorPart = page.findEditor(fileEditorInput); if (editorPart == null) { fileEditorInput.setRepositoryNode(node); page.openEditor(fileEditorInput, CamelMultiPageTalendEditor.ID, true); } else { page.activate(editorPart); } } catch (PartInitException | PersistenceException e) { MessageBoxExceptionHandler.process(e); } }
Example 3
Source File: EditorUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * 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; }
Example 4
Source File: NavigatorLinkHelper.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public void activateEditor(final IWorkbenchPage aPage, final IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) { return; } final Object o = aSelection.getFirstElement(); // if (o instanceof WrappedLink) { // if (!NavigatorRoot.INSTANCE.mapper.validateLocation(((WrappedLink) o).getResource())) { // MessageDialog.openError(WorkbenchHelper.getShell(), "Unknown file", // "The file at location '" + ((WrappedLink) o).getResource().getLocation() + " does not exist"); // return; // } // // } if (o instanceof WrappedFile) { final IEditorInput fileInput = new FileEditorInput(((WrappedFile) o).getResource()); final IEditorPart editor = aPage.findEditor(fileInput); if (editor != null) { aPage.bringToTop(editor); } } }
Example 5
Source File: EditorUtilities.java From ContentAssist with MIT License | 5 votes |
/** * Obtains an editor that may edits the contents of a file. * @param file the file * @return the editor of the file, or <code>null</code> if none */ public static IEditorPart getEditor(IFile file) { IEditorInput input = new FileEditorInput(file); IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { IWorkbenchPage[] pages = window.getPages(); for (IWorkbenchPage page : pages) { IEditorPart part = page.findEditor(input); return part; } } return null; }
Example 6
Source File: ResourceLinkHelper.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) return; if (aSelection.getFirstElement() instanceof IFile) { IEditorInput fileInput = new FileEditorInput((IFile) aSelection.getFirstElement()); IEditorPart editor = null; if ((editor = aPage.findEditor(fileInput)) != null) aPage.bringToTop(editor); } }
Example 7
Source File: ResourceLinkHelper.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) return; if (aSelection.getFirstElement() instanceof IFile) { IEditorInput fileInput = new FileEditorInput((IFile) aSelection.getFirstElement()); IEditorPart editor = null; if ((editor = aPage.findEditor(fileInput)) != null) aPage.bringToTop(editor); } }
Example 8
Source File: JavaSearchEditorOpener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IEditorPart showInEditor(IWorkbenchPage page, IEditorInput input, String editorId) { IEditorPart editor= page.findEditor(input); if (editor != null) { page.bringToTop(editor); return editor; } IEditorReference reusedEditorRef= fReusedEditor; if (reusedEditorRef != null) { boolean isOpen= reusedEditorRef.getEditor(false) != null; boolean canBeReused= isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned(); if (canBeReused) { boolean showsSameInputType= reusedEditorRef.getId().equals(editorId); if (!showsSameInputType) { page.closeEditors(new IEditorReference[] { reusedEditorRef }, false); fReusedEditor= null; } else { editor= reusedEditorRef.getEditor(true); if (editor instanceof IReusableEditor) { ((IReusableEditor) editor).setInput(input); page.bringToTop(editor); return editor; } } } } // could not reuse try { editor= page.openEditor(input, editorId, false); if (editor instanceof IReusableEditor) { IEditorReference reference= (IEditorReference) page.getReference(editor); fReusedEditor= reference; } else { fReusedEditor= null; } return editor; } catch (PartInitException ex) { MessageDialog.openError(JavaPlugin.getActiveWorkbenchShell(), SearchMessages.Search_Error_openEditor_title, SearchMessages.Search_Error_openEditor_message); return null; } }
Example 9
Source File: OpenAPICloudWizardActionDelegate.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override public void run(IAction action) { IWorkbenchPage page = window.getActivePage(); getInput(); IEditorPart part = page.findEditor(input); if(part != null ) { page.bringToTop(part); return; } open(page); }
Example 10
Source File: PerspectiveHelper.java From gama with GNU General Public License v3.0 | 5 votes |
private static void applyActiveEditor(final IWorkbenchPage page) { if ( activeEditor == null ) { return; } final IEditorPart part = page.findEditor(activeEditor); if ( part != null ) { page.activate(part); // DEBUG.OUT("Applying memorized editor to " + page.getPerspective().getId() + " = " + activeEditor.getName()); // page.bringToTop(part); } }
Example 11
Source File: ModelEditorAdapterFactory.java From tlaplus with MIT License | 5 votes |
@SuppressWarnings("unchecked") public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (!ModelEditor.class.equals(adapterType)) { return null; } if (adaptableObject instanceof Model) { final IWorkbenchPage activePage = UIHelper.getActivePage(); if (activePage != null) { final Model model = (Model) adaptableObject; return (T) activePage.findEditor(new FileEditorInput(model.getFile())); } } return null; }
Example 12
Source File: MarkerResolutionGenerator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public XtextEditor findEditor(IResource resource) { if(resource instanceof IFile) { IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = activePage.findEditor(new FileEditorInput((IFile) resource)); if(editor instanceof XtextEditor) { return (XtextEditor)editor; } else if (editor != null) { return Adapters.adapt(editor, XtextEditor.class); } } return null; }
Example 13
Source File: XtextDocumentUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.19 */ public IXtextDocument getXtextDocument(IResource resource) { if (resource instanceof IFile) { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = activePage.findEditor(new FileEditorInput((IFile) resource)); if (editor != null) { return getXtextDocument(editor); } return getXtextDocument(new FileEditorInput((IFile) resource)); } return null; }
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: NavigatorLinkHelper.java From statecharts with Eclipse Public License 1.0 | 4 votes |
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) { return; } if (false == aSelection.getFirstElement() instanceof DomainNavigatorItem) { return; } DomainNavigatorItem abstractNavigatorItem = (DomainNavigatorItem) aSelection .getFirstElement(); View navigatorView = abstractNavigatorItem.getView(); if (navigatorView == null) { return; } IEditorInput editorInput = getEditorInput(navigatorView.getDiagram()); IEditorPart editor = aPage.findEditor(editorInput); if (editor == null) { return; } aPage.bringToTop(editor); if (editor instanceof DiagramEditor) { DiagramEditor diagramEditor = (DiagramEditor) editor; ResourceSet diagramEditorResourceSet = diagramEditor .getEditingDomain().getResourceSet(); EObject selectedView = diagramEditorResourceSet.getEObject( EcoreUtil.getURI(navigatorView), true); if (selectedView == null) { return; } GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor .getAdapter(GraphicalViewer.class); EditPart selectedEditPart = (EditPart) graphicalViewer .getEditPartRegistry().get(selectedView); if (selectedEditPart != null) { graphicalViewer.select(selectedEditPart); graphicalViewer.reveal(selectedEditPart); } } }
Example 16
Source File: TmfEditorLinkHelper.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
@Override public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) { return; } IFile file = null; if ((aSelection.getFirstElement() instanceof TmfTraceElement)) { TmfTraceElement traceElement = ((TmfTraceElement)aSelection.getFirstElement()); // If trace is under an experiment, use the original trace from the traces folder traceElement = traceElement.getElementUnderTraceFolder(); file = traceElement.getBookmarksFile(); } else if ((aSelection.getFirstElement() instanceof TmfExperimentElement)) { TmfExperimentElement experimentElement = (TmfExperimentElement) aSelection.getFirstElement(); file = experimentElement.getBookmarksFile(); } if (file != null) { IEditorInput tmpInput = new FileEditorInput(file); IEditorPart localEditor = aPage.findEditor(tmpInput); if (localEditor != null) { // Editor found. aPage.bringToTop(localEditor); } else { // Search in references for corresponding editor IEditorReference[] refs = aPage.getEditorReferences(); for (IEditorReference editorReference : refs) { try { if (editorReference.getEditorInput().equals(tmpInput)) { localEditor = editorReference.getEditor(true); if (localEditor != null) { aPage.bringToTop(localEditor); } } } catch (PartInitException e) { // Ignore } } } } }
Example 17
Source File: EditorOpener.java From typescript.java with MIT License | 4 votes |
private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate) throws PartInitException { IEditorInput input= new FileEditorInput(file); IEditorPart editor= page.findEditor(input); if (editor != null) { page.bringToTop(editor); if (activate) { page.activate(editor); } return editor; } IEditorReference reusedEditorRef= fReusedEditor; if (reusedEditorRef != null) { boolean isOpen= reusedEditorRef.getEditor(false) != null; boolean canBeReused= isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned(); if (canBeReused) { boolean showsSameInputType= reusedEditorRef.getId().equals(editorId); if (!showsSameInputType) { page.closeEditors(new IEditorReference[] { reusedEditorRef }, false); fReusedEditor= null; } else { editor= reusedEditorRef.getEditor(true); if (editor instanceof IReusableEditor) { ((IReusableEditor) editor).setInput(input); page.bringToTop(editor); if (activate) { page.activate(editor); } return editor; } } } } editor= page.openEditor(input, editorId, activate); if (editor instanceof IReusableEditor) { IEditorReference reference= (IEditorReference) page.getReference(editor); fReusedEditor= reference; } else { fReusedEditor= null; } return editor; }
Example 18
Source File: ThemeUIComposite.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private void showUZWizard() { IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); if (OpenAPICloudWizardActionDelegate.input == null) { OpenAPICloudWizardActionDelegate.input = new IEditorInput() { @SuppressWarnings("rawtypes") public Object getAdapter(Class adapter) { return null; } public String getToolTipText() { return "test"; } public IPersistableElement getPersistable() { return null; } public String getName() { return "uz"; } public ImageDescriptor getImageDescriptor() { return null; } public boolean exists() { return true; } }; } IEditorPart part = page.findEditor(OpenAPICloudWizardActionDelegate.input); if (part != null) { page.bringToTop(part); return; } try { IDE.openEditor(page, OpenAPICloudWizardActionDelegate.input, "com.apicloud.navigator.APICloudWizard"); } catch (PartInitException e) { e.printStackTrace(); } }
Example 19
Source File: EditorOpener.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate) throws PartInitException { IEditorInput input = new FileEditorInput(file); IEditorPart editor = page.findEditor(input); if (editor != null) { page.bringToTop(editor); if (activate) { page.activate(editor); } return editor; } IEditorReference reusedEditorRef = fReusedEditor; if (reusedEditorRef != null) { boolean isOpen = reusedEditorRef.getEditor(false) != null; boolean canBeReused = isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned(); if (canBeReused) { boolean showsSameInputType = reusedEditorRef.getId().equals(editorId); if (!showsSameInputType) { page.closeEditors(new IEditorReference[] { reusedEditorRef }, false); fReusedEditor = null; } else { editor = reusedEditorRef.getEditor(true); if (editor instanceof IReusableEditor) { ((IReusableEditor) editor).setInput(input); page.bringToTop(editor); if (activate) { page.activate(editor); } return editor; } } } } editor = page.openEditor(input, editorId, activate); if (editor instanceof IReusableEditor) { IEditorReference reference = (IEditorReference) page.getReference(editor); fReusedEditor = reference; } else { fReusedEditor = null; } return editor; }
Example 20
Source File: ProcessNavigatorLinkHelper.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
/** * @generated */ public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) { return; } if (false == aSelection.getFirstElement() instanceof ProcessAbstractNavigatorItem) { return; } ProcessAbstractNavigatorItem abstractNavigatorItem = (ProcessAbstractNavigatorItem) aSelection .getFirstElement(); View navigatorView = null; if (abstractNavigatorItem instanceof ProcessNavigatorItem) { navigatorView = ((ProcessNavigatorItem) abstractNavigatorItem).getView(); } else if (abstractNavigatorItem instanceof ProcessNavigatorGroup) { ProcessNavigatorGroup navigatorGroup = (ProcessNavigatorGroup) abstractNavigatorItem; if (navigatorGroup.getParent() instanceof ProcessNavigatorItem) { navigatorView = ((ProcessNavigatorItem) navigatorGroup.getParent()).getView(); } } if (navigatorView == null) { return; } IEditorInput editorInput = getEditorInput(navigatorView.getDiagram()); IEditorPart editor = aPage.findEditor(editorInput); if (editor == null) { return; } aPage.bringToTop(editor); if (editor instanceof DiagramEditor) { DiagramEditor diagramEditor = (DiagramEditor) editor; ResourceSet diagramEditorResourceSet = diagramEditor.getEditingDomain().getResourceSet(); EObject selectedView = diagramEditorResourceSet.getEObject(EcoreUtil.getURI(navigatorView), true); if (selectedView == null) { return; } GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor.getAdapter(GraphicalViewer.class); EditPart selectedEditPart = (EditPart) graphicalViewer.getEditPartRegistry().get(selectedView); if (selectedEditPart != null) { graphicalViewer.select(selectedEditPart); } } }