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

The following examples show how to use org.eclipse.core.resources.IStorage#getName() . 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: JdtToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean removeStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
	if (storage instanceof IFile && JavaCore.isJavaLikeFileName(storage.getName())) {
		IJavaElement element = JavaCore.create(((IFile)storage).getParent());
		String fileName = storage.getName();
		String typeName = fileName.substring(0, fileName.lastIndexOf('.'));
		if (element instanceof IPackageFragmentRoot) {
			queueJavaChange(typeName);
			return true;
		} else if (element instanceof IPackageFragment) {
			IPackageFragment packageFragment = (IPackageFragment) element;
			queueJavaChange(packageFragment.getElementName() + "." + typeName);
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: ContentTypeHelper.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 3
Source File: UriValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return whether there's possibly an {@link IResourceServiceProvider} for the given storage
 * @since 2.4
 */
public boolean isPossiblyManaged(IStorage storage) {
	if (!registry.getContentTypeToFactoryMap().isEmpty())
		return true;
	String name = storage.getName();
	if (name == null) {
		return true;
	}
	name = URI.encodeSegment(name, true); 
	int index = name.lastIndexOf('.');
	if (index == -1) {
		return true;
	}
	return registry.getExtensionToFactoryMap().containsKey(name.substring(index + 1));
}
 
Example 4
Source File: XbaseBreakpointUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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 5
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;
}
 
Example 6
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the styled string for the given storage.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param storage the storage
 * @return the styled string
 * @since 3.4
 */
private static StyledString getStyledStorageLabel(IStorage storage) {
	StyledString result= new StyledString(storage.getName());
	return Strings.markLTR(result);
}