KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > ui > action > PasteAction


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2005 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: PasteAction.java,v 1.3 2005/06/08 06:20:52 nickb Exp $
16  */

17 package org.eclipse.emf.edit.ui.action;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.ui.IEditorPart;
23 import org.eclipse.ui.IWorkbenchPart;
24
25 import org.eclipse.emf.common.command.Command;
26 import org.eclipse.emf.common.command.UnexecutableCommand;
27 import org.eclipse.emf.edit.command.PasteFromClipboardCommand;
28 import org.eclipse.emf.edit.domain.EditingDomain;
29 import org.eclipse.emf.edit.domain.IEditingDomainProvider;
30 import org.eclipse.emf.edit.ui.EMFEditUIPlugin;
31
32
33 /**
34  * A paste action is implemented by creating a {@link PasteFromClipboardCommand}.
35  */

36 public class PasteAction extends CommandActionHandler
37 {
38   public PasteAction(EditingDomain domain)
39   {
40     super(domain, EMFEditUIPlugin.INSTANCE.getString("_UI_Paste_menu_item"));
41   }
42
43   public PasteAction()
44   {
45     super(null, EMFEditUIPlugin.INSTANCE.getString("_UI_Paste_menu_item"));
46   }
47
48   public Command createCommand(Collection JavaDoc selection)
49   {
50     if (selection.size() == 1)
51     {
52       return PasteFromClipboardCommand.create(domain, selection.iterator().next(), null);
53     }
54     else
55     {
56       return UnexecutableCommand.INSTANCE;
57     }
58   }
59
60   /**
61    * @deprecated As of EMF 2.1.0, replaced by {@link #setActiveWorkbenchPart}.
62    */

63   public void setActiveEditor(IEditorPart editorPart)
64   {
65     setActiveWorkbenchPart(editorPart);
66   }
67
68   /**
69    * @since 2.1.0
70    */

71   public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart)
72   {
73     if (workbenchPart instanceof IEditingDomainProvider)
74     {
75       domain = ((IEditingDomainProvider)workbenchPart).getEditingDomain();
76     }
77   }
78 }
79
Popular Tags