blob: 933c2c99e1fd24be68e7da36eda37e5a4d332838 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pierre Allard,
* Regent L'Archeveque,
* Olivier L. Larouche - initial API and implementation
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.emf.ui.impl;
import org.eclipse.apogy.common.emf.ApogyCommonEMFFacade;
import org.eclipse.apogy.common.emf.ui.Activator;
import org.eclipse.apogy.common.emf.ui.ApogyCommonEMFUIFactory;
import org.eclipse.apogy.common.emf.ui.DisplayUnitsRegistry;
import org.eclipse.apogy.common.emf.ui.ETypedElementToUnitsMap;
import org.eclipse.apogy.common.emf.ui.preferences.PreferencesConstants;
import org.eclipse.emf.ecore.EObject;
public class DisplayUnitsRegistryCustomImpl extends DisplayUnitsRegistryImpl {
private static DisplayUnitsRegistry instance = null;
// FIXME Should use APOGY isSingleton="true"
public static DisplayUnitsRegistry getInstance() {
if (instance == null) {
instance = new DisplayUnitsRegistryCustomImpl();
String stringMap = Activator.getDefault().getPreferenceStore()
.getString(PreferencesConstants.TYPED_ELEMENTS_UNITS_ID);
if (!"".equals(stringMap)) {
EObject object = ApogyCommonEMFFacade.INSTANCE.deserializeString(stringMap,
PreferencesConstants.TYPED_ELEMENTS_UNITS_ID);
if (object instanceof ETypedElementToUnitsMap) {
instance.setEntriesMap((ETypedElementToUnitsMap) object);
}
}
}
return instance;
}
public ETypedElementToUnitsMap getEntriesMap() {
ETypedElementToUnitsMap map = super.getEntriesMap();
if (map == null) {
map = ApogyCommonEMFUIFactory.eINSTANCE.createETypedElementToUnitsMap();
setEntriesMap(map);
}
return map;
}
@Override
public void save() {
Activator.getDefault().getPreferenceStore().setValue(PreferencesConstants.TYPED_ELEMENTS_UNITS_ID,
ApogyCommonEMFFacade.INSTANCE.serializeEObject(getEntriesMap(),
PreferencesConstants.TYPED_ELEMENTS_UNITS_ID));
}
} // DisplayUnitsRegistryImpl