[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: GMF/Recipes: Reorder...

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().eGet(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;
}
}