Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » GMF/Recipes: Reorder...
GMF/Recipes: Reorder... [message #217066] Tue, 03 February 2009 08:01 Go to next message
Marcel Bootsma is currently offline Marcel BootsmaFriend
Messages: 11
Registered: July 2009
Junior Member
Hello,

I implemented the GMF/Recipe to reorder nodes in a compartment and it
works nicely.

I wondered if anybody had solved the TODO in the CompartmentEditPolicy:

// TODO ev. reintroduce target feedback
// (actual problem: line is not deleted after dropping)

Having the cursor would be rather nice.

Thank you for you response,

Marcel
Re: GMF/Recipes: Reorder... [message #218946 is a reply to message #217066] Mon, 16 February 2009 14:05 Go to previous message
Marcel Bootsma is currently offline Marcel BootsmaFriend
Messages: 11
Registered: July 2009
Junior Member
I solved this problem.

The eraseLayoutTargetFeedback method should be called during execution of
the reposition commmand.
Finaly because the eraseLayoutTargetFeedback method is protected you
should override it in the CustomCompartmentEditPolicy.
A reference to policy the is needed in the
CompartmentRepositioneObjectCommand.

Implementing this on the code from the GMF/Recipes results in:

______________________________________________

public class CompartmentEditPolicy
extends org.eclipse.gef.editpolicies.FlowLayoutEditPolicy
{

private EStructuralFeature feature = null;

protected Command createAddCommand(EditPart child, EditPart after) {
int index = getHost().getChildren().indexOf(after);
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)
getHost()).getEditingDomain();
AddCommand command = new AddCommand(editingDomain, new
EObjectAdapter((View)getHost().getModel()),
new EObjectAdapter((View)child.getModel()), index);
return new ICommandProxy(command);
}

protected EditPolicy createChildEditPolicy(EditPart child) {
ResizableEditPolicyEx policy = new ResizableEditPolicyEx();
policy.setResizeDirections(0);
return policy;
}

protected Command createMoveChildCommand(EditPart child, EditPart after)
{

int newIndex;
int displacement;

int childIndex = getHost().getChildren().indexOf(child);
int afterIndex = getHost().getChildren().indexOf(after);

if(afterIndex == -1) {
newIndex = getHost().getChildren().size()-1;
displacement = newIndex - childIndex;
} else {
newIndex = afterIndex;
displacement = afterIndex - childIndex;
if (childIndex <= afterIndex) {
newIndex--;
displacement--;
}
}


TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)
getHost()).getEditingDomain();

/*
* Added reference to this policy to enable calling of
* myEraseLayoutTargetFeedback from command
*/


RepositionEObjectCommand command = new
CompartmentRepositionEObjectCommand(child, editingDomain, "",

(EList)((View)child.getParent().getModel()).getElement().eGe t(feature),
((View)child.getModel()).getElement(),
displacement, newIndex,
this);

/*
* these 2 lines can be removed
*/

//TODO ev. reintroduce target feedback (actual problem: line is not
deleted after dropping)
//eraseLayoutTargetFeedback(null);

return new ICommandProxy(command);
}

protected Command getCreateCommand(CreateRequest request) {
return null;
}

protected Command getDeleteDependantCommand(Request request) {
return null;
}

protected Command getOrphanChildrenCommand(Request request) {
return null;
}

/**
* @param feature has to be an EList
*/
public CompartmentEditPolicy(EStructuralFeature feature) {
super();
this.feature = feature;
}

/*
* Will be called from Repostion Command execution
* to remove feedback line
*/
public void myEraseLayoutTargetFeedback() {
super.eraseLayoutTargetFeedback(null);
}
}

________________________________________


public class CompartmentRepositionEObjectCommand extends
RepositionEObjectCommand {

EditPart childToMove = null;
int newIndex = 0;
CustomCompartmentEditPolicy policy;

public CompartmentRepositionEObjectCommand(
TransactionalEditingDomain editingDomain, String label,
EList elements, EObject element, int displacement) {
super(editingDomain, label, elements, element, displacement);
}

/*
* Added a reference to the creating policy to enalbe calling
* from command execution
*/
public CompartmentRepositionEObjectCommand(EditPart childToMove,
TransactionalEditingDomain editingDomain, String label,
EList elements, EObject element, int displacement, int newIndex,

CustomCompartmentEditPolicy policy

) {
super(editingDomain, label, elements, element, displacement);

this.childToMove = childToMove;
this.newIndex = newIndex;
}

public CommandResult doExecuteWithResult(
IProgressMonitor progressMonitor, IAdaptable info)
throws ExecutionException {
CommandResult rs = super.doExecuteWithResult(progressMonitor, info);

/*
* This line will erase the feedback line
*/

policy.eraseLayoutTargetFeedback(null);

EditPart compartment = childToMove.getParent();

ViewUtil.repositionChildAt((View)compartment.getModel(),
(View)childToMove.getModel(), newIndex);
compartment.refresh();

return rs;
}
}
Previous Topic:Inserting nodes in a compartment
Next Topic:How duplicate a node that share the same semantic element?
Goto Forum:
  


Current Time: Fri Mar 05 22:33:50 GMT 2021

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

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

Back to the top