Search in sources :

Example 1 with FlowEvent

use of org.obeonetwork.dsl.cinematic.flow.FlowEvent in project InformationSystem by ObeoNetwork.

the class FlowFlowPropertiesEditionComponent method updateSemanticModel.

/**
 * {@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) {
    Flow flow = (Flow) semanticObject;
    if (FlowViewsRepository.Flow_.Properties.description == event.getAffectedEditor()) {
        flow.setDescription((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (FlowViewsRepository.Flow_.Properties.name == event.getAffectedEditor()) {
        flow.setName((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (FlowViewsRepository.Flow_.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());
        } else if (event.getKind() == PropertiesEditionEvent.MOVE) {
            statesSettings.move(event.getNewIndex(), (FlowState) event.getNewValue());
        }
    }
    if (FlowViewsRepository.Flow_.Properties.transitions == event.getAffectedEditor()) {
        if (event.getKind() == PropertiesEditionEvent.ADD) {
            EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, transitionsSettings, 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) {
            transitionsSettings.removeFromReference((EObject) event.getNewValue());
        } else if (event.getKind() == PropertiesEditionEvent.MOVE) {
            transitionsSettings.move(event.getNewIndex(), (Transition) event.getNewValue());
        }
    }
    if (FlowViewsRepository.Flow_.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());
        } else if (event.getKind() == PropertiesEditionEvent.MOVE) {
            eventsSettings.move(event.getNewIndex(), (FlowEvent) event.getNewValue());
        }
    }
}
Also used : FlowEvent(org.obeonetwork.dsl.cinematic.flow.FlowEvent) EObjectPropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext) FlowState(org.obeonetwork.dsl.cinematic.flow.FlowState) PropertiesEditingProvider(org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider) EObject(org.eclipse.emf.ecore.EObject) Transition(org.obeonetwork.dsl.cinematic.flow.Transition) PropertiesEditingPolicy(org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy) CreateEditingPolicy(org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy) EReferencePropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext) Flow(org.obeonetwork.dsl.cinematic.flow.Flow)

Example 2 with FlowEvent

use of org.obeonetwork.dsl.cinematic.flow.FlowEvent in project InformationSystem by ObeoNetwork.

the class FlowEventFlowEventPropertiesEditionComponent method initPart.

/**
 * {@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 FlowEvent flowEvent = (FlowEvent) elt;
        final FlowEventPropertiesEditionPart flowEventPart = (FlowEventPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(FlowViewsRepository.FlowEvent.Properties.description))
            flowEventPart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, flowEvent.getDescription()));
        if (isAccessible(FlowViewsRepository.FlowEvent.Properties.name))
            flowEventPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, flowEvent.getName()));
        if (isAccessible(FlowViewsRepository.FlowEvent.Properties.binds)) {
            bindsSettings = new ReferencesTableSettings(flowEvent, FlowPackage.eINSTANCE.getFlowEvent_Binds());
            flowEventPart.initBinds(bindsSettings);
        }
        if (isAccessible(FlowViewsRepository.FlowEvent.Properties.binds)) {
            flowEventPart.addFilterToBinds(new EObjectFilter(ViewPackage.Literals.VIEW_EVENT));
        // Start of user code for additional businessfilters for binds
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : EObjectFilter(org.eclipse.emf.eef.runtime.impl.filters.EObjectFilter) FlowEvent(org.obeonetwork.dsl.cinematic.flow.FlowEvent) FlowEventPropertiesEditionPart(org.obeonetwork.dsl.cinematic.flow.parts.FlowEventPropertiesEditionPart) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)

Example 3 with FlowEvent

use of org.obeonetwork.dsl.cinematic.flow.FlowEvent in project InformationSystem by ObeoNetwork.

the class FlowEditLabelSwitch method caseTransition.

@Override
public EObject caseTransition(Transition transition) {
    String eventPart = null;
    String guard = null;
    Collection<String> notFoundEventNames = new ArrayList<String>();
    // We search for '[' and ']' characters
    int openingBracketPos = newLabel.indexOf("[");
    int closingBracketPos = newLabel.lastIndexOf("]");
    if (openingBracketPos != -1 && openingBracketPos != newLabel.length() - 1) {
        // we consider there is a closing bracket at the end of the string
        if (closingBracketPos == -1 || closingBracketPos < openingBracketPos) {
            closingBracketPos = newLabel.length();
        }
        guard = newLabel.substring(openingBracketPos + 1, closingBracketPos).trim();
        // We now consider the rest of the string i.e. trigger events
        eventPart = newLabel.substring(0, openingBracketPos).trim();
    } else {
        guard = null;
        eventPart = newLabel.trim();
    }
    // Get the containing flow
    if (transition.eContainer() != null && transition.eContainer() instanceof Flow) {
        Flow flow = (Flow) transition.eContainer();
        String[] events = eventPart.split(",");
        // Retrieve associated events and possible event types
        Collection<Event> associatedEvents = FlowsUtil.getAssociatedEvents(flow);
        Collection<WidgetEventTypeAndAbstractViewElement> possibleEvents = FlowsUtil.getPossibleWidgetEvents(flow);
        Collection<Object> eventsToBeAssociated = new ArrayList<Object>();
        for (String event : events) {
            List<Object> candidatesEvents = new ArrayList<Object>();
            String eventName = event.trim();
            if (eventName != null && !eventName.equals("")) {
                // Test if the event was already associated
                boolean alreadyAssociatedEvent = false;
                for (Event alreadyAssociated : transition.getOn()) {
                    if (eventName.equals(alreadyAssociated.getName().trim())) {
                        alreadyAssociatedEvent = true;
                        break;
                    }
                }
                if (alreadyAssociatedEvent) {
                    break;
                }
                for (Event associatedEvent : associatedEvents) {
                    if (eventName.equalsIgnoreCase(associatedEvent.getName().trim())) {
                        candidatesEvents.add(associatedEvent);
                    }
                }
                for (WidgetEventTypeAndAbstractViewElement widgetEventTypeAndElement : possibleEvents) {
                    if (eventName.equalsIgnoreCase(widgetEventTypeAndElement.getWidgetEventType().getName().trim())) {
                        candidatesEvents.add(widgetEventTypeAndElement);
                    }
                }
            }
            // Now, let's see if we had some results
            if (candidatesEvents.isEmpty()) {
                notFoundEventNames.add(eventName);
            } else if (candidatesEvents.size() == 1 && candidatesEvents.get(0) instanceof Event) {
                eventsToBeAssociated.add((Event) candidatesEvents.get(0));
            } else if (candidatesEvents.size() == 1 && candidatesEvents.get(0) instanceof WidgetEventTypeAndAbstractViewElement) {
                WidgetEventTypeAndAbstractViewElement info = (WidgetEventTypeAndAbstractViewElement) candidatesEvents.get(0);
                boolean create = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Create a new Event ?", "An event named '" + eventName + "' does not exist yet but a ViewEvent could be created for the widget '" + info.getAbstractViewElement().getName() + "'.\n" + "Do you want to create this event ?");
                if (create) {
                    eventsToBeAssociated.add(info);
                }
            } else {
                Object result = UiUtil.getUserChoiceWithinList("Select an event", "You could pick an existing event or create a new one for '" + eventName + "'", candidatesEvents.toArray(), new LabelProvider() {

                    @Override
                    public Image getImage(Object element) {
                        URL imageURL = null;
                        if (element instanceof FlowEvent) {
                            imageURL = (URL) CinematicEditPlugin.INSTANCE.getImage("full/obj16/FlowEvent");
                        } else if (element instanceof ViewEvent) {
                            imageURL = (URL) CinematicEditPlugin.INSTANCE.getImage("full/obj16/ViewEvent");
                        } else if (element instanceof WidgetEventTypeAndAbstractViewElement) {
                            imageURL = (URL) CinematicEditPlugin.INSTANCE.getImage("full/obj16/NewViewEvent");
                        }
                        if (imageURL != null) {
                            ImageDescriptor imgDesc = ImageDescriptor.createFromURL(imageURL);
                            if (imgDesc != null) {
                                return imgDesc.createImage();
                            }
                        }
                        return null;
                    }

                    @Override
                    public String getText(Object element) {
                        String label = null;
                        if (element instanceof Event) {
                            Event event = (Event) element;
                            label = getLabel(event);
                        } else if (element instanceof WidgetEventTypeAndAbstractViewElement) {
                            AbstractViewElement viewElement = ((WidgetEventTypeAndAbstractViewElement) element).getAbstractViewElement();
                            WidgetEventType eventType = ((WidgetEventTypeAndAbstractViewElement) element).getWidgetEventType();
                            label = getLabel(viewElement) + "::" + eventType.getName() + " (will create a new event)";
                        }
                        return label;
                    }

                    private String getLabel(EObject eObject) {
                        String label = "";
                        if (eObject.eContainer() != null) {
                            String parentLabel = getLabel(eObject.eContainer());
                            if (parentLabel != null) {
                                label = parentLabel + "::";
                            }
                        }
                        if (eObject instanceof NamedElement) {
                            label += ((NamedElement) eObject).getName();
                        }
                        return label;
                    }
                });
                if (result != null) {
                    eventsToBeAssociated.add(result);
                }
            }
        }
        // Warn and ask the user if we have to continue
        boolean doIt = true;
        if (!notFoundEventNames.isEmpty()) {
            String label = "";
            for (String name : notFoundEventNames) {
                label += "'" + name + "',";
            }
            // Remove last comma
            label = label.substring(0, label.length() - 1);
            doIt = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Edit the transition", "No event found for " + label + ".\n" + "Edit the transition anyway ?");
        }
        if (doIt) {
            transition.setGuard(guard);
            // Let's associate the events now
            if (!eventsToBeAssociated.isEmpty()) {
                transition.getOn().clear();
                for (Object object : eventsToBeAssociated) {
                    if (object instanceof Event) {
                        transition.getOn().add((Event) object);
                    } else if (object instanceof WidgetEventTypeAndAbstractViewElement) {
                        AbstractViewElement viewElement = ((WidgetEventTypeAndAbstractViewElement) object).getAbstractViewElement();
                        WidgetEventType eventType = ((WidgetEventTypeAndAbstractViewElement) object).getWidgetEventType();
                        ViewEvent event = ViewFactory.eINSTANCE.createViewEvent();
                        event.setName(eventType.getName());
                        event.setType(eventType);
                        viewElement.getEvents().add(event);
                        transition.getOn().add(event);
                    }
                }
            }
        }
    }
    return transition;
}
Also used : ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) AbstractViewElement(org.obeonetwork.dsl.cinematic.view.AbstractViewElement) WidgetEventTypeAndAbstractViewElement(org.obeonetwork.dsl.cinematic.design.services.flows.WidgetEventTypeAndAbstractViewElement) ViewEvent(org.obeonetwork.dsl.cinematic.view.ViewEvent) EObject(org.eclipse.emf.ecore.EObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Flow(org.obeonetwork.dsl.cinematic.flow.Flow) FlowEvent(org.obeonetwork.dsl.cinematic.flow.FlowEvent) WidgetEventTypeAndAbstractViewElement(org.obeonetwork.dsl.cinematic.design.services.flows.WidgetEventTypeAndAbstractViewElement) WidgetEventType(org.obeonetwork.dsl.cinematic.toolkits.WidgetEventType) ViewEvent(org.obeonetwork.dsl.cinematic.view.ViewEvent) Event(org.obeonetwork.dsl.cinematic.Event) FlowEvent(org.obeonetwork.dsl.cinematic.flow.FlowEvent) EObject(org.eclipse.emf.ecore.EObject) LabelProvider(org.eclipse.jface.viewers.LabelProvider) NamedElement(org.obeonetwork.dsl.cinematic.NamedElement)

Example 4 with FlowEvent

use of org.obeonetwork.dsl.cinematic.flow.FlowEvent in project InformationSystem by ObeoNetwork.

the class FlowFlowPropertiesEditionComponent method initPart.

/**
 * {@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 Flow flow = (Flow) elt;
        final FlowPropertiesEditionPart flowPart = (FlowPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(FlowViewsRepository.Flow_.Properties.description))
            flowPart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, flow.getDescription()));
        if (isAccessible(FlowViewsRepository.Flow_.Properties.name))
            flowPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, flow.getName()));
        if (isAccessible(FlowViewsRepository.Flow_.Properties.states)) {
            statesSettings = new ReferencesTableSettings(flow, FlowPackage.eINSTANCE.getFlow_States());
            flowPart.initStates(statesSettings);
        }
        if (isAccessible(FlowViewsRepository.Flow_.Properties.transitions)) {
            transitionsSettings = new ReferencesTableSettings(flow, FlowPackage.eINSTANCE.getFlow_Transitions());
            flowPart.initTransitions(transitionsSettings);
        }
        if (isAccessible(FlowViewsRepository.Flow_.Properties.events)) {
            eventsSettings = new ReferencesTableSettings(flow, FlowPackage.eINSTANCE.getFlow_Events());
            flowPart.initEvents(eventsSettings);
        }
        if (isAccessible(FlowViewsRepository.Flow_.Properties.states)) {
            flowPart.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) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof FlowState);
                }
            });
        // Start of user code for additional businessfilters for states
        // End of user code
        }
        if (isAccessible(FlowViewsRepository.Flow_.Properties.transitions)) {
            flowPart.addFilterToTransitions(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) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof Transition);
                }
            });
        // Start of user code for additional businessfilters for transitions
        // End of user code
        }
        if (isAccessible(FlowViewsRepository.Flow_.Properties.events)) {
            flowPart.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) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof FlowEvent);
                }
            });
        // Start of user code for additional businessfilters for events
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : FlowPropertiesEditionPart(org.obeonetwork.dsl.cinematic.flow.parts.FlowPropertiesEditionPart) FlowEvent(org.obeonetwork.dsl.cinematic.flow.FlowEvent) FlowState(org.obeonetwork.dsl.cinematic.flow.FlowState) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Transition(org.obeonetwork.dsl.cinematic.flow.Transition) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) Flow(org.obeonetwork.dsl.cinematic.flow.Flow)

Aggregations

FlowEvent (org.obeonetwork.dsl.cinematic.flow.FlowEvent)4 EObject (org.eclipse.emf.ecore.EObject)3 Flow (org.obeonetwork.dsl.cinematic.flow.Flow)3 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)2 FlowState (org.obeonetwork.dsl.cinematic.flow.FlowState)2 Transition (org.obeonetwork.dsl.cinematic.flow.Transition)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)1 EObjectFilter (org.eclipse.emf.eef.runtime.impl.filters.EObjectFilter)1 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)1 CreateEditingPolicy (org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy)1 PropertiesEditingProvider (org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Image (org.eclipse.swt.graphics.Image)1 Event (org.obeonetwork.dsl.cinematic.Event)1