Skip to content

Package: InitializeChildCallback

InitializeChildCallback

nameinstructionbranchcomplexitylinemethod
InitializeChildCallback()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
afterCreateElement(Object)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
beforeCreateElement(Object)
M: 6 C: 41
87%
M: 4 C: 4
50%
M: 4 C: 1
20%
M: 1 C: 10
91%
M: 0 C: 1
100%
initElement(EObject, EReference, EObject)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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: * Clemens Elflein - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.editor;
15:
16: import org.eclipse.emf.ecore.EObject;
17: import org.eclipse.emf.ecore.EReference;
18: import org.eclipse.emf.ecp.view.spi.model.VView;
19: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
20: import org.eclipse.emf.ecp.view.spi.model.VViewModelProperties;
21: import org.eclipse.emf.ecp.view.spi.provider.ViewProviderHelper;
22: import org.eclipse.emfforms.internal.editor.ui.CreateDialog;
23: import org.eclipse.emfforms.spi.swt.treemasterdetail.util.CreateElementCallback;
24: import org.eclipse.jface.window.Window;
25: import org.eclipse.swt.widgets.Display;
26:
27: /**
28: * This CreateElementCallback display a CreateDialog to the user that allows setting initial Values for the newly
29: * created element.
30: *
31: * @author Clemens Elflein
32: */
33: public class InitializeChildCallback implements CreateElementCallback {
34:
35:         @Override
36:         public void initElement(EObject parent, EReference reference, EObject newObject) {
37:                 /* no op */
38:         }
39:
40:         @Override
41:         public boolean beforeCreateElement(Object newElement) {
42:                 // We won't disturb creation of non EObjects
43:•                if (!(newElement instanceof EObject)) {
44:                         return true;
45:                 }
46:
47:                 final VViewModelProperties properties = VViewFactory.eINSTANCE.createViewModelLoadingProperties();
48:                 properties.addInheritableProperty("useOnModifyDatabinding", "true"); //$NON-NLS-1$ //$NON-NLS-2$
49:                 final VView view = ViewProviderHelper.getView((EObject) newElement, properties);
50:•                final boolean isViewEmpty = view == null ? true : view.getChildren().isEmpty();
51:
52:                 int result = Window.OK;
53:
54:•                if (!isViewEmpty) {
55:                         final CreateDialog diag = new CreateDialog(Display.getCurrent().getActiveShell(), (EObject) newElement);
56:                         result = diag.open();
57:                 }
58:
59:•                return result == Window.OK;
60:         }
61:
62:         @Override
63:         public void afterCreateElement(Object newElement) {
64:                 /* no op */
65:         }
66:
67: }