| 1 |
/** |
| 2 |
* Copyright (c) 2002-2006 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v20.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM - Initial API and implementation |
| 10 |
*/ |
| 11 |
package org.eclipse.emf.edit.ui.action; |
| 12 |
|
| 13 |
|
| 14 |
import java.util.Collection; |
| 15 |
|
| 16 |
import org.eclipse.ui.IEditorPart; |
| 17 |
import org.eclipse.ui.IWorkbenchPart; |
| 18 |
|
| 19 |
import org.eclipse.emf.common.command.Command; |
| 20 |
import org.eclipse.emf.common.command.UnexecutableCommand; |
| 21 |
import org.eclipse.emf.edit.command.PasteFromClipboardCommand; |
| 22 |
import org.eclipse.emf.edit.domain.EditingDomain; |
| 23 |
import org.eclipse.emf.edit.domain.IEditingDomainProvider; |
| 24 |
import org.eclipse.emf.edit.ui.EMFEditUIPlugin; |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* A paste action is implemented by creating a {@link PasteFromClipboardCommand}. |
| 29 |
*/ |
| 30 |
public class PasteAction extends CommandActionHandler |
| 31 |
{ |
| 32 |
public PasteAction(EditingDomain domain) |
| 33 |
{ |
| 34 |
super(domain, EMFEditUIPlugin.INSTANCE.getString("_UI_Paste_menu_item")); |
| 35 |
} |
| 36 |
|
| 37 |
public PasteAction() |
| 38 |
{ |
| 39 |
super(null, EMFEditUIPlugin.INSTANCE.getString("_UI_Paste_menu_item")); |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public Command createCommand(Collection<?> selection) |
| 44 |
{ |
| 45 |
if (selection.size() == 1) |
| 46 |
{ |
| 47 |
return PasteFromClipboardCommand.create(domain, selection.iterator().next(), null); |
| 48 |
} |
| 49 |
else |
| 50 |
{ |
| 51 |
return UnexecutableCommand.INSTANCE; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @deprecated As of EMF 2.1.0, replaced by {@link #setActiveWorkbenchPart}. |
| 57 |
*/ |
| 58 |
@Deprecated |
| 59 |
public void setActiveEditor(IEditorPart editorPart) |
| 60 |
{ |
| 61 |
setActiveWorkbenchPart(editorPart); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @since 2.1.0 |
| 66 |
*/ |
| 67 |
public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart) |
| 68 |
{ |
| 69 |
if (workbenchPart instanceof IEditingDomainProvider) |
| 70 |
{ |
| 71 |
domain = ((IEditingDomainProvider)workbenchPart).getEditingDomain(); |
| 72 |
} |
| 73 |
} |
| 74 |
} |