Search in sources :

Example 11 with AbstractTask

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

the class TaskUtils method getNextAvailableId.

/**
 * Returns the next id for the specified type using the specified prefix
 *
 * @param system
 *            System to consider
 * @param type
 *            Type of objects wanted
 * @param prefix
 *            Prefix used for IDs
 * @return the next available ID
 */
private String getNextAvailableId(System system, EClassifier type, String prefix) {
    Pattern ptn = Pattern.compile("^" + prefix + "([0-9]*)$");
    int max = 0;
    for (Iterator<EObject> it = system.eAllContents(); it.hasNext(); ) {
        EObject eObject = it.next();
        if (type.isInstance(eObject)) {
            String id = ((AbstractTask) eObject).getId();
            if (id != null) {
                Matcher m = ptn.matcher(id);
                if (m.matches()) {
                    int numId = Integer.parseInt(m.group(1));
                    if (numId > max) {
                        max = numId;
                    }
                }
            }
        }
    }
    return prefix + (max + 1);
}
Also used : Pattern(java.util.regex.Pattern) AbstractTask(org.obeonetwork.graal.AbstractTask) Matcher(java.util.regex.Matcher) EObject(org.eclipse.emf.ecore.EObject)

Example 12 with AbstractTask

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

the class TaskUtils method candidatesExpresssionForExistingTask.

/**
 * Calculate the candidateExpression defines in creation tool Existing Tasks
 * in Task Graph.
 *
 * @param context
 *            the context of call
 * @param diagram
 *            the representation
 * @return list of existing Tasks
 */
public List<AbstractTask> candidatesExpresssionForExistingTask(EObject context, DSemanticDiagram diagram) {
    TreeIterator<EObject> eAllContents = getSystem(context).eAllContents();
    List<AbstractTask> abstractTasks = new ArrayList<AbstractTask>();
    while (eAllContents.hasNext()) {
        EObject element = eAllContents.next();
        if (element instanceof AbstractTask) {
            abstractTasks.add((AbstractTask) element);
        }
    }
    List<Task> tasksDiagram = new ArrayList<Task>();
    List<EObject> eContents = diagram.getTarget().eContents();
    for (EObject obj : eContents) {
        if (obj instanceof Task) {
            tasksDiagram.add((Task) obj);
        }
    }
    abstractTasks.removeAll(tasksDiagram);
    abstractTasks.remove(context);
    return abstractTasks;
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) Task(org.obeonetwork.graal.Task) AbstractTask(org.obeonetwork.graal.AbstractTask) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList)

Example 13 with AbstractTask

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

the class TaskUtils method computeNameFromTasks.

/**
 * Computes a name from a list of abstract tasks
 *
 * @param abstractTasks
 *            List of abstract tasks for which we want a name
 * @return The computed name depending on the main tasks
 */
public String computeNameFromTasks(List<AbstractTask> abstractTasks) {
    String name = "";
    List<Task> mainTasks = getMainTasks(abstractTasks);
    for (Task task : mainTasks) {
        name += task.getName() + ";";
    }
    if (name.length() <= 1) {
        name = "";
    } else {
        name = name.substring(0, name.length() - 1);
    }
    return name;
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) Task(org.obeonetwork.graal.Task)

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