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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations