EditorŽs Items [message #11356] |
Tue, 08 August 2006 22:10  |
Eclipse User |
|
|
|
Originally posted by: alsacin.gmail.com
I Have an editor and would like to know how many objects i have in that
editor, so i put a button with the function that return the number of
objects in the editor. But, i draw the objects in the editor and when i
press the button, nothing happen. I would like to know how can i acess
this editor to know the number of objects.
Thank you
|
|
|
|
|
Re: EditorŽs Items [message #13424 is a reply to message #11652] |
Wed, 09 August 2006 20:19   |
Eclipse User |
|
|
|
Originally posted by: khai.n.situvista.com
To get the active editor you can use:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActiveEditor()
Now, once you get the active editor you'd want to double check that its
the right one:-)
The count will give you a count of everything, connectors, labels, and
nodes so you might need to filter it down to count the appropriate type.
The following code might give you some hints about what you can access;
I think you can just put it in the run code of your button and execute
it (haven't tried it myself :-)).
Let me know if this is not enough info.
-- Khai --
IEditorPart editorPart =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActiveEditor();
if(editorPart instanceof DiagramEditor){
DiagramEditor diagramEditor = (DiagramEditor)editorPart;
Map epartRegistry =
diagramEditor.getDiagramGraphicalViewer().getEditPartRegistr y();
System.out.println("Number of Elements: " + epartRegistry.size());
for (Iterator iter = epartRegistry.values().iterator();
iter.hasNext();) {
System.out.println("\tEditPart: " + iter.next());
}
System.out.println("======================");
for (Iterator iter = epartRegistry.keySet().iterator();
iter.hasNext();) {
System.out.println("\tView: " + iter.next());
}
System.out.println("======================");
for (Iterator iter = epartRegistry.keySet().iterator();
iter.hasNext();) {
Object view = iter.next();
if(view instanceof View){
System.out.println("\tModel: " + ((View)view).getElement());
}
}
}
Andre wrote:
> Hi,
>
> I have an arrayList with the objects that are add in the editor.
> I want to get the number of objects in the editor. But, i dont know how
> can i get the objects of the active editor. I think i should know,
> first, how can i get the active editor, but i dont know. My count
> function is called in the class of the button, in the run method. Do you
> know what i mean?
>
> Thanks
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.12930 seconds