Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF based RAP Editor(Package with uri 'null' not found)
EMF based RAP Editor [message #1061139] Thu, 30 May 2013 08:14 Go to next message
Sascha Smoo is currently offline Sascha SmooFriend
Messages: 56
Registered: November 2012
Member
Hello friends,

I'm working on an EMF based RAP editor at the moment. I have an ecore model generated from a xsd file and I'm using this model to load instances of xml files. My problem now is that i can't open my generated EMF editor with this xml files as input. I get the "Package with uri 'null' not found" error. I'm aware of the issue that I have to load the file by my ResourceFactoryImpl and I'm doing so before opening the editor.

public class LoadModelResourceOperation implements IRunnableWithProgress {

	private final ResourceSet resourceSet;

	private final URI fileURI;

	public LoadModelResourceOperation(URI fileURI) {
		this.fileURI = fileURI;

		this.resourceSet = new ResourceSetImpl();

		// Register the appropriate resource factory to handle all file
		// extensions.
		this.resourceSet
				.getResourceFactoryRegistry()
				.getExtensionToFactoryMap()
				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
						new WorkerchainResourceFactoryImpl());

		// Register the package to ensure it is available during loading.
		this.resourceSet.getPackageRegistry().put(WorkerchainPackage.eNS_URI,
				WorkerchainPackage.eINSTANCE);
	}

	@Override
	public void run(IProgressMonitor progressMonitor) {
		try {
			// Demand load resource for this file.
			//
			Resource resource = resourceSet.getResource(fileURI, true);
			// Resource resource = new ResourceFactoryImpl()
			// .createResource(fileURI);

			// no options needed
			if (!resource.isLoaded()) {
				resource.load(null);
			}
		} catch (RuntimeException exception) {
			System.out.println("Problem loading " + fileURI);
			exception.printStackTrace();
		} catch (IOException e) {
			System.out.println("Problem loading resource" + fileURI);
			e.printStackTrace();
		}
	}

}


This works fine and the resource contains the complete xml file structure after the getResource call. But within my treeViewPart where I'm opening the editor for the same file URI it won't let me start my editor throwing the "Package with uri null..." exception. The code for running the operation and starting my editor looks like this.

try {
						PlatformUI
								.getWorkbench()
								.getProgressService()
								.run(false, false,
										new LoadModelResourceOperation(fileUri));
					} catch (InvocationTargetException e) {
						e.printStackTrace();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}

					WorkerchainEditorAdvisor.openEditor(
							PlatformUI.getWorkbench(), fileUri);


Any ideas what I'm missing here?

Greetings,
Sascha
Re: EMF based RAP Editor [message #1061144 is a reply to message #1061139] Thu, 30 May 2013 08:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Sascha,

Comments below.

On 30/05/2013 10:14 AM, Sascha Smoo wrote:
> Hello friends,
>
> I'm working on an EMF based RAP editor at the moment.
EMF can generate one of those...
> I have an ecore model generated from a xsd file and I'm using this
> model to load instances of xml files. My problem now is that i can't
> open my generated EMF editor with this xml files as input. I get the
> "Package with uri 'null' not found" error.
Does the normal generated editor work? Or the editor generated for RAP?
> I'm aware of the issue that I have to load the file by my
> ResourceFactoryImpl and I'm doing so before opening the editor.
>
>
> public class LoadModelResourceOperation implements
> IRunnableWithProgress {
>
> private final ResourceSet resourceSet;
>
> private final URI fileURI;
>
> public LoadModelResourceOperation(URI fileURI) {
> this.fileURI = fileURI;
>
> this.resourceSet = new ResourceSetImpl();
>
> // Register the appropriate resource factory to handle all file
> // extensions.
> this.resourceSet
> .getResourceFactoryRegistry()
> .getExtensionToFactoryMap()
> .put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new WorkerchainResourceFactoryImpl());
>
> // Register the package to ensure it is available during loading.
> this.resourceSet.getPackageRegistry().put(WorkerchainPackage.eNS_URI,
> WorkerchainPackage.eINSTANCE);
> }
>
> @Override
> public void run(IProgressMonitor progressMonitor) {
> try {
> // Demand load resource for this file.
> //
> Resource resource = resourceSet.getResource(fileURI, true);
> // Resource resource = new ResourceFactoryImpl()
> // .createResource(fileURI);
>
> // no options needed
> if (!resource.isLoaded()) {
> resource.load(null);
> }
> } catch (RuntimeException exception) {
> System.out.println("Problem loading " + fileURI);
> exception.printStackTrace();
> } catch (IOException e) {
> System.out.println("Problem loading resource" + fileURI);
> e.printStackTrace();
> }
> }
>
> }
>
>
> This works fine and the resource contains the complete xml file
> structure after the getResource call. But within my treeViewPart where
> I'm opening the editor for the same file URI it won't let me start my
> editor throwing the "Package with uri null..." exception. The code for
> running the operation and starting my editor looks like this.
You've verified that you resource factory is being used to create the
resource?
>
>
> try {
> PlatformUI
> .getWorkbench()
> .getProgressService()
> .run(false, false,
> new
> LoadModelResourceOperation(fileUri));
> } catch (InvocationTargetException e) {
> e.printStackTrace();
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
>
> WorkerchainEditorAdvisor.openEditor(
> PlatformUI.getWorkbench(), fileUri);
>
>
> Any ideas what I'm missing here?
I'm a little confused though. When you open the editor, you pass in
fileURI. How does that help locate the model you loaded with
LoadModelResourceOperation? Is it the editor being opened that's
throwing the exception?
>
> Greetings,
> Sascha


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF based RAP Editor [message #1061150 is a reply to message #1061144] Thu, 30 May 2013 08:47 Go to previous messageGo to next message
Sascha Smoo is currently offline Sascha SmooFriend
Messages: 56
Registered: November 2012
Member
Hello Ed,

thanks for your quick answer. You were right, the editor I'm trying to open with the file URI has it's own 'createModel()' method and my LoadModelResourceOperation is completely useless at this point. The generated EMF editor tries to load the resource via the editingDomain resourceSet (see code below).

	public void createModel() {
		URI resourceURI = EditUIUtil.getURI(getEditorInput());
		Exception exception = null;
		Resource resource = null;
		try {
			// Load the resource through the editing domain.
			//
			resource = editingDomain.getResourceSet().getResource(resourceURI,
					true);
		} catch (Exception e) {
			exception = e;
			resource = editingDomain.getResourceSet().getResource(resourceURI,
					false);
		}

		Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
		if (diagnostic.getSeverity() != Diagnostic.OK) {
			resourceToDiagnosticMap.put(resource,
					analyzeResourceProblems(resource, exception));
		}
		editingDomain.getResourceSet().eAdapters()
				.add(problemIndicationAdapter);
	}


The line where the error will be thrown is:

 
resource = editingDomain.getResourceSet().getResource(resourceURI,
					true);


The editing domain is initialized like this:

protected void initializeEditingDomain() {
		// Create an adapter factory that yields item providers.
		//
		adapterFactory = new ComposedAdapterFactory(
				ComposedAdapterFactory.Descriptor.Registry.INSTANCE);

		adapterFactory
				.addAdapterFactory(new ResourceItemProviderAdapterFactory());
		adapterFactory
				.addAdapterFactory(new WorkerchainItemProviderAdapterFactory());
		adapterFactory
				.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

		// Create the command stack that will notify this editor as commands are
		// executed.
		//
		BasicCommandStack commandStack = new BasicCommandStack();

		// Add a listener to set the most recent command's affected objects to
		// be the selection of the viewer with focus.
		//
		commandStack.addCommandStackListener(new CommandStackListener() {
			public void commandStackChanged(final EventObject event) {
				getContainer().getDisplay().asyncExec(new Runnable() {
					public void run() {
						firePropertyChange(IEditorPart.PROP_DIRTY);

						// Try to select the affected objects.
						//
						Command mostRecentCommand = ((CommandStack) event
								.getSource()).getMostRecentCommand();
						if (mostRecentCommand != null) {
							setSelectionToViewer(mostRecentCommand
									.getAffectedObjects());
						}
						for (Iterator<PropertySheetPage> i = propertySheetPages
								.iterator(); i.hasNext();) {
							PropertySheetPage propertySheetPage = i.next();
							if (propertySheetPage.getControl().isDisposed()) {
								i.remove();
							} else {
								propertySheetPage.refresh();
							}
						}
					}
				});
			}
		});

		// Create the editing domain with a special command stack.
		//
		editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
				commandStack, new HashMap<Resource, Boolean>());
	}


I guess the editing domain is aware of the model, is it?

Greetings,
Sascha
Re: EMF based RAP Editor [message #1061152 is a reply to message #1061150] Thu, 30 May 2013 09:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Sascha,

Comments below.

On 30/05/2013 10:47 AM, Sascha Smoo wrote:
> Hello Ed,
>
> thanks for your quick answer. You were right, the editor I'm trying to
> open with the file URI has it's own 'createModel()' method and my
> LoadModelResourceOperation is completely useless at this point.
Yes, that's what I figured...
> The generated EMF editor tries to load the resource via the
> editingDomain resourceSet (see code below).
>
> public void createModel() {
> URI resourceURI = EditUIUtil.getURI(getEditorInput());
> Exception exception = null;
> Resource resource = null;
> try {
> // Load the resource through the editing domain.
> //
> resource =
> editingDomain.getResourceSet().getResource(resourceURI,
> true);
> } catch (Exception e) {
> exception = e;
> resource =
> editingDomain.getResourceSet().getResource(resourceURI,
> false);
> }
>
> Diagnostic diagnostic = analyzeResourceProblems(resource,
> exception);
> if (diagnostic.getSeverity() != Diagnostic.OK) {
> resourceToDiagnosticMap.put(resource,
> analyzeResourceProblems(resource, exception));
> }
> editingDomain.getResourceSet().eAdapters()
> .add(problemIndicationAdapter);
> }
>
>
> The line where the error will be thrown is:
>
>
> resource = editingDomain.getResourceSet().getResource(resourceURI,
> true);
>
>
> The editing domain is initialized like this:
>
>
> protected void initializeEditingDomain() {
> // Create an adapter factory that yields item providers.
> //
> adapterFactory = new ComposedAdapterFactory(
> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>
> adapterFactory
> .addAdapterFactory(new
> ResourceItemProviderAdapterFactory());
> adapterFactory
> .addAdapterFactory(new
> WorkerchainItemProviderAdapterFactory());
> adapterFactory
> .addAdapterFactory(new
> ReflectiveItemProviderAdapterFactory());
>
> // Create the command stack that will notify this editor as
> commands are
> // executed.
> //
> BasicCommandStack commandStack = new BasicCommandStack();
>
> // Add a listener to set the most recent command's affected
> objects to
> // be the selection of the viewer with focus.
> //
> commandStack.addCommandStackListener(new CommandStackListener() {
> public void commandStackChanged(final EventObject event) {
> getContainer().getDisplay().asyncExec(new Runnable() {
> public void run() {
> firePropertyChange(IEditorPart.PROP_DIRTY);
>
> // Try to select the affected objects.
> //
> Command mostRecentCommand = ((CommandStack) event
> .getSource()).getMostRecentCommand();
> if (mostRecentCommand != null) {
> setSelectionToViewer(mostRecentCommand
> .getAffectedObjects());
> }
> for (Iterator<PropertySheetPage> i =
> propertySheetPages
> .iterator(); i.hasNext();) {
> PropertySheetPage propertySheetPage =
> i.next();
> if
> (propertySheetPage.getControl().isDisposed()) {
> i.remove();
> } else {
> propertySheetPage.refresh();
> }
> }
> }
> });
> }
> });
>
> // Create the editing domain with a special command stack.
> //
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack, new HashMap<Resource, Boolean>());
> }
>
>
> I guess the editing domain is aware of the model, is it?
Normally your model will have all the necessary registrations in the
plugin.xml and you'd not need to do anything additional (as you're
showing in your load operation) to get it to load properly. Have a look
at your model's plugin.xml. What extension_parser is registered there?
Is that the extension of the file you're trying to load?
>
> Greetings,
> Sascha


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF based RAP Editor [message #1061153 is a reply to message #1061152] Thu, 30 May 2013 09:15 Go to previous message
Sascha Smoo is currently offline Sascha SmooFriend
Messages: 56
Registered: November 2012
Member
Hello Ed,

yeah. Finally it works. There was a wrong file extension type set for the extension parser. Now it works as it should do. Many many thanks for pushing me into the right direction.

Greetings,
Sascha
Previous Topic:Using eKey
Next Topic:Binding details table to validation
Goto Forum:
  


Current Time: Fri Apr 26 10:33:09 GMT 2024

Powered by FUDForum. Page generated in 0.03224 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top