Search in sources :

Example 1 with AbstractTask

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

the class ActorUtils method getVisibleActors.

/**
 * Returns the visible actors for a tasks group
 * @param group
 * @return
 */
public Set<Actor> getVisibleActors(TasksGroup group) {
    HashMap<Task, Set<Actor>> cache = new HashMap<Task, Set<Actor>>();
    Set<Actor> actors = new LinkedHashSet<Actor>();
    List<Actor> actorsLeft = getAllActorsInContext(group);
    for (AbstractTask abstractTask : group.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 2 with AbstractTask

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

the class GroupAction method executeGroupAction.

/**
 * Executes the grouping action
 * @param context Object needed so the method can be called by Acceleo. It is returned unchanged
 * @param selections Graphical elements selected by the user before launching the action
 * @return The first parameter without any change
 */
public EObject executeGroupAction(EObject context, Collection<? extends EObject> selections) {
    // Filter the selections to retrieve only the Tasks
    List<AbstractTask> tasks = extractTasks(selections);
    String suggestedName = TaskUtils.instance.computeNameFromTasks(tasks);
    InputDialog enterNameDialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Creating a group", "Enter a name for the group", suggestedName, null);
    enterNameDialog.open();
    int returnCode = enterNameDialog.getReturnCode();
    if (returnCode == InputDialog.OK) {
        TasksContainer container = null;
        if (tasks.size() > 0) {
            // Store the current container
            container = (TasksContainer) tasks.get(0).eContainer();
            // Create a new group to contain the selected tasks
            TasksGroup group = GraalFactory.eINSTANCE.createTasksGroup();
            Date createdOn = new Date();
            group.setCreatedOn(createdOn);
            group.setModifiedOn(createdOn);
            // Attach the selected tasks to the new group
            group.getTasks().addAll(tasks);
            group.setName(enterNameDialog.getValue());
            // Get an available ID for the TasksGroup
            System system = TaskUtils.instance.getClosestSystem(container);
            String id = TaskUtils.instance.getNextAvailableTasksGroupId(system);
            group.setId(id);
            // Attach the new group to the container
            ((TasksContainer) container).getTasks().add(group);
        }
    }
    return context;
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) InputDialog(org.eclipse.jface.dialogs.InputDialog) TasksContainer(org.obeonetwork.graal.TasksContainer) TasksGroup(org.obeonetwork.graal.TasksGroup) Date(java.util.Date) System(org.obeonetwork.graal.System)

Example 3 with AbstractTask

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

the class UngroupAction method executeUngroupAction.

/**
 * Executes the ungrouping action
 * @param context Object needed so the method can be called by Acceleo. It is returned unchanged
 * @param selections Graphical elements selected by the user before launching the action
 * @return The first parameter without any change
 */
public EObject executeUngroupAction(EObject context, Collection<? extends EObject> selections) {
    TasksGroup group = extractTasksGroup(selections);
    // Keep attachment to use case
    UseCase useCase = group.getUseCase();
    if (useCase != null) {
        for (AbstractTask abstractTask : group.getTasks()) {
            useCase.getTasks().add(abstractTask);
        }
    }
    TasksContainer container = (TasksContainer) group.eContainer();
    container.getTasks().addAll(group.getTasks());
    // Delete without EcoreUtil.delete()
    DeleteUtils.delete(group);
    return context;
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) TasksContainer(org.obeonetwork.graal.TasksContainer) TasksGroup(org.obeonetwork.graal.TasksGroup) UseCase(org.obeonetwork.graal.UseCase)

Example 4 with AbstractTask

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

the class TaskUtils method tasksUsed.

/**
 * Retrieve all tasks used by the context
 *
 * @param context
 *            the context on which is applied the service
 * @return List of Tasks
 */
public List<Task> tasksUsed(TasksGroup context) {
    List<Task> tasks = new ArrayList<Task>();
    for (AbstractTask task : context.getTasks()) {
        tasks.addAll(tasksUsed(task));
    }
    // Remove tasks contained in the context
    tasks.removeAll(context.getTasks());
    Set<Task> tasksUsed = new HashSet<Task>();
    // Remove duplicates
    tasksUsed.addAll(tasks);
    return new ArrayList<Task>(tasksUsed);
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) Task(org.obeonetwork.graal.Task) AbstractTask(org.obeonetwork.graal.AbstractTask) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with AbstractTask

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

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