Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » GMF Diagram without Resource?
GMF Diagram without Resource? [message #514741] Tue, 16 February 2010 09:13 Go to next message
Giovanni De Sossi is currently offline Giovanni De Sossi
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hi,

it's possible to create and open a GMF Diagram without a Resource (e.g. a File), but instead with a runtime model? If so, where can I find some code sample?


Regards,

Giovanni.
Re: GMF Diagram without Resource? [message #514778 is a reply to message #514741] Tue, 16 February 2010 05:54 Go to previous messageGo to next message
Ali Koudri is currently offline Ali Koudri
Messages: 118
Registered: July 2009
Senior Member
Hi,

You have to implement The IStorageEditorInput interface and pass it to
your editor through the setInput() method using cast.

Best regards.


Le 16/02/2010 15:13, giovanni a écrit :
> Hi,
>
> it's possible to create and open a GMF Diagram without a Resource (e.g.
> a File), but instead with a runtime model? If so, where can I find some
> code sample?
>
>
> Regards,
>
> Giovanni.
Re: GMF Diagram without Resource? [message #514784 is a reply to message #514778] Tue, 16 February 2010 10:58 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De Sossi
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hi Ali,

thank you very much, I'll give it a try

Best regards,

Giovanni.
Re: GMF Diagram without Resource? [message #515363 is a reply to message #514778] Thu, 18 February 2010 10:11 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De Sossi
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hi Ali,

have you any idea how can I implement an IStorageEditorInput (better: an IStorage) which reads an in-memory model object?
Especially, I'm confused about the implementation of public InputStream getContents() method: did you know any example I can read?

Thank you

Best regards,

Giovanni.
Re: GMF Diagram without Resource? [message #515904 is a reply to message #514741] Mon, 22 February 2010 03:00 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban Dugueperoux
Messages: 271
Registered: July 2009
Senior Member
Hi Giovanni,

I would like to do the same thing like you.
I have seen this thread
http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg03878.html
where someone create at each GMF editor opening a new temporary diagram
file by overriden setInput() method, without better solution.

Indeed it would be nice to display with a GMF editor a domain model in
memory with a diagram model created on the fly in memory. But it doesn't
seems possible to use EMF Transaction without associated Resource and a
GMF editor needs transaction to read or write on models.

But by using CDO with a in-memory database would it be possible to
resolve this problem? Although with CDO we can't yet edit models with GMF?

Someone have any (other) idea?
Re: GMF Diagram without Resource? [message #515911 is a reply to message #515904] Mon, 22 February 2010 03:41 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De Sossi
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hi Esteban,

I think you can found this tutorial useful to suite your needs: http://www.elver.org/hibernate/gmftutorial/tutorial1.html .

It's about using Teneo Hibernate having a database as editor input:

page.openEditor(new URIEditorInput(StoreController.DATABASE_URI),
MindmapDiagramEditor.ID);


Regards,

Giovanni.
Re: GMF Diagram without Resource? [message #515953 is a reply to message #515363] Mon, 22 February 2010 00:46 Go to previous messageGo to next message
Ali Koudri is currently offline Ali Koudri
Messages: 118
Registered: July 2009
Senior Member
Hi,

sorry for the late answer, here is a sample of what I did:

1. I have implemented the IStorageEditorInput interface representing the
inputs of my editor, which is actually an object (not a file)

public class MyEditorInput implements
IStorageEditorInput {

private MyObject object;

public MyObject getObject() {
return object;
}

public void setObject(MyObject object) {
this.object = object;
}

public MyEditorInput(MyObject object) {
this.object = object;
}

public IStorage getStorage() throws CoreException {
return null;
}
public boolean exists() {
return false;
}

public ImageDescriptor getImageDescriptor() {
return null;
}

public String getName() {
//insure that object have a name property
//or use adapters
return object.getName();
}

public IPersistableElement getPersistable() {
return null;
}

public String getToolTipText() {
return "My Object";
}

public Object getAdapter(Class adapter) {
return null;
}
}

2. Add a property to your editor and modify related methods

public class MyEditor extends DiagramDocumentEditor implements
IGotoMarker {

//input
private MyEditorInput editorInput;

public void setInput(IEditorInput input) {
stopListening();
editorInput = (MyEditorInput) input;
startListening();
}

public IEditorInput getEditorInput() {
return editorInput;
}

public Diagram getDiagram() {
//insure editor input has a diagram property
//or use adapters
return editorInput.getObject().getDiagram();
}

protected void initializeGraphicalViewerContents() {
//insure editor input has a diagram property
//or use adapters
getDiagramGraphicalViewer().setContents(
editorInput.getObject().getDiagram());
initializeContents(getDiagramEditPart());
}
}

Et voila ! It works for me. I hope it will help.
Best regards.

Le 18/02/2010 16:11, Giovanni a écrit :
> Hi Ali,
>
> have you any idea how can I implement an IStorageEditorInput (better: an
> IStorage) which reads an in-memory model object?
> Especially, I'm confused about the implementation of public InputStream
> getContents() method: did you know any example I can read?
>
> Thank you
>
> Best regards,
>
> Giovanni.
Re: GMF Diagram without Resource? [message #515959 is a reply to message #515953] Mon, 22 February 2010 05:59 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De Sossi
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

HI Ali,

thank you very much, I really appreciate your help.


Regards,

Giovanni.
Re: GMF Diagram without Resource? [message #516025 is a reply to message #515959] Mon, 22 February 2010 09:04 Go to previous messageGo to next message
Ali Koudri is currently offline Ali Koudri
Messages: 118
Registered: July 2009
Senior Member
You welcome,

It seems like we are trying to make the same thing with GMF. I am
combining GMF with CNF to make multi-views modeler (see
http://vimeo.com/8928764). If this the case, maybe we can share our
experience. I have solved many of my issues but it remains lot of issues
I did not solved. I have posted several questions and had no answers, so
I spent hours at debugging to solve my problems. Indeed, I had to modify
the regular GMF flow, and a big part of the resulting flow is automated
through modified xpand templates.

Regards,
Ali.

Le 22/02/2010 11:59, Giovanni a écrit :
> HI Ali,
>
> thank you very much, I really appreciate your help.
>
>
> Regards,
>
> Giovanni.
Re: GMF Diagram without Resource? [message #516060 is a reply to message #516025] Mon, 22 February 2010 11:02 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De Sossi
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Ali,

I've seen your video: very good job, very interesting, especially your use of xPand templates, which I don't know.

My needs are simpler than yours; I'm just trying to show in a Model Navigator (CNF based, of course) ONLY my model objects, not annoying Diagram, Shape, Node and so on, which are provided in the GMF-generated Project Explorer. Especially I don't want to display files.
My Model Navigator shows a statical and hierarchical folder structure, initially empty; then, I generate my model on-the-fly, using only standard EMF methods (XYZFactory.eINSTANCE.createXyz(), etc.) invoked by context menu on my Tree. The last action I want to provide is "Open Diagram", which has to take my model as root element and finally open the GMF-generated graphical editor: that's why I pose the initial question of this thread, 'cause I want to avoid to create a project file, until it's strictly necessary.

That said, if you think I can help you in any manner, I'll be happy to collaborate: this forum is a little...er, greedy of answers, so I hope we can change this.

Best regards,

Giovanni.
Re: GMF Diagram without Resource? [message #516077 is a reply to message #516060] Mon, 22 February 2010 12:16 Go to previous messageGo to next message
Ali Koudri is currently offline Ali Koudri
Messages: 118
Registered: July 2009
Senior Member
Thx Giovanni,

In case you still looking forward to open your diagram, here is the
trick (to complete the previous example I gave you):

1. In your plugin.xml:

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=additions ">
<command
commandId="qualified.name.openDiagram"
label="Open Diagram"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="selection">
<count
value="1">
</count>
<iterate>
<adapt
type="qualified.name.to.MyObject">
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="qualified.name.openDiagram"
name="Open Diagram Command">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="qualified.name.commands.OpenDiagramHandler"
commandId="qualified.name.openDiagram">
</handler>
</extension>

2. Implement the Open Diagram Handler

package qualified.name.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
....

public class OpenDiagramHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!(selection instanceof IStructuredSelection)) return null;
if (!(((IStructuredSelection)selection).getFirstElement() instanceof
MyObject)) return null;
MyObject myObject = (MyObject)
((IStructuredSelection)selection).getFirstElement();
IWorkbenchPage page =
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
try {
page.openEditor(new MyEditorInput(myObject), MyDiagramEditor.ID);
} catch (PartInitException e) {
e.printStackTrace();
return null;
}
return null;
}

}

Hope it will help.
Regards,

Ali.

Le 22/02/2010 17:02, Giovanni a écrit :
> Ali,
>
> I've seen your video: very good job, very interesting, especially your
> use of xPand templates, which I don't know.
>
> My needs are simpler than yours; I'm just trying to show in a Model
> Navigator (CNF based, of course) ONLY my model objects, not annoying
> Diagram, Shape, Node and so on, which are provided in the GMF-generated
> Project Explorer. Especially I don't want to display files.
> My Model Navigator shows a statical and hierarchical folder structure,
> initially empty; then, I generate my model on-the-fly, using only
> standard EMF methods (XYZFactory.eINSTANCE.createXyz(), etc.) invoked by
> context menu on my Tree. The last action I want to provide is "Open
> Diagram", which has to take my model as root element and finally open
> the GMF-generated graphical editor: that's why I pose the initial
> question of this thread, 'cause I want to avoid to create a project
> file, until it's strictly necessary.
>
> That said, if you think I can help you in any manner, I'll be happy to
> collaborate: this forum is a little...er, greedy of answers, so I hope
> we can change this.
>
> Best regards,
>
> Giovanni.
Re: GMF Diagram without Resource? [message #516209 is a reply to message #516077] Tue, 23 February 2010 03:43 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De Sossi
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Thx Ali,

now your example is complete; I'll try it, and I'll give a feedback to you and to the newsgroup.

Regards,

Giovanni.
Re: GMF Diagram without Resource? [message #533861 is a reply to message #516209] Mon, 17 May 2010 06:17 Go to previous message
Giovanni De Sossi is currently offline Giovanni De Sossi
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hi,

I'm trying to implement the preceding example, but
when I execute the code, I get the following error: Could not open the editor: Editor could not be initialized.

This is the stackTrace:

!ENTRY org.eclipse.ui 4 0 2010-05-17 12:13:31.548
!MESSAGE Unable to create editor ID qbxtool.diagram.part.QbxCustomDiagramEditorID: Editor could not be initialized.
!STACK 0
java.lang.NullPointerException
at org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.Di agramDocumentEditor$1.run(DiagramDocumentEditor.java:131)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread( ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.ja va:372)
at org.eclipse.jface.window.ApplicationWindow$1.run(Application Window.java:759)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWi ndow.java:756)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow. java:2579)
at org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.Di agramDocumentEditor.init(DiagramDocumentEditor.java:140)
at org.eclipse.ui.internal.EditorManager.createSite(EditorManag er.java:798)
at org.eclipse.ui.internal.EditorReference.createPartHelper(Edi torReference.java:644)
at org.eclipse.ui.internal.EditorReference.createPart(EditorRef erence.java:462)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(Workb enchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:31 3)
at org.eclipse.ui.internal.presentations.PresentablePart.setVis ible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFo lder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrd er.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresen tation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelecti on(PartStack.java:1256)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.jav a:1209)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:16 08)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:499)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:103 )
at org.eclipse.ui.internal.PartStack.add(PartStack.java:485)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:112 )
at org.eclipse.ui.internal.EditorSashContainer.addEditor(Editor SashContainer.java:63)
at org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorA reaHelper.java:225)
at org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAre aHelper.java:213)
at org.eclipse.ui.internal.EditorManager.createEditorTab(Editor Manager.java:778)
at org.eclipse.ui.internal.EditorManager.openEditorFromDescript or(EditorManager.java:677)
at org.eclipse.ui.internal.EditorManager.openEditor(EditorManag er.java:638)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched( WorkbenchPage.java:2854)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(Workben chPage.java:2762)
at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPag e.java:2754)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.j ava:2705)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2701)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2685)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2668)
at it.theorematica.qbx.navigator.handlers.OpenDiagramHandler.ex ecute(OpenDiagramHandler.java:95)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(Handle rProxy.java:294)
at org.eclipse.core.commands.Command.executeWithChecks(Command. java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithCh ecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeComma nd(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.execute Command(SlaveHandlerService.java:241)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.execute Command(SlaveHandlerService.java:241)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSel ection(CommandContributionItem.java:770)
at org.eclipse.ui.menus.CommandContributionItem.access$10(Comma ndContributionItem.java:756)
at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(C ommandContributionItem.java:746)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3910)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3503)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 21)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at qbxtool.base.Application.start(Application.java:25)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:194)
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:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
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.equinox.launcher.Main.invokeFramework(Main.java: 559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)



When I write the code from "MyEditor" class (method
protected void initializeGraphicalViewerContents() {
//insure editor input has a diagram property
//or use adapters
getDiagramGraphicalViewer().setContents(
editorInput.getObject().getDiagram());
initializeContents(getDiagramEditPart());
}

)
Eclipse complains: The method initializeContents(EditPart) from the type DiagramEditor is not visible.

Right, it is private; so, how can I initialize my custom editor?

Thanks, regards
Previous Topic:Problem with Outline view
Next Topic:Mixing between packages
Goto Forum:
  


Current Time: Wed May 22 19:53:04 EDT 2013

Powered by FUDForum. Page generated in 0.02765 seconds