Debian Codegraph @

plugins/org.eclipse.emf.edit.ui/src/org/eclipse/emf/edit/ui/action/CreateChildAction.java

raw
1 /**
2 * Copyright (c) 2002-2007 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.jface.viewers.ISelection;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.IWorkbenchPart;
19
20 import org.eclipse.emf.common.command.Command;
21 import org.eclipse.emf.common.command.UnexecutableCommand;
22 import org.eclipse.emf.edit.command.CreateChildCommand;
23 import org.eclipse.emf.edit.domain.EditingDomain;
24
25
26 /**
27 * A child creation action is implemented by creating a {@link
28 * CreateChildCommand}.
29 */
30 public class CreateChildAction extends StaticSelectionCommandAction
31 {
32 /**
33 * This describes the child to be created.
34 */
35 protected Object descriptor;
36
37 /**
38 * This constructs an instance of an action that uses the workbench part's editing domain to create a child
39 * specified by <code>descriptor</code> for the single object in the
40 * <code>selection</code>.
41 * @since 2.1.0
42 */
43 public CreateChildAction(IWorkbenchPart workbenchPart, ISelection selection, Object descriptor)
44 {
45 super(workbenchPart);
46 this.descriptor = descriptor;
47 configureAction(selection);
48 }
49
50 /**
51 * This constructor is simply retained for binary compatibility. It just
52 * calls the {@link #CreateChildAction(IWorkbenchPart, ISelection, Object)
53 * new form}.
54 */
55 public CreateChildAction(IEditorPart editorPart, ISelection selection, Object descriptor)
56 {
57 this((IWorkbenchPart)editorPart, selection, descriptor);
58 }
59
60 /**
61 * This constructs an instance of an action that uses the given editing domain to create a child
62 * specified by <code>descriptor</code> for the single object in the
63 * <code>selection</code>.
64 * @since 2.4.0
65 */
66 public CreateChildAction(EditingDomain editingDomain, ISelection selection, Object descriptor)
67 {
68 super(editingDomain);
69 this.descriptor = descriptor;
70 configureAction(selection);
71 }
72
73 /**
74 * This creates the command for {@link
75 * StaticSelectionCommandAction#createActionCommand}.
76 */
77 @Override
78 protected Command createActionCommand(EditingDomain editingDomain, Collection<?> collection)
79 {
80 if (collection.size() == 1)
81 {
82 Object owner = collection.iterator().next();
83 return CreateChildCommand.create(editingDomain, owner,
84 descriptor, collection);
85 }
86 return UnexecutableCommand.INSTANCE;
87 }
88 }