3.7.2. Drag & Drop

Internal use

Internal M This topic is intended for MetaFactory developers only

Steps to implement the feature

Drag & Drop of an item in a list involves a dragable object (e.g. ‘Subtask’) and a reference to a parent object (e.g. ‘Task’).

In order to implement this feature take the following steps:

  1. Add metadata to the draggable object to mark it orderable within a certain reference (e.g. reference ‘task’ )

    Listing 3.11 model.xml
     1<object name="Subtask">
     2        <metadata>
     3
     4                <orderable>task</orderable>
     5        </metadata>
     6
     7        <reference name="task" type="Task">
     8
     9        </reference>
    10</object>
    

    Exclam M In the <orderable> metadata you need to specify the name of a reference, not the name of an object.

  2. Add an attribute sortOrder to the draggable object (here object Subtask)

    Listing 3.12 model.xml
     1<object name="Subtask">
     2        <metadata>
     3                <orderable>task</orderable>
     4        </metadata>
     5
     6        <attribute name="sortOrder" type="Integer" notnull="true">
     7                <metadata>
     8                        <entity.default.value>Integer.MAX_VALUE</entity.default.value>
     9                        <list.relation.mgmt>[number]</list.relation.mgmt>
    10                </metadata>
    11        </attribute>
    12        <reference name="task" type="Task">
    13                <metadata>
    14
    15                </metadata>
    16        </reference>
    17</object>
    
  3. Add metadata to the reference to create a finder (e.g. findByTask)

    Listing 3.13 model.xml
     1<object name="Subtask">
     2        <metadata>
     3
     4                <orderable>task</orderable>
     5        </metadata>
     6
     7        <attribute name="sortOrder" type="Integer" notnull="true">
     8                <metadata>
     9                        <entity.default.value>Integer.MAX_VALUE</entity.default.value>
    10                        <list.relation.mgmt>[number]</list.relation.mgmt>
    11                </metadata>
    12        </attribute>
    13        <reference name="task" type="Task">
    14                <metadata>
    15
    16                        <create.finder.method.list>true</create.finder.method.list>
    17                </metadata>
    18        </reference>
    19</object>
    
  4. Generate the application

  5. Create a changeSet in the Liquibase alters changelog to add the column to the table of the draggable object.

    Set a default value of 0 as the sort_order is required and must not be null. On the entity the default value becomes Integer.MAX_VALUE, however this is not supported by SQL. 0 is fine to start with.

    Listing 3.14 [projectdir]\[backenddir]\src\main\resources\config\liquibase\liquibase-alters-changeLog.xml
    1
    
<<<<<<< HEAD

<databaseChangeLog >

<changeSet id=”[id-named-after-jira-issue]” author=”[your-initials]”>
<addColumn tableName=”subtask”>
<column name=”sort_order” type=”INT” defaultValueNumeric=”0”>

<constraints nullable=”false” />

</column>

</addColumn>

</changeSet>

</databaseChangeLog>

Glasses M Read more about Liquibase change sets

  1. Run the application.