Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Set default position of EditPart at creation time
Set default position of EditPart at creation time [message #174401] Tue, 26 February 2008 10:59 Go to next message
Eclipse UserFriend
Originally posted by: snej_NO-SPAM_.esuark.de

Hi there,

i want to set the location of an (special) EditPart at the moment it is
created. So i have to set the bounds of it, but don't have access to
this editpart. My approach was to handle the bounds setting in the
XXXEditHelper, but there i've got no access to a viewer to get the
EditPart from my model object.
Is there another way to set the bounds?
After setting the bounds, the EditPart has to be moveable again. So the
usecase should be that a user klicks into the compartment after
selecting the associated palette tool and the EditPart appears on the
default position. But if needed the user can move it. The default
positions are stored in our model so i don't know them when i model the
..gmfgraph file.

Any suggestion would be helpful.
Jens
Re: Set default position of EditPart at creation time [message #174409 is a reply to message #174401] Tue, 26 February 2008 12:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: snej_NO-SPAM_.esuark.de

Jens Krause schrieb:
> My approach was to handle the bounds setting in the
> XXXEditHelper, but there i've got no access to a viewer to get the
> EditPart from my model object.

Well, thats indeed wrong ;).

With this post
< http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg02402.html>
i have the hope to get my edit part, but i've got a problem:

In my Eclipse editor where i edit the XXXEditHelper.java, the
EMFCoreUtil.getProxyID(<element>) method and class are resolved. At
runtime not. If i debug my plugin and set a breakpoint to my method then
EMFCoreUtil cannot be resolved. Please help me, i don't know whats wrong
there.

Here is a code snippet from my FieldLabelEditHelper.java:
------------------------------------------------------------ -----------
if (element instanceof FieldLabel) {
FieldLabel label = (FieldLabel) element;
IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorPart editor = window.getActivePage().getActiveEditor();
if (editor instanceof GenloopDiagramEditor) {
IDiagramGraphicalViewer dgv = ((IDiagramWorkbenchPart)
editor).getDiagramGraphicalViewer();
List ep =
dgv.findEditPartsForElement(EMFCoreUtil.getProxyID(label),
FieldLabelEditPart.class);
}

------------------------------------------------------------ -----------

The list "ep" is always empty, and in debugmode i always get the message
"EMFCoreUtil cannot be resolved".


Any ideas?
Jens
Re: Set default position of EditPart at creation time [message #174495 is a reply to message #174409] Wed, 27 February 2008 07:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

Hi Jens,

I don't think EditHelper is the right place to do this.

The container EditPart installs a CreationEditPolicy. You can override
the method that returns the create command. For example:

protected Command
getCreateElementAndViewCommand(
CreateViewAndElementRequest request) {

//get your coords from model here

request.setLocation(new Point(100,100));
return super.getCreateElementAndViewCommand(request);
}

Jens Krause schrieb:
> Jens Krause schrieb:
>> My approach was to handle the bounds setting in the XXXEditHelper, but
>> there i've got no access to a viewer to get the EditPart from my model
>> object.
>
> Well, thats indeed wrong ;).
>
> With this post
> < http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg02402.html>
> i have the hope to get my edit part, but i've got a problem:
>
> In my Eclipse editor where i edit the XXXEditHelper.java, the
> EMFCoreUtil.getProxyID(<element>) method and class are resolved. At
> runtime not. If i debug my plugin and set a breakpoint to my method then
> EMFCoreUtil cannot be resolved. Please help me, i don't know whats wrong
> there.
>
> Here is a code snippet from my FieldLabelEditHelper.java:
> ------------------------------------------------------------ -----------
> if (element instanceof FieldLabel) {
> FieldLabel label = (FieldLabel) element;
> IWorkbenchWindow window =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow();
> IEditorPart editor = window.getActivePage().getActiveEditor();
> if (editor instanceof GenloopDiagramEditor) {
> IDiagramGraphicalViewer dgv = ((IDiagramWorkbenchPart)
> editor).getDiagramGraphicalViewer();
> List ep =
> dgv.findEditPartsForElement(EMFCoreUtil.getProxyID(label),
> FieldLabelEditPart.class);
> }
>
> ------------------------------------------------------------ -----------
>
> The list "ep" is always empty, and in debugmode i always get the message
> "EMFCoreUtil cannot be resolved".
>
>
> Any ideas?
> Jens
Re: Set default position of EditPart at creation time [message #174923 is a reply to message #174495] Fri, 29 February 2008 04:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: snej_NO-SPAM_.esuark.de

Jan Herriger schrieb:
> I don't think EditHelper is the right place to do this.

First of all, thanks for your answer. EditHelper is indeed not a good
place :).

> The container EditPart installs a CreationEditPolicy. You can override
> the method that returns the create command. For example:
> protected Command
> getCreateElementAndViewCommand(
> CreateViewAndElementRequest request) {
>
> //get your coords from model here
>
> request.setLocation(new Point(100,100));
> return super.getCreateElementAndViewCommand(request);
> }

All EditPolicies installed in my EditPart doesn't have the method
getCreateElementAndViewCommand, so i have to install a
CreationEditPolicy by myself, right? If so, what role do i have to set
for a CreationEditPolicy? I tried EditPolicyRoles.CREATION_ROLE, but
that don't work. So which one should i take?

jens
Re: Set default position of EditPart at creation time [message #174982 is a reply to message #174923] Fri, 29 February 2008 09:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

You should have a XxxCompartmentEditPart wich installs CreationEditPolicy.

Jens Krause schrieb:
> Jan Herriger schrieb:
>> I don't think EditHelper is the right place to do this.
>
> First of all, thanks for your answer. EditHelper is indeed not a good
> place :).
>
>> The container EditPart installs a CreationEditPolicy. You can override
>> the method that returns the create command. For example:
>> protected Command
>> getCreateElementAndViewCommand(
>> CreateViewAndElementRequest request) {
>>
>> //get your coords from model here
>>
>> request.setLocation(new Point(100,100));
>> return super.getCreateElementAndViewCommand(request);
>> }
>
> All EditPolicies installed in my EditPart doesn't have the method
> getCreateElementAndViewCommand, so i have to install a
> CreationEditPolicy by myself, right? If so, what role do i have to set
> for a CreationEditPolicy? I tried EditPolicyRoles.CREATION_ROLE, but
> that don't work. So which one should i take?
>
> jens
Re: Set default position of EditPart at creation time [message #175171 is a reply to message #174982] Mon, 03 March 2008 11:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fbanica.soluta.net

Hello guys,

I have the same problem. I have installed a CreationEditPolicy (I created a
class which inherits CreationEditPolicy and installed):
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new
MyCreationEditPolicy());

Inside this class, I overridden the "getCreateElementAndViewCommand" and
"getCreateCommand" methods but, when I run the application, it never passes
them. I noticed in debug that it always passes through the "original"
methods of the "CreationEditPolicy".

I wonder why is this happening? Where did I go wrong? Please, help!

Thanks,


Floppy



"Jan Herriger" <jan.herriger@gmx.de> wrote in message
news:fq93pj$9tg$1@build.eclipse.org...
> You should have a XxxCompartmentEditPart wich installs CreationEditPolicy.
>
> Jens Krause schrieb:
>> Jan Herriger schrieb:
>>> I don't think EditHelper is the right place to do this.
>>
>> First of all, thanks for your answer. EditHelper is indeed not a good
>> place :).
>>
>>> The container EditPart installs a CreationEditPolicy. You can override
>>> the method that returns the create command. For example:
>>> protected Command
>>> getCreateElementAndViewCommand(
>>> CreateViewAndElementRequest request) {
>>>
>>> //get your coords from model here
>>>
>>> request.setLocation(new Point(100,100));
>>> return super.getCreateElementAndViewCommand(request);
>>> }
>>
>> All EditPolicies installed in my EditPart doesn't have the method
>> getCreateElementAndViewCommand, so i have to install a CreationEditPolicy
>> by myself, right? If so, what role do i have to set for a
>> CreationEditPolicy? I tried EditPolicyRoles.CREATION_ROLE, but that don't
>> work. So which one should i take?
>>
>> jens
Re: Set default position of EditPart at creation time [message #175354 is a reply to message #175171] Tue, 04 March 2008 03:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: snej_NO-SPAM_.esuark.de

Florin Banica schrieb:
> Hello guys,
>
> I have the same problem. I have installed a CreationEditPolicy (I created a
> class which inherits CreationEditPolicy and installed):
> installEditPolicy(EditPolicyRoles.CREATION_ROLE, new
> MyCreationEditPolicy());
>
> Inside this class, I overridden the "getCreateElementAndViewCommand" and
> "getCreateCommand" methods but, when I run the application, it never passes
> them. I noticed in debug that it always passes through the "original"
> methods of the "CreationEditPolicy".
>
> I wonder why is this happening? Where did I go wrong? Please, help!

As Jan mentioned you have to use the CreationEditpolicy from the
CompartementEditPart where your EditPart is insert to. The
CreationEditPolicy is then called for creating the childs. If, as in my
editor, you can add more than one element to that compartment, you have
to check the type ....

Here a small snippet how i done the positioning:

installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {

private final int offset = 5;
protected Command
getCreateElementAndViewCommand(CreateViewAndElementRequest request) {
Point cl = figure.getClientArea().getLocation();
figure.translateToAbsolute(cl);
if
("3009" .equals(request.getViewAndElementDescriptor().getSemanticHin t())) {
// FieldLabel
request.setLocation(new Point(cl.x + offset + 10, cl.y + offset + 1));
} else if
("3010" .equals(request.getViewAndElementDescriptor().getSemanticHin t())) {
// InputField
request.setLocation(new Point(cl.x + offset + 120, cl.y + offset + 1));
}
return super.getCreateElementAndViewCommand(request);
}
});

In this case i have taken static values for the position, but i will
read them from my model.

hth jens
Re: Set default position of EditPart at creation time [message #175440 is a reply to message #175354] Tue, 04 March 2008 06:24 Go to previous message
Eclipse UserFriend
Originally posted by: fbanica.soluta.net

Hi Jens,

I think by "CompartementEditPart where your EditPart is insert to" you
understand the other EditPart on which my EditPart will be put on (like the
"father"), right? If so, I did create the new CreationEditPolicy and
override the "getCreateElementAndViewCommand" and "getCreateCommand" methods
and put some breakpoints.

I noticed that the "getCreateCommand" is called when the diagram file is
created (new). The second method: "getCreateElementAndViewCommand" is called
when you create a new object ON the diagram (from the palette, for example),
meaning you already have the diagram open.

I want to create (in code) some objects, when the model is created, before
the diagram is shown up. I create them, but I can not "tell" the application
where exactly to put them on the diagram. So, it seems that the first method
would do for me...

In your example code, you had inside the request just a reference to THE
object to put on the diagram (it was only one, probably selected from the
palette).

:-( But, in "getCreateCommand" method, the request contains a reference to a
list of ALL the contained "children", so I cannot tell the request to set a
different location for every "child". I don't know how to handle with this
situation... I tried also to set the locations for the figures into the
..gmfgraph file, but there's no use.

Did I make myself clear? Is there any solution? Please, help. Thanks,



Floppy


"Jens Krause" <snej_NO-SPAM_@esuark.de> wrote in message
news:fqj288$hao$1@build.eclipse.org...
> Florin Banica schrieb:
>> Hello guys,
>>
>> I have the same problem. I have installed a CreationEditPolicy (I created
>> a class which inherits CreationEditPolicy and installed):
>> installEditPolicy(EditPolicyRoles.CREATION_ROLE, new
>> MyCreationEditPolicy());
>>
>> Inside this class, I overridden the "getCreateElementAndViewCommand" and
>> "getCreateCommand" methods but, when I run the application, it never
>> passes them. I noticed in debug that it always passes through the
>> "original" methods of the "CreationEditPolicy".
>>
>> I wonder why is this happening? Where did I go wrong? Please, help!
>
> As Jan mentioned you have to use the CreationEditpolicy from the
> CompartementEditPart where your EditPart is insert to. The
> CreationEditPolicy is then called for creating the childs. If, as in my
> editor, you can add more than one element to that compartment, you have to
> check the type ....
>
> Here a small snippet how i done the positioning:
>
> installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy()
> {
>
> private final int offset = 5;
> protected Command
> getCreateElementAndViewCommand(CreateViewAndElementRequest request) {
> Point cl = figure.getClientArea().getLocation();
> figure.translateToAbsolute(cl);
> if
> ("3009" .equals(request.getViewAndElementDescriptor().getSemanticHin t())) {
> // FieldLabel
> request.setLocation(new Point(cl.x + offset + 10, cl.y + offset + 1));
> } else if
> ("3010" .equals(request.getViewAndElementDescriptor().getSemanticHin t())) {
> // InputField
> request.setLocation(new Point(cl.x + offset + 120, cl.y + offset + 1));
> }
> return super.getCreateElementAndViewCommand(request);
> }
> });
>
> In this case i have taken static values for the position, but i will read
> them from my model.
>
> hth jens
Previous Topic:Generated GMF Property Sheet problem, editor embedded in multipage editor.
Next Topic:Re: Integrating EMF / GMF editors article - comments
Goto Forum:
  


Current Time: Wed Nov 05 17:45:30 EST 2025

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

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

Back to the top