org.eclipse.ui.IStorageEditorInput Java Examples
The following examples show how to use
org.eclipse.ui.IStorageEditorInput.
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: PropertyKeyHyperlinkDetector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean isEclipseNLSAvailable(IStorageEditorInput editorInput) { IStorage storage; try { storage= editorInput.getStorage(); } catch (CoreException ex) { return false; } if (!(storage instanceof IJarEntryResource)) return false; IJavaProject javaProject= ((IJarEntryResource) storage).getPackageFragmentRoot().getJavaProject(); if (javaProject == null || !javaProject.exists()) return false; try { return javaProject.findType("org.eclipse.osgi.util.NLS") != null; //$NON-NLS-1$ } catch (JavaModelException e) { return false; } }
Example #2
Source File: ImageViewer.java From gama with GNU General Public License v3.0 | 6 votes |
/** * Set the part name based on the editor input. */ void setPartName(final IEditorInput input) { String imageName = null; if (input instanceof IStorageEditorInput) { try { imageName = ((IStorageEditorInput) input).getStorage().getName(); } catch (final CoreException ex) { // intentionally blank } } // this will catch ImageDataEditorInput as well if (imageName == null) { imageName = input.getName(); } if (imageName == null) { imageName = getSite().getRegisteredName(); } setPartName(imageName); }
Example #3
Source File: PackageExplorerPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Object getInputFromEditor(IEditorInput editorInput) { Object input= JavaUI.getEditorInputJavaElement(editorInput); if (input instanceof ICompilationUnit) { ICompilationUnit cu= (ICompilationUnit) input; if (!cu.getJavaProject().isOnClasspath(cu)) { // test needed for Java files in non-source folders (bug 207839) input= cu.getResource(); } } if (input == null) { input= editorInput.getAdapter(IFile.class); } if (input == null && editorInput instanceof IStorageEditorInput) { try { input= ((IStorageEditorInput) editorInput).getStorage(); } catch (CoreException e) { // ignore } } return input; }
Example #4
Source File: XdsModel.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * TODO : common with CoreEditorUtils * @param input * @return */ private static URI toURI(IEditorInput input) { URI uri = null; if (input instanceof IStorageEditorInput) { IStorageEditorInput storageEditorInput = (IStorageEditorInput)input; IFileRevision state = AdapterUtilities.getAdapter(storageEditorInput, IFileRevision.class); if (state != null) { uri = HistoryFs.toURI(state); } } else if (input instanceof IURIEditorInput) { IURIEditorInput uriEditorInput = (IURIEditorInput) input; uri = uriEditorInput.getURI(); } return uri; }
Example #5
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 #6
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 #7
Source File: XbaseBreakpointUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public IResource getBreakpointResource(IEditorInput input) throws CoreException { IResource resource = Adapters.adapt(input, IResource.class); if (resource != null) return resource; if (input instanceof IStorageEditorInput) { IStorage storage = ((IStorageEditorInput) input).getStorage(); if (storage instanceof IResource) return (IResource) storage; if (storage instanceof IJarEntryResource) { IResource underlyingResource = ((IJarEntryResource) storage).getPackageFragmentRoot().getUnderlyingResource(); if (underlyingResource != null) return underlyingResource; } } else { IClassFile classFile = Adapters.adapt(input, IClassFile.class); if (classFile != null) { return getBreakpointResource(classFile.findPrimaryType()); } } return ResourcesPlugin.getWorkspace().getRoot(); }
Example #8
Source File: XtextDocumentProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public String getEncoding(Object element) { String encoding = super.getEncoding(element); if (encoding == null && element instanceof IStorageEditorInput) { try { IStorage storage = ((IStorageEditorInput) element).getStorage(); URI uri = storage2UriMapper.getUri(storage); if (uri != null) { encoding = encodingProvider.getEncoding(uri); } else if (storage instanceof IEncodedStorage) { encoding = ((IEncodedStorage)storage).getCharset(); } } catch (CoreException e) { throw new WrappedException(e); } } if (encoding == null) { if (isWorkspaceExternalEditorInput(element)) encoding = getWorkspaceExternalEncoding((IURIEditorInput)element); else encoding = getWorkspaceOrDefaultEncoding(); } return encoding; }
Example #9
Source File: EditorInputAdapterFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public Object getAdapter(Object element, Class key) { updateLazyLoadedAdapters(); if (fSearchPageScoreComputer != null && ISearchPageScoreComputer.class.equals(key) && element instanceof IEditorInput && JavaUI.getEditorInputJavaElement((IEditorInput)element) != null) return fSearchPageScoreComputer; if (IJavaElement.class.equals(key) && element instanceof IEditorInput) { IJavaElement je= JavaUI.getWorkingCopyManager().getWorkingCopy((IEditorInput)element); if (je != null) return je; if (element instanceof IStorageEditorInput) { try { return ((IStorageEditorInput)element).getStorage().getAdapter(key); } catch (CoreException ex) { // Fall through } } } return null; }
Example #10
Source File: AbstractAnnotationHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IPath getEditorInputPath() { if (getEditor() == null) return null; IEditorInput input= getEditor().getEditorInput(); if (input instanceof IStorageEditorInput) { try { return ((IStorageEditorInput)input).getStorage().getFullPath(); } catch (CoreException ex) { JavaPlugin.log(ex.getStatus()); } } return null; }
Example #11
Source File: ImageViewerEditor.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
private static void checkEditorInput( IEditorInput input ) { if( !( input instanceof IStorageEditorInput ) && !( input instanceof IPathEditorInput ) && !( input instanceof IURIEditorInput ) ) { throw new IllegalArgumentException( "Invalid input: " + input ); } }
Example #12
Source File: PropertyKeyHyperlinkDetector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
static boolean checkEnabled(ITextEditor textEditor, int offset) { if (offset < 0) return false; IEditorInput editorInput= textEditor.getEditorInput(); return editorInput instanceof IFileEditorInput || (editorInput instanceof IStorageEditorInput && isEclipseNLSAvailable((IStorageEditorInput) editorInput)); }
Example #13
Source File: JavaMergeViewer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected IEditorInput getEditorInput(ISourceViewer sourceViewer) { IEditorInput editorInput= super.getEditorInput(sourceViewer); if (editorInput == null) return null; if (getSite() == null) return null; if (!(editorInput instanceof IStorageEditorInput)) return null; return editorInput; }
Example #14
Source File: DFSActionImpl.java From RDFS with Apache License 2.0 | 5 votes |
/** * Open the selected DfsPath in the editor window * * @param selection * @throws JSchException * @throws IOException * @throws PartInitException * @throws InvocationTargetException * @throws InterruptedException */ private void open(IStructuredSelection selection) throws IOException, PartInitException, InvocationTargetException, InterruptedException { for (DFSFile file : filterSelection(DFSFile.class, selection)) { IStorageEditorInput editorInput = new DFSFileEditorInput(file); targetPart.getSite().getWorkbenchWindow().getActivePage().openEditor( editorInput, "org.eclipse.ui.DefaultTextEditor"); } }
Example #15
Source File: BaseEditor.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @return the project for the file that's being edited (or null if not available) */ public IProject getProject() { IEditorInput editorInput = this.getEditorInput(); if (editorInput instanceof IAdaptable) { IAdaptable adaptable = editorInput; IFile file = adaptable.getAdapter(IFile.class); if (file != null) { return file.getProject(); } IResource resource = adaptable.getAdapter(IResource.class); if (resource != null) { return resource.getProject(); } if (editorInput instanceof IStorageEditorInput) { IStorageEditorInput iStorageEditorInput = (IStorageEditorInput) editorInput; try { IStorage storage = iStorageEditorInput.getStorage(); IPath fullPath = storage.getFullPath(); if (fullPath != null) { IWorkspace ws = ResourcesPlugin.getWorkspace(); for (String s : fullPath.segments()) { IProject p = ws.getRoot().getProject(s); if (p.exists()) { return p; } } } } catch (Exception e) { Log.log(e); } } } return null; }
Example #16
Source File: MultiPageCSVEditor.java From gama with GNU General Public License v3.0 | 5 votes |
private static IFile getFileFor(final IEditorInput input) { if (input instanceof IFileEditorInput) { return ((IFileEditorInput) input).getFile(); } else if (input instanceof IStorageEditorInput) { try { final IStorage storage = ((IStorageEditorInput) input).getStorage(); if (storage instanceof IFile) { return (IFile) storage; } } catch (final CoreException ignore) { // intentionally blank } } return null; }
Example #17
Source File: ImageViewer.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Load the image data from the current editor input. This operation can take time and should not be called on the * ui thread. */ void loadImageData() throws CoreException { final IEditorInput input = getEditorInput(); final Object o = input.getAdapter(ImageData.class); if (o instanceof ImageData) { imageData = (ImageData) o; } else if (input instanceof IStorageEditorInput) { final IFile file = getFileFor(input); imageData = ImageDataLoader.getImageData(file); } // save this away so we don't compute it all the time this.maxZoomFactor = determineMaxZoomFactor(); }
Example #18
Source File: ImageViewer.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Get the IFile corresponding to the specified editor input, or null for none. */ IFile getFileFor(final IEditorInput input) { if (input instanceof IFileEditorInput) { return ((IFileEditorInput) input).getFile(); } else if (input instanceof IStorageEditorInput) { try { final IStorage storage = ((IStorageEditorInput) input).getStorage(); if (storage instanceof IFile) { return (IFile) storage; } } catch (final CoreException ignore) { // intentionally blank } } return null; }
Example #19
Source File: DFSActionImpl.java From hadoop-gpu with Apache License 2.0 | 5 votes |
/** * Open the selected DfsPath in the editor window * * @param selection * @throws JSchException * @throws IOException * @throws PartInitException * @throws InvocationTargetException * @throws InterruptedException */ private void open(IStructuredSelection selection) throws IOException, PartInitException, InvocationTargetException, InterruptedException { for (DFSFile file : filterSelection(DFSFile.class, selection)) { IStorageEditorInput editorInput = new DFSFileEditorInput(file); targetPart.getSite().getWorkbenchWindow().getActivePage().openEditor( editorInput, "org.eclipse.ui.DefaultTextEditor"); } }
Example #20
Source File: ImageViewer.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void init(final IEditorSite site, final IEditorInput input) throws PartInitException { // we need either an IStorage or an input that can return an ImageData if (!(input instanceof IStorageEditorInput) && input.getAdapter(ImageData.class) == null) { throw new PartInitException("Unable to read input: " + input); //$NON-NLS-1$ } setSite(site); setInput(input, false); }
Example #21
Source File: ContentTypeHelper.java From tm4e with Eclipse Public License 1.0 | 5 votes |
/** * Find the content types from the given {@link IDocument} by using * {@link IEditorInput} and null otherwise. * * @param document * @return the content types from the given {@link IDocument} by using * {@link IEditorInput} and null otherwise. */ private static ContentTypeInfo findContentTypesFromEditorInput(IDocument document) { IEditorInput editorInput = getEditorInput(document); if (editorInput != null) { if (editorInput instanceof IStorageEditorInput) { InputStream input = null; try { IStorage storage = ((IStorageEditorInput) editorInput).getStorage(); String fileName = storage.getName(); input = storage.getContents(); return new ContentTypeInfo(fileName, Platform.getContentTypeManager().findContentTypesFor(input, fileName)); } catch (Exception e) { return null; } finally { try { if (input != null) input.close(); } catch (IOException x) { } } } else { // TODO: manage other type of IEditorInput } } return null; }
Example #22
Source File: TypeScriptMergeViewer.java From typescript.java with MIT License | 5 votes |
@Override protected IEditorInput getEditorInput(ISourceViewer sourceViewer) { IEditorInput editorInput = super.getEditorInput(sourceViewer); if (editorInput == null) return null; if (getSite() == null) return null; if (!(editorInput instanceof IStorageEditorInput)) return null; return editorInput; }
Example #23
Source File: AbstractAnnotationHover.java From typescript.java with MIT License | 5 votes |
private IPath getEditorInputPath() { if (getEditor() == null) return null; IEditorInput input = getEditor().getEditorInput(); if (input instanceof IStorageEditorInput) { try { return ((IStorageEditorInput) input).getStorage().getFullPath(); } catch (CoreException ex) { TypeScriptUIPlugin.log(ex.getStatus()); } } return null; }
Example #24
Source File: CoreEditorUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public static IFileStore editorInputToFileStore(IEditorInput input) { if (input == null) return null; IFileStore result = null; if (input instanceof IFileEditorInput) { IFile file = editorInputToIFile(input); if (file != null) { result = ResourceUtils.toFileStore(file); } } else if (input instanceof IURIEditorInput) { IURIEditorInput uriEditorInput = (IURIEditorInput) input; result = ResourceUtils.toFileStore(uriEditorInput.getURI()); } else if (input instanceof CommonSourceNotFoundEditorInput || input instanceof CompareEditorInput) { // do nothing return null; } else if (input instanceof IStorageEditorInput) { IStorageEditorInput storageEditorInput = (IStorageEditorInput)input; IFileRevision state = AdapterUtilities.getAdapter(storageEditorInput, IFileRevision.class); if (state != null) { result = ResourceUtils.toFileStore(HistoryFs.toURI(state)); } } if (result == null){ LogHelper.logError("Unknown editor input"); } return result; }
Example #25
Source File: RunTSVWizard.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 5 votes |
/** * The worker method... */ private void doFinish(File scanDir, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating analysis file", 3); monitor.worked(1); try { runTSVAnalysis(scanDir); monitor.worked(1); monitor.setTaskName("Opening results file..."); getShell().getDisplay().asyncExec(new Runnable() { public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { IStorage storage = new TSVResultsStorage(getResultsString(), new Path("garbage")); IStorageEditorInput input = new TSVResultsInput(storage, "TSV Analysis"); IDE.openEditor(page, input, "com.hybris.hyeclipse.tsv.editors.TSVEditor", true); } catch (PartInitException e) { e.printStackTrace(); } } }); monitor.worked(1); } catch (RuntimeException re) { System.out.println(re.getMessage()); } }
Example #26
Source File: XbaseBreakpointUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public SourceRelativeURI getBreakpointURI(IEditorInput input) { IResource resource = Adapters.adapt(input, IResource.class); if (resource != null) return null; if (input instanceof IStorageEditorInput) { IStorage storage; try { storage = ((IStorageEditorInput) input).getStorage(); if (storage instanceof IResource) return null; if (storage instanceof IJarEntryResource) { IJarEntryResource jarEntryResource = (IJarEntryResource) storage; if (!jarEntryResource.getPackageFragmentRoot().isArchive()) return null; Object parent = jarEntryResource.getParent(); if (parent instanceof IPackageFragment) { String path = ((IPackageFragment) parent).getElementName().replace('.', '/'); return new SourceRelativeURI(path + "/" + storage.getName()); } else if (parent instanceof IPackageFragmentRoot) { return new SourceRelativeURI(storage.getName()); } } } catch (CoreException e) { logger.error("Error finding breakpoint URI", e); return null; } } else { IClassFile classFile = Adapters.adapt(input, IClassFile.class); if (classFile != null) { ITrace traceToSource = traceForTypeRootProvider.getTraceToSource(classFile); if (traceToSource == null) return null; for (ILocationInResource loc : traceToSource.getAllAssociatedLocations()) return loc.getSrcRelativeResourceURI(); return null; } } return null; }
Example #27
Source File: OpenDocumentTracker.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected URI getResourceURI(XtextEditor editor) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IStorageEditorInput) { try { return storage2UriMapper.getUri(((IStorageEditorInput) editorInput).getStorage()); } catch (CoreException e) { LOG.error("Error getting URI for storage", e); } } return null; }
Example #28
Source File: XtextReadonlyEditorInput.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public boolean equals(Object obj) { try { return (obj == this || obj != null && (obj instanceof IStorageEditorInput) && storage.equals(((IStorageEditorInput)obj).getStorage())); } catch (CoreException e) { return false; } }
Example #29
Source File: DefaultMergeViewer.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected IEditorInput getEditorInput(ISourceViewer sourceViewer) { IEditorInput editorInput = super.getEditorInput(sourceViewer); if (editorInput == null) { return null; } if (getSite() == null) { return null; } if (!(editorInput instanceof IStorageEditorInput)) { return null; } return editorInput; }
Example #30
Source File: DefaultEditorInputLabelProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public String text(IStorageEditorInput editorInput) { try { return editorInput.getStorage().getFullPath().lastSegment(); } catch (CoreException e) { LOG.error("Error resolving IStorage from IStorageEditorInput", e); } return null; }