Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Getting IResource instance from *Command classes
Getting IResource instance from *Command classes [message #202321] Tue, 19 August 2008 06:55 Go to next message
Eclipse UserFriend
Originally posted by: martin.divbyzero.net

Hi,

when creating a link between two nodes in my GMF diagram, I want to add
a new entry to the Tasks section in Eclipse's Resource Perspective.

I understand that I need to add the necessary functionality in the
ConnectionCreateCommand class (a link is called Connection in my model),
but I'm a bit lost about getting the correct IResource instance there,
which is needed to create a task using MarkerUtilties. Currently I'm
using the following code in ConnectionCreateCommand:

> protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
> IAdaptable info) throws ExecutionException {
>
> /* ... */
>
> HashMap attributes = new HashMap();
> MarkerUtilities.setMessage(attributes, "hello world");
>
> IResource resource = ...;
>
> try {
> MarkerUtilities.createMarker(resource, attributes, IMarker.TASK);
> } catch (CoreException e) {
> /* ... */
> }
>
> return super.doExecuteWithResult(monitor, info);
> }

My question now is how to get the correct value for the variable resource?

Best,
Martin
Re: Getting IResource instance from *Command classes [message #202400 is a reply to message #202321] Tue, 19 August 2008 09:20 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Martin,

Use org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile () to get
appropriate IResource instance using EMF Resource as a parameter.
Use ConnectionCreateCommand.getElementToEdit() to get EObject corresponding
to the underlying domain model element.
Use EObject.eResource() to get resource instance from this EObject.

If you need to access IResource associated with diagram file then you go
to the ConnectionCreateCommand.getElementToEdit() implementation to see how
you can access View instance using associated CreateElementRequest from within
ConnectionCreateCommand.

-----------------
Alex Shatalin
Previous Topic:Customize property sheet tutorial
Next Topic:same filename for model and diagram
Goto Forum:
  


Current Time: Fri Sep 20 10:15:16 GMT 2024

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

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

Back to the top