Skip to content

Package: CreateChildAction

CreateChildAction

nameinstructionbranchcomplexitylinemethod
CreateChildAction(EditingDomain, ISelection, Object)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createActionCommand(EditingDomain, Collection)
M: 2 C: 15
88%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 4
80%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (c) 2002-2007 IBM Corporation and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * IBM - Initial API and implementation
13: */
14: // REUSED CLASS
15: package org.eclipse.emf.edit.ui.action.ecp;
16:
17: import java.util.Collection;
18:
19: import org.eclipse.emf.common.command.Command;
20: import org.eclipse.emf.common.command.UnexecutableCommand;
21: import org.eclipse.emf.edit.command.CreateChildCommand;
22: import org.eclipse.emf.edit.domain.EditingDomain;
23: import org.eclipse.jface.viewers.ISelection;
24:
25: /**
26: * A child creation action is implemented by creating a {@link CreateChildCommand}.
27: */
28: public class CreateChildAction extends StaticSelectionCommandAction {
29:         /**
30:          * This describes the child to be created.
31:          */
32:         protected Object descriptor;
33:
34:         /**
35:          * This constructs an instance of an action that uses the given editing domain to create a child
36:          * specified by <code>descriptor</code> for the single object in the <code>selection</code>.
37:          *
38:          * @since 2.4.0
39:          */
40:         public CreateChildAction(EditingDomain editingDomain, ISelection selection, Object descriptor) {
41:                 super(editingDomain);
42:                 this.descriptor = descriptor;
43:                 configureAction(selection);
44:         }
45:
46:         /**
47:          * This creates the command for {@link StaticSelectionCommandAction#createActionCommand}.
48:          */
49:         @Override
50:         protected Command createActionCommand(EditingDomain editingDomain, Collection<?> collection) {
51:•                if (collection.size() == 1) {
52:                         final Object owner = collection.iterator().next();
53:                         return CreateChildCommand.create(editingDomain, owner,
54:                                 descriptor, collection);
55:                 }
56:                 return UnexecutableCommand.INSTANCE;
57:         }
58: }