Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Selection Listeners (Howto use in an Graphiti editor selected objects in other views?)
Selection Listeners [message #756707] Mon, 14 November 2011 13:18 Go to next message
Bjoern Ickx is currently offline Bjoern Ickx
Messages: 17
Registered: June 2011
Junior Member
Hello together,

Simple Scenario: I have a RCP Application with a Graphiti-Editor-View and a TableView.

To react on selection changes within the GraphitiEditor I use the selection listener provided by the ToolBehaviorProvider.
When I select a shape within the diagram I get the corresponding business object in this way:

public PictogramElement getSelection(PictogramElement originalPE, PictogramElement[] oldSelection) { IFeatureProvider featureProvider = getFeatureProvider();
Object businessObject = featureProvider.getBusinessObjectForPictogramElement(PictogramElement);
		if (businessObject instanceof Process) {
			System.out.println("It is a process");			
		}
...


Now I want to display some properties of the selected (shape) business object in the table view.
As it seems to me, the Eclipse-way to do this is by adding a selection listener to the tableViewer.

But the problem with this is that I only get internal Graphiti objects from the selection listener e.g. Type: org.eclipse.graphiti.ui.internal.parts.ContainerShapeEditPart

I think I can't use these internal Graphiti objects to get the underlying business object as it was possible in the ToolBehaviorProvider.

Does anyone has an Idea how to solve this issue elegantly in the model view controller way? I am a liitle bit lost at the moment. In fact I don't know how to handover the business object to the tableView without violating the MVC paradigm.

I hint or explanation would make me very happy.

Best regards

Bjoern

[Updated on: Mon, 14 November 2011 13:20]

Report message to a moderator

Re: Selection Listeners [message #756893 is a reply to message #756707] Tue, 15 November 2011 08:16 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
Hi Bjoern,

the object which is provided as selection is basically a gef edit part.
See GFPropertySection on how to extract the business object.

If you do not want to have the graphiti/gef dependency in
your listener, you might use a callback, extension point etc
(an business object provider could be registered with the plugin containing your listener, the listener could simply pass the selection to the provider who can compute and return the domain object if possible)

Does it help?

Best, Tim
Re: Selection Listeners [message #756951 is a reply to message #756893] Tue, 15 November 2011 12:15 Go to previous messageGo to next message
Bjoern Ickx is currently offline Bjoern Ickx
Messages: 17
Registered: June 2011
Junior Member
Hey Tim,

thanks a lot for your answer. Well, as I am very new to Eclipse development I only have a very rudimentary understanding of what you mentioned, in fact I never did this, but it sounds as it is a good point to start searching for.

Best regards

Björn
Re: Selection Listeners [message #758847 is a reply to message #756951] Thu, 24 November 2011 12:34 Go to previous message
Bjoern Ickx is currently offline Bjoern Ickx
Messages: 17
Registered: June 2011
Junior Member
Hey Tim,

I really tried it to solve it myself, but I am totally lost. Would you mind help me with a short example?

I tried to find out what getBusinessObjectForPictogramElement() is doing internally, but I couldn't find the method in the source code.
Another problem is the documentation (JavaDoc) of Graphiti. Most classes and interfaces only contain the automatically generated components. No describing text. Puuh. So hard to get in. Sad

EDIT:

ok, with the last try I found a way. But I think it is a very very dirty one. Here is the code of the selection listener in my TableVew class


...selection listener ...
Object element = structuredSelection.getFirstElement();
...
if (element instanceof ContainerShapeEditPart) {
     editPart = (ContainerShapeEditPart) element;
     IFeatureProvider fp = editPart.getFeatureProvider();
     Object bo = fp.getBusinessObjectForPictogramElement(editPart.getPictogramElement());
		if (bo instanceof Process) {
					System.out.println("It is a process");
		}
}			


I think the problem with this solution is, that I use some internal methods, i.a. the getFeatureProvider() and getPictogramElement() which shouldn't be used here.

For both I get this type of warning:

Quote:
"Discouraged access: The method getPictogramElement() from the type ShapeEditPart is not accessible due to restriction on required library /Applications/eclipse/"


But at least it is working somehow. What would be a better (clean) way to get the business object?

[Updated on: Thu, 24 November 2011 13:14]

Report message to a moderator

Previous Topic:ConnectionDecorator text decoration
Next Topic:Making sense of listeners in DiagramEditor
Goto Forum:
  


Current Time: Thu Jul 31 13:54:15 EDT 2014

Powered by FUDForum. Page generated in 0.01892 seconds