Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.editor.model;
  
 
 import  org.eclipse.core.resources.IFile;
 import  org.eclipse.core.resources.IProject;
 import  org.eclipse.core.resources.IStorage;
 import  org.eclipse.core.resources.IWorkspace;
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IPath;
 import  org.eclipse.ui.IEditorInput;
 import  org.eclipse.ui.IStorageEditorInput;
 import  org.eclipse.ui.IURIEditorInput;
 

Author(s):
Holger Schill - Initial contribution and API
 
 
 	
 
 
 	
 	
 	
 	@Inject(optional = true)
 	private IWorkspace workspace;

Throws:
IllegalArgumentException if no resource can be provided for the given input.
 
 	public Resource createResource(IEditorInput editorInput) {
 		try {
 			if (editorInput instanceof IStorageEditorInput) {
 				IStorage storage = ((IStorageEditorInput) editorInput).getStorage();
 				Resource result = createResource(storage);
 				if (result != null)
 					return result;
 			} else if (editorInput instanceof IURIEditorInput) {
 				Resource result = createResource(((IURIEditorInput) editorInput).getURI());
 				if (result != null)
 					return result;
 			}
 		} catch (CoreException e) {
 			throw new WrappedException(e);
 		}
 		throw new IllegalArgumentException("Couldn't create EMF Resource for input " + editorInput);
 	}

Since:
2.3
 
 	protected Resource createResource(java.net.URI uri) {
 		ResourceSet resourceSet = getResourceSet(null);
 		URI emfUri = URI.createURI(uri.toString());
 		configureResourceSet(resourceSetemfUri);
 		resourceSet.getResources().add(resource);
		resource.setValidationDisabled(true);
		return resource;
	}
	protected Resource createResource(IStorage storagethrows CoreException {
		return createResourceFor(storage);
	}
	protected Resource createResourceFor(IStorage storagethrows CoreException {
		ResourceSet resourceSet = getResourceSet(storage);
		URI uri = URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
		configureResourceSet(resourceSeturi);
		URI uriForResource = uri
		if (!uri.isPlatform()) {
			uriForResource = resourceSet.getURIConverter().normalize(uri);
		}
		resourceSet.getResources().add(resource);
		return resource;
	}

Parameters:
uri
Since:
2.5
	protected boolean isValidationDisabled(URI uri, IStorage storage) {
		return false;
	}

Since:
2.4
	protected boolean isValidationDisabled(IStorage storage) {
		return isValidationDisabled(nullstorage);
	}
	protected XtextResource createResource(ResourceSet resourceSetURI uri) {
		//TODO use the resource factory directly (injected), since the user might open any file with this editor.
		if (!(aResource instanceof XtextResource))
			throw new IllegalStateException("The resource factory registered for " + uri
" does not yield an XtextResource. Make sure the file name extension is correct (case matters).");
		return (XtextResourceaResource;
	}
	protected ResourceSet getResourceSet(/* @Nullable */ IStorage storage) {
		if (storage instanceof IFile) {
			return .get(((IFile) storage).getProject());
		}
		if ( != null && storage != null) {
			IPath path = storage.getFullPath();
			if (path != null && !path.isEmpty()) {
				String firstSegment = path.segment(0);
				if (firstSegment != null) {
					IProject project = .getRoot().getProject(firstSegment);
					if (project.isAccessible()) {
						return .get(project);
					}
				}
			}
		}
		return .get(null);
	}
	protected void configureResourceSet(ResourceSet resourceSetURI primaryURI) {
		// TODO: Filter external content - primary resource should not use dirty state
			SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.singleton(primaryURI));
					if (!.hasContent(resource.getURI())) {
						return null;
					}
				}
			});
		}
	}
	}
	}
	}

Since:
2.4
	}
New to GrepCode? Check out our FAQ X