| /******************************************************************************* |
| * 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.preferences; |
| |
| import org.eclipse.apogy.common.emf.ui.Activator; |
| import org.eclipse.apogy.common.emf.ui.DisplayUnitsRegistry; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.jface.preference.PreferencePage; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.layout.FillLayout; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Control; |
| import org.eclipse.swt.widgets.Group; |
| import org.eclipse.ui.IWorkbench; |
| import org.eclipse.ui.IWorkbenchPreferencePage; |
| |
| public class TypedElementsUnitsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { |
| |
| private UnitsProvidersUnitsMapComposite composite; |
| private Group structuralFeaturesUnitsGroup; |
| |
| /** |
| * Create the preference page. |
| */ |
| public TypedElementsUnitsPreferencePage() { |
| } |
| |
| /** |
| * Create contents of the preference page. |
| * |
| * @param parent |
| */ |
| @Override |
| public Control createContents(Composite parent) { |
| Composite container = new Composite(parent, SWT.NULL); |
| container.setLayout(new GridLayout(1, false)); |
| |
| this.structuralFeaturesUnitsGroup = new Group(container, SWT.None); |
| this.structuralFeaturesUnitsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
| this.structuralFeaturesUnitsGroup.setLayout(new FillLayout()); |
| this.structuralFeaturesUnitsGroup.setText("Typed elements units display"); |
| |
| this.composite = new UnitsProvidersUnitsMapComposite(this.structuralFeaturesUnitsGroup, SWT.None); |
| this.composite.setMap(EcoreUtil.copy(DisplayUnitsRegistry.INSTANCE.getEntriesMap())); |
| |
| return container; |
| } |
| |
| /** |
| * Initialize the preference page. |
| */ |
| @Override |
| public void init(IWorkbench workbench) { |
| setPreferenceStore(Activator.getDefault().getPreferenceStore()); |
| } |
| |
| @Override |
| public boolean performOk() { |
| storePreferences(); |
| return super.performOk(); |
| } |
| |
| @Override |
| protected void performApply() { |
| storePreferences(); |
| super.performApply(); |
| } |
| |
| @Override |
| protected void performDefaults() { |
| DisplayUnitsRegistry.INSTANCE.getEntriesMap().getEntries().clear(); |
| this.composite.setMap((EcoreUtil.copy(DisplayUnitsRegistry.INSTANCE.getEntriesMap()))); |
| super.performDefaults(); |
| } |
| |
| private void storePreferences() { |
| DisplayUnitsRegistry.INSTANCE.setEntriesMap(this.composite.getMap()); |
| DisplayUnitsRegistry.INSTANCE.save(); |
| } |
| } |