|
Re: 'Selecting' nodes through IAction [message #219622 is a reply to message #219436] |
Fri, 20 February 2009 21:11 |
Eclipse User |
|
|
|
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 #220187 is a reply to message #220089] |
Fri, 27 February 2009 10:36 |
Eclipse User |
|
|
|
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 #220540 is a reply to message #220535] |
Wed, 04 March 2009 15:23 |
Eclipse User |
|
|
|
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
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03460 seconds