Search in sources :

Example 6 with TasksGroup

use of org.obeonetwork.graal.TasksGroup in project InformationSystem by ObeoNetwork.

the class TaskUtils method getMainTasks.

/**
 * Gets the main tasks from a list of abstract tasks
 *
 * @param abstractTasks
 *            List of abstract tasks to be considered
 * @return the main tasks from the list, considering the "use" relationships
 *         between tasks
 */
private List<Task> getMainTasks(List<AbstractTask> abstractTasks) {
    List<Task> mainTasks = new ArrayList<Task>();
    // We have to consider every task in groups or not
    List<Task> tasks = new ArrayList<Task>();
    for (AbstractTask abstractTask : abstractTasks) {
        if (abstractTask instanceof Task) {
            tasks.add((Task) abstractTask);
        } else {
            tasks.addAll(getAllEnclosedTasks((TasksGroup) abstractTask));
        }
    }
    // Get all tasks in the group
    for (Task task : tasks) {
        boolean usedByInnerTask = false;
        for (Task usingTask : task.getUsedBy()) {
            if (tasks.contains(usingTask)) {
                usedByInnerTask = true;
                break;
            }
        }
        if (usedByInnerTask == false) {
            mainTasks.add(task);
        }
    }
    return mainTasks;
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) Task(org.obeonetwork.graal.Task) AbstractTask(org.obeonetwork.graal.AbstractTask) TasksGroup(org.obeonetwork.graal.TasksGroup) ArrayList(java.util.ArrayList)

Example 7 with TasksGroup

use of org.obeonetwork.graal.TasksGroup in project InformationSystem by ObeoNetwork.

the class TaskUtils method deleteTaskUseTaskEdge.

/**
 * This service is used to remove the "use" relationship between 2 abstract
 * tasks and remove the corresponding elements on the using task's Actions
 * Plan when needed
 *
 * @param usingTask
 *            Source AbstractTask instance of the relationship
 * @param usedTask
 *            Target AbstractTask instance of the relationship
 */
public void deleteTaskUseTaskEdge(AbstractTask usingTask, AbstractTask usedTask) {
    Session session = SessionManager.INSTANCE.getSession(usingTask);
    ModelAccessor modelAccessor = session.getModelAccessor();
    // Get all potentially concerned used Tasks
    List<Task> usedTasks = new ArrayList<Task>();
    if (usedTask instanceof Task) {
        usedTasks.add((Task) usedTask);
    } else {
        usedTasks.addAll(getAllUsedTasks((TasksGroup) usedTask));
    }
    // Check if the using "task" is a Task or a Group
    if (usingTask instanceof Task) {
        for (Task realUsedTask : usedTasks) {
            deleteUseRelationship((Task) usingTask, realUsedTask, session, modelAccessor);
        }
    } else {
        for (Task realUsedTask : usedTasks) {
            for (Task realUsingTask : getTasksFromGroupUsingTask((TasksGroup) usingTask, realUsedTask)) {
                deleteUseRelationship(realUsingTask, realUsedTask, session, modelAccessor);
            }
        }
    }
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) Task(org.obeonetwork.graal.Task) TasksGroup(org.obeonetwork.graal.TasksGroup) ModelAccessor(org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor) ArrayList(java.util.ArrayList) Session(org.eclipse.sirius.business.api.session.Session)

Example 8 with TasksGroup

use of org.obeonetwork.graal.TasksGroup in project InformationSystem by ObeoNetwork.

the class ActorUtils method internalGetVisibleActors.

/**
 * Collect the visible actors for a task, using an internal cache
 * @param abstractTask
 * @param cache Map to store already calculated links between Tasks and Actors
 * @param actorsLeft List of actors not yet in the final list (used to improve performance)
 * @return
 */
private Set<Actor> internalGetVisibleActors(AbstractTask abstractTask, Map<Task, Set<Actor>> cache, List<Actor> actorsLeft) {
    if (!actorsLeft.isEmpty()) {
        if (abstractTask instanceof Task) {
            Task task = (Task) abstractTask;
            if (cache.containsKey(task)) {
                return cache.get(task);
            } else {
                Set<Actor> actors = new LinkedHashSet<Actor>();
                cache.put(task, actors);
                if (task.getActors().isEmpty()) {
                    for (Task usingTask : task.getUsedBy()) {
                        if (!cache.containsKey(usingTask) && !actorsLeft.isEmpty()) {
                            actors.addAll(internalGetVisibleActors(usingTask, cache, actorsLeft));
                        }
                    }
                } else {
                    actors.addAll(task.getActors());
                    actorsLeft.removeAll(actors);
                }
                cache.put(task, actors);
                return actors;
            }
        } else if (abstractTask instanceof TasksGroup) {
            Set<Actor> actors = new LinkedHashSet<Actor>();
            TasksGroup group = (TasksGroup) abstractTask;
            for (AbstractTask subTask : group.getTasks()) {
                if (!actorsLeft.isEmpty()) {
                    actors.addAll(internalGetVisibleActors(subTask, cache, actorsLeft));
                }
            }
            return actors;
        }
    }
    return new LinkedHashSet<Actor>();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractTask(org.obeonetwork.graal.AbstractTask) Task(org.obeonetwork.graal.Task) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) AbstractTask(org.obeonetwork.graal.AbstractTask) TasksGroup(org.obeonetwork.graal.TasksGroup) Actor(org.obeonetwork.graal.Actor)

Example 9 with TasksGroup

use of org.obeonetwork.graal.TasksGroup in project InformationSystem by ObeoNetwork.

the class TaskUtils method deleteChildrenTasksAndTasksGroups.

/**
 * Deletes the children tasks and groups in a TasksContainer
 *
 * @param container
 */
public void deleteChildrenTasksAndTasksGroups(TasksContainer container) {
    // Deletion of sub-groups
    List<TasksGroup> childrenGroups = new ArrayList<TasksGroup>(container.getOwnedGroups());
    for (TasksGroup childGroup : childrenGroups) {
        deleteChildrenTasksAndTasksGroups(childGroup);
    }
    // Deletion of tasks
    List<Task> childrenTasks = new ArrayList<Task>(container.getOwnedTasks());
    for (Task childTask : childrenTasks) {
        deleteTask(childTask);
    }
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) Task(org.obeonetwork.graal.Task) TasksGroup(org.obeonetwork.graal.TasksGroup) ArrayList(java.util.ArrayList)

Example 10 with TasksGroup

use of org.obeonetwork.graal.TasksGroup in project InformationSystem by ObeoNetwork.

the class RelatedActorsTests method addGroup.

private TasksGroup addGroup(TasksContainer container, String name) {
    TasksGroup group = GraalFactory.eINSTANCE.createTasksGroup();
    group.setName(name);
    container.getTasks().add(group);
    return group;
}
Also used : TasksGroup(org.obeonetwork.graal.TasksGroup)

Aggregations

TasksGroup (org.obeonetwork.graal.TasksGroup)11 AbstractTask (org.obeonetwork.graal.AbstractTask)9 Task (org.obeonetwork.graal.Task)7 ArrayList (java.util.ArrayList)5 System (org.obeonetwork.graal.System)3 EObject (org.eclipse.emf.ecore.EObject)2 EReference (org.eclipse.emf.ecore.EReference)2 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 TasksContainer (org.obeonetwork.graal.TasksContainer)2 GraalUsageCrossReferencer (org.obeonetwork.graal.util.GraalUsageCrossReferencer)2 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 Session (org.eclipse.sirius.business.api.session.Session)1 ModelAccessor (org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor)1 Test (org.junit.Test)1 Actor (org.obeonetwork.graal.Actor)1 Loop (org.obeonetwork.graal.Loop)1