Skip to content

Package: NewModelElementHandler

NewModelElementHandler

nameinstructionbranchcomplexitylinemethod
NewModelElementHandler()
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%
canExecute(ECPProject)
M: 6 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
execute(Shell, ECPProject)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 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.e4.handlers;
16:
17: import javax.inject.Named;
18:
19: import org.eclipse.e4.core.di.annotations.CanExecute;
20: import org.eclipse.e4.core.di.annotations.Execute;
21: import org.eclipse.e4.core.di.annotations.Optional;
22: import org.eclipse.e4.ui.services.IServiceConstants;
23: import org.eclipse.emf.ecp.core.ECPProject;
24: import org.eclipse.emf.ecp.spi.ui.util.ECPHandlerHelper;
25: import org.eclipse.swt.widgets.Shell;
26:
27: /**
28: * Handler to create new model elements on the root level of {@link ECPProject}s.
29: *
30: * @author Jonas
31: *
32: */
33: public class NewModelElementHandler {
34:         /**
35:          * Opens a dialog to select a new {@link org.eclipse.emf.ecore.EObject} to be created.
36:          *
37:          * @param shell the Shell to display the dialog.
38:          * @param ecpProject the selected {@link ECPProject}, parent of the newly created
39:          * {@link org.eclipse.emf.ecore.EObject}
40:          */
41:         @Execute
42:         public void execute(Shell shell, @Named(IServiceConstants.ACTIVE_SELECTION) @Optional ECPProject ecpProject) {
43:•                if (ecpProject == null) {
44:                         return;
45:                 }
46:                 ECPHandlerHelper.addModelElement(ecpProject, shell, true);
47:         }
48:
49:         /**
50:          * Checks if the current selection is an {@link ECPProject}.
51:          *
52:          * @param ecpProject the current selection, if it is an {@link ECPProject} or null otherwise.
53:          * @return if the current selection is an {@link ECPProject}
54:          */
55:         @CanExecute
56:         public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ECPProject ecpProject) {
57:•                return ecpProject != null;
58:         }
59: }