/** * Generated with Acceleo */ package org.eclipse.xtext.example.fowlerdsl.statemachine.components; // Start of user code for imports import org.eclipse.emf.common.command.Command; 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.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent; import org.eclipse.emf.eef.runtime.context.PropertiesEditingContext; import org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext; import org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext; 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.policies.PropertiesEditingPolicy; import org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy; import org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider; import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.xtext.example.fowlerdsl.statemachine.Event; import org.eclipse.xtext.example.fowlerdsl.statemachine.State; import org.eclipse.xtext.example.fowlerdsl.statemachine.Statemachine; import org.eclipse.xtext.example.fowlerdsl.statemachine.StatemachinePackage; import org.eclipse.xtext.example.fowlerdsl.statemachine.parts.StatemachinePropertiesEditionPart; import org.eclipse.xtext.example.fowlerdsl.statemachine.parts.StatemachineViewsRepository; // End of user code /** * * */ public class StatemachinePropertiesEditionComponent extends SinglePartPropertiesEditingComponent { public static String BASE_PART = "Base"; //$NON-NLS-1$ /** * Settings for events ReferencesTable */ protected ReferencesTableSettings eventsSettings; /** * Settings for resetEvents ReferencesTable */ private ReferencesTableSettings resetEventsSettings; /** * Settings for commands ReferencesTable */ protected ReferencesTableSettings commandsSettings; /** * Settings for states ReferencesTable */ protected ReferencesTableSettings statesSettings; /** * Default constructor * */ public StatemachinePropertiesEditionComponent(PropertiesEditingContext editingContext, EObject statemachine, String editing_mode) { super(editingContext, statemachine, editing_mode); parts = new String[] { BASE_PART }; repositoryKey = StatemachineViewsRepository.class; partKey = StatemachineViewsRepository.Statemachine_.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 Statemachine statemachine = (Statemachine)elt; final StatemachinePropertiesEditionPart basePart = (StatemachinePropertiesEditionPart)editingPart; // init values if (isAccessible(StatemachineViewsRepository.Statemachine_.Properties.events)) { eventsSettings = new ReferencesTableSettings(statemachine, StatemachinePackage.eINSTANCE.getStatemachine_Events()); basePart.initEvents(eventsSettings); } if (isAccessible(StatemachineViewsRepository.Statemachine_.Properties.resetEvents)) { resetEventsSettings = new ReferencesTableSettings(statemachine, StatemachinePackage.eINSTANCE.getStatemachine_ResetEvents()); basePart.initResetEvents(resetEventsSettings); } if (isAccessible(StatemachineViewsRepository.Statemachine_.Properties.commands)) { commandsSettings = new ReferencesTableSettings(statemachine, StatemachinePackage.eINSTANCE.getStatemachine_Commands()); basePart.initCommands(commandsSettings); } if (isAccessible(StatemachineViewsRepository.Statemachine_.Properties.states)) { statesSettings = new ReferencesTableSettings(statemachine, StatemachinePackage.eINSTANCE.getStatemachine_States()); basePart.initStates(statesSettings); } // init filters basePart.addFilterToEvents(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) { return (element instanceof String && element.equals("")) || (element instanceof Event); //$NON-NLS-1$ } }); // Start of user code for additional businessfilters for events // End of user code basePart.addFilterToResetEvents(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.isContainedInResetEventsTable((EObject)element)); return element instanceof Resource; } }); basePart.addFilterToResetEvents(new EObjectFilter(StatemachinePackage.eINSTANCE.getEvent())); // Start of user code for additional businessfilters for resetEvents // End of user code basePart.addFilterToCommands(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) { return (element instanceof String && element.equals("")) || (element instanceof Command); //$NON-NLS-1$ } }); // Start of user code for additional businessfilters for commands // End of user code basePart.addFilterToStates(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) { return (element instanceof String && element.equals("")) || (element instanceof State); //$NON-NLS-1$ } }); // Start of user code for additional businessfilters for states // 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) { Statemachine statemachine = (Statemachine)semanticObject; if (StatemachineViewsRepository.Statemachine_.Properties.events == event.getAffectedEditor()) { if (event.getKind() == PropertiesEditionEvent.ADD) { EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, eventsSettings, editingContext.getAdapterFactory()); PropertiesEditingProvider provider = (PropertiesEditingProvider)editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class); if (provider != null) { PropertiesEditingPolicy policy = provider.getPolicy(context); if (policy instanceof CreateEditingPolicy) { policy.execute(); } } } else if (event.getKind() == PropertiesEditionEvent.EDIT) { EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory()); PropertiesEditingProvider provider = (PropertiesEditingProvider)editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class); if (provider != null) { PropertiesEditingPolicy editionPolicy = provider.getPolicy(context); if (editionPolicy != null) { editionPolicy.execute(); } } } else if (event.getKind() == PropertiesEditionEvent.REMOVE) { eventsSettings.removeFromReference((EObject) event.getNewValue()); } } if (StatemachineViewsRepository.Statemachine_.Properties.resetEvents == event.getAffectedEditor()) { if (event.getKind() == PropertiesEditionEvent.ADD) { if (event.getNewValue() instanceof Event) { resetEventsSettings.addToReference((EObject) event.getNewValue()); } } else if (event.getKind() == PropertiesEditionEvent.REMOVE) { resetEventsSettings.removeFromReference((EObject) event.getNewValue()); } } if (StatemachineViewsRepository.Statemachine_.Properties.commands == event.getAffectedEditor()) { if (event.getKind() == PropertiesEditionEvent.ADD) { EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, commandsSettings, editingContext.getAdapterFactory()); PropertiesEditingProvider provider = (PropertiesEditingProvider)editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class); if (provider != null) { PropertiesEditingPolicy policy = provider.getPolicy(context); if (policy instanceof CreateEditingPolicy) { policy.execute(); } } } else if (event.getKind() == PropertiesEditionEvent.EDIT) { EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory()); PropertiesEditingProvider provider = (PropertiesEditingProvider)editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class); if (provider != null) { PropertiesEditingPolicy editionPolicy = provider.getPolicy(context); if (editionPolicy != null) { editionPolicy.execute(); } } } else if (event.getKind() == PropertiesEditionEvent.REMOVE) { commandsSettings.removeFromReference((EObject) event.getNewValue()); } } if (StatemachineViewsRepository.Statemachine_.Properties.states == event.getAffectedEditor()) { if (event.getKind() == PropertiesEditionEvent.ADD) { EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, statesSettings, editingContext.getAdapterFactory()); PropertiesEditingProvider provider = (PropertiesEditingProvider)editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class); if (provider != null) { PropertiesEditingPolicy policy = provider.getPolicy(context); if (policy instanceof CreateEditingPolicy) { policy.execute(); } } } else if (event.getKind() == PropertiesEditionEvent.EDIT) { EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory()); PropertiesEditingProvider provider = (PropertiesEditingProvider)editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class); if (provider != null) { PropertiesEditingPolicy editionPolicy = provider.getPolicy(context); if (editionPolicy != null) { editionPolicy.execute(); } } } else if (event.getKind() == PropertiesEditionEvent.REMOVE) { statesSettings.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()) { StatemachinePropertiesEditionPart basePart = (StatemachinePropertiesEditionPart)editingPart; if (StatemachinePackage.eINSTANCE.getStatemachine_Events().equals(msg.getFeature()) && isAccessible(StatemachineViewsRepository.Statemachine_.Properties.events)) basePart.updateEvents(); if (StatemachinePackage.eINSTANCE.getStatemachine_ResetEvents().equals(msg.getFeature()) && isAccessible(StatemachineViewsRepository.Statemachine_.Properties.resetEvents)) basePart.updateResetEvents(); if (StatemachinePackage.eINSTANCE.getStatemachine_Commands().equals(msg.getFeature()) && isAccessible(StatemachineViewsRepository.Statemachine_.Properties.commands)) basePart.updateCommands(); if (StatemachinePackage.eINSTANCE.getStatemachine_States().equals(msg.getFeature()) && isAccessible(StatemachineViewsRepository.Statemachine_.Properties.states)) basePart.updateStates(); } } /** * {@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 { } catch (IllegalArgumentException iae) { ret = BasicDiagnostic.toDiagnostic(iae); } catch (WrappedException we) { ret = BasicDiagnostic.toDiagnostic(we); } } return ret; } }