Uncorrect parent-child relationship in editpart hierarchy [message #222329] |
Wed, 30 August 2006 16:39 |
Eclipse User |
|
|
|
Originally posted by: paolo.reitelli.datamat.it
HI all,
I created a graphical editor for an XML file which is a definition of a
form; his structure is hierarchical:
form
|-----> Controls
|-----> Containers
|---------->Controls.
The EditParts hierarchy it's like the model one.
When I create controls in the main form Editpart it works, but when I create
a control in a container Editpart I have this situation:
1. In the model hierarchy the control is rightly inserted in the container
(the parent of the Control object is the container object).
2. In the editPart hierarchy the control is inserted as a form editpart
child ( the parent of the Control EditPart is the Form EditPart).
So, when I try to move the control rimaining inside the container the editor
works uncorrectly ( it takes the movement like a control's drag and drop
from form to container)
Thanks in advance,
Paolo.
P.S.
It follows some code snippets:
CONTAINER's EDIT POLICY
public class ContainerContainerEditPolicy extends ContainerEditPolicy {
/**
* @see
org.eclipse.gef.editpolicies.ContainerEditPolicy#getAddComma nd(org.eclipse.gef.requests.GroupRequest)
*/
protected Command getAddCommand(GroupRequest request)
{
return null;
}
/**
* @see
ContainerEditPolicy#getCreateCommand(org.eclipse.gef.request s.CreateRequest)
*/
protected Command getCreateCommand(CreateRequest request)
{
if(request.getType().equals(REQ_CREATE)) {
Object o=request.getNewObject();
if(o instanceof IControl){
IControl control=(IControl)o;
Rectangle bound=new Rectangle();
bound.setLocation(request.getLocation());
if(request.getSize()==null)
bound.setSize(80,10);
else
bound.setSize(request.getSize());
CreateObjectCommand command= new CreateObjectCommand();
command.setBound(bound);
command.setTarget(getHost().getModel());
command.setSource(control);
return command;
}
}
return null;
}
/**
* @see AbstractEditPolicy#getTargetEditPart(org.eclipse.gef.Request )
*/
public EditPart getTargetEditPart(Request request)
{
if (REQ_CREATE.equals(request.getType()))
return getHost();
if (REQ_ADD.equals(request.getType()))
return getHost();
if (REQ_MOVE.equals(request.getType()))
return getHost();
return super.getTargetEditPart(request);
}
}
CREATE COMMAND
public class CreateObjectCommand extends Command {
private IForm _form;
private IContainer _container_target;
private IContainer _container_source;
private IControl _control;
private Rectangle _bound;
public CreateObjectCommand(){
_form=null;
_container_target=null;
_container_source=null;
_control=null;
_bound=null;
}
public void execute() {
if(_form==null) { //se la form non
|
|
|
Powered by
FUDForum. Page generated in 0.02881 seconds