Adding a Delete Button to Multivalue JOI Forms (Functions/Subroutines/Programs)

How do I add a Delete button to my multivalue JOI forms?

The attached code shows how to create and add a Delete button to your JOI development environment. The code in this example is meant for deleting only one multivalued record, and not for relational style deletes.

Note: Netbeans 3.3.1 was used as a development environment in the screen shots below. Forte 3.0 techniques should be exactly the same or very similar.

Installing the Delete button in your development environment

First mount the directory containing the btnDelete class code in Forte or Netbeans, along with the joi.jar file.

charset_utf-8

 Then add the btnDelete class to the JOI component palette:

charset_utf-8

You should get the following in your JOI component palette:

charset_utf-8(The picture attached to the button is defined in the btnDelete.jpg, and can be modified if necessary.)

Using the Delete button with JOI forms

Once the button is in the component palette, simply use drop it on any JOI form to enable delete functionality. In the example below, we created a basic data-entry form against the ADDRESS table in the XML application that comes with JOI. After the form was created, we simply dropped the Delete button on the itgpPanel of the form, and ran the form.

charset_utf-8

 

How the Delete button works

The main code for the Delete button is in the btnDelete class. The class simply extends a Swing JButton, and adds functionality on the actionPerformed event of the button to take care of the delete operation. Here is the code behind the actionPerformed event:

        /** Trigger a Delete of the main record if the LastValidation.Success flag is set to true.

         * @param e the ActionEvent passed in.

         */

        public void actionPerformed(final java.awt.event.ActionEvent e) {

            if ( LastValidationStatus.Success == true){

                TriggerDeleteFromPanel();

            }

        }

 

The actual deleting code is in the TriggerDeleteFromPanel method below:

    private void TriggerDeleteFromPanel(){

        // This method identifies the first base itgpPanel that the Delete button is placed on, and triggers a WriteRecordToDataSet() on it.

       

        itgpPanel panel = itgpUtility.getPanel( this);

        if ( panel != null ){

            // Delete main record

           

            int result = JOptionPane.showConfirmDialog(this , "Are you sure you want to delete this record?" , "Delete Confirmation" , JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

            if ( result == JOptionPane.YES_OPTION) {

                itgpDataSet dSet = panel.getDataSet();

                dSet.deleteRecord( panel.getiMainTable(), 1);

                panel.WriteRecordToDataSet();

                panel.ClearPanel();         // Clear panel just in case WriteRecord does not

            }

        }

    }

 

Basically, we obtain the itgpDataSet behind the itgpPanel that the Delete button sits on. In that itgpDataSet, we delete the first record corresponding to the main table, and then synchronize the changes with the database by writing the changes.

Finally, just as extra insurance, we clear the panel after the delete, just in case the "iClearAfterWrite" property of the panel is not set to true already.

How do we integrate the Delete button in the development tool

 In the same directory, there is a class called btnDeleteBeanInfo . Using the Java beans specifications, this class defines the behavior of the bean at development time, including the picture that shows up the the component palette for the component.

For example, in the btnDeleteBeanInfo code, you will find a reference to btnDelete.jpg as the picture that should show up when the component is added to a component palette.

You can get Forte/Netbeans to help you write or edit a BeanInfo class by following the path in the picture below.

charset_utf-8

Hope this code is useful to you.

 

The JOI Development Team.

 

Click on the link below to download the files needed for this example:

 

{{kb0215_6.html; charset=utf-8}} 

  • kb/kb_articles/kb0215.txt
  • Last modified: 2024/01/30 13:36
  • by 127.0.0.1