Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2007 Anyware Technologies All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Anyware Technologies - initial API and implementation $Id: EReferenceReorientCommand.java,v 1.5 2009/02/02 08:39:07 jlescot Exp $ /
 
 
 package org.eclipse.emf.ecoretools.diagram.edit.commands;
 
 import  org.eclipse.core.runtime.IAdaptable;
 import  org.eclipse.core.runtime.IProgressMonitor;
 import  org.eclipse.gmf.runtime.common.core.command.CommandResult;
 import  org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
 import  org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;

Generated:
 
 public class EReferenceReorientCommand extends EditElementCommand {

Generated:
 
 	private final int reorientDirection;

Generated:
 
 	private final EObject oldEnd;

Generated:
 
 	private final EObject newEnd;

Generated:
 
 	public EReferenceReorientCommand(ReorientRelationshipRequest request) {
 		super(request.getLabel(), request.getRelationship(), request);
 		 = request.getDirection();
 		 = request.getOldRelationshipEnd();
 		 = request.getNewRelationshipEnd();
 	}

Generated:
 
 	public boolean canExecute() {
 		if (false == getElementToEdit() instanceof EReference) {
 			return false;
 		}
 		if ( == ReorientRelationshipRequest.REORIENT_SOURCE) {
 			return canReorientSource();
 		}
 		if ( == ReorientRelationshipRequest.REORIENT_TARGET) {
 			return canReorientTarget();
 		}
 		return false;
 	}

Generated:
 
 	protected boolean canReorientSource() {
 		if (!( instanceof EClass &&  instanceof EClass)) {
 			return false;
 		}
 		EClassifier target = getLink().getEType();
 		return EcoreBaseItemSemanticEditPolicy.LinkConstraints.canExistEReference_3002(getNewSource(), target);
 	}

Generated:
 
 	protected boolean canReorientTarget() {
 		if (!( instanceof EClassifier &&  instanceof EClassifier)) {
 			return false;
 		}
 		if (!(getLink().eContainer() instanceof EClass)) {
 			return false;
 		}
 		EClass source = (EClassgetLink().eContainer();
 		return EcoreBaseItemSemanticEditPolicy.LinkConstraints.canExistEReference_3002(sourcegetNewTarget());
 	}

Set Eopposite to null before reorienting

Generated:
NOT
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable infothrows ExecutionException {
		if (!canExecute()) {
			throw new ExecutionException("Invalid arguments in reorient link command"); //$NON-NLS-1$
		}
		if ( == ReorientRelationshipRequest.REORIENT_SOURCE) {
			if (getLink().getEOpposite() != null) {
			}
			return reorientSource();
		}
		if ( == ReorientRelationshipRequest.REORIENT_TARGET) {
			if (getLink().getEOpposite() != null) {
			}
			return reorientTarget();
		}
		throw new IllegalStateException();
	}

Generated:
	protected CommandResult reorientSource() throws ExecutionException {
		return CommandResult.newOKCommandResult(getLink());
	}

Generated:
	protected CommandResult reorientTarget() throws ExecutionException {
		return CommandResult.newOKCommandResult(getLink());
	}

Generated:
	protected EReference getLink() {
		return (EReference) getElementToEdit();
	}

Generated:
	protected EClass getOldSource() {
		return (EClass;
	}

Generated:
	protected EClass getNewSource() {
		return (EClass;
	}

Generated:
	protected EClassifier getOldTarget() {
		return (EClassifier;
	}

Generated:
	protected EClassifier getNewTarget() {
		return (EClassifier;
	}
New to GrepCode? Check out our FAQ X