Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Saving a Diagram as a GIF
Saving a Diagram as a GIF [message #104180] Thu, 15 February 2007 10:23 Go to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Hello everybody,

I'm trying to save a diagram that I have created as a gif, but the code
I'm using is only producing exceptions ... Has anybody an Idea what
might be wrong? (when I break after loading the resource, to me the
resource doesn't look like it's been loaded correctly. The object loaded
is a DiagramImpl, which is what I expected, but the content seams to be
empty. the file stored is ok, since I can load it to the editor. I am
also wondering, if I somehow have to tell the resourceset, that about
the model file, since the diagram file references to the model...)

private void compile(IFile input) {
IFolder htmlDir = this.getProject().getFolder("html");
String outputFileName =
input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();


IFile output = htmlDir.getFile(outputFileName);

ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.getResource(
URI.createURI(input.getRawLocationURI().toString()), true);

if(resource instanceof XMIResourceImpl){
Object object = resource.getContents().get(0);
CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
try {
copyToImageUtil.copyToImage((Diagram)
object, output.getFullPath(), ImageFileFormat.GIF, null,
PreferencesHint.USE_DEFAULTS);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Re: Saving a Diagram as a GIF [message #104333 is a reply to message #104180] Thu, 15 February 2007 15:18 Go to previous messageGo to next message
Mohammed Mostafa is currently offline Mohammed MostafaFriend
Messages: 143
Registered: July 2009
Senior Member
If your diagram is canonical there is a possibility that all shapes on
it are transient and had not been persisted (which is OK).
You can check if this is the case by opening your diagram file in a text
editor and check if it had children inside it
If the diagram is canonical it will be populated when the editor opens

What exceptions do you get ?
another important thing is to check the Element feature on the diagram
if it is null or proxy , then this explains why your diagram shows up empty


Martin Tauber wrote:
> Hello everybody,
>
> I'm trying to save a diagram that I have created as a gif, but the code
> I'm using is only producing exceptions ... Has anybody an Idea what
> might be wrong? (when I break after loading the resource, to me the
> resource doesn't look like it's been loaded correctly. The object loaded
> is a DiagramImpl, which is what I expected, but the content seams to be
> empty. the file stored is ok, since I can load it to the editor. I am
> also wondering, if I somehow have to tell the resourceset, that about
> the model file, since the diagram file references to the model...)
>
> private void compile(IFile input) {
> IFolder htmlDir = this.getProject().getFolder("html");
> String outputFileName =
> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>
>
> IFile output = htmlDir.getFile(outputFileName);
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet.getResource(
> URI.createURI(input.getRawLocationURI().toString()), true);
>
> if(resource instanceof XMIResourceImpl){
> Object object = resource.getContents().get(0);
> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
> try {
> copyToImageUtil.copyToImage((Diagram)
> object, output.getFullPath(), ImageFileFormat.GIF, null,
> PreferencesHint.USE_DEFAULTS);
> } catch (CoreException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> }
Re: Saving a Diagram as a GIF [message #104573 is a reply to message #104333] Fri, 16 February 2007 10:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

I think I'm getting a bit closer. I debugged the code and found out that
the CoptyToImageUtil.copyToImage method tries to create a new Shell().
This fails.

Hm - I am trying to write a builder that converts diagrams to images as
soon as they are saved. It is the default Nature/Builder configuration
of eclipse that I am making use of here, so the builder is running in a
seperate thread (And I guess not the thread which has all the gui
information ...) So this might be the cause of the exception ...

But ... why the hell does the convertion need SWT? And how can I avoid it?

Regards
Martin

P.S. Sounds interesting the canonical stuff, can you please give some
more information about why I would need it? Has it something to do with
the lazy loading / proxies in EMF?

Thanks

Mohammed Mostafa schrieb:
> If your diagram is canonical there is a possibility that all shapes on
> it are transient and had not been persisted (which is OK).
> You can check if this is the case by opening your diagram file in a text
> editor and check if it had children inside it
> If the diagram is canonical it will be populated when the editor opens
>
> What exceptions do you get ?
> another important thing is to check the Element feature on the diagram
> if it is null or proxy , then this explains why your diagram shows up empty
>
>
> Martin Tauber wrote:
>> Hello everybody,
>>
>> I'm trying to save a diagram that I have created as a gif, but the
>> code I'm using is only producing exceptions ... Has anybody an Idea
>> what might be wrong? (when I break after loading the resource, to me
>> the resource doesn't look like it's been loaded correctly. The object
>> loaded is a DiagramImpl, which is what I expected, but the content
>> seams to be empty. the file stored is ok, since I can load it to the
>> editor. I am also wondering, if I somehow have to tell the
>> resourceset, that about the model file, since the diagram file
>> references to the model...)
>>
>> private void compile(IFile input) {
>> IFolder htmlDir = this.getProject().getFolder("html");
>> String outputFileName =
>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>> IFile output = htmlDir.getFile(outputFileName);
>> ResourceSet resourceSet = new ResourceSetImpl();
>> Resource resource = resourceSet.getResource(
>> URI.createURI(input.getRawLocationURI().toString()), true);
>>
>> if(resource instanceof XMIResourceImpl){
>> Object object = resource.getContents().get(0);
>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>> try {
>> copyToImageUtil.copyToImage((Diagram)
>> object, output.getFullPath(), ImageFileFormat.GIF,
>> null, PreferencesHint.USE_DEFAULTS);
>> } catch (CoreException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>> }
Re: Saving a Diagram as a GIF [message #104627 is a reply to message #104573] Fri, 16 February 2007 15:10 Go to previous messageGo to next message
Mohammed Mostafa is currently offline Mohammed MostafaFriend
Messages: 143
Registered: July 2009
Senior Member
Hi ;
To save the diagram as Image, the diagram had to be opened, opened here
do not mean just open the resource we need to render the diagram it does
not matter if it is rendered in memory or i the actual editor but it had
to be rendered, other wise the transient canonical views will not show
up and layout will not be correct




Martin Tauber wrote:
> I think I'm getting a bit closer. I debugged the code and found out that
> the CoptyToImageUtil.copyToImage method tries to create a new Shell().
> This fails.
>
> Hm - I am trying to write a builder that converts diagrams to images as
> soon as they are saved. It is the default Nature/Builder configuration
> of eclipse that I am making use of here, so the builder is running in a
> seperate thread (And I guess not the thread which has all the gui
> information ...) So this might be the cause of the exception ...
>
> But ... why the hell does the convertion need SWT? And how can I avoid it?
>
> Regards
> Martin
>
> P.S. Sounds interesting the canonical stuff, can you please give some
> more information about why I would need it? Has it something to do with
> the lazy loading / proxies in EMF?
>
> Thanks
>
> Mohammed Mostafa schrieb:
>> If your diagram is canonical there is a possibility that all shapes on
>> it are transient and had not been persisted (which is OK).
>> You can check if this is the case by opening your diagram file in a
>> text editor and check if it had children inside it
>> If the diagram is canonical it will be populated when the editor opens
>>
>> What exceptions do you get ?
>> another important thing is to check the Element feature on the diagram
>> if it is null or proxy , then this explains why your diagram shows up
>> empty
>>
>>
>> Martin Tauber wrote:
>>> Hello everybody,
>>>
>>> I'm trying to save a diagram that I have created as a gif, but the
>>> code I'm using is only producing exceptions ... Has anybody an Idea
>>> what might be wrong? (when I break after loading the resource, to me
>>> the resource doesn't look like it's been loaded correctly. The object
>>> loaded is a DiagramImpl, which is what I expected, but the content
>>> seams to be empty. the file stored is ok, since I can load it to the
>>> editor. I am also wondering, if I somehow have to tell the
>>> resourceset, that about the model file, since the diagram file
>>> references to the model...)
>>>
>>> private void compile(IFile input) {
>>> IFolder htmlDir = this.getProject().getFolder("html");
>>> String outputFileName =
>>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>>> IFile output = htmlDir.getFile(outputFileName);
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>> Resource resource = resourceSet.getResource(
>>> URI.createURI(input.getRawLocationURI().toString()), true);
>>>
>>> if(resource instanceof XMIResourceImpl){
>>> Object object = resource.getContents().get(0);
>>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>>> try {
>>> copyToImageUtil.copyToImage((Diagram)
>>> object, output.getFullPath(), ImageFileFormat.GIF,
>>> null, PreferencesHint.USE_DEFAULTS);
>>> } catch (CoreException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> }
>>> }
Re: Saving a Diagram as a GIF [message #104669 is a reply to message #104627] Fri, 16 February 2007 15:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Does that mean I can't achieve what I was trying to achieve?

Regards
Martin

Mohammed Mostafa schrieb:
> Hi ;
> To save the diagram as Image, the diagram had to be opened, opened
> here do not mean just open the resource we need to render the diagram it
> does not matter if it is rendered in memory or i the actual editor but
> it had to be rendered, other wise the transient canonical views will not
> show up and layout will not be correct
>
>
>
>
> Martin Tauber wrote:
>> I think I'm getting a bit closer. I debugged the code and found out
>> that the CoptyToImageUtil.copyToImage method tries to create a new
>> Shell(). This fails.
>>
>> Hm - I am trying to write a builder that converts diagrams to images
>> as soon as they are saved. It is the default Nature/Builder
>> configuration of eclipse that I am making use of here, so the builder
>> is running in a seperate thread (And I guess not the thread which has
>> all the gui information ...) So this might be the cause of the
>> exception ...
>>
>> But ... why the hell does the convertion need SWT? And how can I avoid
>> it?
>>
>> Regards
>> Martin
>>
>> P.S. Sounds interesting the canonical stuff, can you please give some
>> more information about why I would need it? Has it something to do
>> with the lazy loading / proxies in EMF?
>>
>> Thanks
>>
>> Mohammed Mostafa schrieb:
>>> If your diagram is canonical there is a possibility that all shapes
>>> on it are transient and had not been persisted (which is OK).
>>> You can check if this is the case by opening your diagram file in a
>>> text editor and check if it had children inside it
>>> If the diagram is canonical it will be populated when the editor opens
>>>
>>> What exceptions do you get ?
>>> another important thing is to check the Element feature on the
>>> diagram if it is null or proxy , then this explains why your diagram
>>> shows up empty
>>>
>>>
>>> Martin Tauber wrote:
>>>> Hello everybody,
>>>>
>>>> I'm trying to save a diagram that I have created as a gif, but the
>>>> code I'm using is only producing exceptions ... Has anybody an Idea
>>>> what might be wrong? (when I break after loading the resource, to me
>>>> the resource doesn't look like it's been loaded correctly. The
>>>> object loaded is a DiagramImpl, which is what I expected, but the
>>>> content seams to be empty. the file stored is ok, since I can load
>>>> it to the editor. I am also wondering, if I somehow have to tell the
>>>> resourceset, that about the model file, since the diagram file
>>>> references to the model...)
>>>>
>>>> private void compile(IFile input) {
>>>> IFolder htmlDir = this.getProject().getFolder("html");
>>>> String outputFileName =
>>>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>>>> IFile output = htmlDir.getFile(outputFileName);
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>> Resource resource = resourceSet.getResource(
>>>> URI.createURI(input.getRawLocationURI().toString()), true);
>>>>
>>>> if(resource instanceof XMIResourceImpl){
>>>> Object object = resource.getContents().get(0);
>>>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>>>> try {
>>>> copyToImageUtil.copyToImage((Diagram)
>>>> object, output.getFullPath(), ImageFileFormat.GIF,
>>>> null, PreferencesHint.USE_DEFAULTS);
>>>> } catch (CoreException e) {
>>>> // TODO Auto-generated catch block
>>>> e.printStackTrace();
>>>> }
>>>> }
>>>> }
Re: Saving a Diagram as a GIF [message #104707 is a reply to message #104669] Fri, 16 February 2007 21:06 Go to previous messageGo to next message
Mohammed Mostafa is currently offline Mohammed MostafaFriend
Messages: 143
Registered: July 2009
Senior Member
What I was trying to say is that GMF requires SWT, EMF and GEF

I'm not sure what is the problem in your case may be you need to change
the place where you call CoptyToImageUtil

if you can write a junit to reproduce this problem, then we can look at
it and see if there is possible solution


Martin Tauber wrote:
> Does that mean I can't achieve what I was trying to achieve?
>
> Regards
> Martin
>
> Mohammed Mostafa schrieb:
>> Hi ;
>> To save the diagram as Image, the diagram had to be opened, opened
>> here do not mean just open the resource we need to render the diagram
>> it does not matter if it is rendered in memory or i the actual editor
>> but it had to be rendered, other wise the transient canonical views
>> will not show up and layout will not be correct
>>
>>
>>
>>
>> Martin Tauber wrote:
>>> I think I'm getting a bit closer. I debugged the code and found out
>>> that the CoptyToImageUtil.copyToImage method tries to create a new
>>> Shell(). This fails.
>>>
>>> Hm - I am trying to write a builder that converts diagrams to images
>>> as soon as they are saved. It is the default Nature/Builder
>>> configuration of eclipse that I am making use of here, so the builder
>>> is running in a seperate thread (And I guess not the thread which has
>>> all the gui information ...) So this might be the cause of the
>>> exception ...
>>>
>>> But ... why the hell does the convertion need SWT? And how can I
>>> avoid it?
>>>
>>> Regards
>>> Martin
>>>
>>> P.S. Sounds interesting the canonical stuff, can you please give some
>>> more information about why I would need it? Has it something to do
>>> with the lazy loading / proxies in EMF?
>>>
>>> Thanks
>>>
>>> Mohammed Mostafa schrieb:
>>>> If your diagram is canonical there is a possibility that all shapes
>>>> on it are transient and had not been persisted (which is OK).
>>>> You can check if this is the case by opening your diagram file in a
>>>> text editor and check if it had children inside it
>>>> If the diagram is canonical it will be populated when the editor opens
>>>>
>>>> What exceptions do you get ?
>>>> another important thing is to check the Element feature on the
>>>> diagram if it is null or proxy , then this explains why your diagram
>>>> shows up empty
>>>>
>>>>
>>>> Martin Tauber wrote:
>>>>> Hello everybody,
>>>>>
>>>>> I'm trying to save a diagram that I have created as a gif, but the
>>>>> code I'm using is only producing exceptions ... Has anybody an Idea
>>>>> what might be wrong? (when I break after loading the resource, to
>>>>> me the resource doesn't look like it's been loaded correctly. The
>>>>> object loaded is a DiagramImpl, which is what I expected, but the
>>>>> content seams to be empty. the file stored is ok, since I can load
>>>>> it to the editor. I am also wondering, if I somehow have to tell
>>>>> the resourceset, that about the model file, since the diagram file
>>>>> references to the model...)
>>>>>
>>>>> private void compile(IFile input) {
>>>>> IFolder htmlDir = this.getProject().getFolder("html");
>>>>> String outputFileName =
>>>>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>>>>> IFile output = htmlDir.getFile(outputFileName);
>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>> Resource resource = resourceSet.getResource(
>>>>> URI.createURI(input.getRawLocationURI().toString()), true);
>>>>>
>>>>> if(resource instanceof XMIResourceImpl){
>>>>> Object object = resource.getContents().get(0);
>>>>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>>>>> try {
>>>>> copyToImageUtil.copyToImage((Diagram)
>>>>> object, output.getFullPath(), ImageFileFormat.GIF,
>>>>> null, PreferencesHint.USE_DEFAULTS);
>>>>> } catch (CoreException e) {
>>>>> // TODO Auto-generated catch block
>>>>> e.printStackTrace();
>>>>> }
>>>>> }
>>>>> }
Re: Saving a Diagram as a GIF [message #104781 is a reply to message #104707] Sat, 17 February 2007 09:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Hi Mohammed,

sorry I'm not familiar with junit, but I'll try to explain, why I think
it doesn't work. As I see it, GMF creates an image from the diagram
model, by just doing the same as if it would render the image to the
screen. My guess it that at some point the graphic context is changed so
that the rendering is not done to the screen, but to some buffer which
is then converted to the appropriate format and then written to disk.

ok, and here comes the problem. To render the diagram GMF goes nearly
the same route through the code as when rendering to the screen. Which
means that for rendering to an image file, it needs all the SWT suff, it
would also need to render it to the screen.

Now here comes my problem. I'm not trying to render the image in the
main thread of the application and I think this causes the trouble. I'm
trying to render in a serperate builder thread. As it seams some of the
SWT stuff can only be done from the main thread and this causes
copyToImage to fail.

Remember copyToImage needs a shell as a parameter. I'm trying to invoke
the copyToImage in a background thread. There just is no shell!

So I think, how copyToImage is designed today, it is to closly bound to
SWT and as a result, I can't achieve rendering a diagram to a image in a
background job.

Hope this informs
Martin

Mohammed Mostafa schrieb:
>
> What I was trying to say is that GMF requires SWT, EMF and GEF
>
> I'm not sure what is the problem in your case may be you need to change
> the place where you call CoptyToImageUtil
>
> if you can write a junit to reproduce this problem, then we can look at
> it and see if there is possible solution
>
>
> Martin Tauber wrote:
>> Does that mean I can't achieve what I was trying to achieve?
>>
>> Regards
>> Martin
>>
>> Mohammed Mostafa schrieb:
>>> Hi ;
>>> To save the diagram as Image, the diagram had to be opened,
>>> opened here do not mean just open the resource we need to render the
>>> diagram it does not matter if it is rendered in memory or i the
>>> actual editor but it had to be rendered, other wise the transient
>>> canonical views will not show up and layout will not be correct
>>>
>>>
>>>
>>>
>>> Martin Tauber wrote:
>>>> I think I'm getting a bit closer. I debugged the code and found out
>>>> that the CoptyToImageUtil.copyToImage method tries to create a new
>>>> Shell(). This fails.
>>>>
>>>> Hm - I am trying to write a builder that converts diagrams to images
>>>> as soon as they are saved. It is the default Nature/Builder
>>>> configuration of eclipse that I am making use of here, so the
>>>> builder is running in a seperate thread (And I guess not the thread
>>>> which has all the gui information ...) So this might be the cause of
>>>> the exception ...
>>>>
>>>> But ... why the hell does the convertion need SWT? And how can I
>>>> avoid it?
>>>>
>>>> Regards
>>>> Martin
>>>>
>>>> P.S. Sounds interesting the canonical stuff, can you please give
>>>> some more information about why I would need it? Has it something to
>>>> do with the lazy loading / proxies in EMF?
>>>>
>>>> Thanks
>>>>
>>>> Mohammed Mostafa schrieb:
>>>>> If your diagram is canonical there is a possibility that all shapes
>>>>> on it are transient and had not been persisted (which is OK).
>>>>> You can check if this is the case by opening your diagram file in a
>>>>> text editor and check if it had children inside it
>>>>> If the diagram is canonical it will be populated when the editor opens
>>>>>
>>>>> What exceptions do you get ?
>>>>> another important thing is to check the Element feature on the
>>>>> diagram if it is null or proxy , then this explains why your
>>>>> diagram shows up empty
>>>>>
>>>>>
>>>>> Martin Tauber wrote:
>>>>>> Hello everybody,
>>>>>>
>>>>>> I'm trying to save a diagram that I have created as a gif, but the
>>>>>> code I'm using is only producing exceptions ... Has anybody an
>>>>>> Idea what might be wrong? (when I break after loading the
>>>>>> resource, to me the resource doesn't look like it's been loaded
>>>>>> correctly. The object loaded is a DiagramImpl, which is what I
>>>>>> expected, but the content seams to be empty. the file stored is
>>>>>> ok, since I can load it to the editor. I am also wondering, if I
>>>>>> somehow have to tell the resourceset, that about the model file,
>>>>>> since the diagram file references to the model...)
>>>>>>
>>>>>> private void compile(IFile input) {
>>>>>> IFolder htmlDir = this.getProject().getFolder("html");
>>>>>> String outputFileName =
>>>>>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>>>>>> IFile output = htmlDir.getFile(outputFileName);
>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>> Resource resource = resourceSet.getResource(
>>>>>> URI.createURI(input.getRawLocationURI().toString()), true);
>>>>>>
>>>>>> if(resource instanceof XMIResourceImpl){
>>>>>> Object object = resource.getContents().get(0);
>>>>>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>>>>>> try {
>>>>>> copyToImageUtil.copyToImage((Diagram)
>>>>>> object, output.getFullPath(), ImageFileFormat.GIF,
>>>>>> null, PreferencesHint.USE_DEFAULTS);
>>>>>> } catch (CoreException e) {
>>>>>> // TODO Auto-generated catch block
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> }
>>>>>> }
Re: Saving a Diagram as a GIF [message #105826 is a reply to message #104707] Wed, 21 February 2007 13:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Is something unclear about my description?

Regards
Martin

Mohammed Mostafa schrieb:
>
> What I was trying to say is that GMF requires SWT, EMF and GEF
>
> I'm not sure what is the problem in your case may be you need to change
> the place where you call CoptyToImageUtil
>
> if you can write a junit to reproduce this problem, then we can look at
> it and see if there is possible solution
>
>
> Martin Tauber wrote:
>> Does that mean I can't achieve what I was trying to achieve?
>>
>> Regards
>> Martin
>>
>> Mohammed Mostafa schrieb:
>>> Hi ;
>>> To save the diagram as Image, the diagram had to be opened,
>>> opened here do not mean just open the resource we need to render the
>>> diagram it does not matter if it is rendered in memory or i the
>>> actual editor but it had to be rendered, other wise the transient
>>> canonical views will not show up and layout will not be correct
>>>
>>>
>>>
>>>
>>> Martin Tauber wrote:
>>>> I think I'm getting a bit closer. I debugged the code and found out
>>>> that the CoptyToImageUtil.copyToImage method tries to create a new
>>>> Shell(). This fails.
>>>>
>>>> Hm - I am trying to write a builder that converts diagrams to images
>>>> as soon as they are saved. It is the default Nature/Builder
>>>> configuration of eclipse that I am making use of here, so the
>>>> builder is running in a seperate thread (And I guess not the thread
>>>> which has all the gui information ...) So this might be the cause of
>>>> the exception ...
>>>>
>>>> But ... why the hell does the convertion need SWT? And how can I
>>>> avoid it?
>>>>
>>>> Regards
>>>> Martin
>>>>
>>>> P.S. Sounds interesting the canonical stuff, can you please give
>>>> some more information about why I would need it? Has it something to
>>>> do with the lazy loading / proxies in EMF?
>>>>
>>>> Thanks
>>>>
>>>> Mohammed Mostafa schrieb:
>>>>> If your diagram is canonical there is a possibility that all shapes
>>>>> on it are transient and had not been persisted (which is OK).
>>>>> You can check if this is the case by opening your diagram file in a
>>>>> text editor and check if it had children inside it
>>>>> If the diagram is canonical it will be populated when the editor opens
>>>>>
>>>>> What exceptions do you get ?
>>>>> another important thing is to check the Element feature on the
>>>>> diagram if it is null or proxy , then this explains why your
>>>>> diagram shows up empty
>>>>>
>>>>>
>>>>> Martin Tauber wrote:
>>>>>> Hello everybody,
>>>>>>
>>>>>> I'm trying to save a diagram that I have created as a gif, but the
>>>>>> code I'm using is only producing exceptions ... Has anybody an
>>>>>> Idea what might be wrong? (when I break after loading the
>>>>>> resource, to me the resource doesn't look like it's been loaded
>>>>>> correctly. The object loaded is a DiagramImpl, which is what I
>>>>>> expected, but the content seams to be empty. the file stored is
>>>>>> ok, since I can load it to the editor. I am also wondering, if I
>>>>>> somehow have to tell the resourceset, that about the model file,
>>>>>> since the diagram file references to the model...)
>>>>>>
>>>>>> private void compile(IFile input) {
>>>>>> IFolder htmlDir = this.getProject().getFolder("html");
>>>>>> String outputFileName =
>>>>>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>>>>>> IFile output = htmlDir.getFile(outputFileName);
>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>> Resource resource = resourceSet.getResource(
>>>>>> URI.createURI(input.getRawLocationURI().toString()), true);
>>>>>>
>>>>>> if(resource instanceof XMIResourceImpl){
>>>>>> Object object = resource.getContents().get(0);
>>>>>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>>>>>> try {
>>>>>> copyToImageUtil.copyToImage((Diagram)
>>>>>> object, output.getFullPath(), ImageFileFormat.GIF,
>>>>>> null, PreferencesHint.USE_DEFAULTS);
>>>>>> } catch (CoreException e) {
>>>>>> // TODO Auto-generated catch block
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> }
>>>>>> }
Re: Saving a Diagram as a GIF [message #105923 is a reply to message #105826] Wed, 21 February 2007 15:37 Go to previous messageGo to next message
Mohammed Mostafa is currently offline Mohammed MostafaFriend
Messages: 143
Registered: July 2009
Senior Member
No; what you said is clear enough

when it fails to create the shell do you get an
ERROR_THREAD_INVALID_ACCESS exception ?
if not what exception do you get

id you can send me a sample code to reproduce it this will help, if not
that is OK, i think i know what is going on


Martin Tauber wrote:
> Is something unclear about my description?
>
> Regards
> Martin
>
> Mohammed Mostafa schrieb:
>>
>> What I was trying to say is that GMF requires SWT, EMF and GEF
>>
>> I'm not sure what is the problem in your case may be you need to
>> change the place where you call CoptyToImageUtil
>>
>> if you can write a junit to reproduce this problem, then we can look
>> at it and see if there is possible solution
>>
>>
>> Martin Tauber wrote:
>>> Does that mean I can't achieve what I was trying to achieve?
>>>
>>> Regards
>>> Martin
>>>
>>> Mohammed Mostafa schrieb:
>>>> Hi ;
>>>> To save the diagram as Image, the diagram had to be opened,
>>>> opened here do not mean just open the resource we need to render the
>>>> diagram it does not matter if it is rendered in memory or i the
>>>> actual editor but it had to be rendered, other wise the transient
>>>> canonical views will not show up and layout will not be correct
>>>>
>>>>
>>>>
>>>>
>>>> Martin Tauber wrote:
>>>>> I think I'm getting a bit closer. I debugged the code and found out
>>>>> that the CoptyToImageUtil.copyToImage method tries to create a new
>>>>> Shell(). This fails.
>>>>>
>>>>> Hm - I am trying to write a builder that converts diagrams to
>>>>> images as soon as they are saved. It is the default Nature/Builder
>>>>> configuration of eclipse that I am making use of here, so the
>>>>> builder is running in a seperate thread (And I guess not the thread
>>>>> which has all the gui information ...) So this might be the cause
>>>>> of the exception ...
>>>>>
>>>>> But ... why the hell does the convertion need SWT? And how can I
>>>>> avoid it?
>>>>>
>>>>> Regards
>>>>> Martin
>>>>>
>>>>> P.S. Sounds interesting the canonical stuff, can you please give
>>>>> some more information about why I would need it? Has it something
>>>>> to do with the lazy loading / proxies in EMF?
>>>>>
>>>>> Thanks
>>>>>
>>>>> Mohammed Mostafa schrieb:
>>>>>> If your diagram is canonical there is a possibility that all
>>>>>> shapes on it are transient and had not been persisted (which is OK).
>>>>>> You can check if this is the case by opening your diagram file in
>>>>>> a text editor and check if it had children inside it
>>>>>> If the diagram is canonical it will be populated when the editor
>>>>>> opens
>>>>>>
>>>>>> What exceptions do you get ?
>>>>>> another important thing is to check the Element feature on the
>>>>>> diagram if it is null or proxy , then this explains why your
>>>>>> diagram shows up empty
>>>>>>
>>>>>>
>>>>>> Martin Tauber wrote:
>>>>>>> Hello everybody,
>>>>>>>
>>>>>>> I'm trying to save a diagram that I have created as a gif, but
>>>>>>> the code I'm using is only producing exceptions ... Has anybody
>>>>>>> an Idea what might be wrong? (when I break after loading the
>>>>>>> resource, to me the resource doesn't look like it's been loaded
>>>>>>> correctly. The object loaded is a DiagramImpl, which is what I
>>>>>>> expected, but the content seams to be empty. the file stored is
>>>>>>> ok, since I can load it to the editor. I am also wondering, if I
>>>>>>> somehow have to tell the resourceset, that about the model file,
>>>>>>> since the diagram file references to the model...)
>>>>>>>
>>>>>>> private void compile(IFile input) {
>>>>>>> IFolder htmlDir = this.getProject().getFolder("html");
>>>>>>> String outputFileName =
>>>>>>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>>>>>>> IFile output = htmlDir.getFile(outputFileName);
>>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>>> Resource resource = resourceSet.getResource(
>>>>>>> URI.createURI(input.getRawLocationURI().toString()), true);
>>>>>>>
>>>>>>> if(resource instanceof XMIResourceImpl){
>>>>>>> Object object = resource.getContents().get(0);
>>>>>>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>>>>>>> try {
>>>>>>> copyToImageUtil.copyToImage((Diagram)
>>>>>>> object, output.getFullPath(),
>>>>>>> ImageFileFormat.GIF, null, PreferencesHint.USE_DEFAULTS);
>>>>>>> } catch (CoreException e) {
>>>>>>> // TODO Auto-generated catch block
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> }
>>>>>>> }
Re: Saving a Diagram as a GIF [message #105937 is a reply to message #105826] Wed, 21 February 2007 15:57 Go to previous messageGo to next message
Mohammed Mostafa is currently offline Mohammed MostafaFriend
Messages: 143
Registered: July 2009
Senior Member
What happens if you wrap the call for the copyToImageUtil in a
dispaly.syncExec or asyncExec

does it help ?



Martin Tauber wrote:
> Is something unclear about my description?
>
> Regards
> Martin
>
> Mohammed Mostafa schrieb:
>>
>> What I was trying to say is that GMF requires SWT, EMF and GEF
>>
>> I'm not sure what is the problem in your case may be you need to
>> change the place where you call CoptyToImageUtil
>>
>> if you can write a junit to reproduce this problem, then we can look
>> at it and see if there is possible solution
>>
>>
>> Martin Tauber wrote:
>>> Does that mean I can't achieve what I was trying to achieve?
>>>
>>> Regards
>>> Martin
>>>
>>> Mohammed Mostafa schrieb:
>>>> Hi ;
>>>> To save the diagram as Image, the diagram had to be opened,
>>>> opened here do not mean just open the resource we need to render the
>>>> diagram it does not matter if it is rendered in memory or i the
>>>> actual editor but it had to be rendered, other wise the transient
>>>> canonical views will not show up and layout will not be correct
>>>>
>>>>
>>>>
>>>>
>>>> Martin Tauber wrote:
>>>>> I think I'm getting a bit closer. I debugged the code and found out
>>>>> that the CoptyToImageUtil.copyToImage method tries to create a new
>>>>> Shell(). This fails.
>>>>>
>>>>> Hm - I am trying to write a builder that converts diagrams to
>>>>> images as soon as they are saved. It is the default Nature/Builder
>>>>> configuration of eclipse that I am making use of here, so the
>>>>> builder is running in a seperate thread (And I guess not the thread
>>>>> which has all the gui information ...) So this might be the cause
>>>>> of the exception ...
>>>>>
>>>>> But ... why the hell does the convertion need SWT? And how can I
>>>>> avoid it?
>>>>>
>>>>> Regards
>>>>> Martin
>>>>>
>>>>> P.S. Sounds interesting the canonical stuff, can you please give
>>>>> some more information about why I would need it? Has it something
>>>>> to do with the lazy loading / proxies in EMF?
>>>>>
>>>>> Thanks
>>>>>
>>>>> Mohammed Mostafa schrieb:
>>>>>> If your diagram is canonical there is a possibility that all
>>>>>> shapes on it are transient and had not been persisted (which is OK).
>>>>>> You can check if this is the case by opening your diagram file in
>>>>>> a text editor and check if it had children inside it
>>>>>> If the diagram is canonical it will be populated when the editor
>>>>>> opens
>>>>>>
>>>>>> What exceptions do you get ?
>>>>>> another important thing is to check the Element feature on the
>>>>>> diagram if it is null or proxy , then this explains why your
>>>>>> diagram shows up empty
>>>>>>
>>>>>>
>>>>>> Martin Tauber wrote:
>>>>>>> Hello everybody,
>>>>>>>
>>>>>>> I'm trying to save a diagram that I have created as a gif, but
>>>>>>> the code I'm using is only producing exceptions ... Has anybody
>>>>>>> an Idea what might be wrong? (when I break after loading the
>>>>>>> resource, to me the resource doesn't look like it's been loaded
>>>>>>> correctly. The object loaded is a DiagramImpl, which is what I
>>>>>>> expected, but the content seams to be empty. the file stored is
>>>>>>> ok, since I can load it to the editor. I am also wondering, if I
>>>>>>> somehow have to tell the resourceset, that about the model file,
>>>>>>> since the diagram file references to the model...)
>>>>>>>
>>>>>>> private void compile(IFile input) {
>>>>>>> IFolder htmlDir = this.getProject().getFolder("html");
>>>>>>> String outputFileName =
>>>>>>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>>>>>>> IFile output = htmlDir.getFile(outputFileName);
>>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>>> Resource resource = resourceSet.getResource(
>>>>>>> URI.createURI(input.getRawLocationURI().toString()), true);
>>>>>>>
>>>>>>> if(resource instanceof XMIResourceImpl){
>>>>>>> Object object = resource.getContents().get(0);
>>>>>>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>>>>>>> try {
>>>>>>> copyToImageUtil.copyToImage((Diagram)
>>>>>>> object, output.getFullPath(),
>>>>>>> ImageFileFormat.GIF, null, PreferencesHint.USE_DEFAULTS);
>>>>>>> } catch (CoreException e) {
>>>>>>> // TODO Auto-generated catch block
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> }
>>>>>>> }
Re: Saving a Diagram as a GIF [message #214480 is a reply to message #105937] Sun, 04 January 2009 18:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: info.pw-toxic.de

Hi,

I think i have a similar Problem. I want to do the following:
I have a GMFDiagram, and i want to export the diagram to an external
file (for example a gif image).
But there is no Editor opened or something like this. The following code
is executed by an extension point of my plug-in:
so i use the extension points org.eclipse.ui.menus and
org.eclipse.ui.commands.

CopyToImageUtil util = new CopyToImageUtil();

DiagramEditPart editPart = util.createDiagramEditPart(
diagram.getGmfdiagram(),
null,
PreferencesHint.USE_DEFAULTS
);

util.copyToImage(
editPart,
new Path("test"),
ImageFileFormat.GIF,
null
);


But i get this error:
org.eclipse.swt.SWTException: Invalid thread access
at the line "DiagramEditPart editPart = util.createDiagramEditPart("


So i tried something different:
util.copyToImage(
diagram.getGmfdiagram(),
new Path("test"),
ImageFileFormat.GIF,
null,
PreferencesHint.USE_DEFAULTS
);

but then i get the following error:
java.lang.NullPointerException (first line of code above)



I have browsed the GMF newsgroup, but i couldn't find any solution to
this topic. Google couldn't help me too, so you are my last hope ;)

Any help would be appreciated!



Both full stack traces:

org.eclipse.swt.SWTException: Invalid thread access
at
org.eclipse.draw2d.DeferredUpdateManager.sendUpdateRequest(D eferredUpdateManager.java:243)
at
org.eclipse.draw2d.DeferredUpdateManager.queueWork(DeferredU pdateManager.java:231)
at
org.eclipse.draw2d.DeferredUpdateManager.addInvalidFigure(De ferredUpdateManager.java:126)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1349)
at org.eclipse.draw2d.Figure.setLayoutManager(Figure.java:1538)
at
org.eclipse.draw2d.LightweightSystem.createRootFigure(Lightw eightSystem.java:166)
at org.eclipse.draw2d.LightweightSystem.init(LightweightSystem. java:184)
at org.eclipse.draw2d.LightweightSystem.<init>(LightweightSystem.java:77)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalVie wer$LightweightSystemWithUpdateToggle. <init>(DiagramGraphicalViewer.java:136)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalVie wer$LightweightSystemWithUpdateToggle. <init>(DiagramGraphicalViewer.java:136)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalVie wer.createLightweightSystem(DiagramGraphicalViewer.java:173)
at
org.eclipse.gef.ui.parts.GraphicalViewerImpl.<init>(GraphicalViewerImpl.java:66)
at
org.eclipse.gef.ui.parts.ScrollingGraphicalViewer.<init>(ScrollingGraphicalViewer.java:44)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalVie wer. <init>(DiagramGraphicalViewer.java:53)
at
org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory. createDiagramEditPart(OffscreenEditPartFactory.java:98)
at
org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUt il.createDiagramEditPart(CopyToImageUtil.java:86)




java.lang.NullPointerException
at
org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUt il.copyToImage(CopyToImageUtil.java:400)
at
org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUt il.copyToImage(CopyToImageUtil.java:305)
at
org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUt il.copyToImage(CopyToImageUtil.java:123)




Mohammed Mostafa schrieb:
>
> What happens if you wrap the call for the copyToImageUtil in a
> dispaly.syncExec or asyncExec
>
> does it help ?
>
>
>
> Martin Tauber wrote:
>> Is something unclear about my description?
>>
>> Regards
>> Martin
>>
>> Mohammed Mostafa schrieb:
>>>
>>> What I was trying to say is that GMF requires SWT, EMF and GEF
>>>
>>> I'm not sure what is the problem in your case may be you need to
>>> change the place where you call CoptyToImageUtil
>>>
>>> if you can write a junit to reproduce this problem, then we can look
>>> at it and see if there is possible solution
>>>
>>>
>>> Martin Tauber wrote:
>>>> Does that mean I can't achieve what I was trying to achieve?
>>>>
>>>> Regards
>>>> Martin
>>>>
>>>> Mohammed Mostafa schrieb:
>>>>> Hi ;
>>>>> To save the diagram as Image, the diagram had to be opened,
>>>>> opened here do not mean just open the resource we need to render
>>>>> the diagram it does not matter if it is rendered in memory or i the
>>>>> actual editor but it had to be rendered, other wise the transient
>>>>> canonical views will not show up and layout will not be correct
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Martin Tauber wrote:
>>>>>> I think I'm getting a bit closer. I debugged the code and found
>>>>>> out that the CoptyToImageUtil.copyToImage method tries to create a
>>>>>> new Shell(). This fails.
>>>>>>
>>>>>> Hm - I am trying to write a builder that converts diagrams to
>>>>>> images as soon as they are saved. It is the default Nature/Builder
>>>>>> configuration of eclipse that I am making use of here, so the
>>>>>> builder is running in a seperate thread (And I guess not the
>>>>>> thread which has all the gui information ...) So this might be the
>>>>>> cause of the exception ...
>>>>>>
>>>>>> But ... why the hell does the convertion need SWT? And how can I
>>>>>> avoid it?
>>>>>>
>>>>>> Regards
>>>>>> Martin
>>>>>>
>>>>>> P.S. Sounds interesting the canonical stuff, can you please give
>>>>>> some more information about why I would need it? Has it something
>>>>>> to do with the lazy loading / proxies in EMF?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> Mohammed Mostafa schrieb:
>>>>>>> If your diagram is canonical there is a possibility that all
>>>>>>> shapes on it are transient and had not been persisted (which is OK).
>>>>>>> You can check if this is the case by opening your diagram file in
>>>>>>> a text editor and check if it had children inside it
>>>>>>> If the diagram is canonical it will be populated when the editor
>>>>>>> opens
>>>>>>>
>>>>>>> What exceptions do you get ?
>>>>>>> another important thing is to check the Element feature on the
>>>>>>> diagram if it is null or proxy , then this explains why your
>>>>>>> diagram shows up empty
>>>>>>>
>>>>>>>
>>>>>>> Martin Tauber wrote:
>>>>>>>> Hello everybody,
>>>>>>>>
>>>>>>>> I'm trying to save a diagram that I have created as a gif, but
>>>>>>>> the code I'm using is only producing exceptions ... Has anybody
>>>>>>>> an Idea what might be wrong? (when I break after loading the
>>>>>>>> resource, to me the resource doesn't look like it's been loaded
>>>>>>>> correctly. The object loaded is a DiagramImpl, which is what I
>>>>>>>> expected, but the content seams to be empty. the file stored is
>>>>>>>> ok, since I can load it to the editor. I am also wondering, if I
>>>>>>>> somehow have to tell the resourceset, that about the model file,
>>>>>>>> since the diagram file references to the model...)
>>>>>>>>
>>>>>>>> private void compile(IFile input) {
>>>>>>>> IFolder htmlDir = this.getProject().getFolder("html");
>>>>>>>> String outputFileName =
>>>>>>>> input.getLocation().removeFileExtension().addFileExtension("gif ").lastSegment();
>>>>>>>> IFile output = htmlDir.getFile(outputFileName);
>>>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>>>> Resource resource = resourceSet.getResource(
>>>>>>>> URI.createURI(input.getRawLocationURI().toString()), true);
>>>>>>>>
>>>>>>>> if(resource instanceof XMIResourceImpl){
>>>>>>>> Object object = resource.getContents().get(0);
>>>>>>>> CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
>>>>>>>> try {
>>>>>>>> copyToImageUtil.copyToImage((Diagram)
>>>>>>>> object, output.getFullPath(),
>>>>>>>> ImageFileFormat.GIF, null, PreferencesHint.USE_DEFAULTS);
>>>>>>>> } catch (CoreException e) {
>>>>>>>> // TODO Auto-generated catch block
>>>>>>>> e.printStackTrace();
>>>>>>>> }
>>>>>>>> }
>>>>>>>> }
Re: Saving a Diagram as a GIF [message #214491 is a reply to message #214480] Sun, 04 January 2009 20:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atoulme.intalio.com

For reference the fix consists of wrapping the code:

PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public
void run() {// do the transformation here}});

Thanks,

Antoine
Re: Saving a Diagram as a GIF [message #214522 is a reply to message #214491] Mon, 05 January 2009 11:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: info.pw-toxic.de

Thanks Toulme, this fixes the first error, but the image export still
only works, if i have previousivly opened the diagram in an GMF editor
manually in my eclipse RCP. The GMF Diagrams don't need to be opened
currently. It helps if I open the diagrams once, and close them again.
Eclipse seems to remember which diagrams i have opened previousivly.

Anyway, if i haven't opened the diagram yet, this error occurs:

org.eclipse.swt.SWTException: Failed to execute runnable
(java.lang.NullPointerException)
at org.eclipse.swt.SWT.error(SWT.java:3777)
at org.eclipse.swt.SWT.error(SWT.java:3695)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.j ava:194)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchroniz er.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4021)
at
org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl.renderDiagram(DefaultM odelElementRendererImpl.java:288)
at
org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl.render(DefaultModelEle mentRendererImpl.java:137)
at
org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.renderModelElement(Default DocumentRendererImpl.java:250)
at
org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.renderDocLeafSection(Defau ltDocumentRendererImpl.java:130)
at
org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.render(DefaultDocumentRend ererImpl.java:95)
at org.unicase.docExport.DocumentExport.export(DocumentExport.j ava:58)
at org.unicase.docExport.DocumentExport.run(DocumentExport.java :73)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:121)
Caused by: java.lang.NullPointerException
at
org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr( ViewUtil.java:646)
at
org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUt il.copyToImage(CopyToImageUtil.java:121)
at
org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl$1.run(DefaultModelElem entRendererImpl.java:303)


org.unicase.docExport is my plugin and
DefaultModelElementRendererImpl.java:303 is the following line:
util.copyToImage(



Here is the full code:
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
CopyToImageUtil util = new CopyToImageUtil();

try {
util.copyToImage(
diagram.getGmfdiagram(),
new Path(tmpImage.toString()),
ImageFileFormat.SVG,
new NullProgressMonitor(),
PreferencesHint.USE_DEFAULTS
);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});



Antoine Toulme schrieb:
> For reference the fix consists of wrapping the code:
>
> PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public
> void run() {// do the transformation here}});
>
> Thanks,
>
> Antoine
Re: Saving a Diagram as a GIF [message #214672 is a reply to message #214522] Tue, 06 January 2009 21:06 Go to previous messageGo to next message
Linda Damus is currently offline Linda DamusFriend
Messages: 85
Registered: July 2009
Member
Sebastian,

What does "diagram.getGmfdiagram()" do? I'm guessing that it returns
null when you haven't previously opened the diagram, which makes me
think that maybe you're not loading the resource that contains the
diagram in that case?

Regards,
Linda


Sebastian Höcht wrote:
> Thanks Toulme, this fixes the first error, but the image export still
> only works, if i have previousivly opened the diagram in an GMF editor
> manually in my eclipse RCP. The GMF Diagrams don't need to be opened
> currently. It helps if I open the diagrams once, and close them again.
> Eclipse seems to remember which diagrams i have opened previousivly.
>
> Anyway, if i haven't opened the diagram yet, this error occurs:
>
> org.eclipse.swt.SWTException: Failed to execute runnable
> (java.lang.NullPointerException)
> at org.eclipse.swt.SWT.error(SWT.java:3777)
> at org.eclipse.swt.SWT.error(SWT.java:3695)
> at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.j ava:194)
> at
> org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchroniz er.java:150)
> at org.eclipse.swt.widgets.Display.syncExec(Display.java:4021)
> at
> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl.renderDiagram(DefaultM odelElementRendererImpl.java:288)
>
> at
> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl.render(DefaultModelEle mentRendererImpl.java:137)
>
> at
> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.renderModelElement(Default DocumentRendererImpl.java:250)
>
> at
> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.renderDocLeafSection(Defau ltDocumentRendererImpl.java:130)
>
> at
> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.render(DefaultDocumentRend ererImpl.java:95)
>
> at org.unicase.docExport.DocumentExport.export(DocumentExport.j ava:58)
> at org.unicase.docExport.DocumentExport.run(DocumentExport.java :73)
> at
> org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:121)
>
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr( ViewUtil.java:646)
>
> at
> org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUt il.copyToImage(CopyToImageUtil.java:121)
>
> at
> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl$1.run(DefaultModelElem entRendererImpl.java:303)
>
>
>
> org.unicase.docExport is my plugin and
> DefaultModelElementRendererImpl.java:303 is the following line:
> util.copyToImage(
>
>
>
> Here is the full code:
> PlatformUI.getWorkbench().getDisplay().syncExec(new
> Runnable() {
> public void run() {
> CopyToImageUtil util = new CopyToImageUtil();
>
> try {
> util.copyToImage(
> diagram.getGmfdiagram(),
> new Path(tmpImage.toString()),
> ImageFileFormat.SVG,
> new NullProgressMonitor(),
> PreferencesHint.USE_DEFAULTS
> );
> } catch (CoreException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> });
>
>
>
> Antoine Toulme schrieb:
>> For reference the fix consists of wrapping the code:
>>
>> PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
>> public void run() {// do the transformation here}});
>>
>> Thanks,
>>
>> Antoine
Re: Saving a Diagram as a GIF [message #214679 is a reply to message #214672] Wed, 07 January 2009 00:43 Go to previous message
Eclipse UserFriend
Originally posted by: info.pw-toxic.de

Hi Linda,

You are right. diagram.getGmfDiagram() returned null in these cases. The
resource was loaded, but the Diagram needs to be initialized within an
transaction.

Thanks a lot!


Linda Damus schrieb:
> Sebastian,
>
> What does "diagram.getGmfdiagram()" do? I'm guessing that it returns
> null when you haven't previously opened the diagram, which makes me
> think that maybe you're not loading the resource that contains the
> diagram in that case?
>
> Regards,
> Linda
>
>
> Sebastian Höcht wrote:
>> Thanks Toulme, this fixes the first error, but the image export still
>> only works, if i have previousivly opened the diagram in an GMF editor
>> manually in my eclipse RCP. The GMF Diagrams don't need to be opened
>> currently. It helps if I open the diagrams once, and close them again.
>> Eclipse seems to remember which diagrams i have opened previousivly.
>>
>> Anyway, if i haven't opened the diagram yet, this error occurs:
>>
>> org.eclipse.swt.SWTException: Failed to execute runnable
>> (java.lang.NullPointerException)
>> at org.eclipse.swt.SWT.error(SWT.java:3777)
>> at org.eclipse.swt.SWT.error(SWT.java:3695)
>> at
>> org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.j ava:194)
>> at
>> org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchroniz er.java:150)
>> at org.eclipse.swt.widgets.Display.syncExec(Display.java:4021)
>> at
>> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl.renderDiagram(DefaultM odelElementRendererImpl.java:288)
>>
>> at
>> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl.render(DefaultModelEle mentRendererImpl.java:137)
>>
>> at
>> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.renderModelElement(Default DocumentRendererImpl.java:250)
>>
>> at
>> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.renderDocLeafSection(Defau ltDocumentRendererImpl.java:130)
>>
>> at
>> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultDocumentRendererImpl.render(DefaultDocumentRend ererImpl.java:95)
>>
>> at
>> org.unicase.docExport.DocumentExport.export(DocumentExport.j ava:58)
>> at org.unicase.docExport.DocumentExport.run(DocumentExport.java :73)
>> at
>> org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:121)
>>
>> Caused by: java.lang.NullPointerException
>> at
>> org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr( ViewUtil.java:646)
>>
>> at
>> org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUt il.copyToImage(CopyToImageUtil.java:121)
>>
>> at
>> org.unicase.docExport.exportModel.renderers.defaultRenderers .impl.DefaultModelElementRendererImpl$1.run(DefaultModelElem entRendererImpl.java:303)
>>
>>
>>
>> org.unicase.docExport is my plugin and
>> DefaultModelElementRendererImpl.java:303 is the following line:
>> util.copyToImage(
>>
>>
>>
>> Here is the full code:
>> PlatformUI.getWorkbench().getDisplay().syncExec(new
>> Runnable() {
>> public void run() {
>> CopyToImageUtil util = new CopyToImageUtil();
>> try {
>> util.copyToImage(
>> diagram.getGmfdiagram(),
>> new Path(tmpImage.toString()),
>> ImageFileFormat.SVG,
>> new NullProgressMonitor(),
>> PreferencesHint.USE_DEFAULTS
>> );
>> } catch (CoreException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> } });
>>
>>
>>
>> Antoine Toulme schrieb:
>>> For reference the fix consists of wrapping the code:
>>>
>>> PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
>>> public void run() {// do the transformation here}});
>>>
>>> Thanks,
>>>
>>> Antoine
Previous Topic:after configure command executed twice?
Next Topic:Drag and drop from diagram to a view
Goto Forum:
  


Current Time: Thu Mar 28 10:46:43 GMT 2024

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

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

Back to the top