| /******************************************************************************* |
| * 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 - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.addons.vehicle.ui.impl; |
| |
| import org.eclipse.apogy.addons.vehicle.ui.Activator; |
| import org.eclipse.apogy.addons.vehicle.ui.ApogyAddonsVehicleUIPackage; |
| import org.eclipse.apogy.addons.vehicle.ui.ThrusterSceneObject; |
| import org.eclipse.apogy.addons.vehicle.ui.preferences.VehicleUIPreferencesConstants; |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.jface.preference.IPreferenceStore; |
| import org.eclipse.jface.preference.PreferenceConverter; |
| import org.eclipse.jface.util.IPropertyChangeListener; |
| import org.eclipse.jface.util.PropertyChangeEvent; |
| import org.eclipse.swt.graphics.RGB; |
| |
| public class ThrusterPresentationCustomImpl extends ThrusterPresentationImpl { |
| |
| protected IPropertyChangeListener preferencesListener = null; |
| |
| protected ThrusterPresentationCustomImpl() { |
| super(); |
| |
| applyPreferences(); |
| |
| // Register a listener to the preference store |
| Activator.getDefault().getPreferenceStore().addPropertyChangeListener(getPreferencesListener()); |
| } |
| |
| @Override |
| protected void applyPreferences() { |
| IPreferenceStore store = Activator.getDefault().getPreferenceStore(); |
| |
| // Plume Envelope Color |
| setColor(PreferenceConverter.getColor(store, |
| VehicleUIPreferencesConstants.DEFAULT_THRUSTER_PLUME_ENVELOPE_COLOR_ID)); |
| |
| // Plume Envelope Visibility |
| setPlumeEnvelopeVisible( |
| store.getBoolean(VehicleUIPreferencesConstants.DEFAULT_THRUSTER_PLUME_ENVELOPE_VISIBILITY_ID)); |
| |
| // Plume Envelope Length |
| setPlumeEnvelopeLength( |
| store.getDouble(VehicleUIPreferencesConstants.DEFAULT_THRUSTER_PLUME_ENVELOPE_LENGTH_ID)); |
| |
| super.applyPreferences(); |
| } |
| |
| @Override |
| protected void updateSceneObject(Notification notification) { |
| if (this.sceneObject != null) { |
| ThrusterSceneObject thrusterSceneObject = (ThrusterSceneObject) this.sceneObject; |
| |
| int featureID = notification.getFeatureID(ThrusterPresentationCustomImpl.class); |
| |
| switch (featureID) { |
| case ApogyAddonsVehicleUIPackage.THRUSTER_PRESENTATION__PLUME_ENVELOPE_VISIBLE: |
| thrusterSceneObject.setPlumeEnvelopeVisible(notification.getNewBooleanValue()); |
| break; |
| |
| case ApogyAddonsVehicleUIPackage.THRUSTER_PRESENTATION__PLUME_ENVELOPE_LENGTH: |
| thrusterSceneObject.setPlumeEnvelopeLength(notification.getNewDoubleValue()); |
| break; |
| |
| case ApogyAddonsVehicleUIPackage.THRUSTER_PRESENTATION__COLOR: |
| if (notification.getNewValue() instanceof RGB) { |
| RGB color = (RGB) notification.getNewValue(); |
| thrusterSceneObject.setColor(color); |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| |
| super.updateSceneObject(notification); |
| } |
| |
| @Override |
| protected void initialSceneObject() { |
| ThrusterSceneObject thrusterSceneObject = (ThrusterSceneObject) this.sceneObject; |
| |
| // Plume Envelope |
| thrusterSceneObject.setPlumeEnvelopeVisible(isPlumeEnvelopeVisible()); |
| thrusterSceneObject.setPlumeEnvelopeLength(getPlumeEnvelopeLength()); |
| thrusterSceneObject.setColor(getColor()); |
| |
| super.initialSceneObject(); |
| } |
| |
| private IPropertyChangeListener getPreferencesListener() { |
| if (this.preferencesListener == null) { |
| this.preferencesListener = new IPropertyChangeListener() { |
| @Override |
| public void propertyChange(PropertyChangeEvent event) { |
| applyPreferences(); |
| } |
| }; |
| } |
| |
| return this.preferencesListener; |
| } |
| |
| @Override |
| protected void finalize() throws Throwable { |
| Activator.getDefault().getPreferenceStore().removePropertyChangeListener(getPreferencesListener()); |
| super.finalize(); |
| } |
| } // ThrusterPresentationImpl |