Drag and drop an EditPart [message #199718] |
Tue, 18 October 2005 15:32 |
Eclipse User |
|
|
|
Originally posted by: prashanto.chatterjee.softwareag.com
Hi All,
I am trying to drag an object(ServiceEditPart) with the following edit
policy:
------------------------------------------------------------ ------------------
protected void createEditPolicies() {
installEditPolicy(EditPolicy.COMPONENT_ROLE, new
StandardGUIAppComponentEditPolicy());
------------------------------------------------------------ ------------------
into a different editor altogether.
Now this particular object sits inside a section(ServiceSectionEditPart)
that has the following editpolicy:
------------------------------------------------------------ ------------------
protected void createEditPolicies() {
installEditPolicy(EditPolicy.LAYOUT_ROLE, new LayoutEditPolicy(){
protected EditPolicy createChildEditPolicy(EditPart child) {
// TODO Auto-generated method stub
return null;
}
protected Command getCreateCommand(CreateRequest request) {
// TODO Auto-generated method stub
Object newType = request.getNewObjectType();
if(newType == Service.class){
ServiceAddCommand singlePageCommand = new
ServiceAddCommand((Shape)request.getNewObject(),
(ServiceSection)getHost().getModel(), new Rectangle(0, 0, 80, 64));
return singlePageCommand;
}else{
return null;
}
}
protected Command getDeleteDependantCommand(Request request) {
// TODO Auto-generated method stub
return null;
}
protected Command getMoveChildrenCommand(Request request) {
// TODO Auto-generated method stub
return null;
}
});
installEditPolicy(EditPolicy.COMPONENT_ROLE, new
StandardGUIAppComponentEditPolicy());
}
------------------------------------------------------------ ------------------
I can assume that I require another policy:
------------------------------------------------------------ ------------------
installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new
NonResizableEditPolicy());
------------------------------------------------------------ ------------------
to allow drag (Plz correct me if I am wrong).
Now I have the following questions:
1. Can I have edit-policies that allow dragging across editors?
2. If yes then which editpolicy do I use for the drag-source and the
drag-target?
Appreciate any help in this regard,
Prashanto Chatterjee
|
|
|
Re: Drag and drop an EditPart [message #199733 is a reply to message #199718] |
Tue, 18 October 2005 21:08 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
You must use native Drag-and-Drop to drag from one Canvas to another SWT
control or another application.
See TransferDragSourceListener.
"Prashanto" <prashanto.chatterjee@softwareag.com> wrote in message
news:a8456d407d00397361c54f28d2aca934$1@www.eclipse.org...
> Hi All,
> I am trying to drag an object(ServiceEditPart) with the following edit
> policy:
>
> ------------------------------------------------------------ ------------------
> protected void createEditPolicies() {
> installEditPolicy(EditPolicy.COMPONENT_ROLE, new
> StandardGUIAppComponentEditPolicy());
> ------------------------------------------------------------ ------------------
>
> into a different editor altogether.
>
> Now this particular object sits inside a section(ServiceSectionEditPart)
> that has the following editpolicy:
>
> ------------------------------------------------------------ ------------------
> protected void createEditPolicies() {
> installEditPolicy(EditPolicy.LAYOUT_ROLE, new LayoutEditPolicy(){
>
> protected EditPolicy createChildEditPolicy(EditPart child) {
> // TODO Auto-generated method stub
> return null;
> }
>
> protected Command getCreateCommand(CreateRequest request) {
> // TODO Auto-generated method stub
> Object newType = request.getNewObjectType();
> if(newType == Service.class){
> ServiceAddCommand singlePageCommand = new
> ServiceAddCommand((Shape)request.getNewObject(),
> (ServiceSection)getHost().getModel(), new Rectangle(0, 0, 80, 64));
> return singlePageCommand;
> }else{
> return null;
> }
> }
>
> protected Command getDeleteDependantCommand(Request request) {
> // TODO Auto-generated method stub
> return null;
> }
>
> protected Command getMoveChildrenCommand(Request request) {
> // TODO Auto-generated method stub
> return null;
> }
>
> }); installEditPolicy(EditPolicy.COMPONENT_ROLE, new
> StandardGUIAppComponentEditPolicy());
> }
> ------------------------------------------------------------ ------------------
>
> I can assume that I require another policy:
>
> ------------------------------------------------------------ ------------------
> installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new
> NonResizableEditPolicy());
> ------------------------------------------------------------ ------------------
>
> to allow drag (Plz correct me if I am wrong).
>
> Now I have the following questions:
> 1. Can I have edit-policies that allow dragging across editors?
> 2. If yes then which editpolicy do I use for the drag-source and the
> drag-target?
>
> Appreciate any help in this regard,
> Prashanto Chatterjee
>
|
|
|
Re: Drag and drop an EditPart [message #199795 is a reply to message #199733] |
Wed, 19 October 2005 11:17 |
Eclipse User |
|
|
|
Originally posted by: prashanto.chatterjee.softwareag.com
Your suggestion worked. Thanks a lot.
I actually based my TransferDragSourceListener to something similar to
TemplateTransferDragSourceLIstener as follows:
------------------------------------------------------------ ------------------
private class ServiceDragSourceListener implements
TransferDragSourceListener {
private EditPartViewer viewer;
private Transfer transfer;
ServiceDragSourceListener(EditPartViewer p_viewer, Transfer p_transfer){
this.viewer = p_viewer;
this.transfer = p_transfer;
}
public Transfer getTransfer() {
return this.transfer;
}
public void dragStart(DragSourceEvent event) {
Object template = getTemplate();
if (template == null)
event.doit = false;
TemplateTransfer.getInstance().setTemplate(template);
}
public void dragSetData(DragSourceEvent event) {
event.data = getTemplate();
}
public void dragFinished(DragSourceEvent event) {
TemplateTransfer.getInstance().setTemplate(null);
}
/**
* A helper method that returns <code>null</code> or the <i>template</i>
Object from the
* currently selected EditPart.
* @return the template
*/
protected Object getTemplate() {
return ((Service)(ServiceEditPart.this.getModel())).getClass();
}
}
------------------------------------------------------------ ------------------
and there I had a perfectly working code.
Thanks once again. Kudos to you guys that we, who are new to GEF, are
getting such wonderful support.
Hoping to trouble you again with more queries,
Prashanto Chatterjee
|
|
|
Powered by
FUDForum. Page generated in 0.03768 seconds