blob: 5e15e8213c8b8c588fd9f8831b24bae2db399776 [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.core.invocator.ui.composites;
import org.eclipse.apogy.common.converters.ApogyCommonConvertersFacade;
import org.eclipse.apogy.common.converters.IFileExporter;
import org.eclipse.apogy.common.converters.ui.wizards.ExportToFileWizard;
import org.eclipse.apogy.common.emf.ApogyCommonEMFFacade;
import org.eclipse.apogy.common.emf.ui.emfforms.ApogyCommonEMFUiEMFFormsFacade;
import org.eclipse.apogy.core.invocator.AbstractResultValue;
import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorFacade;
import org.eclipse.apogy.core.invocator.OperationCallResult;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
public class AbstractResultValueDetailsComposite extends Composite {
private AbstractResultValue resultValue;
private Object value = null;
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
private final ScrolledForm scrldResults;
private final Section sctnProductDetails;
private final Button exportButton;
private final Composite compositeDetails;
public AbstractResultValueDetailsComposite(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(1, false));
this.scrldResults = this.formToolkit.createScrolledForm(this);
this.scrldResults.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
this.scrldResults.setBounds(0, 0, 186, 165);
this.formToolkit.paintBordersFor(this.scrldResults);
{
TableWrapLayout tableWrapLayout = new TableWrapLayout();
tableWrapLayout.makeColumnsEqualWidth = true;
tableWrapLayout.numColumns = 1;
this.scrldResults.getBody().setLayout(tableWrapLayout);
}
// Abstract Result Details
this.sctnProductDetails = this.formToolkit.createSection(this.scrldResults.getBody(),
ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
TableWrapData twd_sctnNewSection = new TableWrapData(TableWrapData.FILL, TableWrapData.FILL, 1, 1);
twd_sctnNewSection.grabHorizontal = true;
twd_sctnNewSection.grabVertical = true;
twd_sctnNewSection.valign = TableWrapData.FILL;
this.sctnProductDetails.setLayoutData(twd_sctnNewSection);
// sctnProductDetails.setBounds(0, 0, 112, 27);
this.formToolkit.paintBordersFor(this.sctnProductDetails);
this.sctnProductDetails.setText("Return Value Details");
// Details
Composite detailsTop = new Composite(this.sctnProductDetails, SWT.NONE);
detailsTop.setLayout(new GridLayout(1, false));
// Export.
this.exportButton = new Button(detailsTop, SWT.PUSH);
this.exportButton.setText("Export Data Product to File...");
this.exportButton.setToolTipText("Export this Data Product to file(s).");
this.exportButton.setEnabled(false);
this.exportButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent arg0) {
IFileExporter iFileExporter = ApogyCommonConvertersFacade.INSTANCE
.getIFileExporter(AbstractResultValueDetailsComposite.this.value);
ExportToFileWizard wizard = new ExportToFileWizard(iFileExporter,
AbstractResultValueDetailsComposite.this.value);
WizardDialog dialog = new WizardDialog(getShell(), wizard);
dialog.open();
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
});
// Details
this.compositeDetails = new Composite(detailsTop, SWT.NONE);
GridData gd_compositeDetails = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_compositeDetails.widthHint = 398;
gd_compositeDetails.minimumWidth = 398;
this.compositeDetails.setLayoutData(gd_compositeDetails);
this.compositeDetails.setLayout(new GridLayout(1, false));
this.formToolkit.adapt(detailsTop);
this.formToolkit.paintBordersFor(detailsTop);
this.sctnProductDetails.setClient(detailsTop);
this.sctnProductDetails.setExpanded(true);
}
public AbstractResultValue getAbstractResultValue() {
return this.resultValue;
}
public void setAbstractResultValue(AbstractResultValue resultValue) {
this.resultValue = resultValue;
if (!isDisposed()) {
// Dispose of the compositeDetails children.
for (Control control : this.compositeDetails.getChildren()) {
control.dispose();
}
if (resultValue != null) {
this.value = ApogyCoreInvocatorFacade.INSTANCE.getResultValue(resultValue.getResult());
if (this.value instanceof EObject) {
EObject eObject = (EObject) this.value;
// VView viewModel =
// ApogyCommonEMFUiEMFFormsFacade.INSTANCE.createDefaultViewModel(eObject);
// ApogyCommonEMFUiEMFFormsFacade.INSTANCE.createEMFForms(compositeDetails,
// eObject, viewModel);
ApogyCommonEMFUiEMFFormsFacade.INSTANCE.createEMFForms(this.compositeDetails, eObject);
if (!this.exportButton.isDisposed())
this.exportButton.setEnabled(canBeExportedToFile(eObject));
} else if (this.value != null) {
if (!this.exportButton.isDisposed())
this.exportButton.setEnabled(false);
if (!this.compositeDetails.isDisposed())
createValueLabel(this.compositeDetails, resultValue);
} else {
if (!this.exportButton.isDisposed())
this.exportButton.setEnabled(false);
ApogyCommonEMFUiEMFFormsFacade.INSTANCE.createEMFForms(this.compositeDetails, null,
"No data to display");
}
if (!this.compositeDetails.isDisposed())
this.compositeDetails.layout();
}
}
}
protected void createValueLabel(Composite parent, AbstractResultValue resultValue) {
parent.setLayout(new GridLayout(1, false));
Object value = ApogyCoreInvocatorFacade.INSTANCE.getResultValue(resultValue.getResult());
Composite baseComposite = new Composite(parent, SWT.NONE);
baseComposite.setLayout(new GridLayout(3, false));
baseComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
Label resultLabel = new Label(baseComposite, SWT.NONE);
resultLabel.setText("Result : ");
Text valueLabel = new Text(baseComposite, SWT.NONE);
valueLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
valueLabel.setText(value.toString());
valueLabel.setEditable(false);
Label unitsLabel = new Label(baseComposite, SWT.NONE);
if (resultValue.getResult() instanceof OperationCallResult) {
OperationCallResult operationCallResult = (OperationCallResult) resultValue.getResult();
if (operationCallResult.getOperationCall() != null) {
String units = ApogyCommonEMFFacade.INSTANCE
.getEngineeringUnitsAsString(operationCallResult.getOperationCall().getEOperation());
if (units != null)
unitsLabel.setText(units);
} else {
unitsLabel.setText("No units applicable.");
}
}
}
protected boolean canBeExportedToFile(EObject eObject) {
return (ApogyCommonConvertersFacade.INSTANCE.getIFileExporter(eObject) != null);
}
}