/******************************************************************************
 * Copyright (c) 2006, Intalio Inc.
 * 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:
 *     Intalio Inc. - initial API and implementation
 *******************************************************************************/

package org.eclipse.stp.bpmn.diagram.edit.policies;

import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.diagram.core.commands.SetConnectionAnchorsCommand;
import org.eclipse.gmf.runtime.diagram.core.commands.SetConnectionEndsCommand;
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.internal.commands.SetConnectionBendpointsCommand;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeConnectionRequest;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.MetamodelType;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.stp.bpmn.Activity;
import org.eclipse.stp.bpmn.diagram.edit.parts.ActivityEditPart;
import org.eclipse.stp.bpmn.diagram.providers.BpmnElementTypes;

/**
 * @generated
 */
public class ActivityGraphicalNodeEditPolicy extends
        BpmnGraphicalNodeEditPolicy {

    /*
    @Override
    protected Command getConnectionCompleteCommand(
            CreateConnectionRequest request) {
        ICommandProxy proxy = (ICommandProxy) request.getStartCommand();
        if (proxy == null) {
            return null;
        }

        // reset the target edit-part for the request
        INodeEditPart targetEP = getConnectionCompleteEditPart(request);
        if (targetEP == null) {
            return null;
        }

        CompositeCommand cc = (CompositeCommand) proxy.getICommand();
        ConnectionAnchor targetAnchor = targetEP
                .getTargetConnectionAnchor(request);
        Iterator commandItr = cc.iterator();
        commandItr.next(); // 0
        SetConnectionEndsCommand sceCommand = (SetConnectionEndsCommand) commandItr
                .next(); // 1
        sceCommand.setNewTargetAdaptor(new EObjectAdapter(
                ((IGraphicalEditPart) targetEP).getNotationView()));
        SetConnectionAnchorsCommand scaCommand = (SetConnectionAnchorsCommand) commandItr
                .next(); // 2
        scaCommand.setNewTargetTerminal(targetEP
                .mapConnectionAnchorToTerminal(targetAnchor));
        setViewAdapter(sceCommand.getEdgeAdaptor());
        INodeEditPart sourceEditPart = (INodeEditPart) request
                .getSourceEditPart();

        MetamodelType connType = null;
        if (request instanceof CreateConnectionViewAndElementRequest) {
            IAdaptable adapter = ((CreateConnectionViewAndElementRequest) request)
                    .getConnectionViewDescriptor().getElementAdapter();
            if (adapter instanceof CreateElementRequestAdapter) {
                connType = (MetamodelType) ((CreateElementRequestAdapter) adapter)
                        .getAdapter(IElementType.class);
            }
        } else if (request instanceof CreateUnspecifiedTypeConnectionRequest) {
            List o = ((CreateUnspecifiedTypeConnectionRequest) request)
                    .getElementTypes();
            if (o.size() == 1) {
                if (o.get(0) instanceof MetamodelType) {
                    connType = (MetamodelType) o.get(0);
                }
            }
        }

        if (connType == BpmnElementTypes.SequenceEdge_3001) {
            return super.getConnectionCompleteCommand(request);
        }

        List messages = ((Activity) (((Node) ((ActivityEditPart) sourceEditPart)
                .getModel()).getElement())).getOrderedMessages();
        int connOrderNumber = -1; // not real order
        if (connType == BpmnElementTypes.MessagingEdge_3002) {
            connOrderNumber = messages.size();
        }

        ConnectionAnchor sourceAnchor = ((ActivityEditPart) sourceEditPart)
                .mapTerminalToConnectionAnchorEx(scaCommand
                        .getNewSourceTerminal(), connType, connOrderNumber,
                        messages.size() + 1);
        PointList pointList = new PointList();
        if (request.getLocation() == null) {
            pointList.addPoint(sourceAnchor.getLocation(targetAnchor
                    .getReferencePoint()));
            pointList.addPoint(targetAnchor.getLocation(sourceAnchor
                    .getReferencePoint()));
        } else {
            pointList.addPoint(sourceAnchor.getLocation(request.getLocation()));
            pointList.addPoint(targetAnchor.getLocation(request.getLocation()));
        }
        SetConnectionBendpointsCommand sbbCommand = (SetConnectionBendpointsCommand) commandItr
                .next(); // 3
        sbbCommand.setNewPointList(pointList, sourceAnchor.getReferencePoint(),
                targetAnchor.getReferencePoint());
        return request.getStartCommand();
    }
    */
    
    
}
