Skip to content

Package: EcoreCreateNewChildDialog

EcoreCreateNewChildDialog

nameinstructionbranchcomplexitylinemethod
EcoreCreateNewChildDialog(Shell, String, EObject, ISelectionProvider)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getNewChildActions(Collection, EditingDomain, EObject)
M: 77 C: 0
0%
M: 18 C: 0
0%
M: 10 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 EclipseSource Muenchen GmbH 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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.editor.ecore;
15:
16: import java.util.ArrayList;
17: import java.util.Collection;
18: import java.util.List;
19:
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.edit.command.CommandParameter;
22: import org.eclipse.emf.edit.domain.EditingDomain;
23: import org.eclipse.emfforms.internal.editor.ecore.helpers.EcoreHelpers;
24: import org.eclipse.emfforms.internal.editor.ui.CreateNewChildDialog;
25: import org.eclipse.emfforms.spi.editor.InitializeChildCallback;
26: import org.eclipse.jface.action.Action;
27: import org.eclipse.jface.viewers.ISelectionProvider;
28: import org.eclipse.swt.widgets.Shell;
29:
30: /**
31: * Dialog which is shown when a new element is created in the ecore editor.
32: *
33: * @author Johannes Faltermeier
34: *
35: */
36: public class EcoreCreateNewChildDialog extends CreateNewChildDialog {
37:
38:         /**
39:          * Constructs a new {@link EcoreCreateNewChildDialog}.
40:          *
41:          * @param parentShell the parent shell
42:          * @param title the title of the dialog
43:          * @param parent the parent EObject which will contain the new child
44:          * @param selectionProvider a provider which gives access to the current selection
45:          */
46:         public EcoreCreateNewChildDialog(Shell parentShell, String title, EObject parent,
47:                 ISelectionProvider selectionProvider) {
48:                 super(parentShell, title, parent, selectionProvider);
49:         }
50:
51:         @Override
52:         protected List<Action> getNewChildActions(Collection<?> descriptors,
53:                 final EditingDomain domain, final EObject eObject) {
54:
55:                 final List<Action> result = new ArrayList<Action>();
56:
57:•                for (final Object descriptor : descriptors) {
58:
59:                         final CommandParameter cp = (CommandParameter) descriptor;
60:•                        if (!CommandParameter.class.isInstance(descriptor)) {
61:                                 continue;
62:                         }
63:•                        if (cp.getEReference() == null) {
64:                                 continue;
65:                         }
66:•                        if (EcoreHelpers.isGenericFeature(cp.getFeature())) {
67:                                 // This ensures, that we won't show any generic features anymore
68:                                 continue;
69:                         }
70:•                        if (!cp.getEReference().isMany()
71:•                                && eObject.eIsSet(cp.getEStructuralFeature())) {
72:                                 continue;
73:•                        } else if (cp.getEReference().isMany()
74:•                                && cp.getEReference().getUpperBound() != -1
75:                                 && cp.getEReference().getUpperBound() <= ((List<?>) eObject
76:•                                        .eGet(cp.getEReference())).size()) {
77:                                 continue;
78:                         }
79:
80:                         result.add(new CreateChildActionWithAccelerator(eObject, domain, getSelectionProvider(), cp,
81:                                 new InitializeChildCallback()));
82:                 }
83:                 return result;
84:         }
85: }