Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 Tools » Creating diagram using UML2 tools APIs
Creating diagram using UML2 tools APIs [message #476297] Thu, 22 January 2009 00:22 Go to next message
Kishore Kushwaha is currently offline Kishore Kushwaha
Messages: 36
Registered: July 2009
Location: Lucknow, India
Member

Hi All;

I am creating a UML file into Eclipse workspace and want to create/open
diagram as well for this file using UML2 Tools APIs as :


String uriFile = file.getFullPath().toString();
URI resourceURI = URI.createPlatformResourceURI(uriFile, false);
URI diagramURI = URI.createPlatformResourceURI(uriFile + "act", false);
Resource diagram = UMLDiagramEditorUtil.createDiagram(diagramURI,
resourceURI, new NullProgressMonitor());
UMLDiagramEditorUtil.openDiagram(diagram);

but above piece of code creates a diagram file into workspace but it does
not contains any contents and the resource uml file becomes empty.
And generates the "Null Pointer Exception" error.


Please tell me, what is wrong in my code or tell me the right way to
create a diagram (activity, Class, use case) by giving a uml file path.

Thanks in Advance.
Kishore


Regards,
Kishore
Re: Creating diagram using UML2 tools APIs [message #476302 is a reply to message #476297] Fri, 30 January 2009 06:34 Go to previous messageGo to next message
Tatiana Fesenko is currently offline Tatiana Fesenko
Messages: 530
Registered: July 2009
Senior Member
Hello Kishore,

UMLDiagramEditorUtil.createDiagram(URI diagramURI, URI modelURI, IProgressMonitor
progressMonitor) method creates a _new_ model, and a new diagram:
....Package model = createInitialModel();
....
So, if you want to create a new diagram for an _existing_ model you have
to copy the code from the method and assign 'model' variable with content
of the existing modelFile:
Package model = getModelRoot(modelURI);

getModelRoot() method can look like this:
private EObject getModelRoot(URI domainModelURI , ResourceSet resourceSet) {
myModelResource = resourceSet.getResource(domainModelURI, true);
EObject modelRoot = (EObject) myModelResource.getContents().get(0);
return modelRoot;
}

Best wishes,
Tanya.

> Hi All;
>
> I am creating a UML file into Eclipse workspace and want to
> create/open diagram as well for this file using UML2 Tools APIs as :
>
> String uriFile = file.getFullPath().toString();
> URI resourceURI = URI.createPlatformResourceURI(uriFile, false);
> URI diagramURI = URI.createPlatformResourceURI(uriFile + "act",
> false);
> Resource diagram = UMLDiagramEditorUtil.createDiagram(diagramURI,
> resourceURI, new NullProgressMonitor());
> UMLDiagramEditorUtil.openDiagram(diagram);
> but above piece of code creates a diagram file into workspace but it
> does
> not contains any contents and the resource uml file becomes empty.
> And generates the "Null Pointer Exception" error.
> Please tell me, what is wrong in my code or tell me the right way to
> create a diagram (activity, Class, use case) by giving a uml file
> path.
>
> Thanks in Advance.
> Kishore
Re: Creating diagram using UML2 tools APIs [message #476332 is a reply to message #476297] Mon, 02 March 2009 02:20 Go to previous message
wenpengsong is currently offline wenpengsong
Messages: 4
Registered: July 2009
Junior Member
I want to create diagram from a xml file. Can you tell me to do this in
detail?My email:wenpengsong@gmail.com
Thanks.
Re: Creating diagram using UML2 tools APIs [message #623529 is a reply to message #476297] Fri, 30 January 2009 06:34 Go to previous message
Tatiana Fesenko is currently offline Tatiana Fesenko
Messages: 530
Registered: July 2009
Senior Member
Hello Kishore,

UMLDiagramEditorUtil.createDiagram(URI diagramURI, URI modelURI, IProgressMonitor
progressMonitor) method creates a _new_ model, and a new diagram:
....Package model = createInitialModel();
....
So, if you want to create a new diagram for an _existing_ model you have
to copy the code from the method and assign 'model' variable with content
of the existing modelFile:
Package model = getModelRoot(modelURI);

getModelRoot() method can look like this:
private EObject getModelRoot(URI domainModelURI , ResourceSet resourceSet) {
myModelResource = resourceSet.getResource(domainModelURI, true);
EObject modelRoot = (EObject) myModelResource.getContents().get(0);
return modelRoot;
}

Best wishes,
Tanya.

> Hi All;
>
> I am creating a UML file into Eclipse workspace and want to
> create/open diagram as well for this file using UML2 Tools APIs as :
>
> String uriFile = file.getFullPath().toString();
> URI resourceURI = URI.createPlatformResourceURI(uriFile, false);
> URI diagramURI = URI.createPlatformResourceURI(uriFile + "act",
> false);
> Resource diagram = UMLDiagramEditorUtil.createDiagram(diagramURI,
> resourceURI, new NullProgressMonitor());
> UMLDiagramEditorUtil.openDiagram(diagram);
> but above piece of code creates a diagram file into workspace but it
> does
> not contains any contents and the resource uml file becomes empty.
> And generates the "Null Pointer Exception" error.
> Please tell me, what is wrong in my code or tell me the right way to
> create a diagram (activity, Class, use case) by giving a uml file
> path.
>
> Thanks in Advance.
> Kishore
Re: Creating diagram using UML2 tools APIs [message #623614 is a reply to message #476297] Mon, 02 March 2009 02:20 Go to previous message
wenpengsong is currently offline wenpengsong
Messages: 4
Registered: July 2009
Junior Member
I want to create diagram from a xml file. Can you tell me to do this in
detail?My email:wenpengsong@gmail.com
Thanks.
Previous Topic:how to create a statemachine diagram from a xml file?
Next Topic:Stereotype for associations
Goto Forum:
  


Current Time: Wed Aug 27 11:20:59 EDT 2014

Powered by FUDForum. Page generated in 0.07040 seconds