[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: 'Selecting' nodes through IAction

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().getDiagramGraphicalViewer();
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.??