Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Best practice for "invisible" figures with an EditPart?
icon3.gif  Best practice for "invisible" figures with an EditPart? [message #1010887] Mon, 18 February 2013 12:20 Go to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 59
Registered: October 2011
Location: Berlin, Germany
Member

I'm wondering whether there is such a thing as a best practice for handling cases where you must have an EditPart (e.g., to implement a needed Adapter) without wanting a Figure to actually be displayed.

In my case, I have a graph model where elements can be annotated with "meta" - non-semantic - information, e.g., at which coordinates a node should be placed. I.e., nodes don't "have" constraints which I can set/get via set/getConstraints() or a similar method. (I believe this to be a best practice in itself, as visual information shouldn't be mixed up with domain information? I'm using a mixed case.)

I need EditParts for this kind of annotation, because I need to notify their parent to refresh() whenever annotations' values are changed in a Command (e.g., node.getAnnotation("X_COORD").setValue(100)). The annotations' EditPart thus has an Adapter which calls getParent().refresh() in notifyChanged().

However, I obviously don't need a Figure for the annotations' EditPart, as this info shouldn't be displayed.

At the moment, I have the EditPart's createFigure() simply return new Figure().
Is there a better way to do this? I felt better if I wasn't creating such an awful amount of Figure objects Wink.

Thanks!
Re: Best practice for "invisible" figures with an EditPart? [message #1011556 is a reply to message #1010887] Tue, 19 February 2013 19:40 Go to previous messageGo to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 59
Registered: October 2011
Location: Berlin, Germany
Member

To specify further, the EditPart in question extends AbstractGraphicalEditPart, which AFAIK needs a non-null return from its createFigure() method. I've tried to have my EditPart extend AbstractEditPart instead, but I get a ClassCastException error (cf. error stack below), possibly because the EditPart extending AbstractEditPart is a child of an extension of AbstractGraphicalEditPart(?)...

Any suggestions are *much* appreciated Smile. Thanks!

java.lang.ClassCastException: my.editor.editparts.AnnotationEditPart cannot be cast to org.eclipse.gef.GraphicalEditPart
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addChildVisual(AbstractGraphicalEditPart.java:208)
at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:211)
at org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(AbstractEditPart.java:781)
at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:726)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:644)
at org.eclipse.gef.editparts.AbstractEditPart.addNotify(AbstractEditPart.java:253)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addNotify(AbstractGraphicalEditPart.java:223)
at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:212)
at org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(AbstractEditPart.java:781)
at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:726)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:644)
at org.eclipse.gef.editparts.AbstractEditPart.addNotify(AbstractEditPart.java:253)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addNotify(AbstractGraphicalEditPart.java:223)
at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:212)
at org.eclipse.gef.editparts.SimpleRootEditPart.setContents(SimpleRootEditPart.java:105)
at org.eclipse.gef.ui.parts.AbstractEditPartViewer.setContents(AbstractEditPartViewer.java:617)
at org.eclipse.gef.ui.parts.AbstractEditPartViewer.setContents(AbstractEditPartViewer.java:626)
at my.editor.Editor.initializeGraphicalViewer(Editor.java:55)
at org.eclipse.gef.ui.parts.GraphicalEditor.createGraphicalViewer(GraphicalEditor.java:158)
at org.eclipse.gef.ui.parts.GraphicalEditor.createPartControl(GraphicalEditor.java:171)
at org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette.createPartControl(GraphicalEditorWithFlyoutPalette.java:75)
at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:670)
at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1597)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:493)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:103)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:479)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:112)
at org.eclipse.ui.internal.EditorSashContainer.addEditor(EditorSashContainer.java:63)
at org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorAreaHelper.java:225)
at org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAreaHelper.java:213)
at org.eclipse.ui.internal.EditorManager.createEditorTab(EditorManager.java:808)
at org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager.java:707)
at org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:666)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2942)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2850)
at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2842)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2793)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2789)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2773)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2764)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:651)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:610)
at org.eclipse.ui.actions.OpenFileAction.openFile(OpenFileAction.java:99)
at org.eclipse.ui.actions.OpenSystemEditorAction.run(OpenSystemEditorAction.java:99)
at org.eclipse.ui.actions.RetargetAction.run(RetargetAction.java:221)
at org.eclipse.ui.navigator.CommonNavigatorManager$3.open(CommonNavigatorManager.java:185)
at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(OpenAndLinkWithEditorHelper.java:48)
at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:866)
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.viewers.StructuredViewer.fireOpen(StructuredViewer.java:864)
at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1152)
at org.eclipse.ui.navigator.CommonViewer.handleOpen(CommonViewer.java:462)
at org.eclipse.jface.viewers.StructuredViewer$6.handleOpen(StructuredViewer.java:1256)
at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:275)
at org.eclipse.jface.util.OpenStrategy.access$2(OpenStrategy.java:269)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:309)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at my.application.start(Saltomic.java:104)
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:344)
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:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Re: Best practice for "invisible" figures with an EditPart? [message #1011797 is a reply to message #1011556] Wed, 20 February 2013 09:19 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi, I don't understand why you need EditParts for that meta information at all.

The node's EditPart should listen to node meta information changes and then refresh its (or parents) visual representation.
Re: Best practice for "invisible" figures with an EditPart? [message #1011945 is a reply to message #1011797] Wed, 20 February 2013 15:07 Go to previous messageGo to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 59
Registered: October 2011
Location: Berlin, Germany
Member

Hi Jan, and thanks for your answer.

My problem is that no visual information may be stored in the underlying EMF model, but I have (?) to set Constraints on the parent EditPart, don't I? So my workaround is to persist this information in the annotation.

However, if you let me know how to listen to the change of constraints, I'll be more than happy to listen Smile.
Re: Best practice for "invisible" figures with an EditPart? [message #1012372 is a reply to message #1011945] Thu, 21 February 2013 12:39 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, I've never used EMF before and I always have the visual representation tied to the domain model.

What about creating a visual representation model using the EMF as well? It would contain the constraints and a reference to the domain model. Some kind of wrapper.
This model would be model for EditParts.
Previous Topic:Create Pie chart Figure
Next Topic:BendpointEditPolicy - incorrect location after zooming
Goto Forum:
  


Current Time: Fri Dec 19 02:17:41 GMT 2014

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

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