Skip to content

Package: MigrateHandler

MigrateHandler

nameinstructionbranchcomplexitylinemethod
MigrateHandler()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
execute(ExecutionEvent)
M: 84 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 27 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /**
2: * Copyright (c) 2011-2013 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: * Eugen Neufeld - initial API and implementation
13: */
14: package org.eclipse.emf.ecp.view.internal.editor.handler;
15:
16: import java.util.HashMap;
17: import java.util.List;
18: import java.util.Map;
19:
20: import org.eclipse.core.commands.AbstractHandler;
21: import org.eclipse.core.commands.ExecutionEvent;
22: import org.eclipse.core.commands.ExecutionException;
23: import org.eclipse.core.databinding.property.value.IValueProperty;
24: import org.eclipse.emf.common.util.TreeIterator;
25: import org.eclipse.emf.ecore.EClass;
26: import org.eclipse.emf.ecore.EObject;
27: import org.eclipse.emf.ecore.EReference;
28: import org.eclipse.emf.ecore.EStructuralFeature;
29: import org.eclipse.emf.ecp.view.internal.editor.controls.Activator;
30: import org.eclipse.emf.ecp.view.spi.editor.controls.Helper;
31: import org.eclipse.emf.ecp.view.spi.model.VControl;
32: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
33: import org.eclipse.emf.ecp.view.spi.model.VView;
34: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
35: import org.eclipse.emf.edit.command.AddCommand;
36: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
37: import org.eclipse.emf.edit.domain.EditingDomain;
38: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
39: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
40: import org.eclipse.jface.viewers.IStructuredSelection;
41: import org.eclipse.ui.handlers.HandlerUtil;
42:
43: /**
44: * The Handler for migrating existing models.
45: *
46: * @author Eugen Neufeld
47: *
48: */
49: // TODO needed?
50: public class MigrateHandler extends AbstractHandler {
51:         /**
52:          *
53:          * {@inheritDoc}
54:          *
55:          * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
56:          */
57:         @Override
58:         public Object execute(ExecutionEvent event) throws ExecutionException {
59:                 final Object selection = ((IStructuredSelection) HandlerUtil.getCurrentSelection(event)).getFirstElement();
60:                 final VView view = (VView) selection;
61:
62:                 final Map<EClass, EReference> childParentReferenceMap = new HashMap<EClass, EReference>();
63:                 final EClass rootClass = Helper.getRootEClass(view);
64:
65:                 Helper.getReferenceMap(rootClass, childParentReferenceMap);
66:
67:                 final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(view);
68:
69:                 final TreeIterator<EObject> eAllContents = view.eAllContents();
70:•                while (eAllContents.hasNext()) {
71:                         final EObject eObject = eAllContents.next();
72:•                        if (!VControl.class.isInstance(eObject)) {
73:                                 continue;
74:                         }
75:                         final VControl control = (VControl) eObject;
76:                         IValueProperty valueProperty;
77:                         try {
78:                                 valueProperty = Activator.getDefault().getEMFFormsDatabinding()
79:                                         .getValueProperty(control.getDomainModelReference(), null);
80:                         } catch (final DatabindingFailedException ex) {
81:                                 Activator.getDefault().getReportService().report(new DatabindingFailedReport(ex));
82:                                 continue;
83:                         }
84:                         final EStructuralFeature structuralFeature = (EStructuralFeature) valueProperty.getValueType();
85:                         final List<EReference> bottomUpPath = Helper.getReferencePath(rootClass,
86:                                 structuralFeature.getEContainingClass(), childParentReferenceMap);
87:                         // control.getPathToFeature().addAll(bottomUpPath);
88:                         ((VFeaturePathDomainModelReference) control.getDomainModelReference()).getDomainModelEReferencePath()
89:                                 .clear();
90:                         editingDomain.getCommandStack().execute(
91:                                 AddCommand.create(editingDomain, control.getDomainModelReference(),
92:                                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEReferencePath(),
93:                                         bottomUpPath));
94:                 }
95:                 return null;
96:         }
97:
98: }