| /******************************************************************************* |
| * 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: |
| * Regent L'Archeveque - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.environment.earth.orbit.planner.ui.composites; |
| |
| import java.text.DecimalFormat; |
| |
| import org.eclipse.apogy.common.emf.ApogyCommonEMFFacade; |
| import org.eclipse.apogy.common.emf.EObjectReferencesList; |
| import org.eclipse.apogy.common.emf.ui.ECollectionCompositeSettings; |
| import org.eclipse.apogy.common.emf.ui.composites.AbstractECollectionComposite; |
| import org.eclipse.apogy.common.emf.ui.emfforms.composites.EMFFormsEListComposite; |
| import org.eclipse.apogy.core.environment.earth.orbit.planner.ApogyCoreEnvironmentEarthOrbitPlannerFacade; |
| import org.eclipse.apogy.core.environment.earth.orbit.planner.ApogyCoreEnvironmentEarthOrbitPlannerPackage; |
| import org.eclipse.apogy.core.environment.earth.orbit.planner.ObservationAnalysisPlanner; |
| import org.eclipse.apogy.core.environment.earth.orbit.planner.ObservationAnalysisPlannerNode; |
| import org.eclipse.apogy.core.environment.earth.orbit.planner.ui.wizards.ExportObservationPlanWizard; |
| import org.eclipse.emf.common.notify.AdapterFactory; |
| import org.eclipse.emf.databinding.FeaturePath; |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; |
| import org.eclipse.jface.viewers.ColumnLabelProvider; |
| import org.eclipse.jface.viewers.TreeViewer; |
| import org.eclipse.jface.viewers.TreeViewerColumn; |
| import org.eclipse.jface.wizard.Wizard; |
| import org.eclipse.jface.wizard.WizardDialog; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.widgets.Composite; |
| |
| public class PlannerSolutionsComposite extends |
| EMFFormsEListComposite<ObservationAnalysisPlanner, ObservationAnalysisPlannerNode, ObservationAnalysisPlannerNode> { |
| |
| // FIXME Duration Format. |
| public static final DecimalFormat DURATION_FORMAT = new DecimalFormat("0.00"); |
| public static final DecimalFormat PERCENT_FORMAT = new DecimalFormat("0.00"); |
| |
| private static final int SOLUTION_ID_COL_MIN_WIDTH = 100; |
| private static final int FROM_DATE_COL_MIN_WIDTH = 200; |
| private static final int TO_DATE_COL_MIN_WIDTH = 200; |
| private static final int DURATION_COL_MIN_WIDTH = 120; |
| private static final int RATIO_COL_MIN_WIDTH = 120; |
| private static final int COVERAGE_COL_MIN_WIDTH = 100; |
| private static final int COST_COL_MIN_WIDTH = 100; |
| |
| public PlannerSolutionsComposite(Composite parent, int style, ECollectionCompositeSettings settings) { |
| super(parent, style, FeaturePath.fromList( |
| ApogyCoreEnvironmentEarthOrbitPlannerPackage.Literals.OBSERVATION_ANALYSIS_PLANNER__RESULT, |
| ApogyCoreEnvironmentEarthOrbitPlannerPackage.Literals.OBSERVATION_ANALYSIS_PLANNER_RESULT__PLAN_ROOT_NODE), |
| ApogyCoreEnvironmentEarthOrbitPlannerPackage.Literals.OBSERVATION_ANALYSIS_PLANNER_NODE__CHILDREN, |
| settings); |
| } |
| |
| @Override |
| protected AdapterFactoryContentProvider createContentProvider(AdapterFactory adapterFactory) { |
| return new PlannerSolutionsContentProvider(adapterFactory) { |
| @Override |
| public EStructuralFeature getEStructuralFeature() { |
| return PlannerSolutionsComposite.this.getEStructuralFeature(); |
| } |
| |
| @Override |
| public boolean hasChildren(Object object) { |
| return false; |
| } |
| }; |
| } |
| |
| @Override |
| protected void createButtons(Composite parent, int style) { |
| createExportButton(parent, style); |
| } |
| |
| @Override |
| protected void doExport() { |
| EObjectReferencesList<ObservationAnalysisPlannerNode> plan = ApogyCoreEnvironmentEarthOrbitPlannerFacade.INSTANCE |
| .getPlannerSolution(getSelectedItemObjects().get(0)); |
| Wizard wizard = new ExportObservationPlanWizard( |
| ApogyCoreEnvironmentEarthOrbitPlannerFacade.INSTANCE.getObservationAnalysisPlannerTool(), plan, |
| getRootEObject()); |
| WizardDialog dialog = new WizardDialog(getShell(), wizard); |
| dialog.open(); |
| } |
| |
| @Override |
| protected void createColumns(TreeViewer viewer) { |
| // ID. |
| TreeViewerColumn idColumn = new TreeViewerColumn(viewer, SWT.NONE); |
| idColumn.getColumn().setWidth(75); |
| idColumn.getColumn().setText("ID"); |
| idColumn.setLabelProvider(new ColumnLabelProvider() { |
| @Override |
| public String getText(Object element) { |
| return ((ObservationAnalysisPlannerNode) element).getId(); |
| } |
| }); |
| idColumn.getColumn().setData(AbstractECollectionComposite.TREE_COLUMN_MIN_WIDTH, SOLUTION_ID_COL_MIN_WIDTH); |
| |
| // From Date. |
| TreeViewerColumn fromDateColumn = new TreeViewerColumn(viewer, SWT.NONE); |
| fromDateColumn.getColumn().setWidth(225); |
| fromDateColumn.getColumn().setText("From Date"); |
| fromDateColumn.setLabelProvider(new ColumnLabelProvider() { |
| @Override |
| public String getText(Object element) { |
| return ApogyCommonEMFFacade.INSTANCE |
| .format(((ObservationAnalysisPlannerNode) element).getFirstLevelNode().getPass().getFromDate()); |
| } |
| }); |
| fromDateColumn.getColumn().setData(AbstractECollectionComposite.TREE_COLUMN_MIN_WIDTH, FROM_DATE_COL_MIN_WIDTH); |
| |
| // To Date. |
| TreeViewerColumn toDateColumn = new TreeViewerColumn(viewer, SWT.NONE); |
| toDateColumn.getColumn().setWidth(225); |
| toDateColumn.getColumn().setText("To Date"); |
| toDateColumn.setLabelProvider(new ColumnLabelProvider() { |
| @Override |
| public String getText(Object element) { |
| return ApogyCommonEMFFacade.INSTANCE |
| .format(((ObservationAnalysisPlannerNode) element).getPass().getToDate()); |
| } |
| }); |
| toDateColumn.getColumn().setData(AbstractECollectionComposite.TREE_COLUMN_MIN_WIDTH, TO_DATE_COL_MIN_WIDTH); |
| |
| // Duration. |
| TreeViewerColumn solutionDurationColumn = new TreeViewerColumn(viewer, SWT.NONE); |
| solutionDurationColumn.getColumn().setWidth(225); |
| solutionDurationColumn.getColumn().setText("Solution Duration (min)"); |
| solutionDurationColumn.setLabelProvider(new ColumnLabelProvider() { |
| @Override |
| public String getText(Object element) { |
| return DURATION_FORMAT |
| .format((0.001 / 60) * ((ObservationAnalysisPlannerNode) element).getSolutionDuration()); |
| } |
| }); |
| solutionDurationColumn.getColumn().setData(AbstractECollectionComposite.TREE_COLUMN_MIN_WIDTH, |
| DURATION_COL_MIN_WIDTH); |
| |
| // Duration. |
| TreeViewerColumn passesDurationColumn = new TreeViewerColumn(viewer, SWT.NONE); |
| passesDurationColumn.getColumn().setWidth(225); |
| passesDurationColumn.getColumn().setText("Passes Duration (min)"); |
| passesDurationColumn.setLabelProvider(new ColumnLabelProvider() { |
| @Override |
| public String getText(Object element) { |
| return DURATION_FORMAT |
| .format((0.001 / 60) * ((ObservationAnalysisPlannerNode) element).getTotalPassesDuration()); |
| } |
| }); |
| passesDurationColumn.getColumn().setData(AbstractECollectionComposite.TREE_COLUMN_MIN_WIDTH, |
| DURATION_COL_MIN_WIDTH); |
| |
| // % Usage Ratio. |
| TreeViewerColumn usageRatioColumn = new TreeViewerColumn(viewer, SWT.NONE); |
| usageRatioColumn.getColumn().setWidth(225); |
| usageRatioColumn.getColumn().setText("Usage Ratio (%)"); |
| usageRatioColumn.setLabelProvider(new ColumnLabelProvider() { |
| @Override |
| public String getText(Object element) { |
| return DURATION_FORMAT |
| .format(((ObservationAnalysisPlannerNode) element).getSolutionDuration() < 0.001 ? 0 |
| : 100 * ((ObservationAnalysisPlannerNode) element).getTotalPassesDuration() |
| / ((ObservationAnalysisPlannerNode) element).getSolutionDuration()); |
| } |
| }); |
| passesDurationColumn.getColumn().setData(AbstractECollectionComposite.TREE_COLUMN_MIN_WIDTH, |
| RATIO_COL_MIN_WIDTH); |
| |
| // Coverage. |
| TreeViewerColumn coverageColumn = new TreeViewerColumn(viewer, SWT.NONE); |
| coverageColumn.getColumn().setWidth(225); |
| coverageColumn.getColumn().setText("Coverage (%)"); |
| coverageColumn.setLabelProvider(new ColumnLabelProvider() { |
| @Override |
| public String getText(Object element) { |
| return PERCENT_FORMAT.format(((ObservationAnalysisPlannerNode) element).getLevel() |
| / (double)getRootEObject().getOrbitAnalysisData().getObservationTargets().size() * 100); |
| } |
| }); |
| coverageColumn.getColumn().setData(AbstractECollectionComposite.TREE_COLUMN_MIN_WIDTH, COVERAGE_COL_MIN_WIDTH); |
| |
| // Cost. |
| TreeViewerColumn costColumn = new TreeViewerColumn(viewer, SWT.NONE); |
| costColumn.getColumn().setWidth(225); |
| costColumn.getColumn().setText("Cost"); |
| costColumn.setLabelProvider(new ColumnLabelProvider() { |
| @Override |
| public String getText(Object element) { |
| return Double.toString(ApogyCoreEnvironmentEarthOrbitPlannerFacade.INSTANCE.getSolutionTotalCost( |
| ApogyCoreEnvironmentEarthOrbitPlannerFacade.INSTANCE.getPlannerSolution((ObservationAnalysisPlannerNode) element))); |
| } |
| }); |
| costColumn.getColumn().setData(AbstractECollectionComposite.TREE_COLUMN_MIN_WIDTH, COST_COL_MIN_WIDTH); |
| } |
| } |