Search in sources :

Example 1 with TasksContainer

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

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

Aggregations

AbstractTask (org.obeonetwork.graal.AbstractTask)2 TasksContainer (org.obeonetwork.graal.TasksContainer)2 TasksGroup (org.obeonetwork.graal.TasksGroup)2 Date (java.util.Date)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 System (org.obeonetwork.graal.System)1 UseCase (org.obeonetwork.graal.UseCase)1