Debian Codegraph @

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