Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » how to add a notation view to a file without opening it ?
how to add a notation view to a file without opening it ? [message #22592] Thu, 17 August 2006 12:04 Go to next message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

I know how to add an element programmatically to an editor if it is opened,
but if the editor is not opened, how can I add a notation view to it. If I
can add a notation view to a file directly?

First try, if the editor is not open, I open it first, add element to it,
and then close it. It works, but it will flash the procedure of opening and
closing editor, which makes the user quite uncomfortable.
Is there any better solution? thank you.

I use the code below to add a notation view in an editor which is opened:

CreateViewRequest.ViewDescriptor viewDescriptor = new
CreateViewRequest.ViewDescriptor(
objAdapter, Node.class,
null,ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);

CreateViewRequest cvRequest = new CreateViewRequest((viewDescriptor));
Command cmd =
targetDiagramEditor.getDiagramEditPart().getCommand(cvReques t);
IDiagramEditDomain dEditingDomain =
targetDiagramEditor.getDiagramEditPart().getDiagramEditDomai n();
dEditingDomain.getDiagramCommandStack().execute(cmd);
Re: how to add a notation view to a file without opening it ? [message #22637 is a reply to message #22592] Thu, 17 August 2006 12:28 Go to previous messageGo to next message
Eclipse UserFriend
dzh wrote:
> I know how to add an element programmatically to an editor if it is opened,
> but if the editor is not opened, how can I add a notation view to it. If I
> can add a notation view to a file directly?
>
> First try, if the editor is not open, I open it first, add element to it,
> and then close it. It works, but it will flash the procedure of opening and
> closing editor, which makes the user quite uncomfortable.
> Is there any better solution? thank you.
>
> I use the code below to add a notation view in an editor which is opened:
>
> CreateViewRequest.ViewDescriptor viewDescriptor = new
> CreateViewRequest.ViewDescriptor(
> objAdapter, Node.class,
> null,ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
>
> CreateViewRequest cvRequest = new CreateViewRequest((viewDescriptor));
> Command cmd =
> targetDiagramEditor.getDiagramEditPart().getCommand(cvReques t);
> IDiagramEditDomain dEditingDomain =
> targetDiagramEditor.getDiagramEditPart().getDiagramEditDomai n();
> dEditingDomain.getDiagramCommandStack().execute(cmd);
>
>
You can always use EMF API's to add and delete to the Resource, but this
means you have to create the view your self, for example use the
NotationFactory to create the generic View, Node or Diagram then you set
the attributes on it and add it to the resource using EMF API's

Or the other way is to visualize your diagram off screen without opening
an editor (check the CopyToImageUtil), then use the edit parts you had
in memory to get the commands.
Re: how to add a notation view to a file without opening it ? [message #23556 is a reply to message #22637] Fri, 18 August 2006 12:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

"Mohammed Mostafa" <mmostafa@ca.ibm.com>
??????:ec25fk$lnl$1@utils.eclipse.org...

> You can always use EMF API's to add and delete to the Resource, but this
> means you have to create the view your self, for example use the
> NotationFactory to create the generic View, Node or Diagram then you set
> the attributes on it and add it to the resource using EMF API's

Thank you for your quick answer:)
yes, I am tring to do that. Could you please tell me which Api should I use?
> Or the other way is to visualize your diagram off screen without opening
> an editor (check the CopyToImageUtil), then use the edit parts you had in
> memory to get the commands.

a few classes listed below perform complex initialization of graphical
viewer
with sole purpose to obtain DiagramEditPart:

PrintHelper.createDiagramEditPart(Diagram,PreferencesHint)
CopyToImageUtil.createDiagramEditPart(Diagram,Shell,Preferen cesHint)
OffscreenEditPartFactory.createDiagramEditPart(Diagram)

How can I get the Diagram from file, use EMF API's ? which api should i
use.
looking forward to your answers:)
Re: how to add a notation view to a file without opening it ? [message #43447 is a reply to message #22637] Sat, 09 September 2006 03:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

I do it in the second method you suggest me:
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, and I use resource.save(Collections.EMPTY_MAP) to save, but
after reopen the diagram file, I found nothing changed.

so I suspect second way is right?
Then I would try frist way. Would you please give me more detail suggests?
Which method should I use to add View created by NotationFactory to
resource? thank you
Best regards,
dzh
"Mohammed Mostafa" <mmostafa@ca.ibm.com>
??????:ec25fk$lnl$1@utils.eclipse.org...
> dzh wrote:
>> I know how to add an element programmatically to an editor if it is
>> opened, but if the editor is not opened, how can I add a notation view to
>> it. If I can add a notation view to a file directly?
>>
>> First try, if the editor is not open, I open it first, add element to it,
>> and then close it. It works, but it will flash the procedure of opening
>> and closing editor, which makes the user quite uncomfortable.
>> Is there any better solution? thank you.
>>
>> I use the code below to add a notation view in an editor which is opened:
>>
>> CreateViewRequest.ViewDescriptor viewDescriptor = new
>> CreateViewRequest.ViewDescriptor(
>> objAdapter, Node.class,
>> null,ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
>>
>> CreateViewRequest cvRequest = new
>> CreateViewRequest((viewDescriptor));
>> Command cmd =
>> targetDiagramEditor.getDiagramEditPart().getCommand(cvReques t);
>> IDiagramEditDomain dEditingDomain =
>> targetDiagramEditor.getDiagramEditPart().getDiagramEditDomai n();
>> dEditingDomain.getDiagramCommandStack().execute(cmd);
> You can always use EMF API's to add and delete to the Resource, but this
> means you have to create the view your self, for example use the
> NotationFactory to create the generic View, Node or Diagram then you set
> the attributes on it and add it to the resource using EMF API's
>
> Or the other way is to visualize your diagram off screen without opening
> an editor (check the CopyToImageUtil), then use the edit parts you had in
> memory to get the commands.
Re: how to add a notation view to a file without opening it ? [message #43730 is a reply to message #22637] Sun, 10 September 2006 06:43 Go to previous message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

oh,yes! I did it by create view use CopytoImageUtil and add ito to the
resource using EMF API's.
"Mohammed Mostafa" <mmostafa@ca.ibm.com>
??????:ec25fk$lnl$1@utils.eclipse.org...
> dzh wrote:
>> I know how to add an element programmatically to an editor if it is
>> opened, but if the editor is not opened, how can I add a notation view to
>> it. If I can add a notation view to a file directly?
>>
>> First try, if the editor is not open, I open it first, add element to it,
>> and then close it. It works, but it will flash the procedure of opening
>> and closing editor, which makes the user quite uncomfortable.
>> Is there any better solution? thank you.
>>
>> I use the code below to add a notation view in an editor which is opened:
>>
>> CreateViewRequest.ViewDescriptor viewDescriptor = new
>> CreateViewRequest.ViewDescriptor(
>> objAdapter, Node.class,
>> null,ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
>>
>> CreateViewRequest cvRequest = new
>> CreateViewRequest((viewDescriptor));
>> Command cmd =
>> targetDiagramEditor.getDiagramEditPart().getCommand(cvReques t);
>> IDiagramEditDomain dEditingDomain =
>> targetDiagramEditor.getDiagramEditPart().getDiagramEditDomai n();
>> dEditingDomain.getDiagramCommandStack().execute(cmd);
> You can always use EMF API's to add and delete to the Resource, but this
> means you have to create the view your self, for example use the
> NotationFactory to create the generic View, Node or Diagram then you set
> the attributes on it and add it to the resource using EMF API's
>
> Or the other way is to visualize your diagram off screen without opening
> an editor (check the CopyToImageUtil), then use the edit parts you had in
> memory to get the commands.
Previous Topic:Adding listener to semantic changes
Next Topic:Modeling bidirectional associations in GMF's Ecore editor
Goto Forum:
  


Current Time: Sat May 03 13:22:07 EDT 2025

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

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

Back to the top