blob: 96a1589d10476e86059099d969f259cdd4604166 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2017 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.editor.properties.ext.widgets.reference.internal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.sirius.editor.properties.sections.common.AbstractComboPropertySection;
import org.eclipse.sirius.properties.ext.widgets.reference.propertiesextwidgetsreference.PropertiesExtWidgetsReferencePackage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
public class AbstractExtReferenceDescriptionExtendsPropertySection extends AbstractComboPropertySection {
@Override
protected String getDefaultLabelText() {
return "Extends"; //$NON-NLS-1$
}
@Override
protected String getLabelText() {
String labelText;
labelText = super.getLabelText() + ":"; //$NON-NLS-1$
return labelText;
}
@Override
protected EReference getFeature() {
return PropertiesExtWidgetsReferencePackage.eINSTANCE.getAbstractExtReferenceDescription_Extends();
}
@Override
protected Object getFeatureValue(int index) {
return getFeatureValueAt(index);
}
@Override
protected boolean isEqual(int index) {
boolean isEqual = false;
if (getFeatureValueAt(index) == null) {
isEqual = eObject.eGet(getFeature()) == null;
} else {
isEqual = getFeatureValueAt(index).equals(eObject.eGet(getFeature()));
}
return isEqual;
}
/**
* Returns the value at the specified index in the choice of values for the feature.
*
* @param index
* Index of the value.
* @return the value at the specified index in the choice of values.
*/
protected Object getFeatureValueAt(int index) {
List<?> values = getChoiceOfValues();
if (values.size() < index || values.size() == 0 || index == -1) {
return null;
}
return values.get(index);
}
/**
* Fetches the list of available values for the feature.
*
* @return The list of available values for the feature.
*/
@Override
protected List<?> getChoiceOfValues() {
List<?> values = Collections.emptyList();
List<IItemPropertyDescriptor> propertyDescriptors = getDescriptors();
for (IItemPropertyDescriptor propertyDescriptor : propertyDescriptors) {
if (((EStructuralFeature) propertyDescriptor.getFeature(eObject)) == getFeature()) {
values = new ArrayList<Object>(propertyDescriptor.getChoiceOfValues(eObject));
}
}
return values;
}
@Override
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent, tabbedPropertySheetPage);
}
}