Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ac164296420628968dcecdc553535459fc1101a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*****************************************************************************
 * Copyright (c) 2014 CEA LIST.
 *
 *    
 * 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:
 *  Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
 *  
 *****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.menu.handlers;

import java.util.List;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.IStrategy;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.PasteStrategyManager;


/**
 * The handler for the paste with model in Diagram 
 * 
 */
public class PasteInDiagramHandler extends AbstractGraphicalCommandHandler {

	/**
	 * 
	 * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand()
	 * 
	 * @return
	 */
	@Override
	protected Command getCommand() {
		List<IGraphicalEditPart> selectedElements = getSelectedElements();
		if (selectedElements.size() == 1){ // Paste is only enabled on a simple selection
			//if (PapyrusClipboard.getInstance().size() > 0) { // TODO : Paste is only enabled if there is something inside the clipboard
			GraphicalEditPart targetOwnerEditPart = (GraphicalEditPart) selectedElements.get(0);
			org.eclipse.gef.commands.CompoundCommand compoundCommand = new org.eclipse.gef.commands.CompoundCommand("Paste all elements"); //$NON-NLS-1$
			
			List<IStrategy> allStrategies = PasteStrategyManager.getInstance()
					.getAllActiveStrategies();			
			for (IStrategy iStrategy : allStrategies) {
				IPasteStrategy iPasteStrategy = (IPasteStrategy) iStrategy;
				Command graphicalCommand = iPasteStrategy.getGraphicalCommand(getEditingDomain(), targetOwnerEditPart, PapyrusClipboard.getInstance());
				if (graphicalCommand!=null) {
					compoundCommand.add(graphicalCommand);
				}
			}
			return compoundCommand;	
		//	}
		}
		return UnexecutableCommand.INSTANCE;
	}

	// TODO : setEnable if selection.size == 1 and Papyrus Clipboard  or other is not empty
	
}

Back to the top