/******************************************************************************* * <copyright> * * Copyright (c) 2005, 2010 SAP AG. * 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: * SAP AG - initial API, implementation and documentation * * </copyright> * *******************************************************************************/ package org.eclipse.sapphire.ui.swt.gef.dnd; import org.eclipse.gef.EditPartViewer; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; import org.eclipse.gef.dnd.AbstractTransferDropTargetListener; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gef.requests.CreationFactory; import org.eclipse.jface.util.LocalSelectionTransfer; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.dnd.DND; /** * @noinstantiate This class is not intended to be instantiated by clients. * @noextend This class is not intended to be subclassed by clients. * @author <a href="mailto:shenxue.zhou@oracle.com">Shenxue Zhou</a> */ public class ObjectsTransferDropTargetListener extends AbstractTransferDropTargetListener { public ObjectsTransferDropTargetListener(EditPartViewer viewer) { super(viewer, LocalSelectionTransfer.getTransfer()); setEnablementDeterminedByCommand(true); } @Override protected void handleDrop() { super.handleDrop(); if (getCurrentEvent().detail == DND.DROP_MOVE) { getCurrentEvent().detail = DND.DROP_COPY; } } @Override protected void updateTargetRequest() { ((CreateRequest) getTargetRequest()).setLocation(getDropLocation()); } @Override protected Request createTargetRequest() { CreateRequest request = new CreateRequest(); request.setFactory(new MyCreationFactory()); request.setLocation(getDropLocation()); return request; } @Override protected void handleDragOver() { super.handleDragOver(); Command command = getCommand(); if (command != null && command.canExecute()) getCurrentEvent().detail = DND.DROP_COPY; } private static class MyCreationFactory implements CreationFactory { public MyCreationFactory() { } public Object getNewObject() { return LocalSelectionTransfer.getTransfer().getSelection(); } public Object getObjectType() { return ISelection.class; } } }