[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,

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