org.eclipse.ui.IFileEditorInput Java Examples
The following examples show how to use
org.eclipse.ui.IFileEditorInput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphEditor.java From depan with Apache License 2.0 | 6 votes |
private void initFromInput(IEditorInput input) throws PartInitException { if (!(input instanceof IFileEditorInput)) { throw new PartInitException("Invalid Input: Must be IFileEditorInput"); } // load the graph file = ((IFileEditorInput) input).getFile(); GraphDocLogger.LOG.info("Reading {}", file.getRawLocationURI()); graph = ResourceCache.fetchGraphDocument(file); GraphDocLogger.LOG.info(" DONE"); DependencyModel model = graph.getDependencyModel(); graphResources = GraphResourceBuilder.forModel(model); // set the title to the filename, excepted the file extension String title = file.getName(); title = title.substring(0, title.lastIndexOf('.')); this.setPartName(title); }
Example #2
Source File: QuickOutline.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 6 votes |
@Override public void setInput(Object input) { if (input instanceof Model) { Model model = (Model) input; if (model.getPath() == null) { IFile currentFile = null; IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { currentFile = ((IFileEditorInput) editorInput).getFile(); } if (currentFile != null) { model.setPath(currentFile.getFullPath()); } } } treeViewer.setInput(input); treeViewer.setSelection(null, true); }
Example #3
Source File: UIUtils.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example #4
Source File: OccurrencesSearchResult.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean isShownInEditor(Match match, IEditorPart editor) { Object element= match.getElement(); IJavaElement je= ((JavaElementLine) element).getJavaElement(); IEditorInput editorInput= editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { try { return ((IFileEditorInput)editorInput).getFile().equals(je.getCorrespondingResource()); } catch (JavaModelException e) { return false; } } else if (editorInput instanceof IClassFileEditorInput) { return ((IClassFileEditorInput)editorInput).getClassFile().equals(je); } return false; }
Example #5
Source File: MetainformationEditor.java From slr-toolkit with Eclipse Public License 1.0 | 6 votes |
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); //to avoid errors, close editor, when project is not open //use case : project deleted if(!getProjectFromIEditorPart(this).isOpen()) { this.getEditorSite().getPage().closeEditor(this, false); } // initialize whole project unloadDocumentResources(); initializeWholeProject(getProjectFromIEditorPart(this)); // set filename as displayed tab name activeFilePath = ((IFileEditorInput) input).getFile().getLocation(); String pathString = activeFilePath.toOSString(); this.setPartName(pathString.substring(pathString.lastIndexOf(File.separator) + 1)); activeFilePath = ((IFileEditorInput) input).getFile().getLocation(); }
Example #6
Source File: IDEReportProviderFactory.java From birt with Eclipse Public License 1.0 | 6 votes |
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; }
Example #7
Source File: IDEMultiPageReportEditor.java From birt with Eclipse Public License 1.0 | 6 votes |
protected void setInput( IEditorInput input ) { // The workspace never changes for an editor. So, removing and re-adding // the // resourceListener is not necessary. But it is being done here for the // sake // of proper implementation. Plus, the resourceListener needs to be // added // to the workspace the first time around. if ( isWorkspaceResource ) { getFile( getEditorInput( ) ).getWorkspace( ) .removeResourceChangeListener( resourceListener ); } isWorkspaceResource = input instanceof IFileEditorInput; super.setInput( input ); if ( isWorkspaceResource ) { getFile( getEditorInput( ) ).getWorkspace( ) .addResourceChangeListener( resourceListener ); } }
Example #8
Source File: CoreEditorUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * Returns File underlying this editor input. * * This method should be modified, whenever new editor input is supported * for some editor requiring access to File. * * @param input the editor input to operate on. * * @return file underlying given editor input. */ public static File editorInputToFile(IEditorInput input) { if (input == null) return null; if (input instanceof IFileEditorInput) { IFile file = editorInputToIFile(input); if (file != null) { return ResourceUtils.getAbsoluteFile(file); } } else if (input instanceof IURIEditorInput) { IURIEditorInput uriEditorInput = (IURIEditorInput) input; return new File(uriEditorInput.getURI()); } else if (input instanceof CommonSourceNotFoundEditorInput || input instanceof CompareEditorInput || input instanceof IStorageEditorInput) { // do nothing } else{ LogHelper.logError("Unknown editor input"); } return null; }
Example #9
Source File: EditorUtil.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Returns the project that the file for the editor belongs. * * @param editor * a file editor * @return the project the editor belongs */ public static IProject getProject(AbstractThemeableEditor editor) { if (editor != null) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput; return fileEditorInput.getFile().getProject(); } } return null; }
Example #10
Source File: OccurrencesSearchResult.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) { //TODO same code in JavaSearchResult IEditorInput editorInput= editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput= (IFileEditorInput) editorInput; return computeContainedMatches(result, fileEditorInput.getFile()); } else if (editorInput instanceof IClassFileEditorInput) { IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) editorInput; IClassFile classFile= classFileEditorInput.getClassFile(); Object[] elements= getElements(); if (elements.length == 0) return NO_MATCHES; //all matches from same file: JavaElementLine jel= (JavaElementLine) elements[0]; if (jel.getJavaElement().equals(classFile)) return collectMatches(elements); } return NO_MATCHES; }
Example #11
Source File: ClangFormatFormatter.java From CppStyle with MIT License | 6 votes |
private static IPath getSourceFilePathFromEditorInput(IEditorInput editorInput) { if (editorInput instanceof IURIEditorInput) { URI uri = ((IURIEditorInput) editorInput).getURI(); if (uri != null) { IPath path = URIUtil.toPath(uri); if (path != null) { return path; } } } if (editorInput instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) editorInput).getFile(); if (file != null) { return file.getLocation(); } } if (editorInput instanceof ILocationProvider) { return ((ILocationProvider) editorInput).getPath(editorInput); } return null; }
Example #12
Source File: AbstractDesignElementPicker.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
/** * This method will get the DesignerProject for the current XPage and return it. * @param compEditor * @return */ private DesignerProject getDesignerProjectForEditor(CompositeEditor compEditor){ IWorkbenchPart part = super.getWorkBenchPart(); if(part instanceof EditorPart){ EditorPart editor = (EditorPart)part; IEditorInput input = editor.getEditorInput(); if(input instanceof IFileEditorInput){ IFileEditorInput fileInput = (IFileEditorInput)input; IFile xpageFile = fileInput.getFile(); if(null != xpageFile){ IProject project = xpageFile.getProject(); if(null != project){ DesignerProject designerProj = DesignerResource.getDesignerProject(project); if(null != designerProj){ return designerProj; } } } } } return null; }
Example #13
Source File: PropertiesFileDocumentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Checks whether the passed file editor input defines a Java properties file. * * @param element the file editor input * @return <code>true</code> if element defines a Java properties file, <code>false</code> * otherwise * @throws CoreException * * @since 3.7 */ public static boolean isJavaPropertiesFile(Object element) throws CoreException { if (JAVA_PROPERTIES_FILE_CONTENT_TYPE == null || !(element instanceof IFileEditorInput)) return false; IFileEditorInput input= (IFileEditorInput)element; IFile file= input.getFile(); if (file == null || !file.isAccessible()) return false; IContentDescription description= file.getContentDescription(); if (description == null || description.getContentType() == null || !description.getContentType().isKindOf(JAVA_PROPERTIES_FILE_CONTENT_TYPE)) return false; return true; }
Example #14
Source File: PropertyKeyHyperlink.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates a new properties key hyperlink. * * @param region the region * @param key the properties key * @param editor the text editor */ public PropertyKeyHyperlink(IRegion region, String key, ITextEditor editor) { Assert.isNotNull(region); Assert.isNotNull(key); Assert.isNotNull(editor); fRegion= region; fPropertiesKey= key; fEditor= editor; fIsFileEditorInput= fEditor.getEditorInput() instanceof IFileEditorInput; IStorageEditorInput storageEditorInput= (IStorageEditorInput)fEditor.getEditorInput(); fShell= fEditor.getEditorSite().getShell(); try { fStorage= storageEditorInput.getStorage(); } catch (CoreException e) { fStorage= null; } }
Example #15
Source File: ActiveEditorTracker.java From statecharts with Eclipse Public License 1.0 | 6 votes |
/** * @return The project which contains the file that is open in the last * active editor in the current workbench page. */ public static IProject getLastActiveEditorProject() { final IEditorPart editor = getLastActiveEditor(); if (editor == null) return null; final IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { final IFileEditorInput input = (IFileEditorInput) editorInput; return input.getFile().getProject(); } else if (editorInput instanceof URIEditorInput) { final URI uri = ((URIEditorInput) editorInput).getURI(); if (uri.isPlatformResource()) { final String platformString = uri.toPlatformString(true); return ResourcesPlugin.getWorkspace().getRoot().findMember(platformString).getProject(); } } return null; }
Example #16
Source File: ReViewerAction.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
@Override public void run(IAction action) { IFile file = null; IEditorInput input = targetEditor.getEditorInput(); if(input instanceof IFileEditorInput) { file = ((IFileEditorInput) input).getFile(); } String url = file.getLocation().toOSString(); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if(window == null) return; IWorkbenchPage page = window.getActivePage(); if(page == null) return; WebBrowserView part = (WebBrowserView)page.findView("com.aptana.browser.views.webbrowser"); if(part != null) { page.bringToTop(part); part.setURL(url); return; } try { WebBrowserView view = (WebBrowserView)page.showView("com.aptana.browser.views.webbrowser"); view.setURL(url); } catch (PartInitException e) { e.printStackTrace(); } }
Example #17
Source File: EditorInputPropertyTester.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
@Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (IS_EXPERIMENT_EDITOR_INPUT.equals(property)) { if (receiver instanceof IFileEditorInput) { IFileEditorInput editorInput = (IFileEditorInput) receiver; IFile file = editorInput.getFile(); if (file != null) { try { final String traceTypeId = file.getPersistentProperty(TmfCommonConstants.TRACETYPE); if (traceTypeId != null && ITmfEventsEditorConstants.EXPERIMENT_INPUT_TYPE_CONSTANTS.contains(traceTypeId)) { return true; } } catch (CoreException e) { // Ignore } } } } return false; }
Example #18
Source File: ResourceCloseManagement.java From birt with Eclipse Public License 1.0 | 6 votes |
private static IFile getEditorFile( IEditorReference fileRef ) { if ( fileRef != null ) { IEditorPart part = (IEditorPart) fileRef.getPart( false ); if ( part != null ) { IEditorInput input = part.getEditorInput( ); if ( input != null && input instanceof IFileEditorInput ) { return ( (IFileEditorInput) input ).getFile( ); } } } return null; }
Example #19
Source File: TLAProofFoldingStructureProvider.java From tlaplus with MIT License | 6 votes |
/** * Initializes this folding structure provider for the given editor. * * @param editor */ public TLAProofFoldingStructureProvider(TLAEditor editor) { canPerformFoldingCommands = true; this.editor = editor; this.document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); foldPositions = new Vector<TLAProofPosition>(); // add this as listener to document to listen for changes document.addDocumentListener(this); // get a parse result if the parse result broadcaster has already stored one if (editor.getEditorInput() instanceof IFileEditorInput) { IFileEditorInput editorInput = (IFileEditorInput) editor.getEditorInput(); IPath location = editorInput.getFile().getLocation(); ParseResult parseResult = ParseResultBroadcaster.getParseResultBroadcaster().getParseResult(location); if (parseResult != null) { newParseResult(parseResult); } } // now listen to any new parse results ParseResultBroadcaster.getParseResultBroadcaster().addParseResultListener(this); }
Example #20
Source File: BugInfoView.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
private boolean matchInput(IEditorInput input) { if (file != null && (input instanceof IFileEditorInput)) { return file.equals(((IFileEditorInput) input).getFile()); } if (javaElt != null && input != null) { IJavaElement javaElement = JavaUI.getEditorInputJavaElement(input); if (javaElt.equals(javaElement)) { return true; } IJavaElement parent = javaElt.getParent(); while (parent != null && !parent.equals(javaElement)) { parent = parent.getParent(); } if (parent != null && parent.equals(javaElement)) { return true; } } return false; }
Example #21
Source File: PDFBrowserEditor.java From tlaplus with MIT License | 5 votes |
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); this.setPartName(input.getName()); if (browser != null && input instanceof IFileEditorInput) { setFileInput((IFileEditorInput) input); } }
Example #22
Source File: AbstractBaseAction.java From erflute with Apache License 2.0 | 5 votes |
protected void refreshProject() { final IFile iFile = ((IFileEditorInput) getEditorPart().getEditorInput()).getFile(); final IProject project = iFile.getProject(); try { project.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (final CoreException e) { Activator.showExceptionDialog(e); } }
Example #23
Source File: TecoRegister.java From e4macs with Eclipse Public License 1.0 | 5 votes |
private IFile convertToPath(IEditorPart editor) { IFile path = null; if (editor != null && editor instanceof IEditorPart) { IEditorInput input = ((IEditorPart) editor).getEditorInput(); if (input instanceof IFileEditorInput) { path = ((IFileEditorInput) input).getFile(); } } return path; }
Example #24
Source File: ERFluteMultiPageEditor.java From erflute with Apache License 2.0 | 5 votes |
@Override public void doSave(IProgressMonitor monitor) { monitor.setTaskName("save initialize..."); final ZoomManager zoomManager = (ZoomManager) getActiveEditor().getAdapter(ZoomManager.class); final double zoom = zoomManager.getZoom(); diagram.setZoom(zoom); final MainDiagramEditor activeEditor = (MainDiagramEditor) getActiveEditor(); final Point location = activeEditor.getLocation(); diagram.setLocation(location.x, location.y); final Persistent persistent = Persistent.getInstance(); final IFile file = ((IFileEditorInput) getEditorInput()).getFile(); try { monitor.setTaskName("create stream..."); final InputStream source = persistent.write(diagram); if (!file.exists()) { file.create(source, true, monitor); } else { file.setContents(source, true, false, monitor); } } catch (final Exception e) { Activator.showExceptionDialog(e); } monitor.beginTask("saving...", getPageCount()); for (int i = 0; i < getPageCount(); i++) { final IEditorPart editor = getEditor(i); editor.doSave(monitor); monitor.worked(i + 1); } monitor.done(); monitor.setTaskName("finalize..."); validate(); monitor.done(); }
Example #25
Source File: ResourceUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Get the file being edited by a given editor. Note that this method can * return null if the specified editor isn't an IFileEditor. */ public static IFile getEditorInput(IEditorPart editor) { IFileEditorInput fileEditorInput = AdapterUtilities.getAdapter( editor.getEditorInput(), IFileEditorInput.class); if (fileEditorInput != null) { return fileEditorInput.getFile(); } return null; }
Example #26
Source File: AbstractXtextUiTest.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Opens an {@link IEditorPart} for a provided {@link org.eclipse.emf.common.util.URI}. * * @param uri * {@link org.eclipse.emf.common.util.URI} to open editor for * @param activate * true if focus is to be set to the opened editor * @return {@link IEditorPart} created */ private IEditorPart openEditor(final org.eclipse.emf.common.util.URI uri, final boolean activate) { UiAssert.isNotUiThread(); final IEditorPart editorPart = UIThreadRunnable.syncExec(getBot().getDisplay(), new Result<IEditorPart>() { @Override public IEditorPart run() { IEditorPart editor = getXtextTestUtil().get(GlobalURIEditorOpener.class).open(uri, activate); editor.setFocus(); return editor; } }); waitForEditorJobs(editorPart); getBot().waitUntil(new DefaultCondition() { @Override public boolean test() { if (editorPart.getEditorSite() != null && editorPart.getEditorInput() != null) { IEditorInput input = editorPart.getEditorInput(); if (input instanceof IFileEditorInput) { return !((IFileEditorInput) input).getFile().isReadOnly(); } } return false; } @Override public String getFailureMessage() { return "Editor must be initialized."; } }, EDITOR_ENABLED_TIMEOUT); return editorPart; }
Example #27
Source File: CrossflowDiagramEditor.java From scava with Eclipse Public License 2.0 | 5 votes |
/** * @generated */ protected IDocumentProvider getDocumentProvider(IEditorInput input) { if (input instanceof IFileEditorInput || input instanceof URIEditorInput) { return CrossflowDiagramEditorPlugin.getInstance().getDocumentProvider(); } return super.getDocumentProvider(input); }
Example #28
Source File: NLSSearchResult.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) { //TODO: copied from JavaSearchResult: IEditorInput editorInput= editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput= (IFileEditorInput) editorInput; return computeContainedMatches(result, fileEditorInput.getFile()); } else if (editorInput instanceof IClassFileEditorInput) { IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) editorInput; Set<Match> matches= new HashSet<Match>(); collectMatches(matches, classFileEditorInput.getClassFile()); return matches.toArray(new Match[matches.size()]); } return NO_MATCHES; }
Example #29
Source File: CodeCheckerContext.java From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 | 5 votes |
/** * Refresh change editor part. * * @param partRef the IEditorPart which the user has switched. */ public void refreshChangeEditorPart(IEditorPart partRef) { if (partRef.getEditorInput() instanceof IFileEditorInput){ //could be FileStoreEditorInput //for files which are not part of the //current workspace activeEditorPart = partRef; IFile file = ((IFileEditorInput) partRef.getEditorInput()).getFile(); IProject project = file.getProject(); CodeCheckerProject ccProj = projects.get(project); String filename = ""; if (ccProj != null) filename = ((FileEditorInput) partRef.getEditorInput()).getFile().getLocation().toFile().toPath() .toString(); IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWindow == null) { Logger.log(IStatus.ERROR, NULL_WINDOW); return; } IWorkbenchPage[] pages = activeWindow.getPages(); this.refreshProject(pages, project, true); this.refreshCurrent(pages, project, filename, true); this.refreshCustom(pages, project, "", true); this.activeProject = project; } }
Example #30
Source File: PDFBrowserEditor.java From tlaplus with MIT License | 5 votes |
@Override public void createPartControl(Composite parent) { final Composite body = new Composite(parent, SWT.NONE); body.setLayout(new FillLayout()); this.browser = new Browser(body, SWT.NONE); if (getEditorInput() instanceof IFileEditorInput) { setFileInput((IFileEditorInput) getEditorInput()); } else { this.browser.setText("<html><body></body></html>"); } }