Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Connections and Anchors
Connections and Anchors [message #179585] Thu, 28 April 2005 19:25 Go to next message
Eclipse UserFriend
Originally posted by: Pachwork.hotmail.com

I'm having some difficulty writing my first gef plugin. I am able to get
nodes and connections to appear in my graph, however all of the
connections are being drawn from 10,10 to 100,100 (some default
coordinates, i assume). It seems that each connection is being created
and being assigned a source or a target, but the connections are not
being recognized as being the same. I'm guessing that if a connection
lacks both source and target anchors that it is drawn in this default way?

I guessed that I might need to add the connection models to my data
structure and tried returning them as part of the list from
getModelChildren() on my highest level EditPart, (previously I had only
returned the models for nodes) but that just seems to cause some
IndesOutOfBoundsException.

If anyone has any advice I would greatly appreciate it.

Thanks,
John

Here is the stack trace in case anyone is interested:

java.lang.IndexOutOfBoundsException: Figure.add(...) invalid index
at org.eclipse.draw2d.Figure.add(Figure.java:110)
at org.eclipse.draw2d.Figure.add(Figure.java:157)
at
org.eclipse.gef.editparts.AbstractGraphicalEditPart.addChild Visual(AbstractGraphicalEditPart.java:198)
at
org.eclipse.gef.editparts.AbstractEditPart.addChild(Abstract EditPart.java:195)
at
org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(A bstractEditPart.java:750)
at
org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractE ditPart.java:700)
at
org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh( AbstractGraphicalEditPart.java:554)
at
org.eclipse.gef.editparts.AbstractEditPart.addNotify(Abstrac tEditPart.java:233)
at
org.eclipse.gef.editparts.AbstractGraphicalEditPart.addNotif y(AbstractGraphicalEditPart.java:212)
at
org.eclipse.gef.editparts.AbstractEditPart.addChild(Abstract EditPart.java:196)
at
org.eclipse.gef.editparts.ScalableRootEditPart.setContents(S calableRootEditPart.java:379)
at
org.eclipse.gef.ui.parts.AbstractEditPartViewer.setContents( AbstractEditPartViewer.java:581)
at
com.sri.halo.aura.graph.MyEditor.initializeGraphicalViewer(M yEditor.java:52)
at
org.eclipse.gef.ui.parts.GraphicalEditor.createGraphicalView er(GraphicalEditor.java:138)
at
org.eclipse.gef.ui.parts.GraphicalEditorWithPalette.createPa rtControl(GraphicalEditorWithPalette.java:65)
at
org.eclipse.ui.internal.EditorManager.busyRestoreEditorHelpe r(EditorManager.java:1237)
at
org.eclipse.ui.internal.EditorManager.busyRestoreEditor(Edit orManager.java:1102)
at org.eclipse.ui.internal.EditorManager$7.run(EditorManager.ja va:1064)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:69)
at
org.eclipse.ui.internal.EditorManager.restoreEditor(EditorMa nager.java:1062)
at
org.eclipse.ui.internal.EditorManager$Editor.getEditor(Edito rManager.java:1648)
at
org.eclipse.ui.internal.EditorManager$Editor.getPart(EditorM anager.java:1639)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:26 0)
at
org.eclipse.ui.internal.presentations.PresentablePart.setVis ible(PresentablePart.java:126)
at
org.eclipse.ui.internal.presentations.newapi.PresentablePart Folder.select(PresentablePartFolder.java:268)
at
org.eclipse.ui.internal.presentations.newapi.LeftToRightTabO rder.select(LeftToRightTabOrder.java:65)
at
org.eclipse.ui.internal.presentations.newapi.TabbedStackPres entation.selectPart(TabbedStackPresentation.java:391)
at
org.eclipse.ui.internal.PartStack.refreshPresentationSelecti on(PartStack.java:1070)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.jav a:1019)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:12 23)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:406)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:109 )
at
org.eclipse.ui.internal.EditorSashContainer.addEditor(Editor SashContainer.java:63)
at
org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorA reaHelper.java:267)
at org.eclipse.ui.internal.EditorManager$4.run(EditorManager.ja va:829)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:69)
at
org.eclipse.ui.internal.EditorManager.createEditorTab(Editor Manager.java:809)
at
org.eclipse.ui.internal.EditorManager.restoreEditorState(Edi torManager.java:1869)
at
org.eclipse.ui.internal.EditorManager.restoreState(EditorMan ager.java:1016)
at
org.eclipse.ui.internal.WorkbenchPage.restoreState(Workbench Page.java:2464)
at
org.eclipse.ui.internal.WorkbenchWindow.restoreState(Workben chWindow.java:1660)
at org.eclipse.ui.internal.Workbench.restoreState(Workbench.jav a:1408)
at org.eclipse.ui.internal.Workbench.access$9(Workbench.java:13 58)
at org.eclipse.ui.internal.Workbench$14.run(Workbench.java:1241 )
at
org.eclipse.core.internal.runtime.InternalPlatform.run(Inter nalPlatform.java:1021)
at org.eclipse.core.runtime.Platform.run(Platform.java:757)
at org.eclipse.ui.internal.Workbench.restoreState(Workbench.jav a:1185)
at
org.eclipse.ui.internal.WorkbenchConfigurer.restoreState(Wor kbenchConfigurer.java:173)
at
org.eclipse.ui.application.WorkbenchAdvisor.openWindows(Work benchAdvisor.java:712)
at org.eclipse.ui.internal.Workbench.init(Workbench.java:962)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1510)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:306)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:143)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplicatio n.java:103)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:228)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:344)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:315 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:268)
at org.eclipse.core.launcher.Main.run(Main.java:942)
at org.eclipse.core.launcher.Main.main(Main.java:926)
Re: Connections and Anchors [message #179772 is a reply to message #179585] Sat, 30 April 2005 00:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Pachwork.hotmail.com

So I've figured out two things, but I'm not sure where to go from here.
It seems that the hashmap at "viewer.getEditPartRegistry().map" is not
getting all the connections added to it. And on top of that the one that
I can see that has been added to it has some random java.lang.Object as
its key, and not the connection model like it should.

Can anyone tell me where these parts are added to this registry, and why
my connections wouldn't be getting added correctly?

Thank you,
John
Re: Connections and Anchors [message #179788 is a reply to message #179772] Sat, 30 April 2005 01:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Pachwork.hotmail.com

I can fix the problem by adding these lines to my ConnectionEditPart
implementation:

//TODO DEBUG
public void setTarget(EditPart part){
super.setTarget(part);
EditPartViewer viewer = getViewer();
Map map = viewer.getEditPartRegistry();
ConnectionEditPart conx = (ConnectionEditPart)map.get(getModel());
if (conx != null) return;
map.put(getModel(), this);
}
//TODO DEBUG
public void setSource(EditPart part){
super.setSource(part);
EditPartViewer viewer = getViewer();
Map map = viewer.getEditPartRegistry();
ConnectionEditPart conx = (ConnectionEditPart)map.get(getModel());
if (conx != null) return;
map.put(getModel(), this);
}

But I have a feeling that I shouldn't be doing this manually. Anyone know
where this should be naturally getting done, and how I might be flubbing
it up?

-john
Re: Connections and Anchors [message #179879 is a reply to message #179585] Sun, 01 May 2005 22:47 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
Please refer to our examples on how to do this. Make sure you're properly
implementing the imp. methods: getModelSource/TargetConnections(),
get*ConnectionAnchor(), etc.

"John Pacheco" <Pachwork@hotmail.com> wrote in message
news:c0934be207e1e8bc7d715e6f439e99ee$1@www.eclipse.org...
> I'm having some difficulty writing my first gef plugin. I am able to get
> nodes and connections to appear in my graph, however all of the
> connections are being drawn from 10,10 to 100,100 (some default
> coordinates, i assume). It seems that each connection is being created
> and being assigned a source or a target, but the connections are not
> being recognized as being the same. I'm guessing that if a connection
> lacks both source and target anchors that it is drawn in this default way?
>
> I guessed that I might need to add the connection models to my data
> structure and tried returning them as part of the list from
> getModelChildren() on my highest level EditPart, (previously I had only
> returned the models for nodes) but that just seems to cause some
> IndesOutOfBoundsException.
>
> If anyone has any advice I would greatly appreciate it.
>
> Thanks,
> John
>
> Here is the stack trace in case anyone is interested:
>
> java.lang.IndexOutOfBoundsException: Figure.add(...) invalid index
> at org.eclipse.draw2d.Figure.add(Figure.java:110)
> at org.eclipse.draw2d.Figure.add(Figure.java:157)
> at
>
org.eclipse.gef.editparts.AbstractGraphicalEditPart.addChild Visual(AbstractG
raphicalEditPart.java:198)
> at
>
org.eclipse.gef.editparts.AbstractEditPart.addChild(Abstract EditPart.java:19
5)
> at
>
org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(A bstractEditPart.
java:750)
> at
>
org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractE ditPart.java:700
)
> at
>
org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh( AbstractGraphica
lEditPart.java:554)
> at
>
org.eclipse.gef.editparts.AbstractEditPart.addNotify(Abstrac tEditPart.java:2
33)
> at
>
org.eclipse.gef.editparts.AbstractGraphicalEditPart.addNotif y(AbstractGraphi
calEditPart.java:212)
> at
>
org.eclipse.gef.editparts.AbstractEditPart.addChild(Abstract EditPart.java:19
6)
> at
>
org.eclipse.gef.editparts.ScalableRootEditPart.setContents(S calableRootEditP
art.java:379)
> at
>
org.eclipse.gef.ui.parts.AbstractEditPartViewer.setContents( AbstractEditPart
Viewer.java:581)
> at
>
com.sri.halo.aura.graph.MyEditor.initializeGraphicalViewer(M yEditor.java:52)
> at
>
org.eclipse.gef.ui.parts.GraphicalEditor.createGraphicalView er(GraphicalEdit
or.java:138)
> at
>
org.eclipse.gef.ui.parts.GraphicalEditorWithPalette.createPa rtControl(Graphi
calEditorWithPalette.java:65)
> at
>
org.eclipse.ui.internal.EditorManager.busyRestoreEditorHelpe r(EditorManager.
java:1237)
> at
>
org.eclipse.ui.internal.EditorManager.busyRestoreEditor(Edit orManager.java:1
102)
> at org.eclipse.ui.internal.EditorManager$7.run(EditorManager.ja va:1064)
> at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:69)
> at
>
org.eclipse.ui.internal.EditorManager.restoreEditor(EditorMa nager.java:1062)
> at
>
org.eclipse.ui.internal.EditorManager$Editor.getEditor(Edito rManager.java:16
48)
> at
>
org.eclipse.ui.internal.EditorManager$Editor.getPart(EditorM anager.java:1639
)
> at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:26 0)
> at
>
org.eclipse.ui.internal.presentations.PresentablePart.setVis ible(Presentable
Part.java:126)
> at
>
org.eclipse.ui.internal.presentations.newapi.PresentablePart Folder.select(Pr
esentablePartFolder.java:268)
> at
>
org.eclipse.ui.internal.presentations.newapi.LeftToRightTabO rder.select(Left
ToRightTabOrder.java:65)
> at
>
org.eclipse.ui.internal.presentations.newapi.TabbedStackPres entation.selectP
art(TabbedStackPresentation.java:391)
> at
>
org.eclipse.ui.internal.PartStack.refreshPresentationSelecti on(PartStack.jav
a:1070)
> at org.eclipse.ui.internal.PartStack.setSelection(PartStack.jav a:1019)
> at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:12 23)
> at org.eclipse.ui.internal.PartStack.add(PartStack.java:406)
> at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:109 )
> at
>
org.eclipse.ui.internal.EditorSashContainer.addEditor(Editor SashContainer.ja
va:63)
> at
>
org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorA reaHelper.java:2
67)
> at org.eclipse.ui.internal.EditorManager$4.run(EditorManager.ja va:829)
> at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:69)
> at
>
org.eclipse.ui.internal.EditorManager.createEditorTab(Editor Manager.java:809
)
> at
>
org.eclipse.ui.internal.EditorManager.restoreEditorState(Edi torManager.java:
1869)
> at
>
org.eclipse.ui.internal.EditorManager.restoreState(EditorMan ager.java:1016)
> at
>
org.eclipse.ui.internal.WorkbenchPage.restoreState(Workbench Page.java:2464)
> at
>
org.eclipse.ui.internal.WorkbenchWindow.restoreState(Workben chWindow.java:16
60)
> at org.eclipse.ui.internal.Workbench.restoreState(Workbench.jav a:1408)
> at org.eclipse.ui.internal.Workbench.access$9(Workbench.java:13 58)
> at org.eclipse.ui.internal.Workbench$14.run(Workbench.java:1241 )
> at
>
org.eclipse.core.internal.runtime.InternalPlatform.run(Inter nalPlatform.java
:1021)
> at org.eclipse.core.runtime.Platform.run(Platform.java:757)
> at org.eclipse.ui.internal.Workbench.restoreState(Workbench.jav a:1185)
> at
>
org.eclipse.ui.internal.WorkbenchConfigurer.restoreState(Wor kbenchConfigurer
..java:173)
> at
>
org.eclipse.ui.application.WorkbenchAdvisor.openWindows(Work benchAdvisor.jav
a:712)
> at org.eclipse.ui.internal.Workbench.init(Workbench.java:962)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1510)
> at
>
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:306)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:143)
> at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplicatio n.java:103)
> at
>
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.
java:228)
> at
>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:344)
> at
>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:156)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.eclipse.core.launcher.Main.invokeFramework(Main.java:315 )
> at org.eclipse.core.launcher.Main.basicRun(Main.java:268)
> at org.eclipse.core.launcher.Main.run(Main.java:942)
> at org.eclipse.core.launcher.Main.main(Main.java:926)
>
>
Re: Connections and Anchors [message #180106 is a reply to message #179585] Tue, 03 May 2005 17:03 Go to previous message
Eclipse UserFriend
Originally posted by: dnawrocki.prologic-inc.com

I'm guessing you're having two separate problems that are getting mixed
up. First, don't return the connection models in the top-level EditPart.
That's what causing your Figure.add exception. If you debug the whole
thing, GEF will add the connection to the top-level by adding the
connection's figure to the primary layer, then call activate() on it. The
default implementation of a connection's activate() function will remove
it from the primary layer and add it to the connection layer. The second
time GEF tries to add a connection it throws an exception because it
attempts to add at a specific (invalid) index in the array.

Second, override getModelTargetConnections() and
getModelSourceConnections() for your "Node" edit part (or whatever the
connections go between). When you do this, GEF will create edit parts for
you connections automatically. You may have to play around with the
anchors for the connections to get them to appear correct. Implementing
org.eclipse.gef.NodeEditPart on your "nodes" will probably help.

I had the exact same problem a while back; took me a few hours to find all
the problems ;)
Previous Topic:Enabling keys in Graph Editor
Next Topic:Has anyone implemented GlassPane functionality
Goto Forum:
  


Current Time: Mon Jan 30 12:48:19 GMT 2023

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

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

Back to the top