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 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); }
/** * 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 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); }
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$ }
@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); } } }
@Override public String getEditorId(IEditorInput input, Object element) { IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); if (element instanceof IFile) { IFile file = (IFile)element; return registry.getDefaultEditor(file.getName()).getId(); } else if (element instanceof ILineBreakpoint) { String fileName = ((ILineBreakpoint)element).getMarker().getResource().getName(); return registry.getDefaultEditor(fileName).getId(); } else if (element instanceof IStorage) { IStorage storage = (IStorage)element; return registry.getDefaultEditor(storage.getName()).getId(); } else if (element instanceof URL) { URL url = (URL)element; return registry.getDefaultEditor(url.getFile()).getId(); } return null; }
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(); }
@Override protected void perfomeOK() throws Exception { try { final ProgressMonitorDialog monitor = new ProgressMonitorDialog(getShell()); final ExportWithProgressManager manager = getExportWithProgressManager(settings.getExportSetting()); manager.init(diagram, getBaseDir()); final ExportManagerRunner runner = new ExportManagerRunner(manager); monitor.run(true, true, runner); if (runner.getException() != null) { throw runner.getException(); } if (openAfterSavedButton != null && openAfterSavedButton.getSelection()) { final File openAfterSaved = openAfterSaved(); final URI uri = openAfterSaved.toURI(); final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (openWithExternalEditor()) { IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true); } else { final IFileStore fileStore = EFS.getStore(uri); IDE.openEditorOnFileStore(page, fileStore); } } // there is a case in another project diagram.getEditor().refreshProject(); } catch (final InterruptedException e) { throw new InputException(); } }
@Override public Image getDefaultImage() { IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId()); ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null; return imageDesc != null ? imageHelper.getImage(imageDesc) : super.getDefaultImage(); }
private static String getEditorId(File file, IWorkbenchWindow window) { IWorkbench workbench= window.getWorkbench(); IEditorRegistry editorRegistry= workbench.getEditorRegistry(); IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName()); if (descriptor != null) return descriptor.getId(); return EditorsUI.DEFAULT_TEXT_EDITOR_ID; }
/** * @param filePath * TODO: we should really make this into a utility function, and have the Ruble::Editor.open method use * it. But I am giving up for now because Eclipse plugin dependencies drive me crazy! */ private void openEditorForFile(String filePath) { File file = new File(filePath); // Process an existing file. if (file.exists() && file.isFile()) { Path path = new Path(filePath); IFile fileForLocation = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor editorDescriptor = null; if (fileForLocation == null) { IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(filePath); editorDescriptor = editorRegistry.getDefaultEditor(filePath, contentType); } else { editorDescriptor = editorRegistry.getDefaultEditor(filePath); } String editorId = (editorDescriptor == null) ? "com.aptana.editor.text" : editorDescriptor.getId(); //$NON-NLS-1$ try { IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file.toURI(), editorId, true); } catch (PartInitException e) { IdeLog.logError(UIPlugin.getDefault(), e); } } }
protected IEditorDescriptor getEditorDescriptor() { IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry(); if (uri.getPath() == null || uri.getPath().equals("/") || uri.getPath().trim().equals("")) //$NON-NLS-1$ //$NON-NLS-2$ { return null; } IPath path = new Path(uri.getPath()); return editorReg.getDefaultEditor(path.lastSegment()); }
@Override public void dragStart(DragSourceEvent event) { fEditorInputDatas= new ArrayList<EditorInputData>(); ISelection selection= fProvider.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection= (IStructuredSelection) selection; for (Iterator<?> iter= structuredSelection.iterator(); iter.hasNext();) { Object element= iter.next(); IEditorInput editorInput= EditorUtility.getEditorInput(element); if (editorInput != null && editorInput.getPersistable() != null) { try { String editorId= EditorUtility.getEditorID(editorInput); // see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..): IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor editorDesc= editorReg.findEditor(editorId); if (editorDesc != null && !editorDesc.isOpenExternal()) { fEditorInputDatas.add(EditorInputTransfer.createEditorInputData(editorId, editorInput)); } } catch (PartInitException e) { JavaPlugin.log(e); } } } } event.doit= fEditorInputDatas.size() > 0; }
@Override 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); cursorIbeam = new Cursor(null, SWT.CURSOR_IBEAM); cursorArrow = new Cursor(null, SWT.CURSOR_ARROW); hookListener(); }
/** * 使用系统默认编辑器打开文件 * @param page * IWorkbenchPage 对象 * @param uri * ; */ public static void OpenFileWithSystemEditor(IWorkbenchPage page, URI uri) { try { IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true); } catch (PartInitException e) { e.printStackTrace(); } }
/** * 使用系统默认编辑器打开文件 * @param file * IFile 对象(工作空间内的文件); */ public static void OpenFileWithSystemEditor(IFile file) { try { IDE.openEditor(getCurrentPage(), file, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { e.printStackTrace(); } }
/** * Opens the given source file in the default source editor. * * @param workbench * the workbench object. * @param source * the given source file. */ private IEditorPart openSourceInEditor(IWorkbench workbench, File source) { IEditorPart editor = null; IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); IEditorRegistry editorRegistry = workbench.getEditorRegistry(); try { editor = window.getActivePage().openEditor(createEditorInput(source), editorRegistry.getDefaultEditor(source.getName()).getId()); } catch (PartInitException e) { LOGGER.error("Default source editor for source \"" + source.getAbsolutePath() + "\" could not be opened!", e); } return editor; }
private static String getEditorId(File file) { IWorkbench workbench = PlatformUI.getWorkbench(); IEditorRegistry editorRegistry = workbench.getEditorRegistry(); IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(file.getName(), getContentType(file)); if (descriptor != null) { return descriptor.getId(); } return EditorsUI.DEFAULT_TEXT_EDITOR_ID; }
private IEditorDescriptor getEditorDescriptor( IEditorInput input, boolean determineContentType ) { if ( input == null ) { throw new IllegalArgumentException( ); } IContentType contentType = Platform.getContentTypeManager( ) .findContentTypeFor( input.getName( ) ); IEditorRegistry editorReg = PlatformUI.getWorkbench( ) .getEditorRegistry( ); return editorReg.getDefaultEditor( input.getName( ), contentType ); }
private String getEditorID(IFile file) throws PartInitException { IEditorDescriptor desc = IDE.getEditorDescriptor(file); if (desc == null) return PydevPlugin.getDefault().getWorkbench().getEditorRegistry() .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID).getId(); return desc.getId(); }
@Override protected void openFiles(PythonpathTreeNode[] pythonPathFilesSelected) { for (PythonpathTreeNode n : pythonPathFilesSelected) { try { IDE.openEditor(page, EditorInputFactory.create(n.file, false), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { Log.log(e); } } }
@Override protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) { for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) { try { PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath); PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage); IDE.openEditor(page, input, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { Log.log(e); } } }
/** * Overridden to open the given files with the match provided by the platform. */ @Override protected void openFiles(List<IFile> filesSelected) { for (IFile f : filesSelected) { try { IDE.openEditor(page, f, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { Log.log(e); } } }