| /******************************************************************************* |
| * 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.common.geometry.data3d.provider; |
| |
| import java.text.DecimalFormat; |
| |
| import org.eclipse.apogy.common.geometry.data3d.ApogyCommonGeometryData3DPackage; |
| import org.eclipse.apogy.common.geometry.data3d.CartesianOrientationCoordinates; |
| import org.eclipse.emf.common.notify.AdapterFactory; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; |
| import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; |
| |
| public class CartesianOrientationCoordinatesCustomItemProvider extends CartesianOrientationCoordinatesItemProvider { |
| public CartesianOrientationCoordinatesCustomItemProvider(AdapterFactory adapterFactory) { |
| super(adapterFactory); |
| } |
| |
| // FIXME Should be centralized. |
| private DecimalFormat radiansDecimalFormat = new DecimalFormat("0.000"); |
| private DecimalFormat degreesDecimalFormat = new DecimalFormat("0.000"); |
| |
| protected void addXRotationPropertyDescriptor(Object object) { |
| |
| ItemPropertyDescriptor ipd = new ItemPropertyDescriptor( |
| ((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), |
| getString("_UI_CartesianOrientationCoordinates_xRotation_feature"), |
| getString("_UI_PropertyDescriptor_description", "_UI_CartesianOrientationCoordinates_xRotation_feature", |
| "_UI_CartesianOrientationCoordinates_type"), |
| ApogyCommonGeometryData3DPackage.Literals.CARTESIAN_ORIENTATION_COORDINATES__XROTATION, true, false, |
| false, ItemPropertyDescriptor.REAL_VALUE_IMAGE, null, null) { |
| @Override |
| protected Object getValue(EObject object, EStructuralFeature feature) { |
| CartesianOrientationCoordinates orientation = (CartesianOrientationCoordinates) object; |
| String radians = radiansDecimalFormat.format(orientation.getXRotation()); |
| String degrees = degreesDecimalFormat.format(Math.toDegrees(orientation.getXRotation())); |
| return radians + " (" + degrees + " deg)"; |
| } |
| }; |
| itemPropertyDescriptors.add(ipd); |
| } |
| |
| protected void addYRotationPropertyDescriptor(Object object) { |
| |
| ItemPropertyDescriptor ipd = new ItemPropertyDescriptor( |
| ((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), |
| getString("_UI_CartesianOrientationCoordinates_yRotation_feature"), |
| getString("_UI_PropertyDescriptor_description", "_UI_CartesianOrientationCoordinates_yRotation_feature", |
| "_UI_CartesianOrientationCoordinates_type"), |
| ApogyCommonGeometryData3DPackage.Literals.CARTESIAN_ORIENTATION_COORDINATES__YROTATION, true, false, |
| false, ItemPropertyDescriptor.REAL_VALUE_IMAGE, null, null) { |
| @Override |
| protected Object getValue(EObject object, EStructuralFeature feature) { |
| CartesianOrientationCoordinates orientation = (CartesianOrientationCoordinates) object; |
| String radians = radiansDecimalFormat.format(orientation.getYRotation()); |
| String degrees = degreesDecimalFormat.format(Math.toDegrees(orientation.getYRotation())); |
| return radians + " (" + degrees + " deg)"; |
| } |
| }; |
| itemPropertyDescriptors.add(ipd); |
| } |
| |
| protected void addZRotationPropertyDescriptor(Object object) { |
| |
| ItemPropertyDescriptor ipd = new ItemPropertyDescriptor( |
| ((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), |
| getString("_UI_CartesianOrientationCoordinates_zRotation_feature"), |
| getString("_UI_PropertyDescriptor_description", "_UI_CartesianOrientationCoordinates_zRotation_feature", |
| "_UI_CartesianOrientationCoordinates_type"), |
| ApogyCommonGeometryData3DPackage.Literals.CARTESIAN_ORIENTATION_COORDINATES__ZROTATION, true, false, |
| false, ItemPropertyDescriptor.REAL_VALUE_IMAGE, null, null) { |
| @Override |
| protected Object getValue(EObject object, EStructuralFeature feature) { |
| CartesianOrientationCoordinates orientation = (CartesianOrientationCoordinates) object; |
| String radians = radiansDecimalFormat.format(orientation.getZRotation()); |
| String degrees = degreesDecimalFormat.format(Math.toDegrees(orientation.getZRotation())); |
| return radians + " (" + degrees + " deg)"; |
| } |
| }; |
| itemPropertyDescriptors.add(ipd); |
| } |
| |
| @Override |
| public String getText(Object object) { |
| CartesianOrientationCoordinates orientation = (CartesianOrientationCoordinates) object; |
| String string = getString("_UI_CartesianOrientationCoordinates_type"); |
| string.concat(this.degreesDecimalFormat.format(Math.toDegrees(orientation.getXRotation()))); |
| string.concat(this.degreesDecimalFormat.format(Math.toDegrees(orientation.getYRotation()))); |
| string.concat(this.degreesDecimalFormat.format(Math.toDegrees(orientation.getZRotation()))); |
| return string; |
| } |
| } |