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