Skip to content

Package: CreateNewInstanceAction

CreateNewInstanceAction

nameinstructionbranchcomplexitylinemethod
CreateNewInstanceAction()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
execute(ExecutionEvent)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
execute(List)
M: 83 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
shouldShow(List)
M: 2 C: 21
91%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 3
75%
M: 0 C: 1
100%

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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.editor.ecore.actions;
15:
16: import java.util.List;
17:
18: import org.eclipse.core.commands.ExecutionEvent;
19: import org.eclipse.core.commands.ExecutionException;
20: import org.eclipse.core.runtime.IStatus;
21: import org.eclipse.core.runtime.MultiStatus;
22: import org.eclipse.core.runtime.Status;
23: import org.eclipse.emf.common.util.Diagnostic;
24: import org.eclipse.emf.ecore.EClass;
25: import org.eclipse.emf.ecore.EObject;
26: import org.eclipse.emf.ecore.util.Diagnostician;
27: import org.eclipse.emfforms.spi.swt.treemasterdetail.actions.MasterDetailAction;
28: import org.eclipse.jface.dialogs.ErrorDialog;
29: import org.eclipse.jface.wizard.WizardDialog;
30:
31: /**
32: * @author Lucas Koehler
33: *
34: */
35: public class CreateNewInstanceAction extends MasterDetailAction {
36:
37:         // TODO proper icon
38:         private static final String ICON_PATH = "icons/EcoreModelFile.gif";
39:         private static final String ACTION_NAME = "Create New Dynamic Instance";
40:
41:         /**
42:          * Default constructor.
43:          */
44:         public CreateNewInstanceAction() {
45:                 setLabel(ACTION_NAME);
46:                 setImagePath(ICON_PATH);
47:         }
48:
49:         @Override
50:         public Object execute(ExecutionEvent event) throws ExecutionException {
51:                 return null;
52:         }
53:
54:         @Override
55:         public boolean shouldShow(List<Object> objects) {
56:•                if (objects.size() != 1 || !EObject.class.isInstance(objects.get(0))) {
57:                         return false;
58:                 }
59:                 final EObject eObject = EObject.class.cast(objects.get(0));
60:                 return EClass.class.isInstance(eObject);
61:         }
62:
63:         @Override
64:         public void execute(List<Object> objects) {
65:                 final EObject object = EObject.class.cast(objects.get(0));
66:                 final EClass eClass = EClass.class.cast(object);
67:                 final Diagnostic validate = Diagnostician.INSTANCE.validate(eClass);
68:•                if (validate.getSeverity() == Diagnostic.OK) {
69:                         final CreateNewInstaceWizard wizard = new CreateNewInstaceWizard(eClass);
70:                         new WizardDialog(getTreeViewer().getTree().getShell(), wizard).open();
71:                 } else {
72:                         final MultiStatus status = new MultiStatus("org.eclipse.emfforms.editor.ecore", 4,
73:                                 "Can not create a new instance file for EClass " + eClass.getName() + " because it is invalid.", null);
74:•                        for (final Diagnostic d : validate.getChildren()) {
75:                                 status.add(new Status(IStatus.ERROR, "org.eclipse.emfforms.editor.ecore", d.getMessage()));
76:                         }
77:                         ErrorDialog.openError(getTreeViewer().getTree().getShell(), "Error", null, status);
78:                 }
79:         }
80:
81: }