private static String getEditorId(String fileName, IContentType type) { IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor descriptor = registry.getDefaultEditor(fileName, type); String id; if (descriptor == null || descriptor.isOpenExternal()) { id = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ } else { id = descriptor.getId(); } return id; }
/** * Opens an editor represented by the descriptor with the given input. * * @param fileEditorInput * the input that the editor should open * @param editorDescriptor * the descriptor of the editor to open * @param activate * <tt>true</tt> if the editor should be activated, * <tt>false</tt> otherwise * @param editorState * the previously saved state of the editor as a memento, this * may be <tt>null</tt> * @return the opened editor * @exception PartInitException * if the editor could not be created or initialized */ public IEditorPart openEditorFromDescriptor(IEditorInput fileEditorInput, IEditorDescriptor editorDescriptor, final boolean activate, final IMemento editorState) throws PartInitException { if (editorDescriptor.isOpenExternal()) { openExternalEditor((EditorDescriptor) editorDescriptor, fileEditorInput); return null; } return openEditor(fileEditorInput, editorDescriptor.getId(), activate, MATCH_INPUT, editorState, true); }
private static String getEditorId(String fileName, IContentType type) { IEditorRegistry registry = PlatformUI.getWorkbench() .getEditorRegistry(); IEditorDescriptor descriptor = registry .getDefaultEditor(fileName, type); String id; if (descriptor == null || descriptor.isOpenExternal()) { id = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ } else { id = descriptor.getId(); } return id; }
@Override public void dragStart(DragSourceEvent event) { fEditorInputDatas= new ArrayList<>(); 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 dragStart(DragSourceEvent event) { fEditorInputDatas= new ArrayList<>(); 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; }
.getEditorRegistry(); IEditorDescriptor editorDesc = editorReg.findEditor(editorId); if (editorDesc != null && !editorDesc.isOpenExternal()) { result = page.openEditor(editorInput, editorId); } else {
private static String getEditorId(FileRevisionEditorInput editorInput, IContentType type) { String fileName= editorInput.getFileRevision().getName(); IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor descriptor = registry.getDefaultEditor(fileName, type); IDE.overrideDefaultEditorAssociation(editorInput, type, descriptor); String id; if (descriptor == null || descriptor.isOpenExternal()) { id = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ } else { id = descriptor.getId(); } return id; }
/** * Creates the Other... menu item * * @param menu * the menu to add the item to */ private void createOtherMenuItem(final Menu menu) { final IFileRevision fileResource = getFileRevision(); if (fileResource == null) { return; } new MenuItem(menu, SWT.SEPARATOR); final MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(TeamUIMessages.LocalHistoryPage_OpenWithMenu_Other); Listener listener = event -> { if (event.type == SWT.Selection) { EditorSelectionDialog dialog = new EditorSelectionDialog(menu.getShell()); dialog.setMessage(NLS.bind( TeamUIMessages.LocalHistoryPage_OpenWithMenu_OtherDialogDescription, fileResource.getName())); if (dialog.open() == Window.OK) { IEditorDescriptor editor = dialog.getSelectedEditor(); if (editor != null) { openEditor(editor, editor.isOpenExternal()); } } } }; menuItem.addListener(SWT.Selection, listener); }
IEditorDescriptor editor = dialog.getSelectedEditor(); if (editor != null) { openEditor(editor, editor.isOpenExternal());
if (editorDesc != null && !editorDesc.isOpenExternal()) { result = page.openEditor(new FileEditorInput(file), editorDesc .getId(), true);
&& !defaultEditorDesc.isOpenExternal()) {
if (desc != null && !desc.isOpenExternal() && isLargeDocument(input)) { desc = getAlternateEditor(); if (desc == null) { } else if (desc.isOpenExternal()) { openExternalEditor((EditorDescriptor) desc, input);