Interface ICommandFactory

All Known Implementing Classes:
CommandFactory

public interface ICommandFactory
Factory of EMF commands that create, copy and remove model objects. The factory does not execute the commands. The caller puts them on the command stack of the shared editing domain (CommandsManager), so each action is undone and redone as one step.

The factory keeps an ECrossReferenceAdapter and adds it to every object it creates or copies. remove uses this adapter to find references from other objects to the removed object and clears them in the same command. For this reason the application sets the scenario as the adapter target after loading it, through getCrossReferenceAdapter().setTarget(...).

AbstractApplicationActivator creates the factory and registers it as an OSGi service, and AbstractPagesPart gets it through injection. The default implementation is CommandFactory.

  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends org.eclipse.emf.ecore.EObject>
    com.amalgamasimulation.emf.commands.AddCommand<T>
    copy(T object, int injectionIndex, boolean copyReferences)
    Returns a command that adds a copy of object to the same container.
    <C extends org.eclipse.emf.ecore.EObject, T extends org.eclipse.emf.ecore.EObject>
    com.amalgamasimulation.emf.commands.AddCommand<T>
    create(C container, String patternId, Supplier<T> creator)
    Returns a command that adds a new object to container.
    <C extends org.eclipse.emf.ecore.EObject, T extends org.eclipse.emf.ecore.EObject>
    com.amalgamasimulation.emf.commands.AddCommand<T>
    create(C container, Supplier<T> creator)
    Returns a command that adds a new object to container.
    org.eclipse.emf.ecore.util.ECrossReferenceAdapter
    Returns the adapter that the factory adds to the objects it creates and that remove uses to find references.
    <T extends org.eclipse.emf.ecore.EObject>
    org.eclipse.emf.common.command.CompoundCommand
    remove(T object)
    Returns a command that removes object from its container and clears references to it from other objects, found through the factory's ECrossReferenceAdapter.
    default <T extends org.eclipse.emf.ecore.EObject>
    org.eclipse.emf.common.command.CompoundCommand
    removeAll(List<T> objects)
    Returns one compound command that removes every object of the list as remove does.
    void
    setCrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter crossReferenceAdapter)
    Replaces the adapter.
  • Method Details

    • create

      <C extends org.eclipse.emf.ecore.EObject, T extends org.eclipse.emf.ecore.EObject> com.amalgamasimulation.emf.commands.AddCommand<T> create(C container, String patternId, Supplier<T> creator)
      Returns a command that adds a new object to container. creator is called when this method is called, not when the command is executed. If the object type has a string ID attribute, it gets a unique identifier built from patternId: the next number among the objects of the same list in container (UniqueNameGenerator). If the type has a string name attribute, it gets the same value. Without these attributes the object stays as creator returned it. The object is added to the end of the list; if the container reference is single, the object is set to it.
      Type Parameters:
      C - the type of the container
      T - the type of the new object
      Parameters:
      container - the object whose containment reference receives the new object
      patternId - the identifier pattern, with or without a trailing number
      creator - creates the new object
      Returns:
      the add command; getObject() returns the new object
    • create

      <C extends org.eclipse.emf.ecore.EObject, T extends org.eclipse.emf.ecore.EObject> com.amalgamasimulation.emf.commands.AddCommand<T> create(C container, Supplier<T> creator)
      Returns a command that adds a new object to container. Unlike the method with patternId, ID and name are not set: the object is added as creator returned it.
      Type Parameters:
      C - the type of the container
      T - the type of the new object
      Parameters:
      container - the object whose containment reference receives the new object
      creator - creates the new object
      Returns:
      the add command; getObject() returns the new object
    • remove

      <T extends org.eclipse.emf.ecore.EObject> org.eclipse.emf.common.command.CompoundCommand remove(T object)
      Returns a command that removes object from its container and clears references to it from other objects, found through the factory's ECrossReferenceAdapter. These references are found only if the adapter target is set to the scenario (setTarget).
      Type Parameters:
      T - the type of the removed object
      Parameters:
      object - the object to remove
      Returns:
      the remove command
    • removeAll

      default <T extends org.eclipse.emf.ecore.EObject> org.eclipse.emf.common.command.CompoundCommand removeAll(List<T> objects)
      Returns one compound command that removes every object of the list as remove does. An empty list gives an empty command, and executing it changes nothing.
      Type Parameters:
      T - the type of the removed objects
      Parameters:
      objects - the objects to remove
      Returns:
      the compound remove command
    • copy

      <T extends org.eclipse.emf.ecore.EObject> com.amalgamasimulation.emf.commands.AddCommand<T> copy(T object, int injectionIndex, boolean copyReferences)
      Returns a command that adds a copy of object to the same container. The copy is created when this method is called and enters the model when the command is executed. The ID attribute of the copy gets the next free number based on the ID of the original; other attributes are copied as they are, so name does not change. Contained objects are always copied.

      With copyReferences set to true, plain (non-containment) references are copied too. A reference to an object inside the copy points to that object's copy. A reference to an object outside the copy points to the same object. If the reference has an opposite list, the copy is added to that list by the same command, so undo removes it from there. If the opposite reference is single, the reference is not copied, because otherwise the copy would take the objects away from the original. With copyReferences set to false, plain references are not copied, including references inside the copy.

      Type Parameters:
      T - the type of the copied object
      Parameters:
      object - the object to copy; it must be in a container
      injectionIndex - the position of the copy in the container list; -1 adds it to the end
      copyReferences - whether plain references are copied
      Returns:
      the add command; getObject() returns the copy
    • getCrossReferenceAdapter

      org.eclipse.emf.ecore.util.ECrossReferenceAdapter getCrossReferenceAdapter()
      Returns the adapter that the factory adds to the objects it creates and that remove uses to find references.
      Returns:
      the cross reference adapter
    • setCrossReferenceAdapter

      void setCrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter crossReferenceAdapter)
      Replaces the adapter. Objects created earlier keep the old adapter; the new one needs the scenario as its target (setTarget).
      Parameters:
      crossReferenceAdapter - the new adapter