public static IJavaProject[] getJavaProjects(final IEditorPart part) { if (part == null || part.getEditorInput() == null) { return new IJavaProject[0]; } final IEditorInput editorInput = part.getEditorInput(); if (editorInput instanceof IPathEditorInput) { final IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput; final IJavaProject javaProject = getJavaProject(pathEditorInput.getPath()); if (javaProject != null && javaProject.exists()) { return new IJavaProject[] { javaProject }; } } final IJavaElement element = editorInput.getAdapter(IJavaElement.class); if (element == null) { return new IJavaProject[0]; } return new IJavaProject[] { element.getJavaProject() }; }
@Override public boolean equals(final Object obj) { if (obj instanceof QueryDocumentEditorInput) { final QueryDocumentEditorInput other = (QueryDocumentEditorInput) obj; return targetEditorId.equals(other.targetEditorId) && queryDocument.equals(other.queryDocument); } if (obj instanceof IPathEditorInput && queryDocument.getFile() != null && targetEditorId.equals(QueryEditor.ID)) { final IPathEditorInput pathEditorInput = (IPathEditorInput) obj; final File file = pathEditorInput.getPath().toFile(); return queryDocument.getFile().equals(file); } return false; }
/** * Returns the URI for the specific editor input. * * @param input * the editor input * @return the URI, or null if none could be determined */ public static URI getURI(IEditorInput input) { if (input instanceof IFileEditorInput) { return ((IFileEditorInput) input).getFile().getLocationURI(); } if (input instanceof IURIEditorInput) { return ((IURIEditorInput) input).getURI(); } if (input instanceof IPathEditorInput) { return URIUtil.toURI(((IPathEditorInput) input).getPath()); } return null; }
private IPath getPath(IEditorPart otherEditor) { IEditorInput input = otherEditor.getEditorInput(); try { if (input instanceof IPathEditorInput) { return ((IPathEditorInput) input).getPath(); } URI uri = (URI) input.getAdapter(URI.class); if (uri != null) { return new Path(uri.getHost() + Path.SEPARATOR + uri.getPath()); } if (input instanceof IURIEditorInput) { return URIUtil.toPath(((IURIEditorInput) input).getURI()); } } catch (Exception e) { } return null; }
@Override public void run() { IEditorPart ed = ActionBarContributor.getActiveEditor(); if (!(ed instanceof MarkdownEditor)) { return; } MarkdownEditor editor = (MarkdownEditor) ed; IEditorInput i = editor.getEditorInput(); if (i instanceof IPathEditorInput) { IPathEditorInput input = (IPathEditorInput) i; IPath path = input.getPath(); path = path.removeFileExtension(); path = path.addFileExtension("html"); File file = path.toFile(); String html = editor.getMarkdownPage().html(); FileUtils.write(file, html); } }
/** * Gets the project folder from the input * * @param input * @return */ public static String getProjectFolder( IEditorInput input ) { Object fileAdapter = input.getAdapter( IFile.class ); IFile file = null; if ( fileAdapter != null ) file = (IFile) fileAdapter; if ( file != null && file.getProject( ) != null ) { return file.getProject( ).getLocation( ).toOSString( ); } if ( input instanceof IPathEditorInput ) { File fileSystemFile = ( (IPathEditorInput) input ).getPath( ) .toFile( ); return fileSystemFile.getParent( ); } return null; }
/** * * @param fileName * the fileName * @return the editor with the given fileName, or null if not found. */ public static IEditorPart findOpenedEditor( String fileName ) { IWorkbenchPage page = PlatformUI.getWorkbench( ) .getActiveWorkbenchWindow( ) .getActivePage( ); IEditorReference[] editors = page.getEditorReferences( ); for ( int i = 0; i < editors.length; i++ ) { IEditorPart part = editors[i].getEditor( true ); IPath location = ( (IPathEditorInput) part.getEditorInput( ) ).getPath( ); if ( fileName.equalsIgnoreCase( location.toOSString( ) ) ) { return part; } } return null; }
public IReportProvider getProvider( IEditorInput input ) { if ( input instanceof IFileEditorInput ) { return new IDEFileReportProvider( ); } else if ( input instanceof IPathEditorInput ) { return super.getProvider( input ); } // else // { // return FileReportProvider.getInstance( ); // } return null; }
/** * @return the IEditorInput if we're dealing with an external file (or null otherwise) */ public static IEditorInput getExternalFileEditorInput(ITextEditor editor) { IEditorInput input = editor.getEditorInput(); //only return not null if it's an external file (IFileEditorInput marks a workspace file, not external file) if (input instanceof IFileEditorInput) { return null; } if (input instanceof IPathEditorInput) { //PydevFileEditorInput would enter here return input; } try { if (input instanceof IURIEditorInput) { return input; } } catch (Throwable e) { //IURIEditorInput not added until eclipse 3.3 } //Note that IStorageEditorInput is not handled for external files (files from zip) return input; }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); setPartName(input.getName()); mResource = null; mFilePath = null; if (input instanceof IFileEditorInput) { mResource = ((IFileEditorInput)input).getFile(); mFilePath = mResource.getLocation().toOSString(); } else if (input instanceof IPathEditorInput) { mFilePath = ((IPathEditorInput)input).getPath().toOSString(); } if (mFilePath==null) throw new PartInitException("Invalid editor input"); load(mFilePath,mXmlWarnings); }
/** * Gets the current document html content with a header containing only the title. Intended only for * React updates of the body content. */ public String getUpdate() { IPathEditorInput input = (IPathEditorInput) editor.getEditorInput(); if (input == null) return ""; String title = input.getPath().toString(); return String.format(Update, title, convert().trim()); }
private static File getFile( IEditorInput editorInput ) { File result = null; if( editorInput instanceof IPathEditorInput ) { IPathEditorInput pathEditorInput = ( IPathEditorInput )editorInput; result = pathEditorInput.getPath().toFile(); } else if( editorInput instanceof IURIEditorInput ) { IURIEditorInput uriEditorInput = ( IURIEditorInput )editorInput; result = URIUtil.toFile( uriEditorInput.getURI() ); } return result; }
@Test public void testExecuteWithPathEditorInput() throws IOException { File file = tempFolder.newFile( "foo.txt" ); IPathEditorInput editorInput = mockPathEditorInput( file ); executeHandler( editorInput ); assertThat( file ).doesNotExist(); }
private static void checkEditorInput( IEditorInput input ) { if( !( input instanceof IStorageEditorInput ) && !( input instanceof IPathEditorInput ) && !( input instanceof IURIEditorInput ) ) { throw new IllegalArgumentException( "Invalid input: " + input ); } }
/** * Gets the indexing associated with the editor. * * @param editor * @return */ public static Index getIndex(AbstractThemeableEditor editor) { // NOTE: Moved from CommonContentAssistProcessor if (editor != null) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput; IFile file = fileEditorInput.getFile(); return getIndexManager().getIndex(file.getProject().getLocationURI()); } if (editorInput instanceof IURIEditorInput) { IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput; // FIXME This file may be a child, we need to check to see if there's an index with a parent URI. return getIndexManager().getIndex(uriEditorInput.getURI()); } if (editorInput instanceof IPathEditorInput) { IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput; // FIXME This file may be a child, we need to check to see if there's an index with a parent URI. return getIndexManager().getIndex(URIUtil.toURI(pathEditorInput.getPath())); } } return null; }
private IFile getResource(MarkdownEditor markdownEditor) { IPathEditorInput input = (IPathEditorInput) getEditorInput(); IPath path = input.getPath(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IFile[] files = root.findFilesForLocation(path); if (files.length != 1) return null; IFile docFile = files[0]; return docFile; }
public void saveReport( ModuleHandle moduleHandle, Object element, IPath origReportPath, IProgressMonitor monitor ) { if ( element instanceof IPathEditorInput ) { IPathEditorInput input = (IPathEditorInput) element; saveFile( moduleHandle, input.getPath( ).toFile( ), origReportPath, monitor ); } }
public IPath getSaveAsPath( Object element ) { if ( element instanceof IPathEditorInput ) { IEditorInput input = (IEditorInput) element; SaveReportAsWizardDialog dialog = new SaveReportAsWizardDialog( UIUtil.getDefaultShell( ), new SaveReportAsWizard( model, input ) ); if ( dialog.open( ) == Window.OK ) { return dialog.getResult( ); } } return null; }
public IPath getInputPath( IEditorInput input ) { if ( input instanceof IPathEditorInput ) { return ( (IPathEditorInput) input ).getPath( ); } return null; }
private File getInputForlder( ) { IEditorPart editor = UIUtil.getActiveEditor( true ); if ( editor != null ) { IEditorInput input = editor.getEditorInput( ); if ( input instanceof IPathEditorInput ) { return ( (IPathEditorInput) input ).getPath( ) .toFile( ) .getParentFile( ); } } return null; }
public boolean isReadOnly( Object element ) { if ( element instanceof IPathEditorInput ) { File file = ( (IPathEditorInput) element ).getPath( ).toFile( ); return !file.canWrite( ); } return super.isReadOnly( element ); }
public boolean equals( Object obj ) { if ( this == obj ) return true; if ( obj instanceof IPathEditorInput ) { obj = new ReportEditorInput( (IPathEditorInput) obj ); } if ( !( obj instanceof ReportEditorInput ) ) return false; return file.equals( ( (ReportEditorInput) obj ).file ); }
public void setOriginalFile( IEditorInput input ) { String container = ( (IPathEditorInput) input ).getPath( ) .removeLastSegments( 1 ) .toOSString( ); support.setInitialFileLocation( container ); support.setInitialFileName( input.getName( ) ); }
public IEditorInput findFromOpenedPyEdits() { Object ret = PyEdit.iterOpenEditorsUntilFirstReturn(new ICallback<Object, PyEdit>() { @Override public Object call(PyEdit pyEdit) { IEditorInput editorInput = pyEdit.getEditorInput(); if (editorInput instanceof IPathEditorInput) { IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput; IPath localPath = pathEditorInput.getPath(); if (localPath != null) { if (matchesPath(matchName, editorInput, localPath)) { return editorInput; } } } else { File editorFile = pyEdit.getEditorFile(); if (editorFile != null) { if (matchesFile(matchName, editorInput, editorFile)) { return editorInput; } } } return null; } }); return (IEditorInput) ret; }
protected AvroSchema getAvroSchema() { IPathEditorInput pathInput = (IPathEditorInput) getEditorInput(); IPath path = pathInput.getPath(); File file = path.toFile(); return new AvroSchemaFile(file); }
private static IPathEditorInput mockPathEditorInput( File file ) throws IOException { IPathEditorInput editorInput = mock( IPathEditorInput.class ); when( editorInput.getPath() ).thenReturn( new Path( file.getCanonicalPath() ) ); return editorInput; }
/** * Gets the URI associated with the editor. * * @param editor * @return */ public static URI getURI(IEditorPart editor) { // NOTE: Moved from CommonContentAssistProcessor if (editor != null) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IURIEditorInput) { IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput; return uriEditorInput.getURI(); } if (editorInput instanceof IPathEditorInput) { IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput; return URIUtil.toURI(pathEditorInput.getPath()); } if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput; return fileEditorInput.getFile().getLocationURI(); } try { if (editorInput instanceof IStorageEditorInput) { IStorageEditorInput storageEditorInput = (IStorageEditorInput) editorInput; IStorage storage = storageEditorInput.getStorage(); if (storage != null) { IPath path = storage.getFullPath(); if (path != null) { return URIUtil.toURI(path); } } } } catch (CoreException e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } if (editorInput instanceof ILocationProviderExtension) { ILocationProviderExtension lpe = (ILocationProviderExtension) editorInput; return lpe.getURI(null); } if (editorInput instanceof ILocationProvider) { ILocationProvider lp = (ILocationProvider) editorInput; return URIUtil.toURI(lp.getPath(null)); } } return null; }
/** * Gets the current document html content with a header as determined by HtmlKind. * * @param hdr defines the intended use of the HTML: for export, for the embedded view, or minimal. */ public String getPage(HtmlKind hdr) { IPathEditorInput input = (IPathEditorInput) editor.getEditorInput(); return addHeader(hdr, convert(), input.getPath()); }
/** * Constructor * * @param input */ public ReportEditorInput( IPathEditorInput input ) { this( input.getPath( ).toFile( ) ); }