How can I get the Diagram from Diagram file without opening it? [message #42140] |
Thu, 07 September 2006 12:17  |
Eclipse User |
|
|
|
Originally posted by: dzhpingbo.sohu.com
I get the Diagram from digramfile, and then I use copyToImageUtil to create
a diagramEditPart based on the diagram. List codes below:
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(600,800);
shell.setText("testcopytoutil");
IPath resourcePath = diagramFile.getFullPath();
ResourceSet resourceSet = myEditingDomain.getResourceSet();
try {
Resource modelResource = resourceSet.getResource(
URI.createPlatformResourceURI(resourcePath
.toString()), true);
if(modelResource instanceof XMIResourceImpl){
Object[] objs = getElements(modelResource);
CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
diagramEditPart = copyToImageUtil.createDiagramEditPart((Diagram)
objs[0],new Shell(),ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT) ;
}
} catch (WrappedException e) {
ProcessDiagramEditorPlugin
.getInstance()
.logError(
"Unable to load resource: " + resourcePath.toString(), e);
//$NON-NLS-1$
}
shell.layout();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
The code works well without reporting error, but I can not see anything from
the shell shows up....So I suspect if I did right?
By the way, I use the diagramEditPart which is returned by
copyToImageUtil.createDiagramEditPart method to get the commands to create
view on it, then how to save the Diagram? I know if it is an editor, I can
use editor.doSave(), but it is Ddiagram, how to save it back to its
diagramfile.
|
|
|
|
|
Re: How can I get the Diagram from Diagram file without opening it? [message #45338 is a reply to message #43354] |
Mon, 11 September 2006 15:08  |
Eclipse User |
|
|
|
Originally posted by: cmahoney.ca.ibm.com
Hello,
No, you shouldn't see the diagram in the shell. This method allows you
to create a DiagramEditPart without creating an editor. You could then
use the DiagramEditPart for whatever reason you needed it. For example,
GMF uses this mechanism to create an image from a diagram (see
CopyToImageUtil.copyToImage()).
Regards,
Cherie
dzh wrote:
> Thank you for your quick answer:)
> The code works well without reporting error, but I can not see anything from
> the shell shows up....So I suspect if I did right?
> If there any example of using copyToImageUtil ? If rightly created, the
> diagram should show up in the shell?
>
> I use the diagramEditPart which is returned by
> copyToImageUtil.createDiagramEditPart method to get the commands to create
> view on it, and I use resource.save(Collections.EMPTY_MAP) to save, but
> after reopen the diagram file, I found nothing changed.
>
> Best reagrds,
> dzh
>
> "Alex Shatalin" <vano@borland.com> дÈëÏûÏ¢ÐÂÎÅ:cd695fb3116688c8a1538267a876@news.eclipse.org...
>> Hello dzh,
>>
>>> use editor.doSave(), but it is Ddiagram, how to save it back to its
>>> diagramfile.
>> call resource.save(Collections.EMPTY_MAP); for the diagram file resource.
>>
>> -----------------
>> Alex Shatalin
>>
>>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04065 seconds