Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Drag child of figure
Drag child of figure [message #232082] Fri, 23 March 2007 09:51 Go to next message
Eclipse UserFriend
Originally posted by: michele.l.evinco.it

Hello,
I've a problem with the drag of a child Figure.

The situation is :

i've a figure that had size like the editor size where there's draw a
map the i drag objects from another view to the mapfigure so i add this
object like childs of mapfigure and the mapfigure is updated.
Now i want change the position of that child with an operation of drag.

The problem is that i can't understand how to manage the dragevent on
that figure.

i've tryed to implement the method getDragTracker on childEditPart and
i have installed an implementation class of XYLayoutEditPolicy on child
EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event never been captured.

What's the best way for implement the drag operation of child figure
written over another ?

Thank's
Michele
Re: Drag child of figure [message #232089 is a reply to message #232082] Fri, 23 March 2007 10:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michele.l.evinco.it

the only way that i find to get the drag event is to implement a
mouseMotionListener on the child figure but it's no good because i want
work with the editPart of figure to get the model to set the new coordinate

is there a better way to do this?

michele wrote:
> Hello,
> I've a problem with the drag of a child Figure.
>
> The situation is :
>
> i've a figure that had size like the editor size where there's draw
> a map the i drag objects from another view to the mapfigure so i add
> this object like childs of mapfigure and the mapfigure is updated.
> Now i want change the position of that child with an operation of drag.
>
> The problem is that i can't understand how to manage the dragevent on
> that figure.
>
> i've tryed to implement the method getDragTracker on childEditPart and
> i have installed an implementation class of XYLayoutEditPolicy on child
> EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event never been captured.
>
> What's the best way for implement the drag operation of child figure
> written over another ?
>
> Thank's
> Michele
Re: Drag child of figure [message #232121 is a reply to message #232089] Fri, 23 March 2007 16:18 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
I'm confused: are you just adding a child figure to the parent, or do you have a
model element for the object that you are placing into the mapfigure? Generally
in GEF, what you would do is update your model to have a new object as a child
of whatever is represented by the mapfigure in your view. Add the new object to
your model, have a separate editpart for that model element (created by your
editpart factory), and refresh the children of the editpart that the mapfigure
is on.

Once you have an editpart for the new object in your model, it can have its own
edit policies for dragging, etc.

Del


> the only way that i find to get the drag event is to implement a
> mouseMotionListener on the child figure but it's no good because i want
> work with the editPart of figure to get the model to set the new coordinate
>
> is there a better way to do this?
>
> michele wrote:
>> Hello,
>> I've a problem with the drag of a child Figure.
>>
>> The situation is :
>>
>> i've a figure that had size like the editor size where there's
>> draw a map the i drag objects from another view to the mapfigure so i
>> add this object like childs of mapfigure and the mapfigure is updated.
>> Now i want change the position of that child with an operation of drag.
>>
>> The problem is that i can't understand how to manage the dragevent on
>> that figure.
>>
>> i've tryed to implement the method getDragTracker on childEditPart and
>> i have installed an implementation class of XYLayoutEditPolicy on
>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event never
>> been captured.
>>
>> What's the best way for implement the drag operation of child figure
>> written over another ?
>>
>> Thank's
>> Michele
Re: Drag child of figure [message #232129 is a reply to message #232121] Fri, 23 March 2007 17:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michele.l.evinco.it

I've a model element and his relative editpart for the object that i'm
placing into the mapfigure.
I've installed an implementation class of XYLayoutEditPolicy on child
EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
But the drag event never been raised.

Del Myers wrote:
> I'm confused: are you just adding a child figure to the parent, or do
> you have a model element for the object that you are placing into the
> mapfigure? Generally in GEF, what you would do is update your model to
> have a new object as a child of whatever is represented by the mapfigure
> in your view. Add the new object to your model, have a separate editpart
> for that model element (created by your editpart factory), and refresh
> the children of the editpart that the mapfigure is on.
>
> Once you have an editpart for the new object in your model, it can have
> its own edit policies for dragging, etc.
>
> Del
>
>
>> the only way that i find to get the drag event is to implement a
>> mouseMotionListener on the child figure but it's no good because i
>> want work with the editPart of figure to get the model to set the new
>> coordinate
>>
>> is there a better way to do this?
>>
>> michele wrote:
>>
>>> Hello,
>>> I've a problem with the drag of a child Figure.
>>>
>>> The situation is :
>>>
>>> i've a figure that had size like the editor size where there's
>>> draw a map the i drag objects from another view to the mapfigure so i
>>> add this object like childs of mapfigure and the mapfigure is updated.
>>> Now i want change the position of that child with an operation of drag.
>>>
>>> The problem is that i can't understand how to manage the dragevent on
>>> that figure.
>>>
>>> i've tryed to implement the method getDragTracker on childEditPart and
>>> i have installed an implementation class of XYLayoutEditPolicy on
>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event never
>>> been captured.
>>>
>>> What's the best way for implement the drag operation of child figure
>>> written over another ?
>>>
>>> Thank's
>>> Michele
Re: Drag child of figure [message #232137 is a reply to message #232129] Fri, 23 March 2007 20:44 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Try something like NonResizableEditPolicy.

The roles don't matter that much. I don't really understand why they are there.
What you need is an edit policy that understands the REQ_MOVE request in the
understandsReuest() method.


michele wrote:
> I've a model element and his relative editpart for the object that i'm
> placing into the mapfigure.
> I've installed an implementation class of XYLayoutEditPolicy on child
> EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
> But the drag event never been raised.
>
> Del Myers wrote:
>> I'm confused: are you just adding a child figure to the parent, or do
>> you have a model element for the object that you are placing into the
>> mapfigure? Generally in GEF, what you would do is update your model to
>> have a new object as a child of whatever is represented by the
>> mapfigure in your view. Add the new object to your model, have a
>> separate editpart for that model element (created by your editpart
>> factory), and refresh the children of the editpart that the mapfigure
>> is on.
>>
>> Once you have an editpart for the new object in your model, it can
>> have its own edit policies for dragging, etc.
>>
>> Del
>>
>>
>>> the only way that i find to get the drag event is to implement a
>>> mouseMotionListener on the child figure but it's no good because i
>>> want work with the editPart of figure to get the model to set the new
>>> coordinate
>>>
>>> is there a better way to do this?
>>>
>>> michele wrote:
>>>
>>>> Hello,
>>>> I've a problem with the drag of a child Figure.
>>>>
>>>> The situation is :
>>>>
>>>> i've a figure that had size like the editor size where there's
>>>> draw a map the i drag objects from another view to the mapfigure so
>>>> i add this object like childs of mapfigure and the mapfigure is
>>>> updated.
>>>> Now i want change the position of that child with an operation of drag.
>>>>
>>>> The problem is that i can't understand how to manage the dragevent
>>>> on that figure.
>>>>
>>>> i've tryed to implement the method getDragTracker on childEditPart and
>>>> i have installed an implementation class of XYLayoutEditPolicy on
>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event never
>>>> been captured.
>>>>
>>>> What's the best way for implement the drag operation of child figure
>>>> written over another ?
>>>>
>>>> Thank's
>>>> Michele
Re: Drag child of figure [message #232201 is a reply to message #232137] Mon, 26 March 2007 14:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michele.l.evinco.it

i've tried with NonResizableEditPolicy installed in childEditPart as
DIRECT_EDIT_ROLE but understandsReuest() never been called.
After i've tried to install NonResizableEditPolicy in mapEditPart and
here the understandsReuest() is called.
So I think that this method works only for editpart directly draw on
rootEditPart!
But I can't find the method for editpart drawn over another editPart
that isn't rooteditpart!

Del Myers wrote:
> Try something like NonResizableEditPolicy.
>
> The roles don't matter that much. I don't really understand why they are
> there. What you need is an edit policy that understands the REQ_MOVE
> request in the understandsReuest() method.
>
>
> michele wrote:
>
>> I've a model element and his relative editpart for the object that i'm
>> placing into the mapfigure.
>> I've installed an implementation class of XYLayoutEditPolicy on child
>> EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
>> But the drag event never been raised.
>>
>> Del Myers wrote:
>>
>>> I'm confused: are you just adding a child figure to the parent, or do
>>> you have a model element for the object that you are placing into the
>>> mapfigure? Generally in GEF, what you would do is update your model
>>> to have a new object as a child of whatever is represented by the
>>> mapfigure in your view. Add the new object to your model, have a
>>> separate editpart for that model element (created by your editpart
>>> factory), and refresh the children of the editpart that the mapfigure
>>> is on.
>>>
>>> Once you have an editpart for the new object in your model, it can
>>> have its own edit policies for dragging, etc.
>>>
>>> Del
>>>
>>>
>>>> the only way that i find to get the drag event is to implement a
>>>> mouseMotionListener on the child figure but it's no good because i
>>>> want work with the editPart of figure to get the model to set the
>>>> new coordinate
>>>>
>>>> is there a better way to do this?
>>>>
>>>> michele wrote:
>>>>
>>>>> Hello,
>>>>> I've a problem with the drag of a child Figure.
>>>>>
>>>>> The situation is :
>>>>>
>>>>> i've a figure that had size like the editor size where there's
>>>>> draw a map the i drag objects from another view to the mapfigure so
>>>>> i add this object like childs of mapfigure and the mapfigure is
>>>>> updated.
>>>>> Now i want change the position of that child with an operation of
>>>>> drag.
>>>>>
>>>>> The problem is that i can't understand how to manage the dragevent
>>>>> on that figure.
>>>>>
>>>>> i've tryed to implement the method getDragTracker on childEditPart and
>>>>> i have installed an implementation class of XYLayoutEditPolicy on
>>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event never
>>>>> been captured.
>>>>>
>>>>> What's the best way for implement the drag operation of child
>>>>> figure written over another ?
>>>>>
>>>>> Thank's
>>>>> Michele
Re: Drag child of figure [message #232223 is a reply to message #232201] Mon, 26 March 2007 17:43 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
It should work for objects not inside the root edit part. Can you post your
editpart factory, and your childEditpart code?


michele wrote:
> i've tried with NonResizableEditPolicy installed in childEditPart as
> DIRECT_EDIT_ROLE but understandsReuest() never been called.
> After i've tried to install NonResizableEditPolicy in mapEditPart and
> here the understandsReuest() is called.
> So I think that this method works only for editpart directly draw on
> rootEditPart!
> But I can't find the method for editpart drawn over another editPart
> that isn't rooteditpart!
>
> Del Myers wrote:
>> Try something like NonResizableEditPolicy.
>>
>> The roles don't matter that much. I don't really understand why they
>> are there. What you need is an edit policy that understands the
>> REQ_MOVE request in the understandsReuest() method.
>>
>>
>> michele wrote:
>>
>>> I've a model element and his relative editpart for the object that
>>> i'm placing into the mapfigure.
>>> I've installed an implementation class of XYLayoutEditPolicy on child
>>> EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
>>> But the drag event never been raised.
>>>
>>> Del Myers wrote:
>>>
>>>> I'm confused: are you just adding a child figure to the parent, or
>>>> do you have a model element for the object that you are placing into
>>>> the mapfigure? Generally in GEF, what you would do is update your
>>>> model to have a new object as a child of whatever is represented by
>>>> the mapfigure in your view. Add the new object to your model, have a
>>>> separate editpart for that model element (created by your editpart
>>>> factory), and refresh the children of the editpart that the
>>>> mapfigure is on.
>>>>
>>>> Once you have an editpart for the new object in your model, it can
>>>> have its own edit policies for dragging, etc.
>>>>
>>>> Del
>>>>
>>>>
>>>>> the only way that i find to get the drag event is to implement a
>>>>> mouseMotionListener on the child figure but it's no good because i
>>>>> want work with the editPart of figure to get the model to set the
>>>>> new coordinate
>>>>>
>>>>> is there a better way to do this?
>>>>>
>>>>> michele wrote:
>>>>>
>>>>>> Hello,
>>>>>> I've a problem with the drag of a child Figure.
>>>>>>
>>>>>> The situation is :
>>>>>>
>>>>>> i've a figure that had size like the editor size where there's
>>>>>> draw a map the i drag objects from another view to the mapfigure
>>>>>> so i add this object like childs of mapfigure and the mapfigure is
>>>>>> updated.
>>>>>> Now i want change the position of that child with an operation of
>>>>>> drag.
>>>>>>
>>>>>> The problem is that i can't understand how to manage the dragevent
>>>>>> on that figure.
>>>>>>
>>>>>> i've tryed to implement the method getDragTracker on childEditPart
>>>>>> and
>>>>>> i have installed an implementation class of XYLayoutEditPolicy on
>>>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event never
>>>>>> been captured.
>>>>>>
>>>>>> What's the best way for implement the drag operation of child
>>>>>> figure written over another ?
>>>>>>
>>>>>> Thank's
>>>>>> Michele
Re: Drag child of figure [message #232252 is a reply to message #232223] Tue, 27 March 2007 08:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michele.l.evinco.it

This is a multi-part message in MIME format.
--------------060508030003060409040702
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

In attachment there's the code .

Del Myers wrote:
> It should work for objects not inside the root edit part. Can you post
> your editpart factory, and your childEditpart code?
>
>
> michele wrote:
>
>> i've tried with NonResizableEditPolicy installed in childEditPart as
>> DIRECT_EDIT_ROLE but understandsReuest() never been called.
>> After i've tried to install NonResizableEditPolicy in mapEditPart and
>> here the understandsReuest() is called.
>> So I think that this method works only for editpart directly draw on
>> rootEditPart!
>> But I can't find the method for editpart drawn over another editPart
>> that isn't rooteditpart!
>>
>> Del Myers wrote:
>>
>>> Try something like NonResizableEditPolicy.
>>>
>>> The roles don't matter that much. I don't really understand why they
>>> are there. What you need is an edit policy that understands the
>>> REQ_MOVE request in the understandsReuest() method.
>>>
>>>
>>> michele wrote:
>>>
>>>> I've a model element and his relative editpart for the object that
>>>> i'm placing into the mapfigure.
>>>> I've installed an implementation class of XYLayoutEditPolicy on
>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
>>>> But the drag event never been raised.
>>>>
>>>> Del Myers wrote:
>>>>
>>>>> I'm confused: are you just adding a child figure to the parent, or
>>>>> do you have a model element for the object that you are placing
>>>>> into the mapfigure? Generally in GEF, what you would do is update
>>>>> your model to have a new object as a child of whatever is
>>>>> represented by the mapfigure in your view. Add the new object to
>>>>> your model, have a separate editpart for that model element
>>>>> (created by your editpart factory), and refresh the children of the
>>>>> editpart that the mapfigure is on.
>>>>>
>>>>> Once you have an editpart for the new object in your model, it can
>>>>> have its own edit policies for dragging, etc.
>>>>>
>>>>> Del
>>>>>
>>>>>
>>>>>> the only way that i find to get the drag event is to implement a
>>>>>> mouseMotionListener on the child figure but it's no good because i
>>>>>> want work with the editPart of figure to get the model to set the
>>>>>> new coordinate
>>>>>>
>>>>>> is there a better way to do this?
>>>>>>
>>>>>> michele wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>> I've a problem with the drag of a child Figure.
>>>>>>>
>>>>>>> The situation is :
>>>>>>>
>>>>>>> i've a figure that had size like the editor size where
>>>>>>> there's draw a map the i drag objects from another view to the
>>>>>>> mapfigure so i add this object like childs of mapfigure and the
>>>>>>> mapfigure is updated.
>>>>>>> Now i want change the position of that child with an operation of
>>>>>>> drag.
>>>>>>>
>>>>>>> The problem is that i can't understand how to manage the
>>>>>>> dragevent on that figure.
>>>>>>>
>>>>>>> i've tryed to implement the method getDragTracker on
>>>>>>> childEditPart and
>>>>>>> i have installed an implementation class of XYLayoutEditPolicy on
>>>>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event
>>>>>>> never been captured.
>>>>>>>
>>>>>>> What's the best way for implement the drag operation of child
>>>>>>> figure written over another ?
>>>>>>>
>>>>>>> Thank's
>>>>>>> Michele


--------------060508030003060409040702
Content-Type: text/plain;
name="CodeExample.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="CodeExample.txt"

This is the EditPartFactory registered to my GraphicaViewer --> viewer.setEditPartFactory(new MapEditPartFactory());

public class MapEditPartFactory implements EditPartFactory {

public EditPart createEditPart(EditPart context, Object model) {


EditPart returnValue = null;
if(model instanceof MapRootElement) {
MapRootEditPart mrep = new MapRootEditPart();
returnValue = mrep;
}else if (model instanceof it.evinco.horusstandalone.views.editor.model.AntennaModel){
try{
returnValue = new it.evinco.horusstandalone.views.editor.parts.AntennaEditPart ();
}catch(Exception e){
e.printStackTrace();
}
returnValue.setModel(model);

}else if (model instanceof it.evinco.horusstandalone.views.editor.model.AmbientiModel){
returnValue = new AmbientiEditPart();
returnValue.setModel(model);
}else{
throw new IllegalArgumentException();
}
returnValue.setModel(model);
return returnValue;
}

}

This is the childEditpart that extends AbstractEditPart that extends AbstractGraphicalEditPart :

public class AntennaEditPart extends AbstractEditPart {


private EditPart parentEditPart = null;

public AntennaEditPart() {
super();

}

@Override
public void configureNode(Node node) {
Rectangle newBounds = getFigure().getBounds();
newBounds.setSize(getFigure().getPreferredSize());
node.width = newBounds.width;
node.height = newBounds.height;
node.data = this;

}

@Override
protected IFigure createFigure() {

IFigure returnValue = null;
AntennaFigure antennaFigure = new AntennaFigure();
return antennaFigure;
}

private AntennaFigure getCastedFigure() {
return (AntennaFigure) getFigure();
}

protected void refreshVisuals() {
super.refreshVisuals();
}

@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new AntennaDragPolicy());
installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,new SelectionFeedbackEditPolicy(1));

}

@Override
protected AntennaModel getCastedModel() {
return (AntennaModel) super.getCastedModel();
}

public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) {
return null;
}

public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
return null;
}

public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) {
return null;
}

public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
return null;
}

public DragTracker getDragTracker(Request req)
{

System.out.println("Called HelloTopEditPart.getDragTracker() with req="+req);

if (m_dragTracker==null) {
m_dragTracker = new DragEditPartsTracker(this);
}
return m_dragTracker;
}

static DragTracker m_dragTracker = null;

}


this is AbstractEditPart :


public abstract class AbstractEditPart extends AbstractGraphicalEditPart implements PropertyChangeListener {

protected Label textLabel;

public void activate() {
if (!isActive()) {
super.activate();
getCastedModel().addPropertyChangeListener(this);
}
}

public void deactivate() {
if (isActive()) {
super.deactivate();
getCastedModel().removePropertyChangeListener(this);
}
}

protected abstract IFigure createFigure();


protected AbstractBaseElement getCastedModel() {
return (AbstractBaseElement) getModel();
}

public void propertyChange(PropertyChangeEvent evt) {
refresh();
}

public abstract void configureNode(Node node);

protected void refreshAllParts() {
refresh(getRoot().getChildren());
getRoot().refresh();
}

private void refresh(List pChildren){
for (Iterator i = pChildren.iterator(); i.hasNext();) {
AbstractEditPart p = (AbstractEditPart) i.next();
p.refresh();
refresh(p.getChildren());
}
}
}

And this is AntennaDragPolicy:

public class AntennaDragPolicy extends NonResizableEditPolicy {

@Override
public boolean understandsRequest(Request arg0) {
System.out.println("understandsRequest");
return super.understandsRequest(arg0);
}

@Override
public Command getCommand(Request arg0) {
System.out.println("getCommand");
return super.getCommand(arg0);
}


}



--------------060508030003060409040702--
Re: Drag child of figure [message #232289 is a reply to message #232252] Tue, 27 March 2007 17:49 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
I imagine that your AmbientiEditPart is the parent for your AntennaEditPart.
Does AmbientiEditPart have an instance of XYLayoutEditPolicy installed on it? If
it does, you should be okay. Just make sure that the command that your
XYLayoutEditPolicy sets the constraints properly. Look for other examples of how
to use it.

Del

michele wrote:
> In attachment there's the code .
>
> Del Myers wrote:
>> It should work for objects not inside the root edit part. Can you post
>> your editpart factory, and your childEditpart code?
>>
>>
>> michele wrote:
>>
>>> i've tried with NonResizableEditPolicy installed in childEditPart as
>>> DIRECT_EDIT_ROLE but understandsReuest() never been called.
>>> After i've tried to install NonResizableEditPolicy in mapEditPart and
>>> here the understandsReuest() is called.
>>> So I think that this method works only for editpart directly draw on
>>> rootEditPart!
>>> But I can't find the method for editpart drawn over another editPart
>>> that isn't rooteditpart!
>>>
>>> Del Myers wrote:
>>>
>>>> Try something like NonResizableEditPolicy.
>>>>
>>>> The roles don't matter that much. I don't really understand why they
>>>> are there. What you need is an edit policy that understands the
>>>> REQ_MOVE request in the understandsReuest() method.
>>>>
>>>>
>>>> michele wrote:
>>>>
>>>>> I've a model element and his relative editpart for the object that
>>>>> i'm placing into the mapfigure.
>>>>> I've installed an implementation class of XYLayoutEditPolicy on
>>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
>>>>> But the drag event never been raised.
>>>>>
>>>>> Del Myers wrote:
>>>>>
>>>>>> I'm confused: are you just adding a child figure to the parent, or
>>>>>> do you have a model element for the object that you are placing
>>>>>> into the mapfigure? Generally in GEF, what you would do is update
>>>>>> your model to have a new object as a child of whatever is
>>>>>> represented by the mapfigure in your view. Add the new object to
>>>>>> your model, have a separate editpart for that model element
>>>>>> (created by your editpart factory), and refresh the children of
>>>>>> the editpart that the mapfigure is on.
>>>>>>
>>>>>> Once you have an editpart for the new object in your model, it can
>>>>>> have its own edit policies for dragging, etc.
>>>>>>
>>>>>> Del
>>>>>>
>>>>>>
>>>>>>> the only way that i find to get the drag event is to implement a
>>>>>>> mouseMotionListener on the child figure but it's no good because
>>>>>>> i want work with the editPart of figure to get the model to set
>>>>>>> the new coordinate
>>>>>>>
>>>>>>> is there a better way to do this?
>>>>>>>
>>>>>>> michele wrote:
>>>>>>>
>>>>>>>> Hello,
>>>>>>>> I've a problem with the drag of a child Figure.
>>>>>>>>
>>>>>>>> The situation is :
>>>>>>>>
>>>>>>>> i've a figure that had size like the editor size where
>>>>>>>> there's draw a map the i drag objects from another view to the
>>>>>>>> mapfigure so i add this object like childs of mapfigure and the
>>>>>>>> mapfigure is updated.
>>>>>>>> Now i want change the position of that child with an operation
>>>>>>>> of drag.
>>>>>>>>
>>>>>>>> The problem is that i can't understand how to manage the
>>>>>>>> dragevent on that figure.
>>>>>>>>
>>>>>>>> i've tryed to implement the method getDragTracker on
>>>>>>>> childEditPart and
>>>>>>>> i have installed an implementation class of XYLayoutEditPolicy
>>>>>>>> on child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event
>>>>>>>> never been captured.
>>>>>>>>
>>>>>>>> What's the best way for implement the drag operation of child
>>>>>>>> figure written over another ?
>>>>>>>>
>>>>>>>> Thank's
>>>>>>>> Michele
>
>
> ------------------------------------------------------------ ------------
>
> This is the EditPartFactory registered to my GraphicaViewer --> viewer.setEditPartFactory(new MapEditPartFactory());
>
> public class MapEditPartFactory implements EditPartFactory {
>
> public EditPart createEditPart(EditPart context, Object model) {
>
>
> EditPart returnValue = null;
> if(model instanceof MapRootElement) {
> MapRootEditPart mrep = new MapRootEditPart();
> returnValue = mrep;
> }else if (model instanceof it.evinco.horusstandalone.views.editor.model.AntennaModel){
> try{
> returnValue = new it.evinco.horusstandalone.views.editor.parts.AntennaEditPart ();
> }catch(Exception e){
> e.printStackTrace();
> }
> returnValue.setModel(model);
>
> }else if (model instanceof it.evinco.horusstandalone.views.editor.model.AmbientiModel){
> returnValue = new AmbientiEditPart();
> returnValue.setModel(model);
> }else{
> throw new IllegalArgumentException();
> }
> returnValue.setModel(model);
> return returnValue;
> }
>
> }
>
> This is the childEditpart that extends AbstractEditPart that extends AbstractGraphicalEditPart :
>
> public class AntennaEditPart extends AbstractEditPart {
>
>
> private EditPart parentEditPart = null;
>
> public AntennaEditPart() {
> super();
>
> }
>
> @Override
> public void configureNode(Node node) {
> Rectangle newBounds = getFigure().getBounds();
> newBounds.setSize(getFigure().getPreferredSize());
> node.width = newBounds.width;
> node.height = newBounds.height;
> node.data = this;
>
> }
>
> @Override
> protected IFigure createFigure() {
>
> IFigure returnValue = null;
> AntennaFigure antennaFigure = new AntennaFigure();
> return antennaFigure;
> }
>
> private AntennaFigure getCastedFigure() {
> return (AntennaFigure) getFigure();
> }
>
> protected void refreshVisuals() {
> super.refreshVisuals();
> }
>
> @Override
> protected void createEditPolicies() {
> installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new AntennaDragPolicy());
> installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,new SelectionFeedbackEditPolicy(1));
>
> }
>
> @Override
> protected AntennaModel getCastedModel() {
> return (AntennaModel) super.getCastedModel();
> }
>
> public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) {
> return null;
> }
>
> public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
> return null;
> }
>
> public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) {
> return null;
> }
>
> public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
> return null;
> }
>
> public DragTracker getDragTracker(Request req)
> {
>
> System.out.println("Called HelloTopEditPart.getDragTracker() with req="+req);
>
> if (m_dragTracker==null) {
> m_dragTracker = new DragEditPartsTracker(this);
> }
> return m_dragTracker;
> }
>
> static DragTracker m_dragTracker = null;
>
> }
>
>
> this is AbstractEditPart :
>
>
> public abstract class AbstractEditPart extends AbstractGraphicalEditPart implements PropertyChangeListener {
>
> protected Label textLabel;
>
> public void activate() {
> if (!isActive()) {
> super.activate();
> getCastedModel().addPropertyChangeListener(this);
> }
> }
>
> public void deactivate() {
> if (isActive()) {
> super.deactivate();
> getCastedModel().removePropertyChangeListener(this);
> }
> }
>
> protected abstract IFigure createFigure();
>
>
> protected AbstractBaseElement getCastedModel() {
> return (AbstractBaseElement) getModel();
> }
>
> public void propertyChange(PropertyChangeEvent evt) {
> refresh();
> }
>
> public abstract void configureNode(Node node);
>
> protected void refreshAllParts() {
> refresh(getRoot().getChildren());
> getRoot().refresh();
> }
>
> private void refresh(List pChildren){
> for (Iterator i = pChildren.iterator(); i.hasNext();) {
> AbstractEditPart p = (AbstractEditPart) i.next();
> p.refresh();
> refresh(p.getChildren());
> }
> }
> }
>
> And this is AntennaDragPolicy:
>
> public class AntennaDragPolicy extends NonResizableEditPolicy {
>
> @Override
> public boolean understandsRequest(Request arg0) {
> System.out.println("understandsRequest");
> return super.understandsRequest(arg0);
> }
>
> @Override
> public Command getCommand(Request arg0) {
> System.out.println("getCommand");
> return super.getCommand(arg0);
> }
>
>
> }
>
>
Re: Drag child of figure [message #232312 is a reply to message #232289] Wed, 28 March 2007 09:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michele.l.evinco.it

I've still try this solution but it isn't ok for me.
if i install myXYLayoutPolicy on AmbientiEditPart i intercept all events
of mousedown and drag on the AmbientiFigure and i can't find the
childFigure (AntennaFigure) and her EditPart on the request.
This is bad for me because i want move the figure of "AntennaFigure" and
register her new position in her model so i must install a policy on
AntennaEditPart to obtain, on the event the relative EditPart by the
function getHost().
If I do that, install a policy on AntennaEditPart (the childEditPart),
the events never fired so the policy is never been called.
So i think that isn't possible with GEF to move a figure that is drawn
on a parent figure by a drag operation, or more probabily i can't
understand how to do this.

this is the way i draw the childFigure (AntennaFigure) on the
refreshVisuals method of AmbientiEditPart :

protected void refreshVisuals() {

Iterator it = getModelChildren().iterator();

while (it.hasNext()){

AntennaModel am = (AntennaModel)it.next();
AntennaEditPart aep = new AntennaEditPart();
AntennaFigure antennaFigure = (AntennaFigure)aep.createFigure();
getFigure().add(antennaFigure,new
Rectangle(am.getLocation().x,am.getLocation().y,16,16));

}

}


Del Myers wrote:
> I imagine that your AmbientiEditPart is the parent for your
> AntennaEditPart. Does AmbientiEditPart have an instance of
> XYLayoutEditPolicy installed on it? If it does, you should be okay. Just
> make sure that the command that your XYLayoutEditPolicy sets the
> constraints properly. Look for other examples of how to use it.
>
> Del
>
> michele wrote:
>
>> In attachment there's the code .
>>
>> Del Myers wrote:
>>
>>> It should work for objects not inside the root edit part. Can you
>>> post your editpart factory, and your childEditpart code?
>>>
>>>
>>> michele wrote:
>>>
>>>> i've tried with NonResizableEditPolicy installed in childEditPart as
>>>> DIRECT_EDIT_ROLE but understandsReuest() never been called.
>>>> After i've tried to install NonResizableEditPolicy in mapEditPart
>>>> and here the understandsReuest() is called.
>>>> So I think that this method works only for editpart directly draw on
>>>> rootEditPart!
>>>> But I can't find the method for editpart drawn over another editPart
>>>> that isn't rooteditpart!
>>>>
>>>> Del Myers wrote:
>>>>
>>>>> Try something like NonResizableEditPolicy.
>>>>>
>>>>> The roles don't matter that much. I don't really understand why
>>>>> they are there. What you need is an edit policy that understands
>>>>> the REQ_MOVE request in the understandsReuest() method.
>>>>>
>>>>>
>>>>> michele wrote:
>>>>>
>>>>>> I've a model element and his relative editpart for the object that
>>>>>> i'm placing into the mapfigure.
>>>>>> I've installed an implementation class of XYLayoutEditPolicy on
>>>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
>>>>>> But the drag event never been raised.
>>>>>>
>>>>>> Del Myers wrote:
>>>>>>
>>>>>>> I'm confused: are you just adding a child figure to the parent,
>>>>>>> or do you have a model element for the object that you are
>>>>>>> placing into the mapfigure? Generally in GEF, what you would do
>>>>>>> is update your model to have a new object as a child of whatever
>>>>>>> is represented by the mapfigure in your view. Add the new object
>>>>>>> to your model, have a separate editpart for that model element
>>>>>>> (created by your editpart factory), and refresh the children of
>>>>>>> the editpart that the mapfigure is on.
>>>>>>>
>>>>>>> Once you have an editpart for the new object in your model, it
>>>>>>> can have its own edit policies for dragging, etc.
>>>>>>>
>>>>>>> Del
>>>>>>>
>>>>>>>
>>>>>>>> the only way that i find to get the drag event is to implement a
>>>>>>>> mouseMotionListener on the child figure but it's no good because
>>>>>>>> i want work with the editPart of figure to get the model to set
>>>>>>>> the new coordinate
>>>>>>>>
>>>>>>>> is there a better way to do this?
>>>>>>>>
>>>>>>>> michele wrote:
>>>>>>>>
>>>>>>>>> Hello,
>>>>>>>>> I've a problem with the drag of a child Figure.
>>>>>>>>>
>>>>>>>>> The situation is :
>>>>>>>>>
>>>>>>>>> i've a figure that had size like the editor size where
>>>>>>>>> there's draw a map the i drag objects from another view to the
>>>>>>>>> mapfigure so i add this object like childs of mapfigure and the
>>>>>>>>> mapfigure is updated.
>>>>>>>>> Now i want change the position of that child with an operation
>>>>>>>>> of drag.
>>>>>>>>>
>>>>>>>>> The problem is that i can't understand how to manage the
>>>>>>>>> dragevent on that figure.
>>>>>>>>>
>>>>>>>>> i've tryed to implement the method getDragTracker on
>>>>>>>>> childEditPart and
>>>>>>>>> i have installed an implementation class of XYLayoutEditPolicy
>>>>>>>>> on child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the event
>>>>>>>>> never been captured.
>>>>>>>>>
>>>>>>>>> What's the best way for implement the drag operation of child
>>>>>>>>> figure written over another ?
>>>>>>>>>
>>>>>>>>> Thank's
>>>>>>>>> Michele
>>
>>
>>
>> ------------------------------------------------------------ ------------
>>
>> This is the EditPartFactory registered to my GraphicaViewer -->
>> viewer.setEditPartFactory(new MapEditPartFactory());
>>
>> public class MapEditPartFactory implements EditPartFactory {
>>
>> public EditPart createEditPart(EditPart context, Object model) {
>>
>> EditPart returnValue = null; if(model
>> instanceof MapRootElement) {
>> MapRootEditPart mrep = new MapRootEditPart();
>> returnValue = mrep;
>> }else if (model instanceof
>> it.evinco.horusstandalone.views.editor.model.AntennaModel){
>> try{
>> returnValue = new
>> it.evinco.horusstandalone.views.editor.parts.AntennaEditPart ();
>> }catch(Exception e){
>> e.printStackTrace();
>> }
>> returnValue.setModel(model);
>>
>> }else if (model instanceof
>> it.evinco.horusstandalone.views.editor.model.AmbientiModel){
>> returnValue = new AmbientiEditPart();
>> returnValue.setModel(model); }else{
>> throw new IllegalArgumentException();
>> }
>> returnValue.setModel(model);
>> return returnValue;
>> }
>> }
>>
>> This is the childEditpart that extends AbstractEditPart that extends
>> AbstractGraphicalEditPart :
>> public class AntennaEditPart extends AbstractEditPart {
>>
>>
>> private EditPart parentEditPart = null;
>> public AntennaEditPart() {
>> super();
>>
>> } @Override
>> public void configureNode(Node node) {
>> Rectangle newBounds = getFigure().getBounds();
>> newBounds.setSize(getFigure().getPreferredSize());
>> node.width = newBounds.width;
>> node.height = newBounds.height;
>> node.data = this;
>> }
>>
>> @Override
>> protected IFigure createFigure() {
>>
>> IFigure returnValue = null; AntennaFigure
>> antennaFigure = new AntennaFigure();
>> return antennaFigure;
>> }
>> private AntennaFigure getCastedFigure() {
>> return (AntennaFigure) getFigure();
>> }
>> protected void refreshVisuals() {
>> super.refreshVisuals();
>> }
>> @Override
>> protected void createEditPolicies() {
>> installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new
>> AntennaDragPolicy());
>> installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,new
>> SelectionFeedbackEditPolicy(1));
>> }
>> @Override
>> protected AntennaModel getCastedModel() {
>> return (AntennaModel) super.getCastedModel();
>> }
>>
>> public ConnectionAnchor
>> getSourceConnectionAnchor(ConnectionEditPart arg0) {
>> return null;
>> }
>>
>> public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
>> return null;
>> }
>>
>> public ConnectionAnchor
>> getTargetConnectionAnchor(ConnectionEditPart arg0) {
>> return null;
>> }
>>
>> public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
>> return null;
>> }
>>
>> public DragTracker getDragTracker(Request req)
>> {
>>
>> System.out.println("Called HelloTopEditPart.getDragTracker()
>> with req="+req);
>>
>> if (m_dragTracker==null) {
>> m_dragTracker = new DragEditPartsTracker(this);
>> }
>> return m_dragTracker;
>> }
>> static DragTracker m_dragTracker = null;
>> }
>>
>>
>> this is AbstractEditPart :
>>
>>
>> public abstract class AbstractEditPart extends
>> AbstractGraphicalEditPart implements PropertyChangeListener {
>>
>> protected Label textLabel;
>> public void activate() {
>> if (!isActive()) {
>> super.activate();
>>
>> getCastedModel().addPropertyChangeListener(this); }
>> }
>> public void deactivate() {
>> if (isActive()) {
>> super.deactivate();
>> getCastedModel().removePropertyChangeListener(this);
>> }
>> }
>> protected abstract IFigure createFigure();
>> protected AbstractBaseElement getCastedModel() {
>> return (AbstractBaseElement) getModel();
>> }
>> public void propertyChange(PropertyChangeEvent evt) {
>> refresh();
>> }
>> public abstract void configureNode(Node node);
>> protected void refreshAllParts() {
>> refresh(getRoot().getChildren());
>> getRoot().refresh();
>> }
>> private void refresh(List pChildren){
>> for (Iterator i = pChildren.iterator(); i.hasNext();) {
>> AbstractEditPart p = (AbstractEditPart) i.next();
>> p.refresh();
>> refresh(p.getChildren());
>> }
>> }
>> }
>>
>> And this is AntennaDragPolicy:
>>
>> public class AntennaDragPolicy extends NonResizableEditPolicy {
>>
>> @Override
>> public boolean understandsRequest(Request arg0) {
>> System.out.println("understandsRequest");
>> return super.understandsRequest(arg0);
>> }
>>
>> @Override
>> public Command getCommand(Request arg0) {
>> System.out.println("getCommand");
>> return super.getCommand(arg0);
>> }
>>
>>
>> }
>>
>>
Re: Drag child of figure [message #232345 is a reply to message #232312] Wed, 28 March 2007 16:28 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
It is definitely possible to do; I do it all the time.

Your problem here is that you are trying to move figures around inside the
refreshVisuals of the parent, rather than setting constraints on the children.
The refreshVisuals() of your AmbientiEditPart should have nothing to do with
that. What is probably happening here is that you are setting the bounds of a
figure, but you also have an XYLayout on the parent, which lays-out the children
based on rectangle constraints on the figure.

Also, your edit parts shouldn't be added to the parents within any code that you
write in your edit part. That is the job of the factories. What you should be
doing is listening for additions/subtractions of children in your model, and
calling refresh() on you AmbientiEditPart whenever these kinds of changes
happen. This will cause all of the edit parts to be added/subtracted to/from the
hierarchy and be activated, added to the required maps, etc. If you don't let
GEF take care of that, your child edit parts will never get any notifications
because GEF doesn't know about their existence. Typically, your model should
follow a publisher/subscriber pattern. In the activate() method of your
AmbientiEditPart, you would subscribe your AmbientiEditPart as a listener to
your AmbientiModel. When additions/subtractions of AntennaModel elements happen,
you would call refresh() on AmbientiEditPart.


Your AntennaEditPart, then, would do the same sort of thing, except it would
listen to changes in location (for when drag events occur). When you discover
changes in location in your AntennaModel, you call refreshVisuals() in
AntennaEditPart. Your refreshVisuals() would do something like this:

refreshVisuals() {
AntennaModel model = (AntennaModel)getModel();
IFigure figure = getFigure();
Rectangle rect = new Rectangle(model.getLocation().x, model.getLocation().y,
16, 16).
getParent().setLayoutConstraint(this, figure, rect);
}

This assumes that you have an instance of XYLayout as your layout manager in the
figure for your AmbientiEditPart.

You should look over some of the examples that come with GEF. It can be hard to
understand at first because it isn't well documented. There are a lot of little
methods that you won't know about unless you stumble across them. They typically
do everything that you want, but you just don't know about them. Looking over
the examples again will probably help you to find all of that stuff.

I hope this helps.

Del

michele wrote:
> I've still try this solution but it isn't ok for me.
> if i install myXYLayoutPolicy on AmbientiEditPart i intercept all events
> of mousedown and drag on the AmbientiFigure and i can't find the
> childFigure (AntennaFigure) and her EditPart on the request.
> This is bad for me because i want move the figure of "AntennaFigure" and
> register her new position in her model so i must install a policy on
> AntennaEditPart to obtain, on the event the relative EditPart by the
> function getHost().
> If I do that, install a policy on AntennaEditPart (the childEditPart),
> the events never fired so the policy is never been called.
> So i think that isn't possible with GEF to move a figure that is drawn
> on a parent figure by a drag operation, or more probabily i can't
> understand how to do this.
>
> this is the way i draw the childFigure (AntennaFigure) on the
> refreshVisuals method of AmbientiEditPart :
>
> protected void refreshVisuals() {
>
> Iterator it = getModelChildren().iterator();
>
> while (it.hasNext()){
>
> AntennaModel am = (AntennaModel)it.next();
> AntennaEditPart aep = new AntennaEditPart();
> AntennaFigure antennaFigure =
> (AntennaFigure)aep.createFigure();
> getFigure().add(antennaFigure,new
> Rectangle(am.getLocation().x,am.getLocation().y,16,16));
>
> }
>
> }
>
>
> Del Myers wrote:
>> I imagine that your AmbientiEditPart is the parent for your
>> AntennaEditPart. Does AmbientiEditPart have an instance of
>> XYLayoutEditPolicy installed on it? If it does, you should be okay.
>> Just make sure that the command that your XYLayoutEditPolicy sets the
>> constraints properly. Look for other examples of how to use it.
>>
>> Del
>>
>> michele wrote:
>>
>>> In attachment there's the code .
>>>
>>> Del Myers wrote:
>>>
>>>> It should work for objects not inside the root edit part. Can you
>>>> post your editpart factory, and your childEditpart code?
>>>>
>>>>
>>>> michele wrote:
>>>>
>>>>> i've tried with NonResizableEditPolicy installed in childEditPart
>>>>> as DIRECT_EDIT_ROLE but understandsReuest() never been called.
>>>>> After i've tried to install NonResizableEditPolicy in mapEditPart
>>>>> and here the understandsReuest() is called.
>>>>> So I think that this method works only for editpart directly draw
>>>>> on rootEditPart!
>>>>> But I can't find the method for editpart drawn over another
>>>>> editPart that isn't rooteditpart!
>>>>>
>>>>> Del Myers wrote:
>>>>>
>>>>>> Try something like NonResizableEditPolicy.
>>>>>>
>>>>>> The roles don't matter that much. I don't really understand why
>>>>>> they are there. What you need is an edit policy that understands
>>>>>> the REQ_MOVE request in the understandsReuest() method.
>>>>>>
>>>>>>
>>>>>> michele wrote:
>>>>>>
>>>>>>> I've a model element and his relative editpart for the object
>>>>>>> that i'm placing into the mapfigure.
>>>>>>> I've installed an implementation class of XYLayoutEditPolicy on
>>>>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
>>>>>>> But the drag event never been raised.
>>>>>>>
>>>>>>> Del Myers wrote:
>>>>>>>
>>>>>>>> I'm confused: are you just adding a child figure to the parent,
>>>>>>>> or do you have a model element for the object that you are
>>>>>>>> placing into the mapfigure? Generally in GEF, what you would do
>>>>>>>> is update your model to have a new object as a child of whatever
>>>>>>>> is represented by the mapfigure in your view. Add the new object
>>>>>>>> to your model, have a separate editpart for that model element
>>>>>>>> (created by your editpart factory), and refresh the children of
>>>>>>>> the editpart that the mapfigure is on.
>>>>>>>>
>>>>>>>> Once you have an editpart for the new object in your model, it
>>>>>>>> can have its own edit policies for dragging, etc.
>>>>>>>>
>>>>>>>> Del
>>>>>>>>
>>>>>>>>
>>>>>>>>> the only way that i find to get the drag event is to implement
>>>>>>>>> a mouseMotionListener on the child figure but it's no good
>>>>>>>>> because i want work with the editPart of figure to get the
>>>>>>>>> model to set the new coordinate
>>>>>>>>>
>>>>>>>>> is there a better way to do this?
>>>>>>>>>
>>>>>>>>> michele wrote:
>>>>>>>>>
>>>>>>>>>> Hello,
>>>>>>>>>> I've a problem with the drag of a child Figure.
>>>>>>>>>>
>>>>>>>>>> The situation is :
>>>>>>>>>>
>>>>>>>>>> i've a figure that had size like the editor size where
>>>>>>>>>> there's draw a map the i drag objects from another view to the
>>>>>>>>>> mapfigure so i add this object like childs of mapfigure and
>>>>>>>>>> the mapfigure is updated.
>>>>>>>>>> Now i want change the position of that child with an operation
>>>>>>>>>> of drag.
>>>>>>>>>>
>>>>>>>>>> The problem is that i can't understand how to manage the
>>>>>>>>>> dragevent on that figure.
>>>>>>>>>>
>>>>>>>>>> i've tryed to implement the method getDragTracker on
>>>>>>>>>> childEditPart and
>>>>>>>>>> i have installed an implementation class of XYLayoutEditPolicy
>>>>>>>>>> on child EditPart as EditPolicy.PRIMARY_DRAG_ROLE but the
>>>>>>>>>> event never been captured.
>>>>>>>>>>
>>>>>>>>>> What's the best way for implement the drag operation of child
>>>>>>>>>> figure written over another ?
>>>>>>>>>>
>>>>>>>>>> Thank's
>>>>>>>>>> Michele
>>>
>>>
>>>
>>> ------------------------------------------------------------ ------------
>>>
>>> This is the EditPartFactory registered to my GraphicaViewer -->
>>> viewer.setEditPartFactory(new MapEditPartFactory());
>>>
>>> public class MapEditPartFactory implements EditPartFactory {
>>>
>>> public EditPart createEditPart(EditPart context, Object model) {
>>> EditPart returnValue = null;
>>> if(model instanceof MapRootElement) {
>>> MapRootEditPart mrep = new MapRootEditPart();
>>> returnValue = mrep;
>>> }else if (model instanceof
>>> it.evinco.horusstandalone.views.editor.model.AntennaModel){
>>> try{ returnValue = new
>>> it.evinco.horusstandalone.views.editor.parts.AntennaEditPart ();
>>> }catch(Exception e){
>>> e.printStackTrace();
>>> }
>>> returnValue.setModel(model);
>>> }else if (model instanceof
>>> it.evinco.horusstandalone.views.editor.model.AmbientiModel){
>>> returnValue = new AmbientiEditPart();
>>> returnValue.setModel(model); }else{
>>> throw new IllegalArgumentException();
>>> }
>>> returnValue.setModel(model);
>>> return returnValue;
>>> }
>>> }
>>>
>>> This is the childEditpart that extends AbstractEditPart that extends
>>> AbstractGraphicalEditPart :
>>> public class AntennaEditPart extends AbstractEditPart {
>>>
>>> private EditPart parentEditPart = null; public
>>> AntennaEditPart() {
>>> super();
>>> } @Override
>>> public void configureNode(Node node) {
>>> Rectangle newBounds = getFigure().getBounds();
>>> newBounds.setSize(getFigure().getPreferredSize());
>>> node.width = newBounds.width;
>>> node.height = newBounds.height;
>>> node.data = this;
>>> }
>>>
>>> @Override
>>> protected IFigure createFigure() {
>>> IFigure returnValue = null; AntennaFigure
>>> antennaFigure = new AntennaFigure();
>>> return antennaFigure;
>>> }
>>> private AntennaFigure getCastedFigure() {
>>> return (AntennaFigure) getFigure();
>>> }
>>> protected void refreshVisuals() {
>>> super.refreshVisuals();
>>> }
>>> @Override
>>> protected void createEditPolicies() {
>>> installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new
>>> AntennaDragPolicy());
>>> installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,new
>>> SelectionFeedbackEditPolicy(1));
>>> }
>>> @Override
>>> protected AntennaModel getCastedModel() {
>>> return (AntennaModel) super.getCastedModel();
>>> }
>>>
>>> public ConnectionAnchor
>>> getSourceConnectionAnchor(ConnectionEditPart arg0) {
>>> return null;
>>> }
>>>
>>> public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
>>> return null;
>>> }
>>>
>>> public ConnectionAnchor
>>> getTargetConnectionAnchor(ConnectionEditPart arg0) {
>>> return null;
>>> }
>>>
>>> public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
>>> return null;
>>> }
>>> public DragTracker getDragTracker(Request req)
>>> {
>>> System.out.println("Called
>>> HelloTopEditPart.getDragTracker() with req="+req);
>>>
>>> if (m_dragTracker==null) {
>>> m_dragTracker = new DragEditPartsTracker(this);
>>> }
>>> return m_dragTracker;
>>> }
>>> static DragTracker m_dragTracker = null;
>>> }
>>>
>>>
>>> this is AbstractEditPart :
>>>
>>>
>>> public abstract class AbstractEditPart extends
>>> AbstractGraphicalEditPart implements PropertyChangeListener {
>>>
>>> protected Label textLabel;
>>> public void activate() {
>>> if (!isActive()) {
>>> super.activate();
>>>
>>> getCastedModel().addPropertyChangeListener(this); }
>>> }
>>> public void deactivate() {
>>> if (isActive()) {
>>> super.deactivate();
>>> getCastedModel().removePropertyChangeListener(this);
>>> }
>>> }
>>> protected abstract IFigure createFigure();
>>> protected AbstractBaseElement getCastedModel() {
>>> return (AbstractBaseElement) getModel();
>>> }
>>> public void propertyChange(PropertyChangeEvent evt) {
>>> refresh();
>>> }
>>> public abstract void configureNode(Node node);
>>> protected void refreshAllParts() {
>>> refresh(getRoot().getChildren());
>>> getRoot().refresh();
>>> }
>>> private void refresh(List pChildren){
>>> for (Iterator i = pChildren.iterator(); i.hasNext();) {
>>> AbstractEditPart p = (AbstractEditPart) i.next();
>>> p.refresh();
>>> refresh(p.getChildren());
>>> }
>>> }
>>> }
>>>
>>> And this is AntennaDragPolicy:
>>>
>>> public class AntennaDragPolicy extends NonResizableEditPolicy {
>>>
>>> @Override
>>> public boolean understandsRequest(Request arg0) {
>>> System.out.println("understandsRequest");
>>> return super.understandsRequest(arg0);
>>> }
>>>
>>> @Override
>>> public Command getCommand(Request arg0) {
>>> System.out.println("getCommand");
>>> return super.getCommand(arg0);
>>> }
>>>
>>>
>>> }
>>>
>>>
Re: Drag child of figure [message #232438 is a reply to message #232345] Fri, 30 March 2007 10:42 Go to previous message
Eclipse UserFriend
Originally posted by: michele.l.evinco.it

Thank's Del, now it works.
The drag events are routed to AntennaEditPart.
thank's for you patience and your suggestions

Del Myers wrote:
> It is definitely possible to do; I do it all the time.
>
> Your problem here is that you are trying to move figures around inside
> the refreshVisuals of the parent, rather than setting constraints on the
> children. The refreshVisuals() of your AmbientiEditPart should have
> nothing to do with that. What is probably happening here is that you are
> setting the bounds of a figure, but you also have an XYLayout on the
> parent, which lays-out the children based on rectangle constraints on
> the figure.
>
> Also, your edit parts shouldn't be added to the parents within any code
> that you write in your edit part. That is the job of the factories. What
> you should be doing is listening for additions/subtractions of children
> in your model, and calling refresh() on you AmbientiEditPart whenever
> these kinds of changes happen. This will cause all of the edit parts to
> be added/subtracted to/from the hierarchy and be activated, added to the
> required maps, etc. If you don't let GEF take care of that, your child
> edit parts will never get any notifications because GEF doesn't know
> about their existence. Typically, your model should follow a
> publisher/subscriber pattern. In the activate() method of your
> AmbientiEditPart, you would subscribe your AmbientiEditPart as a
> listener to your AmbientiModel. When additions/subtractions of
> AntennaModel elements happen, you would call refresh() on AmbientiEditPart.
>
>
> Your AntennaEditPart, then, would do the same sort of thing, except it
> would listen to changes in location (for when drag events occur). When
> you discover changes in location in your AntennaModel, you call
> refreshVisuals() in AntennaEditPart. Your refreshVisuals() would do
> something like this:
>
> refreshVisuals() {
> AntennaModel model = (AntennaModel)getModel();
> IFigure figure = getFigure();
> Rectangle rect = new Rectangle(model.getLocation().x,
> model.getLocation().y, 16, 16).
> getParent().setLayoutConstraint(this, figure, rect);
> }
>
> This assumes that you have an instance of XYLayout as your layout
> manager in the figure for your AmbientiEditPart.
>
> You should look over some of the examples that come with GEF. It can be
> hard to understand at first because it isn't well documented. There are
> a lot of little methods that you won't know about unless you stumble
> across them. They typically do everything that you want, but you just
> don't know about them. Looking over the examples again will probably
> help you to find all of that stuff.
>
> I hope this helps.
>
> Del
>
> michele wrote:
>
>> I've still try this solution but it isn't ok for me.
>> if i install myXYLayoutPolicy on AmbientiEditPart i intercept all
>> events of mousedown and drag on the AmbientiFigure and i can't find
>> the childFigure (AntennaFigure) and her EditPart on the request.
>> This is bad for me because i want move the figure of "AntennaFigure"
>> and register her new position in her model so i must install a policy
>> on AntennaEditPart to obtain, on the event the relative EditPart by
>> the function getHost().
>> If I do that, install a policy on AntennaEditPart (the childEditPart),
>> the events never fired so the policy is never been called.
>> So i think that isn't possible with GEF to move a figure that is drawn
>> on a parent figure by a drag operation, or more probabily i can't
>> understand how to do this.
>>
>> this is the way i draw the childFigure (AntennaFigure) on the
>> refreshVisuals method of AmbientiEditPart :
>>
>> protected void refreshVisuals() {
>> Iterator it = getModelChildren().iterator();
>> while (it.hasNext()){
>> AntennaModel am = (AntennaModel)it.next();
>> AntennaEditPart aep = new AntennaEditPart();
>> AntennaFigure antennaFigure =
>> (AntennaFigure)aep.createFigure();
>> getFigure().add(antennaFigure,new
>> Rectangle(am.getLocation().x,am.getLocation().y,16,16));
>> }
>> }
>>
>>
>> Del Myers wrote:
>>
>>> I imagine that your AmbientiEditPart is the parent for your
>>> AntennaEditPart. Does AmbientiEditPart have an instance of
>>> XYLayoutEditPolicy installed on it? If it does, you should be okay.
>>> Just make sure that the command that your XYLayoutEditPolicy sets the
>>> constraints properly. Look for other examples of how to use it.
>>>
>>> Del
>>>
>>> michele wrote:
>>>
>>>> In attachment there's the code .
>>>>
>>>> Del Myers wrote:
>>>>
>>>>> It should work for objects not inside the root edit part. Can you
>>>>> post your editpart factory, and your childEditpart code?
>>>>>
>>>>>
>>>>> michele wrote:
>>>>>
>>>>>> i've tried with NonResizableEditPolicy installed in childEditPart
>>>>>> as DIRECT_EDIT_ROLE but understandsReuest() never been called.
>>>>>> After i've tried to install NonResizableEditPolicy in mapEditPart
>>>>>> and here the understandsReuest() is called.
>>>>>> So I think that this method works only for editpart directly draw
>>>>>> on rootEditPart!
>>>>>> But I can't find the method for editpart drawn over another
>>>>>> editPart that isn't rooteditpart!
>>>>>>
>>>>>> Del Myers wrote:
>>>>>>
>>>>>>> Try something like NonResizableEditPolicy.
>>>>>>>
>>>>>>> The roles don't matter that much. I don't really understand why
>>>>>>> they are there. What you need is an edit policy that understands
>>>>>>> the REQ_MOVE request in the understandsReuest() method.
>>>>>>>
>>>>>>>
>>>>>>> michele wrote:
>>>>>>>
>>>>>>>> I've a model element and his relative editpart for the object
>>>>>>>> that i'm placing into the mapfigure.
>>>>>>>> I've installed an implementation class of XYLayoutEditPolicy on
>>>>>>>> child EditPart as EditPolicy.PRIMARY_DRAG_ROLE.
>>>>>>>> But the drag event never been raised.
>>>>>>>>
>>>>>>>> Del Myers wrote:
>>>>>>>>
>>>>>>>>> I'm confused: are you just adding a child figure to the parent,
>>>>>>>>> or do you have a model element for the object that you are
>>>>>>>>> placing into the mapfigure? Generally in GEF, what you would do
>>>>>>>>> is update your model to have a new object as a child of
>>>>>>>>> whatever is represented by the mapfigure in your view. Add the
>>>>>>>>> new object to your model, have a separate editpart for that
>>>>>>>>> model element (created by your editpart factory), and refresh
>>>>>>>>> the children of the editpart that the mapfigure is on.
>>>>>>>>>
>>>>>>>>> Once you have an editpart for the new object in your model, it
>>>>>>>>> can have its own edit policies for dragging, etc.
>>>>>>>>>
>>>>>>>>> Del
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> the only way that i find to get the drag event is to implement
>>>>>>>>>> a mouseMotionListener on the child figure but it's no good
>>>>>>>>>> because i want work with the editPart of figure to get the
>>>>>>>>>> model to set the new coordinate
>>>>>>>>>>
>>>>>>>>>> is there a better way to do this?
>>>>>>>>>>
>>>>>>>>>> michele wrote:
>>>>>>>>>>
>>>>>>>>>>> Hello,
>>>>>>>>>>> I've a problem with the drag of a child Figure.
>>>>>>>>>>>
>>>>>>>>>>> The situation is :
>>>>>>>>>>>
>>>>>>>>>>> i've a figure that had size like the editor size where
>>>>>>>>>>> there's draw a map the i drag objects from another view to
>>>>>>>>>>> the mapfigure so i add this object like childs of mapfigure
>>>>>>>>>>> and the mapfigure is updated.
>>>>>>>>>>> Now i want change the position of that child with an
>>>>>>>>>>> operation of drag.
>>>>>>>>>>>
>>>>>>>>>>> The problem is that i can't understand how to manage the
>>>>>>>>>>> dragevent on that figure.
>>>>>>>>>>>
>>>>>>>>>>> i've tryed to implement the method getDragTracker on
>>>>>>>>>>> childEditPart and
>>>>>>>>>>> i have installed an implementation class of
>>>>>>>>>>> XYLayoutEditPolicy on child EditPart as
>>>>>>>>>>> EditPolicy.PRIMARY_DRAG_ROLE but the event never been captured.
>>>>>>>>>>>
>>>>>>>>>>> What's the best way for implement the drag operation of child
>>>>>>>>>>> figure written over another ?
>>>>>>>>>>>
>>>>>>>>>>> Thank's
>>>>>>>>>>> Michele
>>>>
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------ ------------
>>>>
>>>>
>>>> This is the EditPartFactory registered to my GraphicaViewer -->
>>>> viewer.setEditPartFactory(new MapEditPartFactory());
>>>>
>>>> public class MapEditPartFactory implements EditPartFactory {
>>>>
>>>> public EditPart createEditPart(EditPart context, Object model) {
>>>> EditPart returnValue = null;
>>>> if(model instanceof MapRootElement) {
>>>> MapRootEditPart mrep = new MapRootEditPart();
>>>> returnValue = mrep;
>>>> }else if (model instanceof
>>>> it.evinco.horusstandalone.views.editor.model.AntennaModel){
>>>> try{ returnValue = new
>>>> it.evinco.horusstandalone.views.editor.parts.AntennaEditPart ();
>>>> }catch(Exception e){
>>>> e.printStackTrace();
>>>> }
>>>> returnValue.setModel(model);
>>>> }else if (model instanceof
>>>> it.evinco.horusstandalone.views.editor.model.AmbientiModel){
>>>> returnValue = new AmbientiEditPart();
>>>> returnValue.setModel(model); }else{
>>>> throw new IllegalArgumentException();
>>>> }
>>>> returnValue.setModel(model);
>>>> return returnValue;
>>>> }
>>>> }
>>>>
>>>> This is the childEditpart that extends AbstractEditPart that extends
>>>> AbstractGraphicalEditPart :
>>>> public class AntennaEditPart extends AbstractEditPart {
>>>>
>>>> private EditPart parentEditPart = null; public
>>>> AntennaEditPart() {
>>>> super();
>>>> } @Override
>>>> public void configureNode(Node node) {
>>>> Rectangle newBounds = getFigure().getBounds();
>>>> newBounds.setSize(getFigure().getPreferredSize());
>>>> node.width = newBounds.width;
>>>> node.height = newBounds.height;
>>>> node.data = this;
>>>> }
>>>>
>>>> @Override
>>>> protected IFigure createFigure() {
>>>> IFigure returnValue = null; AntennaFigure
>>>> antennaFigure = new AntennaFigure();
>>>> return antennaFigure;
>>>> }
>>>> private AntennaFigure getCastedFigure() {
>>>> return (AntennaFigure) getFigure();
>>>> }
>>>> protected void refreshVisuals() {
>>>> super.refreshVisuals();
>>>> }
>>>> @Override
>>>> protected void createEditPolicies() {
>>>> installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new
>>>> AntennaDragPolicy());
>>>> installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,new
>>>> SelectionFeedbackEditPolicy(1));
>>>> }
>>>> @Override
>>>> protected AntennaModel getCastedModel() {
>>>> return (AntennaModel) super.getCastedModel();
>>>> }
>>>>
>>>> public ConnectionAnchor
>>>> getSourceConnectionAnchor(ConnectionEditPart arg0) {
>>>> return null;
>>>> }
>>>>
>>>> public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
>>>> return null;
>>>> }
>>>>
>>>> public ConnectionAnchor
>>>> getTargetConnectionAnchor(ConnectionEditPart arg0) {
>>>> return null;
>>>> }
>>>>
>>>> public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
>>>> return null;
>>>> } public DragTracker getDragTracker(Request req)
>>>> {
>>>> System.out.println("Called
>>>> HelloTopEditPart.getDragTracker() with req="+req);
>>>>
>>>> if (m_dragTracker==null) {
>>>> m_dragTracker = new DragEditPartsTracker(this);
>>>> }
>>>> return m_dragTracker;
>>>> }
>>>> static DragTracker m_dragTracker = null;
>>>> }
>>>>
>>>>
>>>> this is AbstractEditPart :
>>>>
>>>>
>>>> public abstract class AbstractEditPart extends
>>>> AbstractGraphicalEditPart implements PropertyChangeListener {
>>>>
>>>> protected Label textLabel;
>>>> public void activate() {
>>>> if (!isActive()) {
>>>> super.activate();
>>>>
>>>> getCastedModel().addPropertyChangeListener(this); }
>>>> }
>>>> public void deactivate() {
>>>> if (isActive()) {
>>>> super.deactivate();
>>>> getCastedModel().removePropertyChangeListener(this);
>>>> }
>>>> }
>>>> protected abstract IFigure createFigure();
>>>> protected AbstractBaseElement getCastedModel() {
>>>> return (AbstractBaseElement) getModel();
>>>> }
>>>> public void propertyChange(PropertyChangeEvent evt) {
>>>> refresh();
>>>> }
>>>> public abstract void configureNode(Node node);
>>>> protected void refreshAllParts() {
>>>> refresh(getRoot().getChildren());
>>>> getRoot().refresh();
>>>> }
>>>> private void refresh(List pChildren){
>>>> for (Iterator i = pChildren.iterator(); i.hasNext();) {
>>>> AbstractEditPart p = (AbstractEditPart) i.next();
>>>> p.refresh();
>>>> refresh(p.getChildren());
>>>> }
>>>> }
>>>> }
>>>>
>>>> And this is AntennaDragPolicy:
>>>>
>>>> public class AntennaDragPolicy extends NonResizableEditPolicy {
>>>>
>>>> @Override
>>>> public boolean understandsRequest(Request arg0) {
>>>> System.out.println("understandsRequest");
>>>> return super.understandsRequest(arg0);
>>>> }
>>>>
>>>> @Override
>>>> public Command getCommand(Request arg0) {
>>>> System.out.println("getCommand");
>>>> return super.getCommand(arg0);
>>>> }
>>>>
>>>>
>>>> }
>>>>
>>>>
Previous Topic:[QUERY] Superior Routing + Placement
Next Topic:FlowAdapter problem
Goto Forum:
  


Current Time: Tue Apr 16 06:31:17 GMT 2024

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

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

Back to the top