blob: 76a49199284f2d1f6d11a264c48282a76a318112 [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 - initial API and implementation
* Regent L'Archeveque
*
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
package org.eclipse.apogy.addons.vehicle.ui.composites;
import org.eclipse.apogy.addons.vehicle.ApogyAddonsVehiclePackage;
import org.eclipse.apogy.addons.vehicle.VehiclePathPlannerTool;
import org.eclipse.apogy.common.emf.transaction.ApogyCommonTransactionFacade;
import org.eclipse.apogy.common.emf.transaction.impl.ApogyCommonTransactionFacadeCustomImpl;
import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorFacade;
import org.eclipse.apogy.core.invocator.InvocatorSession;
import org.eclipse.apogy.core.invocator.Variable;
import org.eclipse.apogy.core.invocator.ui.composites.VariablesListComposite;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
public class VehiclePathPlannerToolComposite extends Composite {
private VehiclePathPlannerTool vehiclePathPlannerTool;
private final VariablesListComposite variablesListComposite;
public VehiclePathPlannerToolComposite(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(1, false));
Group grpVariable = new Group(this, SWT.NONE);
grpVariable.setLayout(new GridLayout(1, false));
grpVariable.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
grpVariable.setText("Variable");
this.variablesListComposite = new VariablesListComposite(grpVariable, SWT.NONE) {
@Override
protected void newSelection(ISelection selection) {
Variable variable = VehiclePathPlannerToolComposite.this.variablesListComposite.getSelectedVariable();
if (ApogyCommonTransactionFacade.INSTANCE.areEditingDomainsValid(
VehiclePathPlannerToolComposite.this.vehiclePathPlannerTool,
ApogyAddonsVehiclePackage.Literals.VEHICLE_PATH_PLANNER_TOOL__VARIABLE, variable,
false) == ApogyCommonTransactionFacadeCustomImpl.EXECUTE_COMMAND_ON_OWNER_DOMAIN) {
ApogyCommonTransactionFacade.INSTANCE.basicSet(
VehiclePathPlannerToolComposite.this.vehiclePathPlannerTool,
ApogyAddonsVehiclePackage.Literals.VEHICLE_PATH_PLANNER_TOOL__VARIABLE, variable);
} else {
VehiclePathPlannerToolComposite.this.vehiclePathPlannerTool.setVariable(variable);
}
newVariableSelected(variable);
}
};
InvocatorSession invocatorSession = ApogyCoreInvocatorFacade.INSTANCE.getActiveInvocatorSession();
if (invocatorSession != null && invocatorSession.getEnvironment() != null) {
this.variablesListComposite.setVariablesList(invocatorSession.getEnvironment().getVariablesList());
}
}
public VehiclePathPlannerTool getVehiclePathPlannerTool() {
return this.vehiclePathPlannerTool;
}
public void setVehiclePathPlannerTool(VehiclePathPlannerTool vehiclePathPlannerTool) {
this.vehiclePathPlannerTool = vehiclePathPlannerTool;
if (this.variablesListComposite != null && !this.variablesListComposite.isDisposed()) {
// TODO : Select the variable
}
}
/**
* Method called when a variable is selected.
*
* @param variable The variable just selected.
*/
protected void newVariableSelected(Variable variable) {
}
}