Skip to content

Package: ECPSavePropertySource$1

ECPSavePropertySource$1

nameinstructionbranchcomplexitylinemethod
notifyChangeButtonState(ECPProject, boolean)
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%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.ui.tester;
15:
16: import java.util.LinkedHashMap;
17: import java.util.Map;
18:
19: import org.eclipse.emf.ecp.core.ECPProject;
20: import org.eclipse.emf.ecp.core.util.ECPUtil;
21: import org.eclipse.ui.AbstractSourceProvider;
22: import org.eclipse.ui.ISources;
23:
24: /**
25: * @author jfaltermeier
26: *
27: */
28: public class ECPSavePropertySource extends AbstractSourceProvider {
29:
30:         /**
31:          * Name of the property defining the save state of the currently selected project space.
32:          */
33:         public static final String CURRENT_SAVE_STATE_PROPERTY = "org.eclipse.emf.ecp.ui.e3.workbench.menu.currentProjectHasUnsavedChanges"; //$NON-NLS-1$
34:
35:         private final SaveButtonEnablementObserver saveButtonEnablementObserver;
36:
37:         private boolean isSaveButtonEnabled;
38:
39:         private static ECPProject project;
40:
41:         /**
42:          * Default Constructor.
43:          */
44:         public ECPSavePropertySource() {
45:                 saveButtonEnablementObserver = new SaveButtonEnablementObserver() {
46:
47:                         @Override
48:                         public void notifyChangeButtonState(ECPProject currentProject, boolean enableSaveButton) {
49:                                 project = currentProject;
50:                                 fireSourceChanged(ISources.WORKBENCH, CURRENT_SAVE_STATE_PROPERTY, enableSaveButton);
51:                         }
52:                 };
53:                 ECPUtil.getECPObserverBus().register(saveButtonEnablementObserver);
54:         }
55:
56:         /**
57:          * {@inheritDoc}
58:          *
59:          * @see org.eclipse.ui.ISourceProvider#dispose()
60:          */
61:         @Override
62:         public void dispose() {
63:                 if (saveButtonEnablementObserver != null) {
64:                         ECPUtil.getECPObserverBus().unregister(saveButtonEnablementObserver);
65:                 }
66:         }
67:
68:         /**
69:          * {@inheritDoc}
70:          *
71:          * @see org.eclipse.ui.ISourceProvider#getCurrentState()
72:          */
73:         @Override
74:         public Map<String, Object> getCurrentState() {
75:                 final Map<String, Object> map = new LinkedHashMap<String, Object>();
76:                 map.put(CURRENT_SAVE_STATE_PROPERTY, isSaveButtonEnabled);
77:                 return map;
78:         }
79:
80:         /**
81:          * Returns the project to be saved.
82:          *
83:          * @return the project which enabled the save button
84:          */
85:         public static ECPProject getProjectToSave() {
86:                 return project;
87:         }
88:
89:         /**
90:          * {@inheritDoc}
91:          *
92:          * @see org.eclipse.ui.ISourceProvider#getProvidedSourceNames()
93:          */
94:         @Override
95:         public String[] getProvidedSourceNames() {
96:                 return new String[] { CURRENT_SAVE_STATE_PROPERTY };
97:         }
98:
99: }