/** * Generated with Acceleo */ package org.eclipse.amalgam.tutorials.emf.droid.components; // Start of user code for imports import org.eclipse.amalgam.tutorials.emf.droid.DroidPackage; import org.eclipse.amalgam.tutorials.emf.droid.RadioButton; import org.eclipse.amalgam.tutorials.emf.droid.RadioGroup; import org.eclipse.amalgam.tutorials.emf.droid.parts.DroidViewsRepository; import org.eclipse.amalgam.tutorials.emf.droid.parts.RadioGroupPropertiesEditionPart; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.BasicDiagnostic; import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.common.util.WrappedException; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EcorePackage; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.util.Diagnostician; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent; import org.eclipse.emf.eef.runtime.context.PropertiesEditingContext; import org.eclipse.emf.eef.runtime.impl.components.SinglePartPropertiesEditingComponent; import org.eclipse.emf.eef.runtime.impl.filters.EObjectFilter; import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent; import org.eclipse.emf.eef.runtime.impl.utils.EEFConverterUtil; import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; // End of user code /** * * */ public class RadioGroupPropertiesEditionComponent extends SinglePartPropertiesEditingComponent { public static String BASE_PART = "Base"; //$NON-NLS-1$ /** * Settings for radioButtons ReferencesTable */ private ReferencesTableSettings radioButtonsSettings; /** * Default constructor * */ public RadioGroupPropertiesEditionComponent(PropertiesEditingContext editingContext, EObject radioGroup, String editing_mode) { super(editingContext, radioGroup, editing_mode); parts = new String[] { BASE_PART }; repositoryKey = DroidViewsRepository.class; partKey = DroidViewsRepository.RadioGroup.class; } /** * {@inheritDoc} * * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject, * org.eclipse.emf.ecore.resource.ResourceSet) * */ public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) { setInitializing(true); if (editingPart != null && key == partKey) { editingPart.setContext(elt, allResource); final RadioGroup radioGroup = (RadioGroup)elt; final RadioGroupPropertiesEditionPart basePart = (RadioGroupPropertiesEditionPart)editingPart; // init values if (radioGroup.getName() != null && isAccessible(DroidViewsRepository.RadioGroup.Properties.name)) basePart.setName(EEFConverterUtil.convertToString(EcorePackage.eINSTANCE.getEString(), radioGroup.getName())); if (isAccessible(DroidViewsRepository.RadioGroup.Properties.radioButtons)) { radioButtonsSettings = new ReferencesTableSettings(radioGroup, DroidPackage.eINSTANCE.getRadioGroup_RadioButtons()); basePart.initRadioButtons(radioButtonsSettings); } // init filters basePart.addFilterToRadioButtons(new ViewerFilter() { /** * {@inheritDoc} * * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) */ public boolean select(Viewer viewer, Object parentElement, Object element) { if (element instanceof EObject) return (!basePart.isContainedInRadioButtonsTable((EObject)element)); return element instanceof Resource; } }); basePart.addFilterToRadioButtons(new EObjectFilter(DroidPackage.eINSTANCE.getRadioButton())); // Start of user code for additional businessfilters for radioButtons // End of user code // init values for referenced views // init filters for referenced views } setInitializing(false); } /** * {@inheritDoc} * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) * */ public void updateSemanticModel(final IPropertiesEditionEvent event) { RadioGroup radioGroup = (RadioGroup)semanticObject; if (DroidViewsRepository.RadioGroup.Properties.name == event.getAffectedEditor()) { radioGroup.setName((java.lang.String)EEFConverterUtil.createFromString(EcorePackage.eINSTANCE.getEString(), (String)event.getNewValue())); } if (DroidViewsRepository.RadioGroup.Properties.radioButtons == event.getAffectedEditor()) { if (event.getKind() == PropertiesEditionEvent.ADD) { if (event.getNewValue() instanceof RadioButton) { radioButtonsSettings.addToReference((EObject) event.getNewValue()); } } else if (event.getKind() == PropertiesEditionEvent.REMOVE) { radioButtonsSettings.removeFromReference((EObject) event.getNewValue()); } } } /** * {@inheritDoc} * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updatePart(org.eclipse.emf.common.notify.Notification) */ public void updatePart(Notification msg) { if (editingPart.isVisible()) { RadioGroupPropertiesEditionPart basePart = (RadioGroupPropertiesEditionPart)editingPart; if (DroidPackage.eINSTANCE.getRadioGroup_Name().equals(msg.getFeature()) && basePart != null && isAccessible(DroidViewsRepository.RadioGroup.Properties.name)) { if (msg.getNewValue() != null) { basePart.setName(EcoreUtil.convertToString(EcorePackage.eINSTANCE.getEString(), msg.getNewValue())); } else { basePart.setName(""); } } if (DroidPackage.eINSTANCE.getRadioGroup_RadioButtons().equals(msg.getFeature()) && isAccessible(DroidViewsRepository.RadioGroup.Properties.radioButtons)) basePart.updateRadioButtons(); } } /** * {@inheritDoc} * * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) * */ public Diagnostic validateValue(IPropertiesEditionEvent event) { Diagnostic ret = Diagnostic.OK_INSTANCE; if (event.getNewValue() != null) { try { if (DroidViewsRepository.RadioGroup.Properties.name == event.getAffectedEditor()) { Object newValue = event.getNewValue(); if (newValue instanceof String) { newValue = EcoreUtil.createFromString(DroidPackage.eINSTANCE.getRadioGroup_Name().getEAttributeType(), (String)newValue); } ret = Diagnostician.INSTANCE.validate(DroidPackage.eINSTANCE.getRadioGroup_Name().getEAttributeType(), newValue); } } catch (IllegalArgumentException iae) { ret = BasicDiagnostic.toDiagnostic(iae); } catch (WrappedException we) { ret = BasicDiagnostic.toDiagnostic(we); } } return ret; } }