Java Code Examples for org.eclipse.core.resources.IStorage#getFullPath()

The following examples show how to use org.eclipse.core.resources.IStorage#getFullPath() . 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: N4JSEditor.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Provides input so that the Project Explorer can locate the editor's input in its tree.
 */
@Override
public ShowInContext getShowInContext() {
	IEditorInput editorInput = getEditorInput();
	if (editorInput instanceof FileEditorInput) {
		FileEditorInput fei = (FileEditorInput) getEditorInput();
		return new ShowInContext(fei.getFile(), null);
	} else if (editorInput instanceof XtextReadonlyEditorInput) {
		XtextReadonlyEditorInput readOnlyEditorInput = (XtextReadonlyEditorInput) editorInput;
		IStorage storage;
		try {
			storage = readOnlyEditorInput.getStorage();
			return new ShowInContext(storage.getFullPath(), null);
		} catch (CoreException e) {
			// Do nothing
		}
	}
	return new ShowInContext(null, null);
}
 
Example 2
Source File: ResourceForIEditorInputFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected ResourceSet getResourceSet(/* @Nullable */ IStorage storage) {
	if (storage instanceof IFile) {
		return resourceSetProvider.get(((IFile) storage).getProject());
	}
	if (workspace != null && storage != null) {
		IPath path = storage.getFullPath();
		if (path != null && !path.isEmpty()) {
			String firstSegment = path.segment(0);
			if (firstSegment != null) {
				IProject project = workspace.getRoot().getProject(firstSegment);
				if (project.isAccessible()) {
					return resourceSetProvider.get(project);
				}
			}
		}
	}
	return resourceSetProvider.get(null);
}
 
Example 3
Source File: JavaClassPathResourceForIEditorInputFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Resource createResource(IStorage storage) throws CoreException {
	if (storage instanceof IJarEntryResource) {
		Resource result = createResourceFor((IJarEntryResource) storage);
		if (result == null) {
			throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot create resource for storage with path " + storage.getFullPath()));
		}
		return result;
	}
	return super.createResource(storage);
}
 
Example 4
Source File: BaseEditor.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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 5
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: StorageLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Image getImageForJarEntry(IStorage element) {
	if (element instanceof IJarEntryResource && !((IJarEntryResource) element).isFile()) {
		return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
	}

	if (fJarImageMap == null)
		return getDefaultImage();

	if (element == null || element.getName() == null)
		return getDefaultImage();

	// Try to find icon for full name
	String name= element.getName();
	Image image= fJarImageMap.get(name);
	if (image != null)
		return image;
	IFileEditorMapping[] mappings= getEditorRegistry().getFileEditorMappings();
	int i= 0;
	while (i < mappings.length) {
		if (mappings[i].getLabel().equals(name))
			break;
		i++;
	}
	String key= name;
	if (i == mappings.length) {
		// Try to find icon for extension
		IPath path= element.getFullPath();
		if (path == null)
			return getDefaultImage();
		key= path.getFileExtension();
		if (key == null)
			return getDefaultImage();
		image= fJarImageMap.get(key);
		if (image != null)
			return image;
	}

	// Get the image from the editor registry
	ImageDescriptor desc= getEditorRegistry().getImageDescriptor(name);
	image= desc.createImage();

	fJarImageMap.put(key, image);

	return image;
}