private void updateDefaultEditorMappingIfAbsent() { final EditorRegistry registry = (EditorRegistry) WorkbenchPlugin.getDefault().getEditorRegistry(); for (final IFileEditorMapping editorMapping : registry.getFileEditorMappings()) { final IEditorDescriptor defaultEditor = editorMapping.getDefaultEditor(); if (null == defaultEditor) { final String extension = editorMapping.getExtension(); LOGGER.info("No default editor is associated with files with extension: '." + extension + "'."); final IEditorDescriptor defaultTextEditor = registry.findEditor(DEFAULT_TEXT_EDITOR_ID); if (null != defaultTextEditor) { ((FileEditorMapping) editorMapping).setDefaultEditor(defaultTextEditor); String editorName = defaultTextEditor.getLabel(); if (null == editorName) { editorName = defaultTextEditor.getId(); } if (null != editorName) { LOGGER.info("Associated files with extension " + extension + " with '" + editorName + "'."); } } } } registry.saveAssociations(); PrefUtil.savePrefs(); }
/** * Gets the default editor ID for the given {@link IEditorInput} and element. * * @param input * the {@link IEditorInput} * @param element * the element * @return the default editor ID for the given {@link IEditorInput} and element if any, <code>null</code> * otherwise */ public static String getEditorID(IEditorInput input, Object element) { final String res; if (input instanceof URIEditorInput) { res = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor( ((URIEditorInput)input).getURI().lastSegment()).getId(); } else if (input instanceof IFileEditorInput) { IEditorDescriptor defaultEditor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor( ((IFileEditorInput)input).getFile().getName()); if (defaultEditor != null) { res = defaultEditor.getId(); } else { res = "org.eclipse.emf.ecore.presentation.ReflectiveEditorID"; } } else { res = null; } return res; }
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 openFileInEditor(IFile file, IWorkbenchWindow workbenchWindow, IWorkbenchPage page) throws PartInitException{ IEditorRegistry editorRegistry = workbench.getEditorRegistry(); FileEditorInput fileEditorInput = new FileEditorInput(file); IPath filePath = file.getFullPath(); String filePathString = filePath.toString(); IEditorDescriptor defaultEditor = editorRegistry.getDefaultEditor(filePathString); String defaultEditorId = defaultEditor.getId(); page.openEditor(fileEditorInput, defaultEditorId); // Shell shell = workbenchWindow.getShell(); // String title = "Error"; // String message = exception.getMessage(); // MessageDialog.openError(shell, title, message); }
private String getEditorId(IFileStore file) { // IWorkbench workbench= fWindow.getWorkbench(); IWorkbench workbench = PlatformUI.getWorkbench(); IEditorRegistry editorRegistry= workbench.getEditorRegistry(); IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName(), getContentType(file)); // check the OS for in-place editor (OLE on Win32) if (descriptor == null && editorRegistry.isSystemInPlaceEditorAvailable(file.getName())) descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID); // check the OS for external editor if (descriptor == null && editorRegistry.isSystemExternalEditorAvailable(file.getName())) descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); if (descriptor != null) return descriptor.getId(); return EditorsUI.DEFAULT_TEXT_EDITOR_ID; }
private String getEditorId(IFileStore file) { IWorkbench workbench = PlatformUI.getWorkbench(); IEditorRegistry editorRegistry= workbench.getEditorRegistry(); IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName(), getContentType(file)); // check the OS for in-place editor (OLE on Win32) if (descriptor == null && editorRegistry.isSystemInPlaceEditorAvailable(file.getName())) descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID); // check the OS for external editor if (descriptor == null && editorRegistry.isSystemExternalEditorAvailable(file.getName())) descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); if (descriptor != null) return descriptor.getId(); return EditorsUI.DEFAULT_TEXT_EDITOR_ID; }
private void initializeTitle(final IEditorInput input) { final Image oldImage = fTitleImage; fTitleImage = null; String title = ""; //$NON-NLS-1$ if (input != null) { final IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); final IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId()); final ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null; fTitleImage = imageDesc != null ? imageDesc.createImage() : null; title = input.getName(); } setTitleImage(fTitleImage); setPartName(title); firePropertyChange(PROP_DIRTY); if (oldImage != null && !oldImage.isDisposed()) oldImage.dispose(); }
private void initializeTitle(IEditorInput input) { Image oldImage = fTitleImage; fTitleImage = null; String title = ""; //$NON-NLS-1$ if (input != null) { IEditorRegistry editorRegistry = PlatformUI.getWorkbench() .getEditorRegistry(); IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite() .getId()); ImageDescriptor imageDesc = editorDesc != null ? editorDesc .getImageDescriptor() : null; fTitleImage = imageDesc != null ? imageDesc.createImage() : null; title = input.getName(); } setTitleImage(fTitleImage); setPartName(title); firePropertyChange(PROP_DIRTY); if (oldImage != null && !oldImage.isDisposed()) oldImage.dispose(); }
public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate) throws PartInitException { String editorId= null; IEditorDescriptor desc= IDE.getEditorDescriptor(file); if (desc == null || !desc.isInternal()) { editorId= "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ } else { editorId= desc.getId(); } IEditorPart editor; if (NewSearchUI.reuseEditor()) { editor= showWithReuse(file, wbPage, editorId, activate); } else { editor= showWithoutReuse(file, wbPage, editorId, activate); } if (editor instanceof ITextEditor) { ITextEditor textEditor= (ITextEditor) editor; textEditor.selectAndReveal(offset, length); } else if (editor != null) { showWithMarker(editor, file, offset, length); } return editor; }
/** * Returns the image descriptor for the given editor descriptor, or * <code>null</code> if it has no image. */ private ImageDescriptor getImageDescriptor(IEditorDescriptor editorDesc) { ImageDescriptor imageDesc = null; if (editorDesc == null) { imageDesc = fRegistry.getImageDescriptor(fNode.getBuildFile() .getBuildFileResource().getName()); } else { imageDesc = editorDesc.getImageDescriptor(); } if (imageDesc == null && editorDesc != null) { if (editorDesc.getId().equals(SYSTEM_EDITOR_ID)) { imageDesc = getSystemEditorImageDescriptor(fNode.getBuildFile() .getBuildFileResource().getFileExtension()); } } return imageDesc; }
public static void openInEditor(IWorkbenchPage page, IEditorDescriptor editorDescriptor, IJSBuildFileNode node) { IEditorPart editorPart = null; IFile fileResource = node.getBuildFile().getBuildFileResource(); try { if (editorDescriptor == null) { editorPart = page.openEditor(new FileEditorInput(fileResource), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } else { editorPart = page.openEditor(new FileEditorInput(fileResource), editorDescriptor.getId()); } } catch (PartInitException e) { Logger.logException(MessageFormat.format( JSBuildFileUIMessages.JSBuildFileUtil_0, new Object[] { fileResource.getLocation().toOSString() }), e); } revealInEditor(editorPart, node, page); }
/** * <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated */ public static boolean openEditor(IWorkbench workbench, URI uri) { IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); IEditorDescriptor editorDescriptor = EditUIUtil.getDefaultEditor(uri, null); if (editorDescriptor == null) { MessageDialog.openError(workbenchWindow.getShell(), getString("_UI_Error_title"), getString("_WARN_No_Editor", uri.lastSegment())); return false; } else { try { page.openEditor(new URIEditorInput(uri), editorDescriptor.getId()); } catch (PartInitException exception) { MessageDialog.openError(workbenchWindow.getShell(), getString("_UI_OpenEditorError_label"), exception.getMessage()); return false; } } return true; }
/** * Opens a subdiagram for a given {@link Diagram} */ public static IEditorPart openEditor(Diagram diagramToOpen) { IFile file = WorkspaceSynchronizer.getFile(diagramToOpen.eResource()); try { IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); final IWorkbenchPage wbPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (diagramToOpen.getElement() instanceof Statechart) { return wbPage.openEditor(new FileEditorInput(file), desc.getId()); } else if (diagramToOpen.getElement() instanceof State) { return wbPage.openEditor(new DiagramEditorInput(diagramToOpen), desc.getId()); } } catch (PartInitException e) { e.printStackTrace(); } return null; }
private boolean openConceptDefinition(EObject eobj, String stepText) { GaugeWorkspace gaugeWorkspace = GaugePlugin.getDefault() .getGaugeWorkspace(); IProject project = getProjectFor(eobj); ConceptData concept = gaugeWorkspace.searchConcept(project, stepText); if (concept != null) { IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench() .getActiveWorkbenchWindow(); IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); File file = new File(concept.getFilePath()); try { IEditorDescriptor desc = PlatformUI.getWorkbench() .getEditorRegistry().getDefaultEditor(file.getName()); IEditorPart editor = IDE.openEditor(activePage, file.toURI(), desc.getId(), true); goToLineNumber(editor, concept.getLineNumber()); } catch (PartInitException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; } return false; }
public static void resetDefaultEditor(String extension) { EditorRegistry editorRegistry = (EditorRegistry) PlatformUI.getWorkbench().getEditorRegistry(); IFileEditorMapping[] editorMappings = editorRegistry.getFileEditorMappings(); // Search the file=>editor mappings for the specified extension for (IFileEditorMapping editorMapping : editorMappings) { if (extension.equals(editorMapping.getExtension())) { FileEditorMapping internalMapping = (FileEditorMapping) editorMapping; // Only need to do anything if there's an explicit default set if (internalMapping.getDeclaredDefaultEditors().length > 0) { // Clear any default editor associations for this extension List<IEditorDescriptor> list = new ArrayList<IEditorDescriptor>(); internalMapping.setDefaultEditors(list); // Save the updated editor registry to disk editorRegistry.saveAssociations(); // TODO: remove GWTPluginLog.logInfo("Reset default editor for extension: " + extension); } break; } } }
public IEditorPart openFileInWorkspace(final URI uri) throws PartInitException { final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final String uriAsText = uri.toPlatformString(true); final IPath path = uriAsText != null ? new Path(uriAsText) : null; final IFile file = path != null ? root.getFile(path) : null; if (file == null) { return null; } final IEditorInput editorInput = new FileEditorInput(file); final IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); if (desc == null) { return null; } final IWorkbenchPage page = WorkbenchHelper.getPage(); return page.openEditor(editorInput, desc.getId()); }
/** * Method isParentOf() * * @see ummisco.gama.ui.navigator.contents.VirtualContent#isParentOf(java.lang.Object) */ // @Override // public boolean isParentOf(final Object element) { // return false; // } @Override public boolean handleDoubleClick() { final IEditorInput editorInput = new FileEditorInput(file.getResource()); final IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); if (desc == null) { return false; } final IWorkbenchPage page = WorkbenchHelper.getPage(); try { page.openEditor(editorInput, desc.getId()); } catch (final PartInitException e) { e.printStackTrace(); return false; } return true; }
/** * Open a file in an editor and return the opened editor part.<br> * This method will try to open the file in an internal editor, unless there is no editor descriptor assigned to * that file type. * * @param file * @return The {@link IEditorPart} that was created when the file was opened; Return null in case of an error */ public static IEditorPart openInEditor(File file) { // NOTE: Moved from PHP's EditorUtils if (file == null) { IdeLog.logError(CommonEditorPlugin.getDefault(), "Error open a file in the editor", new IllegalArgumentException("file is null")); //$NON-NLS-1$ //$NON-NLS-2$ return null; } try { URI uri = file.toURI(); IEditorDescriptor desc = getEditorDescriptor(uri); String editorId = (desc == null) ? IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID : desc.getId(); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); return IDE.openEditor(page, uri, editorId, true); } catch (Exception e) { IdeLog.logError(CommonEditorPlugin.getDefault(), "Error open a file in the editor", e); //$NON-NLS-1$ } return null; }
@Override public void open() { try { IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); IEditorDescriptor editorDescriptor = IDE .getEditorDescriptor(fStorage.getName()); IEditorPart editor = page.openEditor(new StorageEditorInput( fStorage), editorDescriptor.getId()); selectAndReveal(editor, fHighlightRange); } catch (PartInitException e) { } }
private void setAnATLyzerDefaultEditor() { String extension = "atl"; String editorId = "org.eclipse.m2m.atl.adt.editor.AtlEditor"; EditorRegistry editorReg = (EditorRegistry)PlatformUI.getWorkbench().getEditorRegistry(); //EditorDescriptor editor = (EditorDescriptor) editorReg.findEditor(editorId); //editor. IFileEditorMapping[] mappings = editorReg.getFileEditorMappings(); for (IFileEditorMapping mapping : mappings) { if ( "atl".equals(mapping.getExtension()) ) { IEditorDescriptor[] descriptors = mapping.getEditors(); IEditorDescriptor anatlyzerEditor = null; for (IEditorDescriptor editorDesc : descriptors) { if ( "anatlyzer.atl.editor.AtlEditorExt".equals( ((EditorDescriptor) editorDesc).getClassName()) ) { anatlyzerEditor = editorDesc; break; } } if ( anatlyzerEditor != null ) { ((FileEditorMapping) mapping).setDefaultEditor((EditorDescriptor) anatlyzerEditor); break; } } } }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); setPartName(input.getName()); Image oldTitleImage = titleImage; if (input != null) { IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId()); ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null; titleImage = imageDesc != null ? imageDesc.createImage() : null; } setTitleImage(titleImage); if (oldTitleImage != null && !oldTitleImage.isDisposed()) { oldTitleImage.dispose(); } FileEditorInput fileInput = (FileEditorInput) input; htmlUrl = fileInput.getFile().getLocation().toOSString(); }
/** * 启动编辑器。 * * @param site * the site * @param input * the input * @throws PartInitException * the part init exception * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, * org.eclipse.ui.IEditorInput) */ public void init(IEditorSite site, IEditorInput input) throws PartInitException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("init(IEditorSite site, IEditorInput input)"); } setSite(site); setInput(input); // 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性 setPartName(input.getName()); Image oldTitleImage = titleImage; if (input != null) { IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId()); ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null; titleImage = imageDesc != null ? imageDesc.createImage() : null; } setTitleImage(titleImage); if (oldTitleImage != null && !oldTitleImage.isDisposed()) { oldTitleImage.dispose(); } getSite().setSelectionProvider(this); }
/** * find a prefer editor from all existing editors according to the * fileExtensions * * @param fileExtension * @return */ private String findPreferEditor(RouteResourceInput fileEditorInput) { String editorId = RouteResourceEditor.ID; Object underlingFile = fileEditorInput.getAdapter(IFile.class); if (underlingFile == null) { return editorId; } IEditorDescriptor ed = null; try { ed = IDE.getEditorDescriptor((IFile) underlingFile, true); } catch (PartInitException e) { return editorId; } if (ed == null) { return editorId; } String id = ed.getId(); if (id == null || id.trim() == null) { return editorId; } return id; }
@Override public void run(IAction action) { // TODO check... unclear why this can open ScaleLog projects with other settings // Get the config.xml and open it in the ProductLineEditor IFile configfile = selectedProject.getFile(ProjectConstants.EASY_FILES + ResourcesMgmt.INSTANCE.getSeperator() + PersistenceConstants.CONFIG_FILE); String projectID = ResourcesMgmt.INSTANCE.getIDfromResource(configfile); PLPInfo plp = SPLsManager.INSTANCE.getPLP(projectID); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry() .findEditor("de.uni_hildesheim.sse.easy_producer.ProductLineConfigurationEditor.new"); try { page.openEditor(new ProductLineEditorInput((ProductLineProject) plp), desc.getId()); } catch (PartInitException e) { e.printStackTrace(); } }
/** * Open the specified transformation file * @param fileName */ void openTransformationFile(String fileName) { // First, close the existing role editor shell.close(); // Second, open the transformation file in the corresponding editor IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); IProject project = this.instance.getProject(); IFile file = project.getFile(PROJECT_PATH_TRANSFORMATION + fileName); IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry() .getDefaultEditor(file.getName()); try { page.openEditor(new FileEditorInput(file), desc.getId()); } catch (PartInitException e) { e.printStackTrace(); } }
/******************************************************* * Private: Opens an editor for the given input and descriptor. * * @param editorInput * The input to the editor to be opened. * @param editorDescriptor * The descriptor of the editor to be opened. * @return The {@link IEditorPart} for the opened editor, or null if editor * was not opened, or it is an external editor (outside workspace). *******************************************************/ private static IEditorPart openEditor(IEditorInput editorInput, IEditorDescriptor editorDescriptor) { if (editorInput == null || editorDescriptor == null) { throw new IllegalArgumentException(); } try { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); return page.openEditor(editorInput, editorDescriptor.getId()); } catch (PartInitException e) { System.err.println("Could not open editor"); e.printStackTrace(); return null; } }
private String getEditorId( IFileStore file ) { IWorkbench workbench = window.getWorkbench( ); IEditorRegistry editorRegistry = workbench.getEditorRegistry( ); IEditorDescriptor descriptor = editorRegistry.getDefaultEditor( file.getName( ), getContentType( file ) ); // check the OS for in-place editor (OLE on Win32) if ( descriptor == null && editorRegistry.isSystemInPlaceEditorAvailable( file.getName( ) ) ) { descriptor = editorRegistry.findEditor( IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID ); } // check the OS for external editor if ( descriptor == null && editorRegistry.isSystemExternalEditorAvailable( file.getName( ) ) ) { descriptor = editorRegistry.findEditor( IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID ); } return ( descriptor == null ) ? "" : descriptor.getId( ); //$NON-NLS-1$ }
public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate) throws PartInitException { String editorId = null; IEditorDescriptor desc = IDE.getEditorDescriptor(file); if (desc == null || !desc.isInternal()) { editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ } else { editorId = desc.getId(); } IEditorPart editor; if (NewSearchUI.reuseEditor()) { editor = showWithReuse(file, wbPage, editorId, activate); } else { editor = showWithoutReuse(file, wbPage, editorId, activate); } if (editor instanceof ITextEditor) { ITextEditor textEditor = (ITextEditor) editor; textEditor.selectAndReveal(offset, length); } else if (editor != null) { showWithMarker(editor, file, offset, length); } return editor; }
@Override protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) { for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) { try { if (PythonPathHelper.isValidSourceFile(n.zipPath)) { new PyOpenAction().run(new ItemPointer(n.zipStructure.file, new Location(), new Location(), null, n.zipPath)); } else { IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor defaultEditor = editorReg.getDefaultEditor(n.zipPath); PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath); PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage); if (defaultEditor != null) { IDE.openEditor(page, input, defaultEditor.getId()); } else { IDE.openEditor(page, input, EditorsUI.DEFAULT_TEXT_EDITOR_ID); } } } catch (PartInitException e) { Log.log(e); } } }
public void postHook(IWorkbenchPage page) { try { URI newFile = (new File(this.newFilename)).toURI().normalize(); URI workspaceFile = ResourcesPlugin.getWorkspace().getRoot().getLocationURI().normalize(); if (newFile.toString().toLowerCase().startsWith(workspaceFile.toString().toLowerCase())) { String path = newFile.toString().substring(workspaceFile.toString().length()); path = path.replaceAll("%20", " "); //$NON-NLS-1$ //$NON-NLS-2$ IFile file = (IFile) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(new Path(path), IResource.FILE); file.getParent().refreshLocal(1, null); IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); if (desc == null) desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor("xml.xml"); //$NON-NLS-1$ page.openEditor(new FileEditorInput(file), desc.getId()); } } catch (Exception ex) { // hide any errors. } }
/** * Opens the module diagram. * * @param diagramFile the diagram file. * @return the opened module editor. */ public static IEditorPart openModuleEditor(IFile diagramFile) { if (diagramFile == null) { return null; } IWorkbenchPage workbenchPage = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry() .getDefaultEditor(diagramFile.getName()); if (desc != null) { try { return workbenchPage.openEditor( new FileEditorInput(diagramFile), desc.getId()); } catch (Exception e) { e.printStackTrace(); return null; } } else { return null; } }
private void tryOpenFileInEditor(final IFile file, final IFile generatedFile) { final IEditorDescriptor desc = getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); if (null != desc) { final IWorkbenchPage page = getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.openEditor(new FileEditorInput(generatedFile), desc.getId()); } catch (final PartInitException e) { throw new RuntimeException("Error while trying to open generated JS file for " + file, e); } } }
protected final IEditorPart openEditor(String filePath) throws PartInitException { IPath location = Path.fromOSString(filePath); IFileStore fileStore = EFS.getLocalFileSystem().getStore(location); FileStoreEditorInput fileStoreEditorInput = new FileStoreEditorInput(fileStore); String editorId = IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID; IEditorDescriptor editorDescriptor = getWorkbench().getEditorRegistry().getDefaultEditor(filePath); if (editorDescriptor != null) { editorId = editorDescriptor.getId(); } return openEditor(fileStoreEditorInput, editorId); }
/** * Returns the {@link IEditorDescriptor} associated with this input's editor id. * * @return The {@link IEditorDescriptor} for the editor id. */ protected IEditorDescriptor getEditorDescriptor() { String editorId = getEditorId(); if (editorId == null) { return null; } IWorkbench workBench = PlatformUI.getWorkbench(); IEditorRegistry editorRegistry = workBench.getEditorRegistry(); IEditorDescriptor editorDescriptor = editorRegistry.findEditor(editorId); return editorDescriptor; }
private String getEditorId(String filePath) { IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor desc = editorRegistry.getDefaultEditor(filePath); if (desc == null) { desc = editorRegistry.getDefaultEditor(filePath + ".txt"); } return desc.getId(); }