@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); } } return encoding; }
public static final void openEditor(String content, String name) { IStorageEditorInput input = streditors.get(content); if (input == null) { IStorage storage = new StringStorage(content); input = new StringInput(storage); streditors.put(content, input); } IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) window = PlatformUI.getWorkbench().getWorkbenchWindows()[0]; IWorkbenchPage page = window.getActivePage(); try { IEditorReference[] er = page.findEditors(input, name, IWorkbenchPage.MATCH_INPUT); if (er != null) page.closeEditors(er, false); page.openEditor(input, name); } catch (PartInitException e) { UIUtils.showError(e); } }
/** * Set the part name based on the editor input. */ private 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); }
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; }
/** * 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; } }
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; } }
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; }
/** * 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; IStorageEditorInput storageEditorInput= (IStorageEditorInput)fEditor.getEditorInput(); fShell= fEditor.getEditorSite().getShell(); try { fStorage= storageEditorInput.getStorage(); } catch (CoreException e) { fStorage= null; } }
protected IBaseModel createModel(IEditorInput input) throws CoreException { BuildModel model = null; if (input instanceof IStorageEditorInput) { boolean isReconciling = input instanceof IFileEditorInput; IDocument document = getDocumentProvider().getDocument(input); model = new BuildModel(document, isReconciling); if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput)input).getFile(); model.setUnderlyingResource(file); model.setCharset(file.getCharset()); /*} else if (input instanceof SystemFileEditorInput){ File file = (File)((SystemFileEditorInput)input).getAdapter(File.class); model.setInstallLocation(file.getParent()); model.setCharset(getDefaultCharset());*/ } else { model.setCharset(getDefaultCharset()); } model.load(); } return model; }
/** * 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; }
private void initializeResourceObject(IEditorInput editorInput) { if (editorInput instanceof FileEditorInput) { initializeResourceObjectFromFile((FileEditorInput) editorInput); } else if (editorInput instanceof IStorageEditorInput) { initializeResourceObjectFromStorage((IStorageEditorInput) editorInput); } }
private InputStream openStream(IEditorInput input) throws CoreException, IOException { if (input instanceof IStorageEditorInput) { final IStorage storage = ((IStorageEditorInput) input).getStorage(); return storage.getContents(); } if (input instanceof IURIEditorInput) { final URI uri = ((IURIEditorInput) input).getURI(); return uri.toURL().openStream(); } throw new IOException("Unsupported input type: " + input.getClass()); //$NON-NLS-1$ }
/** * 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()); } }
/** * 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"); } }
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; }
@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; }
public String text(IStorageEditorInput editorInput) { try { return editorInput.getStorage().getFullPath().lastSegment(); } catch (CoreException e) { LOG.error("Error resolving IStorage from IStorageEditorInput", e); } return null; }
@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; }
@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; } }
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; }
public Resource createResource(IEditorInput editorInput) { try { if (editorInput instanceof IStorageEditorInput) { IStorage storage = ((IStorageEditorInput) editorInput).getStorage(); return createResourceFor(storage); } throw new IllegalArgumentException("Couldn't create EMF Resource for input " + editorInput); } catch (CoreException e) { throw new WrappedException(e); } }
private static void checkEditorInput( IEditorInput input ) { if( !( input instanceof IStorageEditorInput ) && !( input instanceof IPathEditorInput ) && !( input instanceof IURIEditorInput ) ) { throw new IllegalArgumentException( "Invalid input: " + input ); } }
/** * Adapted from {@link ProductEditor}, replacing references to * {@link ProductInputContext}. */ @Override protected void createStorageContexts(InputContextManager manager, IStorageEditorInput input) { if (input.getName().endsWith(".product")) { manager.putContext(input, new ProductXMLInputContext(this, input, true)); } }
static String getPath(IStorageEditorInput storageInp) { try { IStorage storage = storageInp.getStorage(); return getPath(storage.getFullPath()); } catch (CoreException e) { return null; } }
@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); }
/** * Get the IFile corresponding to the specified editor input, or null for none. */ private 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; }
/** * Load the image data from the current editor input. This operation can take time and should not be called on the * ui thread. */ private 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(); }
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; }
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)); }
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; }
@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; }