Search in sources :

Example 6 with Flow

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

the class FlowsUtil method getAssociatedEvents.

public static Collection<Event> getAssociatedEvents(Flow flow) {
    Collection<Event> events = new HashSet<Event>();
    events.addAll(flow.getEvents());
    for (Flow subflow : getSubflows(flow)) {
        events.addAll(subflow.getEvents());
    }
    for (AbstractViewElement element : getAssociatedAbstractViewElements(flow)) {
        events.addAll(element.getEvents());
    }
    return events;
}
Also used : AbstractViewElement(org.obeonetwork.dsl.cinematic.view.AbstractViewElement) Event(org.obeonetwork.dsl.cinematic.Event) HashSet(java.util.HashSet) Flow(org.obeonetwork.dsl.cinematic.flow.Flow)

Example 7 with Flow

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

the class FlowsUtil method getFlowsAndAncestors.

/**
 * Return all flows and ancestors.
 * @param context
 * @param flows the flows
 * @return flows and ancestors
 */
public List<EObject> getFlowsAndAncestors(EObject context, List<Flow> flows) {
    List<EObject> containers = new ArrayList<EObject>(flows);
    for (Flow flow : flows) {
        EObject flowContainer = flow.eContainer();
        while (flowContainer != null && !containers.contains(flowContainer)) {
            containers.add(flowContainer);
            flowContainer = flowContainer.eContainer();
        }
    }
    return containers;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Flow(org.obeonetwork.dsl.cinematic.flow.Flow)

Example 8 with Flow

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

the class FlowEditLabelSwitch method caseSubflowState.

@Override
public EObject caseSubflowState(SubflowState subflowState) {
    String flowName = newLabel.trim();
    // Check if the name has changed
    if (flowName != null && subflowState.getSubflow() != null && subflowState.getSubflow().getName() != null) {
        if (flowName.equalsIgnoreCase(subflowState.getSubflow().getName().trim())) {
            // Nothing to do
            return subflowState;
        }
    }
    List<Flow> foundFlows = FlowsUtil.getFlowsWithName(subflowState, flowName);
    if (foundFlows.isEmpty()) {
        // No flow found, let's notify the user
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Unable to find flow", "No found flow with this name");
    } else if (foundFlows.size() == 1) {
        subflowState.setSubflow(foundFlows.get(0));
    } else {
        // Several flows with the same name, we let the user choose the correct one
        Object result = UiUtil.getUserChoiceWithinList("Select a flow", "Select a flow among the flows with the specified name", foundFlows.toArray(), new LabelProvider() {

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

            @Override
            public String getText(Object element) {
                String label = "";
                if (element instanceof Flow) {
                    Flow flow = (Flow) element;
                    label = getLabel(flow);
                }
                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 instanceof Flow) {
            subflowState.setSubflow((Flow) result);
        }
    }
    return subflowState;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) LabelProvider(org.eclipse.jface.viewers.LabelProvider) NamedElement(org.obeonetwork.dsl.cinematic.NamedElement) URL(java.net.URL) Flow(org.obeonetwork.dsl.cinematic.flow.Flow)

Example 9 with Flow

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

the class CinematicServices method getNextStates.

/**
 * Return a collection of {@link ActionState} and/or {@link ViewState}
 * associated with the given {@link FlowState}.
 *
 * @param flowState
 *            the given {@link FlowState}.
 * @param event
 *            the given {@link Event}.
 * @return a collection of {@link FlowState}.
 */
public Set<FlowState> getNextStates(FlowState flowState, Event event) {
    Set<FlowState> nexts = new HashSet<FlowState>();
    if (flowState instanceof SubflowState) {
        Flow flow = ((SubflowState) flowState).getSubflow();
        if (flow != null) {
            InitialState initialState = getInitialState(flow);
            nexts.addAll(getNextStates(initialState, null));
        }
    } else if (flowState instanceof ViewState || flowState instanceof ActionState || flowState instanceof InitialState || flowState instanceof DecisionState) {
        Flow flow = getFlow(flowState);
        if (flow != null) {
            for (Transition transition : flow.getTransitions()) {
                FlowState from = transition.getFrom();
                FlowState to = transition.getTo();
                Collection<Event> on = transition.getOn();
                if (from != null && to != null && from.equals(flowState) && (on.contains(event) || event == null)) {
                    if (to instanceof ViewState) {
                        nexts.add((ViewState) to);
                    } else if (to instanceof ActionState) {
                        nexts.add((ActionState) to);
                    } else if (to instanceof SubflowState) {
                        nexts.addAll(getNextStates((SubflowState) to, null));
                    } else if (to instanceof DecisionState) {
                        nexts.addAll(getNextStates((DecisionState) to, null));
                    } else if (to instanceof FinalState) {
                        Set<SubflowState> subflows = getAllSubFlowStates(flow);
                        Set<Transition> transitions = getAllTransitions(flow);
                        for (SubflowState subflowState : subflows) {
                            if (flow.equals(subflowState.getSubflow())) {
                                for (Transition transitionTmp : transitions) {
                                    FlowState fromTmp = transitionTmp.getFrom();
                                    FlowState toTmp = transitionTmp.getTo();
                                    if (from != null && to != null && fromTmp.equals(subflowState)) {
                                        nexts.add(toTmp);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return nexts;
}
Also used : FlowState(org.obeonetwork.dsl.cinematic.flow.FlowState) Set(java.util.Set) HashSet(java.util.HashSet) SubflowState(org.obeonetwork.dsl.cinematic.flow.SubflowState) ViewState(org.obeonetwork.dsl.cinematic.flow.ViewState) DecisionState(org.obeonetwork.dsl.cinematic.flow.DecisionState) FinalState(org.obeonetwork.dsl.cinematic.flow.FinalState) Flow(org.obeonetwork.dsl.cinematic.flow.Flow) InitialState(org.obeonetwork.dsl.cinematic.flow.InitialState) Transition(org.obeonetwork.dsl.cinematic.flow.Transition) Collection(java.util.Collection) ActionState(org.obeonetwork.dsl.cinematic.flow.ActionState) HashSet(java.util.HashSet)

Example 10 with Flow

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

the class CinematicFlowServices method getViewContainerAssociate.

/**
 * Retrieve the view container associate to flow
 *
 * @param context
 *            the context. In this case should be a flow
 * @return the list of view Container associate to the flow
 */
private List<ViewContainer> getViewContainerAssociate(EObject context) {
    List<ViewContainer> viewContainers = new ArrayList<ViewContainer>();
    if (context instanceof Flow) {
        Flow flow = (Flow) context;
        // Retrieve the flow's states
        EList<FlowState> states = flow.getStates();
        List<ViewState> viewStates = new ArrayList<ViewState>();
        // Retrieve the View state type in the states list
        for (FlowState state : states) {
            if (state instanceof ViewState) {
                viewStates.add((ViewState) state);
            }
        }
        // Retrieve all viewContainers contained in the view State
        for (ViewState viewState : viewStates) {
            viewContainers.addAll(viewState.getViewContainers());
        }
    }
    return viewContainers;
}
Also used : FlowState(org.obeonetwork.dsl.cinematic.flow.FlowState) ArrayList(java.util.ArrayList) ViewState(org.obeonetwork.dsl.cinematic.flow.ViewState) ViewContainer(org.obeonetwork.dsl.cinematic.view.ViewContainer) Flow(org.obeonetwork.dsl.cinematic.flow.Flow)

Aggregations

Flow (org.obeonetwork.dsl.cinematic.flow.Flow)16 EObject (org.eclipse.emf.ecore.EObject)13 ViewContainer (org.obeonetwork.dsl.cinematic.view.ViewContainer)6 ArrayList (java.util.ArrayList)5 EcorePackage (org.eclipse.emf.ecore.EcorePackage)4 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)4 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)4 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)4 CreateEditingPolicy (org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy)4 PropertiesEditingProvider (org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider)4 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)4 Viewer (org.eclipse.jface.viewers.Viewer)4 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)4 CinematicPackage (org.obeonetwork.dsl.cinematic.CinematicPackage)4 Package (org.obeonetwork.dsl.cinematic.Package)4 FlowState (org.obeonetwork.dsl.cinematic.flow.FlowState)4 FlowEvent (org.obeonetwork.dsl.cinematic.flow.FlowEvent)3 SubflowState (org.obeonetwork.dsl.cinematic.flow.SubflowState)3 Transition (org.obeonetwork.dsl.cinematic.flow.Transition)3 EnvironmentPackage (org.obeonetwork.dsl.environment.EnvironmentPackage)3