Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to configure the loocation, name ... of a new created element with GMF
How to configure the loocation, name ... of a new created element with GMF [message #179554] Fri, 28 March 2008 09:32 Go to next message
BLANC Philippe is currently offline BLANC PhilippeFriend
Messages: 89
Registered: July 2009
Member
Hi,
My diagram is partioned (A --> B). When the new diagram is opened, I
want to initialize it with a new created object. So, I have overwritten
the method initializeGraphicalViewerContents like this :

==========================
protected void initializeGraphicalViewerContents() {

super.initializeGraphicalViewerContents();
EObject rootElement = getDiagram().getElement();
com.clearsy.eventB.Machine machine = null;
if (rootElement instanceof com.clearsy.eventB.Machine) {
machine = (com.clearsy.eventB.Machine) rootElement;
} else {
MessageDialog.openError(getSite().getShell(), "Root element is not a
Machine", "The root of your model is not an event B Machine.");
}
if (machine.getContainsM() == null){
ICommandProxy icmd = new ICommandProxy(
new MachineContentCreateCommand(
new CreateElementRequest(
rootElement, EventBElementTypes.MachineContent_2001)));
icmd.execute();
}
}
==========================

My method calls a GMF CreateElementCommand (MachineContentCreateCommand
which is generated by GMF) with w CreateElementRequest.
My object is correctly created. But I would like to change its location,
set some of its labels... I manage to change its labels overwritting
the doDefaultElementCreation() method of MachineContentCreateCommand.
But I failed to change its location. I know I can change its location
with a GEF CreateElement command and a GEF CreateElementRequest request,
but I would like to do this with a GMF command.

Any ideas ?
Thanks for your help.

Regards,

Philippe
Re: How to configure the loocation, name ... of a new created element with GMF [message #179960 is a reply to message #179554] Mon, 31 March 2008 14:24 Go to previous messageGo to next message
BLANC Philippe is currently offline BLANC PhilippeFriend
Messages: 89
Registered: July 2009
Member
Any ideas ?


Philippe BLANC a écrit :
> Hi,
> My diagram is partioned (A --> B). When the new diagram is opened, I
> want to initialize it with a new created object. So, I have overwritten
> the method initializeGraphicalViewerContents like this :
>
> ==========================
> protected void initializeGraphicalViewerContents() {
>
> super.initializeGraphicalViewerContents();
> EObject rootElement = getDiagram().getElement();
> com.clearsy.eventB.Machine machine = null;
> if (rootElement instanceof com.clearsy.eventB.Machine) {
> machine = (com.clearsy.eventB.Machine) rootElement;
> } else {
> MessageDialog.openError(getSite().getShell(), "Root element is
> not a Machine", "The root of your model is not an event B Machine.");
> }
> if (machine.getContainsM() == null){
> ICommandProxy icmd = new ICommandProxy(
> new MachineContentCreateCommand(
> new CreateElementRequest(
> rootElement,
> EventBElementTypes.MachineContent_2001)));
> icmd.execute();
> }
> }
> ==========================
>
> My method calls a GMF CreateElementCommand (MachineContentCreateCommand
> which is generated by GMF) with w CreateElementRequest.
> My object is correctly created. But I would like to change its location,
> set some of its labels... I manage to change its labels overwritting
> the doDefaultElementCreation() method of MachineContentCreateCommand.
> But I failed to change its location. I know I can change its location
> with a GEF CreateElement command and a GEF CreateElementRequest request,
> but I would like to do this with a GMF command.
>
> Any ideas ?
> Thanks for your help.
>
> Regards,
>
> Philippe
>
Re: How to configure the loocation, name ... of a new created element with GMF [message #180041 is a reply to message #179960] Tue, 01 April 2008 08:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ijerez2001.msn.com

Try with SetBoundsCommnad to set the location (and optionally the size).

"Philippe BLANC" <blanc.philippe83@gmail.com> escribió en el mensaje de
noticias:fsqs6m$41c$1@build.eclipse.org...
> Any ideas ?
>
>
> Philippe BLANC a écrit :
>> Hi,
>> My diagram is partioned (A --> B). When the new diagram is opened, I want
>> to initialize it with a new created object. So, I have overwritten the
>> method initializeGraphicalViewerContents like this :
>>
>> ==========================
>> protected void initializeGraphicalViewerContents() {
>> super.initializeGraphicalViewerContents();
>> EObject rootElement = getDiagram().getElement();
>> com.clearsy.eventB.Machine machine = null;
>> if (rootElement instanceof com.clearsy.eventB.Machine) {
>> machine = (com.clearsy.eventB.Machine) rootElement;
>> } else {
>> MessageDialog.openError(getSite().getShell(), "Root element is
>> not a Machine", "The root of your model is not an event B Machine.");
>> }
>> if (machine.getContainsM() == null){
>> ICommandProxy icmd = new ICommandProxy(
>> new MachineContentCreateCommand(
>> new CreateElementRequest(
>> rootElement,
>> EventBElementTypes.MachineContent_2001)));
>> icmd.execute();
>> }
>> }
>> ==========================
>>
>> My method calls a GMF CreateElementCommand (MachineContentCreateCommand
>> which is generated by GMF) with w CreateElementRequest.
>> My object is correctly created. But I would like to change its location,
>> set some of its labels... I manage to change its labels overwritting the
>> doDefaultElementCreation() method of MachineContentCreateCommand. But I
>> failed to change its location. I know I can change its location with a
>> GEF CreateElement command and a GEF CreateElementRequest request, but I
>> would like to do this with a GMF command.
>>
>> Any ideas ?
>> Thanks for your help.
>>
>> Regards,
>>
>> Philippe
>>
Re: How to configure the loocation, name ... of a new created element with GMF [message #180110 is a reply to message #180041] Tue, 01 April 2008 12:52 Go to previous message
BLANC Philippe is currently offline BLANC PhilippeFriend
Messages: 89
Registered: July 2009
Member
Finally, I found my answer using a CreateViewRequest.
Here is my source code :


protected void initializeGraphicalViewerContents() {
super.initializeGraphicalViewerContents();
EObject rootElement = getDiagram().getElement();
Machine machine = null;
if (rootElement instanceof Machine) {
machine = (Machine) rootElement;
} else {
MessageDialog.openError(getSite().getShell(), "Root element is not a
Machine",
"The root of your model is not an event B Machine.");
}
if (machine.getContainsM() == null){
CreateViewRequest request =
CreateViewRequestFactory.getCreateShapeRequest(EventBElement Types.MachineContent_2001,
getPreferencesHint());
Point p = new Point(100,100);
Dimension d = new Dimension(400,600);
request.setLocation(p);
request.setSize(d);
Map map = new HashMap();
map.put("machineId",machine.getId());
request.setExtendedData(map);
Command createMachineContentCmd = (Command)
getDiagramEditPart().getCommand(request);
createMachineContentCmd.execute();
}
}

Iván Jerez a écrit :
> Try with SetBoundsCommnad to set the location (and optionally the size).
>
> "Philippe BLANC" <blanc.philippe83@gmail.com> escribió en el mensaje de
> noticias:fsqs6m$41c$1@build.eclipse.org...
>> Any ideas ?
>>
>>
>> Philippe BLANC a écrit :
>>> Hi,
>>> My diagram is partioned (A --> B). When the new diagram is opened, I
>>> want to initialize it with a new created object. So, I have
>>> overwritten the method initializeGraphicalViewerContents like this :
>>>
>>> ==========================
>>> protected void initializeGraphicalViewerContents() {
>>> super.initializeGraphicalViewerContents();
>>> EObject rootElement = getDiagram().getElement();
>>> com.clearsy.eventB.Machine machine = null;
>>> if (rootElement instanceof com.clearsy.eventB.Machine) {
>>> machine = (com.clearsy.eventB.Machine) rootElement;
>>> } else {
>>> MessageDialog.openError(getSite().getShell(), "Root element
>>> is not a Machine", "The root of your model is not an event B Machine.");
>>> }
>>> if (machine.getContainsM() == null){
>>> ICommandProxy icmd = new ICommandProxy(
>>> new MachineContentCreateCommand(
>>> new CreateElementRequest(
>>> rootElement,
>>> EventBElementTypes.MachineContent_2001)));
>>> icmd.execute();
>>> }
>>> }
>>> ==========================
>>>
>>> My method calls a GMF CreateElementCommand
>>> (MachineContentCreateCommand which is generated by GMF) with w
>>> CreateElementRequest.
>>> My object is correctly created. But I would like to change its
>>> location, set some of its labels... I manage to change its labels
>>> overwritting the doDefaultElementCreation() method of
>>> MachineContentCreateCommand. But I failed to change its location. I
>>> know I can change its location with a GEF CreateElement command and a
>>> GEF CreateElementRequest request, but I would like to do this with a
>>> GMF command.
>>>
>>> Any ideas ?
>>> Thanks for your help.
>>>
>>> Regards,
>>>
>>> Philippe
>>>
Previous Topic:Removing "Save All" etc.
Next Topic:emf tree in outline view
Goto Forum:
  


Current Time: Fri Mar 29 05:55:43 GMT 2024

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

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

Back to the top