Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Create ICreateContext
icon5.gif  Create ICreateContext [message #648533] Thu, 13 January 2011 07:19 Go to next message
Hauke is currently offline Hauke
Messages: 3
Registered: January 2011
Junior Member
Hello

I have a problem.
I create in a CreateFeature (extends from AbstractCreateFeaturea) a vertex (in the create method) and I want to create ports in a static way with them.

...
Vertex vertex = ...
addGraphicalRepresentation(context, vertex);


The problem is at this point.

Port port = ...
addGraphicalRepresentation(context, port);


The context.getTargetContainer() is a instance of Diagram but I need a instance of something which has somting to do with the vertex.
So I have to create a new context which has somting to do with the vertex, but I don't know how to do.
Re: Create ICreateContext [message #648719 is a reply to message #648533] Fri, 14 January 2011 03:40 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1577
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Probably you would simply need to create a new AddContext like this:
AddContext addBookContext = new AddContext(new AreaContext(), <domain
object to add>);
addBookContext.setTargetContainer(<the container shape in which to add
the object representation>);

Michael


"Hauke" <traimiaf@incognitomail.org> wrote in message
news:igmqb9$c0q$1@news.eclipse.org...
> Hello
>
> I have a problem. I create in a CreateFeature (extends from
> AbstractCreateFeaturea) a vertex (in the create method) and I want to
> create ports in a static way with them.
>
> ..
> Vertex vertex = ...
> addGraphicalRepresentation(context, vertex);
>
> The problem is at this point.
>
> Port port = ...
> addGraphicalRepresentation(context, port);
>
> The context.getTargetContainer() is a instance of Diagram but I need a
> instance of something which has somting to do with the vertex.
> So I have to create a new context which has somting to do with the vertex,
> but I don't know how to do.
Re: Create ICreateContext [message #649041 is a reply to message #648719] Mon, 17 January 2011 06:58 Go to previous messageGo to next message
Hauke is currently offline Hauke
Messages: 3
Registered: January 2011
Junior Member
Hello

I have a problem with this one

addBookContext.setTargetContainer(<the container shape in which to add 
the object representation>);


How do I get
<the container shape in which to add the object representation>

The only thing I have is:
PictogramElement v = addGraphicalRepresentation(context, vertex);


And I don't know how I get the right container shape.

This one I tried causes a NullPointerExceptions:
IPeCreateService peCreateService = Graphiti.getPeCreateService();
        ContainerShape contShape = peCreateService.createContainerShape(context.getTargetContainer(),false);
        
        
addBookContext.setTargetContainer(contShape);

[Updated on: Mon, 17 January 2011 08:28]

Report message to a moderator

Re: Create ICreateContext [message #649261 is a reply to message #648533] Tue, 18 January 2011 08:15 Go to previous messageGo to next message
Hauke is currently offline Hauke
Messages: 3
Registered: January 2011
Junior Member
I add somthing
PictogramElement vertexPE = addGraphicalRepresentation(context, vertex);
...
//I add this
contShape.setGraphicsAlgorithm(vertexPE.getGraphicsAlgorithm());


however the NullPointerException happens now after the return.
I write the exception too(I don't thing it is helpful)

java.lang.NullPointerException
	at org.eclipse.draw2d.Figure.add(Figure.java:148)
	at org.eclipse.draw2d.FreeformLayer.add(FreeformLayer.java:28)
	at org.eclipse.draw2d.Figure.add(Figure.java:184)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addChildVisual(AbstractGraphicalEditPart.java:209)
	at org.eclipse.graphiti.ui.internal.parts.ContainerShapeEditPart.addChildVisual(ContainerShapeEditPart.java:161)
	at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:210)
	at org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(AbstractEditPart.java:771)
	at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refreshChildren(ShapeEditPart.java:626)
	at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:718)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:633)
	at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refresh(ShapeEditPart.java:546)
	at org.eclipse.graphiti.ui.internal.parts.DiagramEditPart.refresh(DiagramEditPart.java:181)
	at org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal.internalRefreshEditPart(DiagramEditorInternal.java:1203)
	at org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal.refresh(DiagramEditorInternal.java:1287)
	at org.eclipse.graphiti.ui.internal.editor.DiagramRefreshJob.runInUIThread(DiagramRefreshJob.java:99)
	at org.eclipse.graphiti.ui.internal.editor.DiagramChangeListener.resourceSetChanged(DiagramChangeListener.java:140)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl$1.run(TransactionalEditingDomainImpl.java:781)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.postcommit(TransactionalEditingDomainImpl.java:771)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.deactivate(TransactionalEditingDomainImpl.java:543)
	at org.eclipse.emf.transaction.impl.TransactionImpl.close(TransactionImpl.java:712)
	at org.eclipse.emf.transaction.impl.TransactionImpl.commit(TransactionImpl.java:474)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:155)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:511)
	at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:208)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
	at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandStackImpl.execute(GFWorkspaceCommandStackImpl.java:47)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
	at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandStackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
	at org.eclipse.graphiti.ui.internal.editor.GFCommandStack.execute(GFCommandStack.java:108)
	at org.eclipse.gef.dnd.AbstractTransferDropTargetListener.handleDrop(AbstractTransferDropTargetListener.java:339)
	at org.eclipse.gef.dnd.TemplateTransferDropTargetListener.handleDrop(TemplateTransferDropTargetListener.java:112)
	at org.eclipse.gef.dnd.AbstractTransferDropTargetListener.drop(AbstractTransferDropTargetListener.java:183)
	at org.eclipse.jface.util.DelegatingDropAdapter$3.run(DelegatingDropAdapter.java:211)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
	at org.eclipse.jface.util.DelegatingDropAdapter.drop(DelegatingDropAdapter.java:209)
	at org.eclipse.swt.dnd.DNDListener.handleEvent(DNDListener.java:90)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1282)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1267)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1061)
	at org.eclipse.swt.dnd.DropTarget.drag_data_received(DropTarget.java:371)
	at org.eclipse.swt.dnd.DropTarget.Drag_Data_Received(DropTarget.java:251)
	at org.eclipse.swt.internal.gtk.OS._gtk_drag_get_data(Native Method)
	at org.eclipse.swt.internal.gtk.OS.gtk_drag_get_data(OS.java:6448)
	at org.eclipse.swt.dnd.DropTarget.drag_drop(DropTarget.java:416)
	at org.eclipse.swt.dnd.DropTarget.Drag_Drop(DropTarget.java:258)
	at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
	at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:8168)
	at org.eclipse.swt.widgets.Display.eventProc(Display.java:1238)
	at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
	at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:2229)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3159)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Re: Create ICreateContext [message #649421 is a reply to message #649261] Wed, 19 January 2011 03:20 Go to previous message
Michael Wenz is currently offline Michael Wenz
Messages: 1577
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hauke,

I hope that I understood the issue behind now: it seems that you exspect the
method call to addGraphicalRepresentation to do the adding of the visual
representation to the diagram? But this is not what the method does, it
simply delegates to the feature provider to find a suitable feature that is
capable of adding the stuff to the diagram.

What you would need to in your add feature do instead is create the
graphical representation by yourself (e.g. using the create methods from
PEService and GAService). The method addGraphicalRepresentation is only
meant fo adding sub objects that are handled by their own add feature...

For an example have a look into the TutorialAddEClassFeature.

Michael


"Hauke" wrote in message news:ih43es$2be$1@news.eclipse.org...

I add somthing
PictogramElement vertexPE = addGraphicalRepresentation(context, vertex);
...
//I add this
contShape.setGraphicsAlgorithm(vertexPE.getGraphicsAlgorithm ());

however the NullPointerException happens now after the return.
I write the exception too(I don't thing it is helpful)

java.lang.NullPointerException
at org.eclipse.draw2d.Figure.add(Figure.java:148)
at org.eclipse.draw2d.FreeformLayer.add(FreeformLayer.java:28)
at org.eclipse.draw2d.Figure.add(Figure.java:184)
at
org.eclipse.gef.editparts.AbstractGraphicalEditPart.addChild Visual(AbstractGraphicalEditPart.java:209)
at
org.eclipse.graphiti.ui.internal.parts.ContainerShapeEditPar t.addChildVisual(ContainerShapeEditPart.java:161)
at
org.eclipse.gef.editparts.AbstractEditPart.addChild(Abstract EditPart.java:210)
at
org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(A bstractEditPart.java:771)
at
org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refresh Children(ShapeEditPart.java:626)
at
org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractE ditPart.java:718)
at
org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh( AbstractGraphicalEditPart.java:633)
at
org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refresh (ShapeEditPart.java:546)
at
org.eclipse.graphiti.ui.internal.parts.DiagramEditPart.refre sh(DiagramEditPart.java:181)
at
org.eclipse.graphiti.ui.internal.editor.DiagramEditorInterna l.internalRefreshEditPart(DiagramEditorInternal.java:1203)
at
org.eclipse.graphiti.ui.internal.editor.DiagramEditorInterna l.refresh(DiagramEditorInternal.java:1287)
at
org.eclipse.graphiti.ui.internal.editor.DiagramRefreshJob.ru nInUIThread(DiagramRefreshJob.java:99)
at
org.eclipse.graphiti.ui.internal.editor.DiagramChangeListene r.resourceSetChanged(DiagramChangeListener.java:140)
at
org.eclipse.emf.transaction.impl.TransactionalEditingDomainI mpl$1.run(TransactionalEditingDomainImpl.java:781)
at
org.eclipse.emf.transaction.impl.TransactionalEditingDomainI mpl.runExclusive(TransactionalEditingDomainImpl.java:328)
at
org.eclipse.emf.transaction.impl.TransactionalEditingDomainI mpl.postcommit(TransactionalEditingDomainImpl.java:771)
at
org.eclipse.emf.transaction.impl.TransactionalEditingDomainI mpl.deactivate(TransactionalEditingDomainImpl.java:543)
at
org.eclipse.emf.transaction.impl.TransactionImpl.close(Trans actionImpl.java:712)
at
org.eclipse.emf.transaction.impl.TransactionImpl.commit(Tran sactionImpl.java:474)
at
org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:155)
at
org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:511)
at
org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doE xecute(WorkspaceCommandStackImpl.java:208)
at
org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:165)
at
org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:47)
at
org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:219)
at
org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
at
org.eclipse.graphiti.ui.internal.editor.GFCommandStack.execu te(GFCommandStack.java:108)
at
org.eclipse.gef.dnd.AbstractTransferDropTargetListener.handl eDrop(AbstractTransferDropTargetListener.java:339)
at
org.eclipse.gef.dnd.TemplateTransferDropTargetListener.handl eDrop(TemplateTransferDropTargetListener.java:112)
at
org.eclipse.gef.dnd.AbstractTransferDropTargetListener.drop( AbstractTransferDropTargetListener.java:183)
at
org.eclipse.jface.util.DelegatingDropAdapter$3.run(Delegatin gDropAdapter.java:211)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:17 5)
at
org.eclipse.jface.util.DelegatingDropAdapter.drop(Delegating DropAdapter.java:209)
at org.eclipse.swt.dnd.DNDListener.handleEvent(DNDListener.java :90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1282)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1267)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1 061)
at org.eclipse.swt.dnd.DropTarget.drag_data_received(DropTarget .java:371)
at org.eclipse.swt.dnd.DropTarget.Drag_Data_Received(DropTarget .java:251)
at org.eclipse.swt.internal.gtk.OS._gtk_drag_get_data(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_drag_get_data(OS.java:64 48)
at org.eclipse.swt.dnd.DropTarget.drag_drop(DropTarget.java:416 )
at org.eclipse.swt.dnd.DropTarget.Drag_Drop(DropTarget.java:258 )
at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:81 68)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1238)
at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Na tive Method)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS. java:2229)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3159)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 38)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Previous Topic:Graphiti service release 0.7.1 is available for download
Next Topic:Drag and Drop
Goto Forum:
  


Current Time: Thu Jul 31 19:56:23 EDT 2014

Powered by FUDForum. Page generated in 0.05298 seconds