blob: 1d07c37ff6130a0cd3b1d4141cdb4132fbfefdcd [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.provider;
import java.util.Collection;
import java.util.List;
import org.eclipse.apogy.common.emf.ApogyCommonEMFFacade;
import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorFacade;
import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorPackage;
import org.eclipse.apogy.core.invocator.TypeMemberImplementation;
import org.eclipse.apogy.core.invocator.Variable;
import org.eclipse.apogy.core.invocator.VariableImplementation;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
public class VariableImplementationCustomItemProvider extends VariableImplementationItemProvider {
public VariableImplementationCustomItemProvider(AdapterFactory adapterFactory) {
super(adapterFactory);
}
// FIXME Remove property descriptors.
@Override
protected void addImplementationClassPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(new ItemPropertyDescriptor(
((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), getResourceLocator(),
getString("_UI_VariableImplementation_implementationClass_feature"),
getString("_UI_PropertyDescriptor_description",
"_UI_VariableImplementation_implementationClass_feature", "_UI_VariableImplementation_type"),
ApogyCoreInvocatorPackage.Literals.ABSTRACT_TYPE_IMPLEMENTATION__IMPLEMENTATION_CLASS, true, false,
true, null, null, null) {
@Override
protected Collection<?> getComboBoxObjects(Object object) {
VariableImplementation implementation = (VariableImplementation) object;
return ApogyCommonEMFFacade.INSTANCE
.getAllSubEClasses(implementation.getVariable().getVariableType().getInterfaceClass());
}
});
}
@Override
public String getText(Object object) {
VariableImplementation variableImplementation = (VariableImplementation) object;
String label = getString("_UI_VariableImplementation_type");
Variable variable = variableImplementation.getVariable();
if (variableImplementation.getVariable() != null) {
if (variable.getName() != null && variable.getName().length() > 0) {
label = variable.getName();
}
if (variableImplementation.getImplementationClass() != null) {
label += " -> " + variableImplementation.getImplementationClass().getInstanceClassName();
}
}
return label;
}
@Override
protected Command createSetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Object value,
int index) {
CompoundCommand compoundCommand = new CompoundCommand();
/** Execute default set operation. */
compoundCommand.append(new SetCommand(domain, owner, feature, value, index));
if (feature == ApogyCoreInvocatorPackage.Literals.VARIABLE_IMPLEMENTATION__VARIABLE) {
Variable variable = (Variable) value;
if (variable.getVariableType() != null) {
List<TypeMemberImplementation> implementations = ApogyCoreInvocatorFacade.INSTANCE
.createTypeMemberImplementations(variable.getVariableType());
if (implementations != null && !implementations.isEmpty()) {
/** Clear existing list. */
compoundCommand.append(new SetCommand(domain, owner,
ApogyCoreInvocatorPackage.Literals.ABSTRACT_TYPE_IMPLEMENTATION__TYPE_MEMBER_IMPLEMENTATIONS,
implementations));
compoundCommand.append(new AddCommand(domain, owner,
ApogyCoreInvocatorPackage.Literals.ABSTRACT_TYPE_IMPLEMENTATION__TYPE_MEMBER_IMPLEMENTATIONS,
implementations));
}
}
}
return compoundCommand;
}
}