@Override public void resourceChanged(IResourceChangeEvent event) { if (event.getType() == IResourceChangeEvent.PRE_CLOSE) { Display.getDefault().asyncExec(new Runnable() { public void run() { IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages(); for (int i = 0; i < pages.length; i++) { if (((FileEditorInput) getEditorInput()).getFile().getProject().equals(event.getResource())) { IEditorPart editorPart = pages[i].findEditor(getEditorInput()); pages[i].closeEditor(editorPart, true); } } } }); } }
private IEditorPart getFileEditor(final IFile file1, final IWorkbenchPage page) { internalFileEditor = null; Display.getCurrent().syncExec(new Runnable() { @Override public void run() { try { internalFileEditor = IDE.openEditor(page, file1, getEditorId(), true); } catch (PartInitException e) { e.printStackTrace(); } } }); long start = System.currentTimeMillis(); long end = start; do { end = System.currentTimeMillis(); } while (page.getActiveEditor() != internalFileEditor && (end - start) < 5000); return internalFileEditor; }
/** * Computes and returns the initial pattern for the type search dialog. * * If no initial pattern can be computed, an empty string is returned. */ private String computeInitialPattern() { IEditorPart activeEditor = HandlerServiceUtils.getActiveEditor().orNull(); if (activeEditor instanceof N4JSEditor) { Point range = ((N4JSEditor) activeEditor).getSourceViewer2().getSelectedRange(); try { String text = ((N4JSEditor) activeEditor).getDocument().get(range.x, range.y); if (N4JSLanguageUtils.isValidIdentifier(text) && !startWithLowercaseLetter(text) && !languageHelper.isReservedIdentifier(text)) { return text; } } catch (BadLocationException e) { LOGGER.error("Failed to infer type search pattern from editor selection.", e); } } return ""; }
@Override public void activateEditor(final IWorkbenchPage page, final IStructuredSelection selection) { if (null != selection && !selection.isEmpty()) { final Object firstElement = selection.getFirstElement(); if (firstElement instanceof ResourceNode) { final File fileResource = ((ResourceNode) firstElement).getResource(); if (fileResource.exists() && fileResource.isFile()) { final URI uri = URI.createFileURI(fileResource.getAbsolutePath()); final IResource resource = externalLibraryWorkspace.getResource(uri); if (resource instanceof IFile) { final IEditorInput editorInput = EditorUtils.createEditorInput(new URIBasedStorage(uri)); final IEditorPart editor = page.findEditor(editorInput); if (null != editor) { page.bringToTop(editor); return; } } } } } super.activateEditor(page, selection); }
/** * When the active editor changes, this remembers the change and registers with it as a selection provider. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void setActiveEditor(IEditorPart part) { super.setActiveEditor(part); activeEditorPart = part; // Switch to the new selection provider. // if (selectionProvider != null) { selectionProvider.removeSelectionChangedListener(this); } if (part == null) { selectionProvider = null; } else { selectionProvider = part.getSite().getSelectionProvider(); selectionProvider.addSelectionChangedListener(this); // Fake a selection changed event to update the menus. // if (selectionProvider.getSelection() != null) { selectionChanged(new SelectionChangedEvent(selectionProvider, selectionProvider.getSelection())); } } }
/** * Note: it compares marker's resource file name and open editors' file name. * * @param marker * @return if marker's editor is open, return editor, else return null */ public static IEditorPart getOpenEditorOfMarker(final IMarker marker) { final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); for (final IWorkbenchWindow iWorkbenchWindow : windows) { final IWorkbenchPage[] pages = iWorkbenchWindow.getPages(); for (final IWorkbenchPage iWorkbenchPage : pages) { final IEditorReference[] editors = iWorkbenchPage.getEditorReferences(); for (final IEditorReference iEditorReference : editors) { try { if (iEditorReference instanceof IFileEditorInput) { final IFileEditorInput input = (IFileEditorInput) iEditorReference.getEditorInput(); final IFile file = input.getFile(); // TODO Caused by: java.lang.NullPointerException when delete marker on ecore editor. if (file.getFullPath().equals(marker.getResource().getFullPath())) { return iEditorReference.getEditor(false); } } } catch (final PartInitException e) { e.printStackTrace(); } } } } return null; }
/** * Obtains all editors that are currently opened. * @return the collection of the opened editors */ public static List<IEditorPart> getEditors() { List<IEditorPart> editors = new ArrayList<IEditorPart>(); IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { IWorkbenchPage[] pages = window.getPages(); for (IWorkbenchPage page : pages) { IEditorReference[] refs = page.getEditorReferences(); for (IEditorReference ref : refs) { IEditorPart part = ref.getEditor(false); if (part != null) { editors.add(part); } } } } return editors; }
/** * The constructor */ public ITrace() { IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); /* if(editorPart != null){ StyledText styledText = (StyledText) editorPart.getAdapter(Control.class); if(styledText != null){ ITextOperationTarget t = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class); if(t instanceof ProjectionViewer){ ProjectionViewer projectionViewer = (ProjectionViewer)t; tokenHighlighters.put(activeEditor, new TokenHighlighter(styledText, showTokenHighlights, projectionViewer)); } } } */ eventBroker = PlatformUI.getWorkbench().getService(IEventBroker.class); eventBroker.subscribe("iTrace/newgaze", this); jsonSolver = new JSONGazeExportSolver(); xmlSolver = new XMLGazeExportSolver(); eventBroker.subscribe("iTrace/jsonOutput", jsonSolver); eventBroker.subscribe("iTrace/xmlOutput", xmlSolver); }
/** * Selects the given instruction in the given {@link IEditorPart}. * * @param editorPart * the {@link IEditorPart} * @param instructionUri * the instruction {@link URI} */ public static void selectInstruction(IEditorPart editorPart, final URI instructionUri) { if (editorPart instanceof IViewerProvider) { if (editorPart instanceof IEditingDomainProvider) { final EditingDomain domain = ((IEditingDomainProvider)editorPart).getEditingDomain(); final EObject selection = domain.getResourceSet().getEObject(instructionUri, false); if (selection != null) { ((IViewerProvider)editorPart).getViewer().setSelection( new StructuredSelection(selection), true); } else { DebugIdeUiPlugin.getPlugin().log( new IllegalStateException("can't find source for " + instructionUri)); } } } }
public void propertyChanged(Object source, int propId) { // When a property from the xslEditor Changes, walk the list all the listeners and notify them. Object listeners[] = listenerList.getListeners(); for (int i = 0; i < listeners.length; i++) { IPropertyListener listener = (IPropertyListener) listeners[i]; listener.propertyChanged(this, propId); } if (propId == IEditorPart.PROP_DIRTY) { if (!xmlEditor.isDirty()) { // We changed from Dirty to non dirty ==> User has saved so, // launch Convertigo engine // "touch" the parent style sheet ==> Convertigo engine will // recompile it IPath path; path = file.getRawLocation(); path = path.append("../../" + parentStyleSheetUrl); File parentFile = path.toFile(); parentFile.setLastModified(System.currentTimeMillis()); } } }
public void openSequenceEditor() { Sequence sequence = getObject(); synchronized (sequence) { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (activePage != null) { IEditorPart editorPart = getSequenceEditor(activePage, sequence); if (editorPart != null) { activePage.activate(editorPart); } else { try { editorPart = activePage.openEditor(new SequenceEditorInput(sequence), "com.twinsoft.convertigo.eclipse.editors.sequence.SequenceEditor"); } catch (PartInitException e) { ConvertigoPlugin.logException(e, "Error while loading the sequence editor '" + sequence.getName() + "'"); } } } } }
/** * Open the dashboard representation containing in the representation file * of this Modeling project. * * @param curProject * The modeling project containing the representations file. */ public void openDashboard(IProject curProject) { final Option<ModelingProject> opionalModelingProject = ModelingProject.asModelingProject(curProject); if (opionalModelingProject.some()) { final Session session = opionalModelingProject.get().getSession(); if (session != null) { final boolean initialValue = ActivityExplorerActivator.getDefault().getPreferenceStore() .getBoolean(PreferenceConstants.P_OPEN_ACTIVITY_EXPLORER); // in order to open activity explorer at project creation the // preference store // P_OPEN_ACTIVITY_EXPLORER need to be set to true ActivityExplorerActivator.getDefault().getPreferenceStore() .setValue(PreferenceConstants.P_OPEN_ACTIVITY_EXPLORER, true); final IEditorPart part = ActivityExplorerManager.INSTANCE.getEditorFromSession(session); if (part != null) { // Activity explorer already opened PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(part); } else { ActivityExplorerManager.INSTANCE.openEditor(session); } ActivityExplorerActivator.getDefault().getPreferenceStore() .setValue(PreferenceConstants.P_OPEN_ACTIVITY_EXPLORER, initialValue); } } }
public IEditorPart getJscriptTransactionEditor(Transaction transaction) { IEditorPart editorPart = null; IWorkbenchPage activePage = getActivePage(); if (activePage != null) { if (transaction != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof JscriptTransactionEditorInput)) { if (((JscriptTransactionEditorInput)editorInput).transaction.equals(transaction)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the jscript transaction editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench==null){ return null; } IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); if (activeWorkbenchWindow==null){ return null; } IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); if (activePage==null){ return null; } IEditorPart editor = activePage.getActiveEditor(); if (editor instanceof BashEditor){ executeOnBashEditor((BashEditor) editor); } return null; }
public boolean canRun() { InputType inputType = getInputType(); if (inputType.isStructuredSelection()) { IStructuredSelection structuredSelection = getCurrentStructuredSelection(); if (canRunWithStructuredSelection(structuredSelection)) { return true; } } else if (inputType.isEditorInput()) { IEditorPart editor = getActiveEditor(); IEditorInput editorInput = (editor != null) ? editor.getEditorInput() : null; if (canRunWithEditorInput(editorInput)) { return true; } } else if (canRunWithNothing()) { return true; } return false; }
public void setActivePage(IEditorPart part) { if (activeEditorPart == part) return; activeEditorPart = part; IActionBars actionBars = getActionBars(); if (actionBars != null) { ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null; actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(editor, ITextEditorActionConstants.DELETE)); actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), getAction(editor, ITextEditorActionConstants.UNDO)); actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), getAction(editor, ITextEditorActionConstants.REDO)); actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), getAction(editor, ITextEditorActionConstants.CUT)); actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), getAction(editor, ITextEditorActionConstants.COPY)); actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), getAction(editor, ITextEditorActionConstants.PASTE)); actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getAction(editor, ITextEditorActionConstants.SELECT_ALL)); actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(), getAction(editor, ITextEditorActionConstants.FIND)); actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(editor, IDEActionFactory.BOOKMARK.getId())); actionBars.updateActionBars(); } }
/** * Closes all project files on project close. */ public void resourceChanged(final IResourceChangeEvent event) { if (event.getType() == IResourceChangeEvent.PRE_CLOSE) { Display.getDefault().asyncExec(new Runnable() { public void run() { IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages(); for (int i = 0; i < pages.length; i++) { if (((FileEditorInput) editor.getEditorInput()).getFile().getProject().equals(event.getResource())) { IEditorPart editorPart = pages[i].findEditor(editor.getEditorInput()); pages[i].closeEditor(editorPart, true); } } } }); } }
public static IEditorPart editFile(File file, boolean preferIdeEditor) throws IOException, PartInitException { if (file == null || !file.exists() || !file.isFile() || !file.canRead()) { throw new IOException("Invalid file: '" + file + "'"); } IWorkbench workBench = PlatformUI.getWorkbench(); IWorkbenchPage page = workBench.getActiveWorkbenchWindow().getActivePage(); IPath location = Path.fromOSString(file.getAbsolutePath()); IFileStore fileStore = EFS.getLocalFileSystem().getStore(location); FileStoreEditorInput fileStoreEditorInput = new FileStoreEditorInput(fileStore); String editorId = IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID; if (preferIdeEditor) { IEditorDescriptor editorDescriptor = workBench.getEditorRegistry().getDefaultEditor(file.getName()); if (editorDescriptor != null) { editorId = editorDescriptor.getId(); } } return page.openEditor(fileStoreEditorInput, editorId); }
protected void search(String pattern, SearchType type, boolean withRef) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage workbenchPage = workbenchWindow.getActivePage(); IEditorPart editorPart = workbenchPage.getActiveEditor(); if (editorPart instanceof IWithAvroSchemaEditor) { AvroSchemaEditor schemaEditor = ((IWithAvroSchemaEditor) editorPart).getEditor(); AvroContext masterContext = schemaEditor.getContext().getMaster(); SearchNodeContext searchNodeContext = masterContext.getSearchNodeContext(); if (pattern == null || pattern.trim().isEmpty()) { searchNodeContext.reset(); } else if (searchNodeContext.searchNodes(type, pattern, withRef)) { AvroNode node = searchNodeContext.next(); schemaEditor.getContentPart() .getSchemaViewer(AvroContext.Kind.MASTER) .setSelection(new StructuredSelection(node), true); } refreshCommands(editorPart, SearchNodePropertyTester.PROPERTIES); } }
private static String getSaveFilePath(IEditorPart editorPart, GraphicalViewer viewer, int format) { FileDialog fileDialog = new FileDialog(editorPart.getEditorSite().getShell(), SWT.SAVE); String[] filterExtensions = new String[] { "*.jpeg", "*.bmp"/* * , "*.ico" , "*.png", "*.gif" */ }; if (format == SWT.IMAGE_BMP) filterExtensions = new String[] { "*.bmp" }; else if (format == SWT.IMAGE_JPEG) filterExtensions = new String[] { "*.jpeg" }; // else if (format == SWT.IMAGE_ICO) // filterExtensions = new String[] { "*.ico" }; fileDialog.setFilterExtensions(filterExtensions); return fileDialog.open(); }
/** * Saves the content as a temp-file, opens it using SQL-editor * and ensures that UTF-8 is used for everything. */ public static void saveOpenTmpSqlEditor(String content, String filenamePrefix) throws IOException, CoreException { Log.log(Log.LOG_INFO, "Creating file " + filenamePrefix); //$NON-NLS-1$ Path path = Files.createTempFile(filenamePrefix + '_', ".sql"); //$NON-NLS-1$ Files.write(path, content.getBytes(StandardCharsets.UTF_8)); IFileStore externalFile = EFS.getLocalFileSystem().fromLocalFile(path.toFile()); IEditorInput input = new FileStoreEditorInput(externalFile); IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .openEditor(input, EDITOR.SQL); if (part instanceof ITextEditor) { IDocumentProvider prov = ((ITextEditor) part).getDocumentProvider(); if (prov instanceof TextFileDocumentProvider) { ((TextFileDocumentProvider) prov).setEncoding(input, ApgdiffConsts.UTF_8); prov.resetDocument(input); } } }
private IEditorPart getConnectorEditor(IWorkbenchPage activePage, Connector connector) { IEditorPart editorPart = null; if (activePage != null) { if (connector != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) { if (((ConnectorEditorInput)editorInput).is(connector)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
private IEditorPart getSequenceEditor(IWorkbenchPage activePage, Sequence sequence) { IEditorPart editorPart = null; if (activePage != null) { if (sequence != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof SequenceEditorInput)) { if (((SequenceEditorInput)editorInput).is(sequence)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the sequence editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
@Override protected void setInput ( final IEditorInput input ) { final ConfigurationEditorInput configurationInput = (ConfigurationEditorInput)input; if ( !this.nested ) { configurationInput.performLoad ( new NullProgressMonitor () ); } this.dirtyValue = configurationInput.getDirtyValue (); this.dirtyValue.addValueChangeListener ( new IValueChangeListener () { @Override public void handleValueChange ( final ValueChangeEvent event ) { firePropertyChange ( IEditorPart.PROP_DIRTY ); } } ); super.setInput ( input ); }
/** * * Called by web socket server, message contain execution tracking status that updated on job canvas. * * @param message the message * @param session the session */ @OnMessage public void updateJobTrackingStatus(String message, Session session) { final String status = message; Display.getDefault().asyncExec(new Runnable() { public void run() { Gson gson = new Gson(); ExecutionStatus executionStatus=gson.fromJson(status, ExecutionStatus.class); IWorkbenchPage page = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage(); IEditorReference[] refs = page.getEditorReferences(); for (IEditorReference ref : refs){ IEditorPart editor = ref.getEditor(false); if(editor instanceof ELTGraphicalEditor){ ELTGraphicalEditor editPart=(ELTGraphicalEditor)editor; if(editPart.getJobId().equals(executionStatus.getJobId()) || (((editPart.getContainer()!=null) && (editPart.getContainer().getUniqueJobId().equals(executionStatus.getJobId()))) && editPart.getContainer().isOpenedForTracking() )){ TrackingStatusUpdateUtils.INSTANCE.updateEditorWithCompStatus(executionStatus, (ELTGraphicalEditor)editor,false); } } } } }); }
/** If {@link IWorkbenchPage} is available, will try to force close (without save) provided editor. */ public static final void forceCloseEditor(IEditorPart editor) { Display.getDefault().syncExec(() -> { IWorkbenchPage page = unsafeGetWorkbenchPage(); if (page != null) { boolean allClosed = page.closeEditor(editor, false); logger.info("Editor closed: " + allClosed); } else { logger.info(" Closing all editors: No active page."); } }); }
public void openclose() { Job job = new WorkspaceJob("GW4E Open/Close Editor Job") { @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { Display.getDefault().syncExec(new Runnable() { @Override public void run() { IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (ww != null) { IWorkbenchPage page = ww.getActivePage(); if (page != null) { IEditorReference[] editors = page.getEditorReferences(); for (IEditorReference iEditorReference : editors) { try { IEditorInput input = iEditorReference.getEditorInput(); if (input instanceof FileEditorInput) { FileEditorInput feditorInput = (FileEditorInput) input; if (previousPath.equals(feditorInput.getFile().getFullPath())) { IEditorPart editorPart = iEditorReference.getEditor(false); page.closeEditor(editorPart, false); JDTManager.openEditor(currentFile,PreferenceManager.getGW4EEditorName(),null); } } } catch (PartInitException e) { ResourceManager.logException(e); } } } } } }); return Status.OK_STATUS; } }; job.setRule(project); // lock so that we serialize the // refactoring job.setUser(true); job.schedule(); }
/***/ protected XtextEditor openAndGetXtextEditor(final IFile file1, final IWorkbenchPage page) { IEditorPart fileEditor = getFileEditor(file1, page); assertTrue(fileEditor instanceof XtextEditor); XtextEditor fileXtextEditor = (XtextEditor) fileEditor; return fileXtextEditor; }
@Override public void launch(IEditorPart editor, String mode) { try { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFile selectObj = ((IFileEditorInput) editorInput).getFile(); launchFile(selectObj, mode); } else { showDialogNotImplemented(editor.getClass().getName()); } } catch (CoreException e) { System.out.println(e.getLocalizedMessage() + "\n"); } }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = getCurrentSelection(event); if (null == selection) { return null; } if (selection.isEmpty()) { return null; } final AtomicReference<IFile> fileRef = new AtomicReference<>(); if (selection instanceof IStructuredSelection) { final Object element = ((IStructuredSelection) selection).getFirstElement(); if (element instanceof IFile) { fileRef.set((IFile) element); } } else if (selection instanceof ITextSelection) { final IEditorPart editorPart = getActiveEditor(event); if (null != editorPart) { final IEditorInput input = editorPart.getEditorInput(); if (input instanceof IFileEditorInput) { fileRef.set(((IFileEditorInput) input).getFile()); } } } if (null != fileRef.get()) { final Optional<IFile> generatedSource = fileLocator.tryGetGeneratedSourceForN4jsFile(fileRef.get()); if (generatedSource.isPresent()) { tryOpenFileInEditor(fileRef.get(), generatedSource.get()); } } return null; }
private IFile tryGetFileFromActiveEditor() { final Optional<IEditorPart> editor = getActiveEditor(); if (editor.isPresent() && editor.get().getEditorInput() instanceof IFileEditorInput) { return ((IFileEditorInput) editor.get().getEditorInput()).getFile(); } return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart part = HandlerUtil.getActivePart(event); if(part instanceof CommonNavigator){ DeleteAction action=new DeleteAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()); action.run(); } else if (part instanceof ELTGraphicalEditor) { IEditorPart editor = HandlerUtil.getActiveEditor(event); ((ELTGraphicalEditor) editor).deleteSelection(); ((ELTGraphicalEditor) editor).hideToolTip(); } return null; }
private XtextEditor getEditor(URI uri) { // note: trimming fragment in previous line makes this more stable in case of changes to the // Xtext editor's contents (we are not interested in a particular element, just the editor) final URI uriToEditor = uri != null ? uri.trimFragment() : null; if (uriToEditor != null) { final IEditorPart editor = getEditorOpener().open(uriToEditor, false); if (editor instanceof XtextEditor) return (XtextEditor) editor; } return null; }