@Override public IStructuredSelection findSelection(IEditorInput anInput) { IFile file = ResourceUtil.getFile(anInput); if (file != null) { return new StructuredSelection(file); } return StructuredSelection.EMPTY; }
/** * Return whether the given dirty editor part is editing resources that are * descendants of the given roots. * * @param part the dirty editor part * @return whether the given dirty editor part is editing resources that are * descendants of the given roots */ private boolean isEditingDescendantOf(IEditorPart part) { IFile file = ResourceUtil.getFile(part.getEditorInput()); if (file != null) { return isDescendantOfRoots(file); } return false; }
/** * Return whether the given dirty editor part is editing resources that are * descendants of the given roots. * * @param part the dirty editor part * @return whether the given dirty editor part is editing resources that are * descendants of the given roots */ private boolean isEditingDescendantOf(IEditorPart part) { IFile file = ResourceUtil.getFile(part.getEditorInput()); if (file != null) { return isDescendantOfRoots(file); } return false; }
public IStructuredSelection findSelection(IEditorInput input) { IJavaElement element= JavaUI.getEditorInputJavaElement(input); if (element == null) { IFile file = ResourceUtil.getFile(input); if (file != null) { element= JavaCore.create(file); } } return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY; }
@Override public IStructuredSelection findSelection(IEditorInput input) { IJavaElement element= JavaUI.getEditorInputJavaElement(input); if (element == null) { IFile file = ResourceUtil.getFile(input); if (file != null) { element= JavaCore.create(file); } } return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY; }
@Override public IStructuredSelection findSelection(IEditorInput input) { IJavaElement element= JavaUI.getEditorInputJavaElement(input); if (element == null) { IFile file = ResourceUtil.getFile(input); if (file != null) { element= JavaCore.create(file); } } return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY; }
@Override public boolean matches(IEditorReference editorRef, IEditorInput input) { if (!(input instanceof IFileEditorInput)) return false; IFile inputFile = ResourceUtil.getFile(input); if (inputFile == null) return false; try { IFile currInputFile = ResourceUtil.getFile(editorRef.getEditorInput()); if (currInputFile == null) return false; if (!inputFile.getProject().equals(currInputFile.getProject())) return false; // build.properties matches with editors that have a feature.xml file // as their input and that feature.xml is at the root if (inputFile.getName().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR)) { if (currInputFile.getName().equals(ICoreConstants.BUILD_FILENAME_DESCRIPTOR)) return inputFile.getProjectRelativePath().toString().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR); return inputFile.equals(currInputFile); } else if (inputFile.getName().equals(ICoreConstants.BUILD_FILENAME_DESCRIPTOR)) { if (currInputFile.getName().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR)) return currInputFile.getProjectRelativePath().toString().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR); return inputFile.equals(currInputFile); } return false; } catch (PartInitException e) { return false; } }
private void updateSelection(IWorkbenchPart part, ISelection selection) { // If the action is run from within an editor, try and find the // file for the given editor. setActivePart(null, part); if (part != null && part instanceof IEditorPart) { IEditorInput input = ((IEditorPart) part).getEditorInput(); IFile file = ResourceUtil.getFile(input); if (file != null) { selectionChanged((IAction) null, new StructuredSelection(file)); } } else { // Fallback is to prime the action with the selection selectionChanged((IAction) null, selection); } }
public XtextEditor getEditor(IResource resource) { XtextEditor result = findEditor(resource); if(result == null) { IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); try { IFile file = ResourceUtil.getFile(resource); IEditorInput input = new FileEditorInput(file); result = (XtextEditor) page.openEditor(input, getEditorId()); } catch (PartInitException e) { return null; } } return result; }
/** * @param event * the execution event, must not be null * @return the current selection * @throws ExecutionException * if the selection can't be determined */ protected IStructuredSelection getSelection(ExecutionEvent event) throws ExecutionException { if (event == null) throw new IllegalArgumentException("event must not be NULL"); //$NON-NLS-1$ Object selection = HandlerUtil.getActiveMenuSelection(event); if (selection == null) selection = HandlerUtil.getCurrentSelectionChecked(event); if (selection instanceof TextSelection) { IEditorInput editorInput = (IEditorInput) HandlerUtil.getVariable( event, ISources.ACTIVE_EDITOR_INPUT_NAME); IResource resource = ResourceUtil.getResource(editorInput); if (resource != null) return new StructuredSelection(resource); resource = ResourceUtil.getFile(editorInput); if (resource != null) return new StructuredSelection(resource); } if (selection instanceof IStructuredSelection) return (IStructuredSelection) selection; return StructuredSelection.EMPTY; }
public IXtextDocument getXtextDocument(IResource resource) { IXtextDocument result = XtextDocumentUtil.get(resource); if(result == null) { IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); try { IFile file = ResourceUtil.getFile(resource); IEditorInput input = new FileEditorInput(file); page.openEditor(input, getEditorId()); } catch (PartInitException e) { return null; } } return XtextDocumentUtil.get(resource); }
/** * Returns the editor in the given page whose input represents the given file, * or <code>null</code> if there is no such editor. * * @param page the workbench page * @param file the file * @return the matching editor, or <code>null</code> */ public static IEditorPart findEditor(IWorkbenchPage page, IFile file) { // handle the common case where the editor input is a FileEditorInput IEditorPart editor = page.findEditor(new FileEditorInput(file)); if (editor != null) { return editor; } // check for editors that have their own kind of input that adapts to IFile, // being careful not to force loading of the editor IEditorReference[] refs = page.getEditorReferences(); for (int i = 0; i < refs.length; i++) { IEditorReference ref = refs[i]; IEditorPart part = ref.getEditor(false); if (part != null) { IFile editorFile = getFile(part.getEditorInput()); if (editorFile != null && file.equals(editorFile)) { return part; } } } return null; }
/** * An editor has been activated. Fetch the history if the file is shared and the history view * is visible in the current page. * * @param editor the active editor */ protected void editorActivated(IEditorPart editor) { lastSelectedElement= editor; // Only fetch contents if the view is shown in the current page. if (editor == null || !isLinkingEnabled() || !checkIfPageIsVisible() || isViewPinned()) { return; } IEditorInput input = editor.getEditorInput(); IFile file = ResourceUtil.getFile(input); if (file != null) { showHistory(file); /* don't fetch if already cached */ } else { // see if it adapts to an IHistoryPageSource Object pageSource = Adapters.adapt(input, IHistoryPageSource.class); if (pageSource != null) showHistory(input); } }
/** * An editor has been activated. Sets the selection in this navigator * to be the editor's input, if linking is enabled. * * @param editor the active editor * @since 2.0 */ protected void editorActivated(IEditorPart editor) { if (!isLinkingEnabled()) { return; } IFile file = ResourceUtil.getFile(editor.getEditorInput()); if (file != null) { ISelection newSelection = new StructuredSelection(file); if (getTreeViewer().getSelection().equals(newSelection)) { getTreeViewer().getTree().showSelection(); } else { getTreeViewer().setSelection(newSelection, true); } } }
for (int k = 0; k < editors.length; k++) { IEditorPart editor = editors[k]; IFile inputFile = ResourceUtil.getFile(editor.getEditorInput()); if (inputFile != null) { if (projects.contains(inputFile.getProject())) {
private void execute(IWorkbenchWindow activeWorkbenchWindow, IWorkbenchPart part, ISelection selection) throws InvocationTargetException, InterruptedException { // If the action is run from within an editor, try and find the // file for the given editor. if (part != null && part instanceof IEditorPart) { IEditorInput input = ((IEditorPart) part).getEditorInput(); IFile file = ResourceUtil.getFile(input); if (file != null) { selectionChanged((IAction) null, new StructuredSelection(file)); } } else { // Fallback is to prime the action with the selection selectionChanged((IAction) null, selection); } // Safe guard to ensure that the action is only run when enabled. if (isEnabled()) { execute((IAction) null); } else { MessageDialog.openInformation(activeWorkbenchWindow.getShell(), TeamUIMessages.TeamAction_handlerNotEnabledTitle, TeamUIMessages.TeamAction_handlerNotEnabledMessage); } }
private void execute(IWorkbenchWindow activeWorkbenchWindow, IWorkbenchPart part, ISelection selection) throws InvocationTargetException, InterruptedException { // If the action is run from within an editor, try and find the // file for the given editor. if (part != null && part instanceof IEditorPart) { IEditorInput input = ((IEditorPart) part).getEditorInput(); IFile file = ResourceUtil.getFile(input); if (file != null) { selectionChanged((IAction) null, new StructuredSelection(file)); } } else { // Fallback is to prime the action with the selection selectionChanged((IAction) null, selection); } // Safe guard to ensure that the action is only run when enabled. if (isEnabled()) { execute((IAction) null); } else { MessageDialog.openInformation(activeWorkbenchWindow.getShell(), TeamUIMessages.TeamAction_handlerNotEnabledTitle, TeamUIMessages.TeamAction_handlerNotEnabledMessage); } }
/** * An editor has been activated. Fetch the history if the file is shared and the history view * is visible in the current page. * * @param editor the active editor */ protected void editorActivated(IEditorPart editor) { //If this history view is not visible, keep track of this editor //for future use if (editor != null && !checkIfPageIsVisible()) lastSelectedElement = editor; //Only fetch contents if the view is shown in the current page. if (editor == null || !isLinkingEnabled() || !checkIfPageIsVisible() || isViewPinned()) { return; } IEditorInput input = editor.getEditorInput(); IFile file = ResourceUtil.getFile(input); if (file != null) { showHistory(file); /* don't fetch if already cached */ } else { //see if it adapts to an IHistoryPageSource Object pageSource = Utils.getAdapter(input, IHistoryPageSource.class); if (pageSource != null) showHistory(input); } }
if (editor != null) { IEditorInput input = editor.getEditorInput(); IFile file = ResourceUtil.getFile(input); if (file != null) { if (marker.getResource().equals(file) && OpenStrategy.activateOnOpen()) {
IFile file = ResourceUtil.getFile(editor.getEditorInput()); if (file != null) { selected = new IProject[] {file.getProject()};