Search in sources :

Example 6 with AbstractTask

use of org.obeonetwork.graal.AbstractTask 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 7 with AbstractTask

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

the class CreateUseCaseAction method executeCreateUseCaseAction.

/**
 * creates a new use case from selected Task and TasksGroup instances
 * @param context EObject needed so the method can be called by Acceleo
 * @param selections Graphical elements selected by the user before invoking the action
 * @return unmodified "context" parameter
 */
public EObject executeCreateUseCaseAction(EObject context, Collection<? extends EObject> selections) {
    // Filter the selections to retrieve only the Tasks
    List<AbstractTask> tasks = extractTasks(selections);
    String suggestedName = "UC - " + TaskUtils.instance.computeNameFromTasks(tasks);
    InputDialog enterNameDialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Creating an use case", "Enter a name for the Use Case", suggestedName, null);
    enterNameDialog.open();
    int returnCode = enterNameDialog.getReturnCode();
    if (returnCode == InputDialog.OK && tasks.size() > 0) {
        // Get the containing System
        System system = tasks.get(0).getContainingSystem();
        // Create a new Use Case
        UseCase useCase = GraalFactory.eINSTANCE.createUseCase();
        Date createdOn = new Date();
        useCase.setCreatedOn(createdOn);
        useCase.setModifiedOn(createdOn);
        useCase.getTasks().addAll(tasks);
        useCase.setName(enterNameDialog.getValue());
        system.getUseCases().add(useCase);
        return useCase;
    }
    return null;
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) InputDialog(org.eclipse.jface.dialogs.InputDialog) UseCase(org.obeonetwork.graal.UseCase) System(org.obeonetwork.graal.System) Date(java.util.Date)

Example 8 with AbstractTask

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

the class ActorUtils method getVisibleActors.

/**
 * Returns the visible actors for a use case
 * @param useCase
 * @return
 */
public Set<Actor> getVisibleActors(UseCase useCase) {
    HashMap<Task, Set<Actor>> cache = new HashMap<Task, Set<Actor>>();
    Set<Actor> actors = new LinkedHashSet<Actor>();
    List<Actor> actorsLeft = getAllActorsInContext(useCase);
    for (AbstractTask abstractTask : useCase.getTasks()) {
        actors.addAll(internalGetVisibleActors(abstractTask, cache, actorsLeft));
    }
    return actors;
}
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) HashMap(java.util.HashMap) Actor(org.obeonetwork.graal.Actor)

Example 9 with AbstractTask

use of org.obeonetwork.graal.AbstractTask 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 10 with AbstractTask

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

the class ActorUtils method getVisibleActors.

/**
 * Returns the visible actors for a system
 * @param system
 * @return
 */
public Set<Actor> getVisibleActors(System system) {
    HashMap<Task, Set<Actor>> cache = new HashMap<Task, Set<Actor>>();
    Set<Actor> actors = new LinkedHashSet<Actor>();
    List<Actor> actorsLeft = getAllActorsInContext(system);
    for (AbstractTask abstractTask : system.getTasks()) {
        actors.addAll(internalGetVisibleActors(abstractTask, cache, actorsLeft));
    }
    return actors;
}
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) HashMap(java.util.HashMap) Actor(org.obeonetwork.graal.Actor)

Aggregations

AbstractTask (org.obeonetwork.graal.AbstractTask)13 Task (org.obeonetwork.graal.Task)9 LinkedHashSet (java.util.LinkedHashSet)5 TasksGroup (org.obeonetwork.graal.TasksGroup)5 ArrayList (java.util.ArrayList)4 Set (java.util.Set)4 Actor (org.obeonetwork.graal.Actor)4 HashMap (java.util.HashMap)3 Date (java.util.Date)2 EObject (org.eclipse.emf.ecore.EObject)2 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 System (org.obeonetwork.graal.System)2 TasksContainer (org.obeonetwork.graal.TasksContainer)2 UseCase (org.obeonetwork.graal.UseCase)2 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Session (org.eclipse.sirius.business.api.session.Session)1 ModelAccessor (org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor)1