Skip to content

Package: DeleteProjectHandler

DeleteProjectHandler

nameinstructionbranchcomplexitylinemethod
DeleteProjectHandler()
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, List)
M: 8 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
execute(Shell, ECPProject, List)
M: 23 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 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:
16: package org.eclipse.emf.ecp.ui.e4.handlers;
17:
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: import javax.inject.Named;
22:
23: import org.eclipse.e4.core.di.annotations.CanExecute;
24: import org.eclipse.e4.core.di.annotations.Execute;
25: import org.eclipse.e4.core.di.annotations.Optional;
26: import org.eclipse.e4.ui.services.IServiceConstants;
27: import org.eclipse.emf.ecp.core.ECPProject;
28: import org.eclipse.emf.ecp.core.util.ECPContainer;
29: import org.eclipse.emf.ecp.spi.ui.util.ECPHandlerHelper;
30: import org.eclipse.swt.widgets.Shell;
31:
32: /**
33: * Handler to delete selected projects.
34: *
35: * @author Jonas
36: *
37: */
38: public class DeleteProjectHandler {
39:         /**
40:          * Deletes a project or a list of projects, based on the selection.
41:          *
42:          * @param shell
43:          * the current shell to display a confimation dialog.
44:          * @param ecpProject
45:          * an {@link ECPProject}, if only one is selected or null.
46:          * @param ecpProjects
47:          * a List of {@link ECPProject}s, is several projects are
48:          * selected or null
49:          */
50:         @Execute
51:         public void execute(
52:                 Shell shell,
53:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional final ECPProject ecpProject,
54:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional final List<ECPProject> ecpProjects) {
55:                 final List<ECPContainer> toBeDeleted = new ArrayList<ECPContainer>();
56:•                if (ecpProject != null) {
57:                         toBeDeleted.add(ecpProject);
58:                 }
59:•                if (ecpProjects != null) {
60:                         toBeDeleted.addAll(ecpProjects);
61:                 }
62:•                if (!toBeDeleted.isEmpty()) {
63:                         ECPHandlerHelper.deleteHandlerHelper(
64:                                 toBeDeleted, shell);
65:                 }
66:         }
67:
68:         /**
69:          * Checks if a single project or a list of projects are selected.
70:          *
71:          * @param ecpProject
72:          * an {@link ECPProject}, if only one is selected or null.
73:          * @param ecpProjects
74:          * a List of {@link ECPProject}s, is several projects are
75:          * selected or null
76:          *
77:          * @return true, if either a single project or a list of projects are selected
78:          */
79:         @CanExecute
80:         public boolean canExecute(
81:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional ECPProject ecpProject,
82:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional List<ECPProject> ecpProjects) {
83:•                return ecpProject != null || ecpProjects != null;
84:         }
85: }