Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » 'Selecting' nodes through IAction
'Selecting' nodes through IAction [message #219436] Fri, 20 February 2009 11:03 Go to next message
Conor Missing name is currently offline Conor Missing nameFriend
Messages: 159
Registered: July 2009
Senior Member
Hi all,

I need to be able to iterate through ALL nodes of a CERTAIN TYPE that have
been created within my GMF editor. My idea is to be able to alter the
nodes line color IF one of their properties is set to a specific value.

The first thing I therefore need to do is to be able to ‘select’ all the
nodes (note: I want to do this in the using a program not graphically) so
I can iterate through them.

I have a popup menu that is accessed by right clicking the blank space of
the editor (I have called this space the Canvas in the GMF model).

The IAction I have so far is below but I’m not sure how to ‘select’ the
nodes so I can iterate through them.

Could someone suggest how I might do this so I can firstly check one of
their properties and secondly change their line color if necessary?

(When the user calls this IAction I need all nodes to be iterated through,
irrelevant if none, some, all nodes have been graphically selected within
the GMF editor.)

Thanks for your help,

Gaff

Type of node trying to iterate through: AAA

public class HighlightPropertiesAction implements IObjectActionDelegate {
private CanvasEditPart editParter;

public void run(IAction action) {


IGraphicalEditPart editPart = (IGraphicalEditPart) editParter;
EObject modelElement = editPart.resolveSemanticElement();
Canvas my_canvas = (Canvas) modelElement;


List <AAA> list_of_aaa = my_canvas.getAAA();
// I know this will get a list of AAA nodes but probably isn’t much help
as I need to alter the nodes graphically.



}


public void selectionChanged(IAction action, ISelection selection) {
//???
}

public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
}


??Possibly what I should be doing is iterating through the nodes and
selecting the nodes that have their properties is set to specific value
THEN changing all their line colors in one go rather than doing each
individually.??
Re: 'Selecting' nodes through IAction [message #219622 is a reply to message #219436] Fri, 20 February 2009 21:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

Hello Gaff,

I don`t think you need this IAction.

If you want to do something, when an attribute changes to a certain
value, I would say that you should do this:
Put the methods addNotationalListeners() and removeNotationalListeners()
into the EditPart of the node which value you want to observe. In the
add-method you add a Listener on the value you want to observe with the
method addListenerFilter(...) and in the remove-method you remove the
listener with removeListenerFilter(...).
Then you need to catch the Listener's Event in
handleNotificationEvent(...) in this EditPart (you have to check
notification.getFeature()).
So now when the observed value changes, you catch the event in
handleNotificationEvent(...).

Then you need to iterate over all nodes of this type:
all created EditParts can be found in the EditPartRegistry.
I get the EditPartRegistry like that:
DiagramGraphicalViewer dgv =
(DiagramGraphicalViewer)XXXDiagramEditor.getInstance().getDi agramGraphicalViewer();
Map editPartRegistry = dgv.getEditPartRegistry();
For that approach you need to add the getInstance-Method in
.....diagram.part.XXXDiagramEditor.
I don`t know, if there`s a better way to get the EditPartRegistry or a
better way to get all EditParts...

And when you have all EditParts you can iterate, search for the desired
type, get their figures and change the line-color.

Have fun! :)
Best wishes
Julia


Gaff schrieb:
> Hi all,
>
> I need to be able to iterate through ALL nodes of a CERTAIN TYPE that
> have been created within my GMF editor. My idea is to be able to alter
> the nodes line color IF one of their properties is set to a specific value.
>
> The first thing I therefore need to do is to be able to �select� all the
> nodes (note: I want to do this in the using a program not graphically)
> so I can iterate through them.
> I have a popup menu that is accessed by right clicking the blank space
> of the editor (I have called this space the Canvas in the GMF model).
> The IAction I have so far is below but I�m not sure how to �select� the
> nodes so I can iterate through them.
> Could someone suggest how I might do this so I can firstly check one of
> their properties and secondly change their line color if necessary?
>
> (When the user calls this IAction I need all nodes to be iterated
> through, irrelevant if none, some, all nodes have been graphically
> selected within the GMF editor.)
>
> Thanks for your help,
>
> Gaff
>
> Type of node trying to iterate through: AAA
>
> public class HighlightPropertiesAction implements IObjectActionDelegate {
> private CanvasEditPart editParter;
> public void run(IAction action) {
>
>
> IGraphicalEditPart editPart = (IGraphicalEditPart) editParter;
> EObject modelElement = editPart.resolveSemanticElement();
> Canvas my_canvas = (Canvas) modelElement;
>
>
> List <AAA> list_of_aaa = my_canvas.getAAA();
> // I know this will get a list of AAA nodes but probably isn�t much help
> as I need to alter the nodes graphically.
>
>
>
> }
>
> public void selectionChanged(IAction action, ISelection selection) {
> //???
> }
>
> public void setActivePart(IAction action, IWorkbenchPart targetPart) {
> }
> }
>
>
> ??Possibly what I should be doing is iterating through the nodes and
> selecting the nodes that have their properties is set to specific value
> THEN changing all their line colors in one go rather than doing each
> individually.??
>
>
Re: 'Selecting' nodes through IAction [message #220089 is a reply to message #219622] Thu, 26 February 2009 19:12 Go to previous messageGo to next message
Conor Missing name is currently offline Conor Missing nameFriend
Messages: 159
Registered: July 2009
Senior Member
Hi Julia,

Thanks for your help (and detailed answer) but I don't think the
functionality I have in mind will work with this approach. I need to be
able to iterate through all of the nodes of a certain type from within the
IAction. I don’t think the method you suggested would be as flexible as I
need it as the user should be able to change the property that is being
examined as well as it value and be allowed to turn on/off the
functionality. Basically everything needs to be dealt with in the IAction.

The procedure would be as follows:
- right click on the canvas
- select the new popup menu item
- an SWT interface appears
- user can input their own property to be checked against a property of
all the nodes
- these nodes will then have their line color changed if their property
matches the user input

Everything set up except I’m unsure how to access and iterate through all
the nodes.

Possibly within the IAction I could select the appropriate nodes and then
use selectionChanged to iterate through all the selected node edit parts
and change the line color? Might be able to do this with
IStructuredSelection?

This leads me back to begin able to:
1) select all the nodes that are contained in the model (then sperate and
do functs)
OR
2) select just the nodes that have a certain value in one of their
properties


Thanks for your help,

Gaff
Re: 'Selecting' nodes through IAction [message #220187 is a reply to message #220089] Fri, 27 February 2009 10:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

Hello Gaff,

ok, if I understand you right, you have set up everything, and your only
problem is to iterate over all nodes to find the nodes with the right
property-values.

I still don`t understand why you want to select the nodes. But no matter
what you want to do with a certain amount of nodes (selecting them,
changing their color, changing their properties...), you first have to
iterate over all nodes and find the ones you want to work with.

Why don`t you take my suggested method:
DiagramGraphicalViewer dgv =
(DiagramGraphicalViewer)XXXDiagramEditor.getInstance().getDi agramGraphicalViewer();
Map editPartRegistry = dgv.getEditPartRegistry();
(you can do this also from within you IAction)

In this Map are all EditParts of the Surface, inclusive the
DiagramSurface itself.(debug it to see whats inside) When you iterate
over all EditParts you can ask if the elements are an instance of the
Nodes you`re searching for.
Then you get the sematic Element and ask, if it has the property-value
what you`re searching for. And if yes, you can do whatever you want with
the node :)

I do something simliar in my code. Here I´m searching for Locations:

DiagramGraphicalViewer dgv =
(DiagramGraphicalViewer)CmseditorDiagramEditor.getInstance() .getDiagramGraphicalViewer();
Map<?, ?> editPartRegistry = dgv.getEditPartRegistry();
if(!editPartRegistry.isEmpty())
{
Iterator<?> registryValues = editPartRegistry.values().iterator();
while(registryValues.hasNext())
{
Object o = registryValues.next();

if(o instanceof LocationEditPart)
{
LocationEditPart locationEditPart = (LocationEditPart) o;
Location location = (Location) locationEditPart.resolveSemanticElement();
}
}
}

Like I told you before, you need to add
.....diagram.part.XXXDiagramEditor.getInstance() manually.
XXXDiagramEditor is innately a Singelton, you just need to add the
method, so that you can grab its instance.

Best wishes
Julia
Re: 'Selecting' nodes through IAction [message #220535 is a reply to message #220187] Wed, 04 March 2009 14:05 Go to previous messageGo to next message
Conor Missing name is currently offline Conor Missing nameFriend
Messages: 159
Registered: July 2009
Senior Member
Hi Julia,

I'm not sure what I should be putting into .getInstance() method that I
add to the XXXDiagramEditor? I thought what I have below is what I needed
and although it compiles it does not work:


public static XXXDiagramEditor getInstance() {
return XXXDiagramEditor.getInstance();
}

It is the xxxDiagramEditor that I need to return an instance of?


Thanks,

Gaff
Re: 'Selecting' nodes through IAction [message #220540 is a reply to message #220535] Wed, 04 March 2009 15:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

Hi Gaff,

that`s what I meant with getInstance():

/**
* @generated NOT
*/
private static XXXDiagramEditor instance;

/**
* @generated NOT
*/
public XXXDiagramEditor() {
super(true);
instance = this;
}

/**
* @ generated NOT
*/
public static XXXDiagramEditor getInstance() {
return instance;
}

Best wishes
Julia


Gaff schrieb:
> Hi Julia,
>
> I'm not sure what I should be putting into .getInstance() method that I
> add to the XXXDiagramEditor? I thought what I have below is what I
> needed and although it compiles it does not work:
>
>
> public static XXXDiagramEditor getInstance() {
> return XXXDiagramEditor.getInstance();
> }
>
> It is the xxxDiagramEditor that I need to return an instance of?
>
>
> Thanks,
>
> Gaff
>
Re: 'Selecting' nodes through IAction [message #220781 is a reply to message #220535] Mon, 09 March 2009 10:21 Go to previous message
daniele Mising name is currently offline daniele Mising nameFriend
Messages: 48
Registered: July 2009
Member
sorry for the meddling, but i need something similar.
i want change property of an object selected in the editor. That is to
say: right-click on an object, choose an action in the menu and perform
it. Now..how can I take the selected object? So then i can resolve the
semantic element and modify property...

thanks and sorry Gaff
Previous Topic:how get the "impl" class from an "editPart"
Next Topic:Create 2 nodes and their link at the same time
Goto Forum:
  


Current Time: Tue Mar 02 15:15:11 GMT 2021

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

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

Back to the top