Creating Blocks

Use

You can create blocks using the GP design time API. The interface allows you to manipulate with block types and structure.

Prerequisites

You have instantiated the IGPDesigntimeUpdateManager . For more information, see Instantiating the Design Time Manager .

Procedure

  1. Create a block by providing its basic data:

You need to specify a category for the newly-created block. For this purpose, you can create a new category or provide the Id of an existing one.

Creating a Block
importjava.util.Locale;
importcom.sap.caf.eu.gp.context.api.IGPUserContext;
importcom.sap.caf.eu.gp.process.api.IGPCategory;
importcom.sap.caf.eu.gp.process.api.IGPModifiableBlock;
importcom.sap.caf.eu.gp.process.api.GPProcessFactory;
importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeManager;
importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager;
importcom.sap.caf.eu.gp.process.api.GPBlockType;
 
// instantiate the design time manager to get the root category
IGPDesigntimeManagerdtManager = GPProcessFactory.getDesigntimeManager();
IGPCategoryroot = dtManager.getRootCategory(userContext);
 
// create a new category "test" in the root category
IGPCategory cat = manager.createCategory("test","A test category", root);
 
// create a block in the cat category
StringbName = "Block";
StringbDescription = "A test block";
IGPModifiableBlockb = manager.createBlock(
         GPBlockType.BLOCK_TYPE_SEQUENTIAL,
         Locale.getDefault(),
         bName,
         bDescription,
         cat.getID()
);

The example above implements a sequential block type. Currently, the GP API supports the following block types:

  • BLOCK_TYPE_SEQUENTIAL
  • BLOCK_TYPE_PARALLEL

For more information on block types, see Creating Blocks in Modeling and Configuring Workflows.

  1. Add content to the block.

    The block content is represented by a block structure ( IGPModifiableBlockStructure ). It is an indexed sequence of items ( IGPModifiableBlockStructureItem ), which hold object references to activities within the block.

    The GP design time API provides the following functionalities for block structure manipulation:

    • Adding an item to the structure

      We define a block b with three actions: a_0 , a_1 , a_2 .

      importcom.sap.caf.eu.gp.process.api.IGPModifiableAction;
       
      IGPModifiableBlockb = null;
       
      try{
         // create the block and the actions
         ...
        // add the actions to the structure
         b.getModifiableStructure().addItem(a_0);
         b.getModifiableStructure().addItem(a_1);
         b.getModifiableStructure().addItem(a_2);
       
         // save the block object
         manager.save(b);
         } finally {
             if (b != null) {
                // release the block object
                manager.release(b);
             }
         }

    For more information on how to implement actions, see Creating Actions .

    • Inserting an item into a specific position in the structure

      Suppose you have already created and saved block b, and for some reason you decide that you need to execute another activity before action a_1 , a block named b_0 for example. You insert the block into the structure on position 2. Thus, action a_1 is shifted to position 3.

      b.getModifiableStructure().insertItem(2,b_0);
    • Replacing an item in the structure

      To replace the item on position 3 (in our case,
      a_1b_0
      ) with , write:
      b.getModifiableStructure().setItem(3, b_0);
    • Exchanging two items in the structure

      To swap items on positions 3 and 4 (in our case,
      b_0a_2
      and ), write:
      b.getModifiableStructure().swap(3, 4);
  • Deleting an item from the structure

    To delete the item on position 1 (a _0 ), write:

    b.getModifiableStructure().removeItem(1);
  1. Make sure you save and release the block after you have created and modified it.
    manager.save(b);
    manager.release(b);

Result

Once you have assigned actions to the block, you can also:

For more information about block editing, see Editing GP Development Objects .