Skip to content

Package: ExportHandler

ExportHandler

nameinstructionbranchcomplexitylinemethod
ExportHandler()
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: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getSelfContainedModelElementTree(ExecutionEvent)
M: 35 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 11 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: *******************************************************************************/
15: package org.eclipse.emf.ecp.ui.commands;
16:
17: import java.util.ArrayList;
18: import java.util.List;
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.emf.ecore.EObject;
24: import org.eclipse.emf.ecore.util.EcoreUtil;
25: import org.eclipse.emf.ecp.internal.ui.util.ECPExportHandlerHelper;
26: import org.eclipse.jface.viewers.ISelection;
27: import org.eclipse.jface.viewers.IStructuredSelection;
28: import org.eclipse.ui.handlers.HandlerUtil;
29:
30: /**
31: * Export model element handler.
32: *
33: * @author Eugen Neufeld
34: *
35: */
36: public class ExportHandler extends AbstractHandler {
37:
38:         /**
39:          * {@inheritDoc}
40:          *
41:          * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
42:          */
43:         @Override
44:         public Object execute(ExecutionEvent event) throws ExecutionException {
45:
46:                 final List<EObject> exportModelElements = getSelfContainedModelElementTree(event);
47:
48:                 ECPExportHandlerHelper.export(HandlerUtil.getActiveShell(event), exportModelElements);
49:
50:                 return null;
51:         }
52:
53:         private List<EObject> getSelfContainedModelElementTree(ExecutionEvent event) {
54:                 final List<EObject> result = new ArrayList<EObject>();
55:
56:                 final ISelection selection = HandlerUtil.getActiveMenuSelection(event);
57:                 IStructuredSelection strucSel = null;
58:                 EObject copyModelElement = null;
59:
60:•                if (selection != null && selection instanceof IStructuredSelection) {
61:                         strucSel = (IStructuredSelection) selection;
62:                         final Object firstElement = strucSel.getFirstElement();
63:•                        if (firstElement instanceof EObject) {
64:                                 // TODO: ChainSaw - check whether specific clone functionality of ModelUtil is needed here
65:                                 copyModelElement = EcoreUtil.copy((EObject) firstElement);
66:                                 // copyModelElement = ModelUtil.clone((EObject) firstElement);
67:
68:                                 // only export the rootnode makes xml with references, otherwise (see (commented) line two) the children
69:                                 // will be "real" nested as containments of the node (is not necessary)
70:                                 result.add(copyModelElement);
71:                                 // result.addAll(copyModelElement.getAllContainedModelElements());
72:
73:                         } else {
74:                                 // do nothing System.out.println("NOT A MODELELEMENT");
75:                         }
76:                 }
77:
78:                 return result;
79:         }
80: }