下面列出了org.eclipse.ui.IPathEditorInput#org.eclipse.ui.IStorageEditorInput 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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();
}
/**
* 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;
}
/**
* 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;
}
/**
* 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);
}
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;
}
/**
* 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;
}
protected IStorage getStorage(IEditorPart editor) {
try {
if (editor.getEditorInput() instanceof IStorageEditorInput)
return ((IStorageEditorInput) editor.getEditorInput()).getStorage();
return null;
} catch (CoreException e) {
LOG.error(e.getMessage(), e);
return null;
}
}
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 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;
}
/**
* 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());
}
}
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;
}
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;
}
private static void checkEditorInput( IEditorInput input ) {
if( !( input instanceof IStorageEditorInput )
&& !( input instanceof IPathEditorInput )
&& !( input instanceof IURIEditorInput ) )
{
throw new IllegalArgumentException( "Invalid input: " + input );
}
}
@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.
*/
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.
*/
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;
}
/**
* 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");
}
}
/**
* @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;
}