Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » [GMF] Read attribute of current selected node in canvas
[GMF] Read attribute of current selected node in canvas [message #759156] Sat, 26 November 2011 21:45 Go to next message
Snakebyte Missing name is currently offline Snakebyte Missing name
Messages: 130
Registered: November 2011
Senior Member
Suppose i got the following model :
(its an eugenia model)

@namespace(uri="trustcasemodel", prefix="trustcasemodel")
@gmf(foo="bar")
package trustCase;

@gmf.diagram(onefile="false")
class TrustCase {
attr String path;
val Claim[*] valclaims;
val Fact[*] facts;
}
@gmf.node(foo="bar")
class Claim {
attr String path;
}
@gmf.node(foo="bar")
class Fact {
attr String path;
}


Now i have a new Plugin adding an action to the top menu bar.
This Plugin should now read the "path" variable from the current selected Node in canvas.
Whats the code for that ?

I simply want to open the file shown by path.

If that doesn't work, can i do it by double click on a node ?

I'm really frustrated an that.
I only need the option to make a systemcall on the mentioned path.
It's not really important which action triggers that call.....
Anybody got an idea ?

How can i get a specific known attribute ("path") from a selected node in canvas ?

With

( EditPart part = ((EditPart)((IStructuredSelection)HandlerUtil.getCurrentSelection(event)).getFirstElement());


i get the currently selected node in canvas.
This is a ClaimEditPart or a FactEditPart.

How can i get the path-attribute from that EditPart ?

If i want to cast the EditPart to a specific xxxEditPart.java like that

FactEditPart editpart = (FactEditPart) part;
editpart.resolveSemanticElement();


i always got the following error :

java.lang.NoClassDefFoundError: trustCase/diagram/edit/parts/FactEditPart

How can i fix this ?

Greeting
Snakebyte

[Updated on: Sun, 27 November 2011 10:48]

Report message to a moderator

Re: [GMF] Read attribute of current selected node in canvas [message #759183 is a reply to message #759156] Sun, 27 November 2011 08:12 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing name
Messages: 130
Registered: November 2011
Senior Member
Can somebody plz give me some hints on that ?

Where would you add that action ? how ?

How can i access the attribute of the selected node?

[Updated on: Sun, 27 November 2011 10:48]

Report message to a moderator

Re: [GMF] Read attribute of current selected node in canvas [message #759296 is a reply to message #759156] Mon, 28 November 2011 04:53 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael Istria
Messages: 735
Registered: July 2009
Location: Grenoble, France
Senior Member
Hi Snakebyte,

You should ask the EMFatic community for that.


--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Read attribute of current selected node in canvas [message #760175 is a reply to message #759296] Thu, 01 December 2011 09:31 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing name
Messages: 130
Registered: November 2011
Senior Member
this is not an emfatic question.
The community over there just told me to ask here.
Because everything modelled in emfatic just creates an .ecore file.

In this file i got an entity type called Claim and Fact.

In GMF this will result in 2 types of nodes : Claim and Fact.

Now i want to read the attribute of the current selected node in canvas.

Is this possible ?

[Updated on: Thu, 01 December 2011 09:32]

Report message to a moderator

Re: [GMF] Read attribute of current selected node in canvas [message #760180 is a reply to message #760175] Thu, 01 December 2011 09:47 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael Istria
Messages: 735
Registered: July 2009
Location: Grenoble, France
Senior Member
Ok,

Then:
1. Retrieve the selection:
ISelection sel
PlatformUI.getActiveWorkbenchWindow().getActiveSite().getSelection()
2. Get EditPart for it:
editPart = (IGraphicalEditPart)
((IStructuredSelection)sel).getFirstElement()
3. Get your model element:
Claim claim = (Claim) editPart.resolveSemanticElement()
4. Request your claim:
claim.getMyAttribute()

Is this what you want?

--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Read attribute of current selected node in canvas [message #760190 is a reply to message #760180] Thu, 01 December 2011 10:04 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing name
Messages: 130
Registered: November 2011
Senior Member
Yes thats what i would like to do:

Exactly i cast the Object to ClaimImpl.

But when i do this i get the following error.

java.lang.NoClassDefFoundError: trustCase/ClaimImpl

How can that be ?

I imported the class :

import trustCase.impl.ClaimImpl;


??
Re: [GMF] Read attribute of current selected node in canvas [message #760197 is a reply to message #760190] Thu, 01 December 2011 10:15 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael Istria
Messages: 735
Registered: July 2009
Location: Grenoble, France
Senior Member
The java.lang.NoClassDefFoundError is probably not related to GMF.
That's probably an issue with your classpath (Require-Bundle or
Bundle-Classpath or build.properties...) or your JVM version being
different at runtime and devtime.
The Stack should give you more details to troubleshot it.

On 01/12/2011 16:04, Snakebyte wrote:
> Yes thats what i would like to do:
>
> Exactly i cast the Object to ClaimImpl.
>
> But when i do this i get the following error.
>
> java.lang.NoClassDefFoundError: trustCase/ClaimImpl
>
> How can that be ?
> I imported the class :
>
> import trustCase.impl.ClaimImpl;
>
>
> ??


--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Read attribute of current selected node in canvas [message #760201 is a reply to message #760197] Thu, 01 December 2011 10:27 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing name
Messages: 130
Registered: November 2011
Senior Member

I tried it like this :

EObject obj = geditpart.resolveSemanticElement();
FactImpl fact = ((FactImpl) obj);


and get this:
!ENTRY org.eclipse.ui 4 0 2011-12-01 16:26:49.229
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.ClassCastException: trustCase.impl.FactImpl cannot be cast to trustCase.impl.FactImpl
	at trustcasemodel.openfile.handlers.SampleHandler.execute(SampleHandler.java:83)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
	at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
	at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
	at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)


Re: [GMF] Read attribute of current selected node in canvas [message #760203 is a reply to message #760201] Thu, 01 December 2011 10:33 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael Istria
Messages: 735
Registered: July 2009
Location: Grenoble, France
Senior Member
> java.lang.ClassCastException: trustCase.impl.FactImpl cannot be cast to
> trustCase.impl.FactImpl

That means you have several references to the jar that provide you the
FactImpl in your classpath. The dependency should only be defined in
your Require-Bundle, nothing more.
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Read attribute of current selected node in canvas [message #760206 is a reply to message #760203] Thu, 01 December 2011 10:42 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing name
Messages: 130
Registered: November 2011
Senior Member
hmm ok...
and why i can simply use

Fact fact;


then ?

And i got the same error when i only use the current package and copy my sources to my src dir.

[Updated on: Thu, 01 December 2011 10:47]

Report message to a moderator

Re: [GMF] Read attribute of current selected node in canvas [message #760212 is a reply to message #760206] Thu, 01 December 2011 10:45 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael Istria
Messages: 735
Registered: July 2009
Location: Grenoble, France
Senior Member
On 01/12/2011 16:42, Snakebyte wrote:
> hmm ok...
> and why i can simply use
> Fact fact;
>
> then ?

Because you're lucky ;)
By the way, I suggest you to use the interface rather than the Impl objects.

--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Read attribute of current selected node in canvas [message #760243 is a reply to message #760212] Thu, 01 December 2011 11:55 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing name
Messages: 130
Registered: November 2011
Senior Member
My fault.
I tried to add the project in the properties view.
Because its a plugin in want the dependancie in the Manifest file.

Thats why i got 2 References.
Now its running.
Re: [GMF] Read attribute of current selected node in canvas [message #760251 is a reply to message #760243] Thu, 01 December 2011 12:06 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing name
Messages: 130
Registered: November 2011
Senior Member
Another question.
Is it possible to simple use one of the set- methods to change a property ?
Or is that in some case problematic in a generated model ?

Re: [GMF] Read attribute of current selected node in canvas [message #760384 is a reply to message #760251] Fri, 02 December 2011 04:01 Go to previous message
Mickael Istria is currently offline Mickael Istria
Messages: 735
Registered: July 2009
Location: Grenoble, France
Senior Member
With GMF, your models must be modified withing Transaction. This
transaction will require you to use a command stack and to feed it with
the EMF commands to modify your model,
Using a set... method on model elements will fail because you need to
use these commandStack.

So you should
1. Get your Editor
2. Get your TransactionEditDomain.getCommandStack()
3. commandStack.execute(new SetCommand(...))

This pattern provides you ability to save and perform undo/redo.

Regards.
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Previous Topic:Broken link on the homepage of GMP
Next Topic:how to hide the file extension name in the project explore?
Goto Forum:
  


Current Time: Tue Jul 22 09:32:38 EDT 2014

Powered by FUDForum. Page generated in 0.03349 seconds