/** * Opens the editor currently associated with the given element (IJavaElement, IFile, IStorage...) * * @param inputElement the input element * @param activate <code>true</code> if the editor should be activated * @return an open editor or <code>null</code> if an external editor was opened * @throws PartInitException if the editor could not be opened or the input element is not valid * Status code {@link IJavaStatusConstants#EDITOR_NO_EDITOR_INPUT} if opening the editor failed as * no editor input could be created for the given element. */ public static IEditorPart openInEditor(Object inputElement, boolean activate) throws PartInitException { if (inputElement instanceof IFile) { IFile file= (IFile) inputElement; if (!isClassFile(file)) return openInEditor(file, activate); inputElement= JavaCore.createClassFileFrom(file); } IEditorPart editor= findEditor(inputElement, activate); if (editor != null) return editor; IEditorInput input= getEditorInput(inputElement); if (input == null) throwPartInitException(JavaEditorMessages.EditorUtility_no_editorInput, IJavaStatusConstants.EDITOR_NO_EDITOR_INPUT); return openInEditor(input, getEditorID(input), activate); }
/** * Returns the Java element wrapped by this editors input. * * @return the Java element wrapped by this editors input. * @since 3.0 */ protected ITypeRoot getInputJavaElement() { return EditorUtility.getEditorInputJavaElement(this, false); }
@Override protected void activate(ISelection selection) { try { final Object selectedElement= SelectionUtil.getSingleElement(selection); if (EditorUtility.isOpenInEditor(selectedElement) != null) EditorUtility.openInEditor(selectedElement, true); } catch (PartInitException ex) { // ignore if no editor input can be found } }
private boolean openInNewEditor(Object element) { try { IEditorPart newEditor= EditorUtility.openInEditor(element); if (newEditor != null && element instanceof IJavaElement) EditorUtility.revealInEditor(newEditor, (IJavaElement) element); return true; } catch (PartInitException e) { JavaPlugin.log(e); return false; } }
private IEditorPart showWithReuse(Object element, IWorkbenchPage wbPage) throws PartInitException { IEditorInput input= EditorUtility.getEditorInput(element); if (input == null) return null; String editorID= EditorUtility.getEditorID(input); return showInEditor(wbPage, input, editorID); }
public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) { if (selection == null || selection.isEmpty()) return; Object element= selection.getFirstElement(); IEditorPart part= EditorUtility.isOpenInEditor(element); if (part != null) { page.bringToTop(part); if (element instanceof IJavaElement) EditorUtility.revealInEditor(part, (IJavaElement) element); } }
/** * Opens a Java editor for the given element if the element is a Java compilation unit or a Java * class file. * * @return the IEditorPart or null if wrong element type or opening failed */ public static IEditorPart openInEditor(ICompilationUnit aCompilationUnit, String editorId) throws JavaModelException, PartInitException { return openInEditor(EditorUtility.getEditorInput(aCompilationUnit), editorId); }
/** * Opens a Java editor for the given element if the element is a Java compilation unit or a Java * class file. * * @return the IEditorPart or null if wrong element type or opening failed */ public static IEditorPart openInEditor(ICompilationUnit aCompilationUnit) throws JavaModelException, PartInitException { return EditorUtility.openInEditor(aCompilationUnit); }
case SAVE_ALL_ALWAYS_ASK: case SAVE_ALL: dirtyEditors= EditorUtility.getDirtyEditors(true); break; dirtyEditors= EditorUtility.getDirtyEditorsToSave(false); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=175495 break; dirtyEditors= EditorUtility.getDirtyEditorsToSave(false); break;
/** * Reveals the given java element in the given editor. If the element is not an instance * of <code>ISourceReference</code> this method result in a NOP. If it is a source * reference no checking is done if the editor displays a compilation unit or class file that * contains the source reference element. The editor simply reveals the source range * denoted by the given element. * * @param part the editor displaying a compilation unit or class file * @param element the element to be revealed * * @since 2.0 */ public static void revealInEditor(IEditorPart part, IJavaElement element) { EditorUtility.revealInEditor(part, element); }
/** * 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; }
public void init(IWorkbench workbench, IStructuredSelection structuredSelection) { IWorkbenchWindow window= workbench.getActiveWorkbenchWindow(); List selected= Collections.EMPTY_LIST; if (window != null) { ISelection selection= window.getSelectionService().getSelection(); if (selection instanceof IStructuredSelection) { selected= ((IStructuredSelection) selection).toList(); } else { IJavaElement element= EditorUtility.getActiveEditorJavaInput(); if (element != null) { selected= new ArrayList(); selected.add(element); } } } fStore= new JavadocOptionsManager(fXmlJavadocFile, getDialogSettings(), selected); }
public static IEditorPart isOpenInEditor(Object elem) { IJavaElement javaElement= null; if (elem instanceof MethodWrapper) { javaElement= ((MethodWrapper) elem).getMember(); } else if (elem instanceof CallLocation) { javaElement= ((CallLocation) elem).getMember(); } if (javaElement != null) { return EditorUtility.isOpenInEditor(javaElement); } return null; }
/** * Returns the modifier string for the given SWT modifier * modifier bits. * * @param stateMask the SWT modifier bits * @return the modifier string * @since 2.1.1 */ public static String getModifierString(int stateMask) { String modifierString= ""; //$NON-NLS-1$ if ((stateMask & SWT.CTRL) == SWT.CTRL) modifierString= appendModifierString(modifierString, SWT.CTRL); if ((stateMask & SWT.ALT) == SWT.ALT) modifierString= appendModifierString(modifierString, SWT.ALT); if ((stateMask & SWT.SHIFT) == SWT.SHIFT) modifierString= appendModifierString(modifierString, SWT.SHIFT); if ((stateMask & SWT.COMMAND) == SWT.COMMAND) modifierString= appendModifierString(modifierString, SWT.COMMAND); return modifierString; }
/** * Computes the state mask for the given modifier string. * * @param modifiers the string with the modifiers, separated by '+', '-', ';', ',' or '.' * @return the state mask or -1 if the input is invalid */ public static int computeStateMask(String modifiers) { if (modifiers == null) return -1; if (modifiers.length() == 0) return SWT.NONE; int stateMask= 0; StringTokenizer modifierTokenizer= new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$ while (modifierTokenizer.hasMoreTokens()) { int modifier= EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken()); if (modifier == 0 || (stateMask & modifier) == modifier) return -1; stateMask= stateMask | modifier; } return stateMask; }
/** * Returns an array of all editors that have an unsaved content. If the identical content is * presented in more than one editor, only one of those editor parts is part of the result. * * @return an array of all dirty editor parts. * @since 3.2 * @deprecated TODO: remove for 3.4 */ public static IEditorPart[] getDirtyEditors() { return getDirtyEditors(false); }
@Override public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) { if (selection == null || selection.isEmpty()) return; Object element= selection.getFirstElement(); IEditorPart part= EditorUtility.isOpenInEditor(element); if (part != null) { page.bringToTop(part); if (element instanceof IJavaElement) EditorUtility.revealInEditor(part, (IJavaElement) element); } }
private boolean openInNewEditor(Object element) { try { IEditorPart newEditor= EditorUtility.openInEditor(element); if (newEditor != null && element instanceof IJavaElement) EditorUtility.revealInEditor(newEditor, (IJavaElement) element); return true; } catch (PartInitException e) { JavaPlugin.log(e); return false; } }
public static IFile getFile(JavaClass javaClass) { ICompilationUnit comp = getCompilationUnit(javaClass); if (comp == null) return null; IEditorInput input = null; try { input = EditorUtility.getEditorInput(comp); } catch (JavaModelException ex) { return null; } if (input != null) { return (IFile) input.getAdapter(IFile.class); } return null; }
/** * Opens a Java editor for an element such as <code>IJavaElement</code>, <code>IFile</code>, or <code>IStorage</code>. * The editor is activated by default. * * @param inputElement the input element * @return an open editor or <code>null</code> if an external editor was opened * @throws PartInitException if the editor could not be opened or the input element is not valid. * Status code {@link IJavaStatusConstants#EDITOR_NO_EDITOR_INPUT} if opening the editor failed as * no editor input could be created for the given element. */ public static IEditorPart openInEditor(Object inputElement) throws PartInitException { return openInEditor(inputElement, true); }