Skip to content

Package: SaveProjectHandler

SaveProjectHandler

nameinstructionbranchcomplexitylinemethod
SaveProjectHandler()
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(Object)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
execute(Object, IEventBroker)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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 - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.ui.e4.handlers;
15:
16: import javax.inject.Named;
17:
18: import org.eclipse.e4.core.di.annotations.CanExecute;
19: import org.eclipse.e4.core.di.annotations.Execute;
20: import org.eclipse.e4.core.di.annotations.Optional;
21: import org.eclipse.e4.core.services.events.IEventBroker;
22: import org.eclipse.e4.ui.services.IServiceConstants;
23: import org.eclipse.e4.ui.workbench.UIEvents;
24: import org.eclipse.emf.ecp.core.ECPProject;
25: import org.eclipse.emf.ecp.core.util.ECPUtil;
26: import org.eclipse.emf.ecp.spi.ui.util.ECPHandlerHelper;
27:
28: /**
29: * @author Eugen
30: *
31: */
32: public class SaveProjectHandler {
33:
34:         /**
35:          * Saves the current {@link ECPProject}.
36:          *
37:          * @param object an object adaptable to an {@link ECPProject}
38:          * @param eventBroker the e4 event broker
39:          */
40:         @Execute
41:         public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional Object object, IEventBroker eventBroker) {
42:                 final ECPProject ecpProject = ECPUtil.getECPProjectManager().getProject(object);
43:•                if (ecpProject != null) {
44:                         ECPHandlerHelper.saveProject(ecpProject);
45:                         eventBroker.send(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC,
46:                                 "org.eclipse.emf.ecp.application.e4.handledtoolitem.0"); //$NON-NLS-1$
47:                 }
48:         }
49:
50:         /**
51:          * Checks whether the current selection is adaptable to an {@link ECPProject} and if so, whether this is dirty.
52:          *
53:          * @param object an object adaptable to an {@link ECPProject}
54:          * @return true if the object is adaptable to an {@link ECPProject} and dirty ot false otherwise.
55:          */
56:         @CanExecute
57:         public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional Object object) {
58:                 final ECPProject ecpProject = ECPUtil.getECPProjectManager().getProject(object);
59:•                if (ecpProject != null) {
60:                         return ecpProject.hasDirtyContents();
61:                 }
62:                 return false;
63:         }
64:
65: }