Oracle Forms – Javabean

 

A java multi-choice alert box

 

Home page

 

 

1.    Purpose

 

 

This is a Javabean component that allow to display an Alert box with many options

 

 

 

 

 

 

 

2.    The Javabean

 

 

package oracle.forms.fd;

 

import java.util.StringTokenizer;

import oracle.forms.handler.IHandler;

import oracle.forms.properties.ID;

import oracle.forms.ui.VBean;

import javax.swing.JOptionPane;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

import javax.swing.plaf.metal.MetalLookAndFeel;

 

/**

 * A javabean multi choice alert for Oracle Forms

 *

 * @author Francois Degrelle

 * @version 1.0

 */

 

public class BigAlert extends VBean {

 

    static String title = "" ;

    static String text  = "" ;

    static String result = "" ;

    static String list = "" ;   

    static String OptionList[] = new String[100];

    static String sDelimiter = "|" ;

    static int    icon  = JOptionPane.QUESTION_MESSAGE ;

 

    private IHandler mHandler;

    private static final ID pSetTitle   = ID.registerProperty("SETTITLE");

    private static final ID pSetText    = ID.registerProperty("SETTEXT");

    private static final ID pSetList    = ID.registerProperty("SETLIST");

    private static final ID pSetDelim   = ID.registerProperty("SETDELIM");

    private static final ID pGetString  = ID.registerProperty("GETSTRING");   

 

    public BigAlert() {

      super();

      try

      {

        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        SwingUtilities.updateComponentTreeUI(this);

      }

      catch (Exception ex)

      {

        ex.printStackTrace();

      }       

    }

 

    public void init(IHandler handler) {

        super.init(handler);

        mHandler = handler;

    }

 

    /**

     * Set the properties from Forms

     **/

    public boolean setProperty(ID id, Object value) {

        if (id == pSetTitle) { /** Set the title **/

            title = (String)value ;

            return true;

        }

        else if (id == pSetList) { /** Set the list of choices **/

            int i = 0 ;

            list = (String)value ;

            StringTokenizer st = new StringTokenizer(list,sDelimiter);

             while (st.hasMoreTokens()) {

               OptionList[i] = st.nextToken() ;

               i++ ;

             }

          return true;

        }       

        else if (id == pSetText) { /** Set the message and display the dialog box **/

            text = (String)value ;

            result = ShowAlert();

            return true;

        }

      else if (id == pSetDelim) { /** Set the list delimiter **/

          sDelimiter = (String)value ;

          return true;

      }

        else {

            return true;

        }

    }

 

  /**

   * Get the result string from Forms

   **/

  public Object getProperty(ID pId)

  {

    if (pId == pGetString)

    {

      return "" + result ;

    }

    else

    {

      return super.getProperty(pId);

    }

  } // getProperty()

 

    /**

     * Display the Alert box

     */

    public static String ShowAlert() {

 

        String sReturn = (String)JOptionPane.showInputDialog(

             null,

             text,

             title,

             JOptionPane.QUESTION_MESSAGE,

             null,

             OptionList,

             OptionList[0]);

 

        if( sReturn == null ) return "" ;

        else return sReturn ;

 

    }

   

       

}

 

 

 

3.    Forms configuration

 

Ø      Copy the bigalert.jar file in the /forms/java directory

 

Ø      Edit the /forms/server/formsweb.cfg file to add the jar file to the archive_jini variable

 

archive_jini=f90all_jinit.jar,……,bigalert.jar

 

 

 

4.    How to implement this bean in your own form

 

Ø      Open your form

 

Ø      Add a Javabean component to any block

 

Ø      Set its Implementation class property to : oracle.forms.fd.BigAlert

 

 

 

5.    The properties that can be sent to the bean

 

 

 

Ø      The title of the alert box

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘SETTITLE’, ‘the_title’ ) ;

 

 

Ø      The choices’ list of the alert box

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘SETLIST’, ‘the_list’ ) ;

 

The values must be separated with the delimiter character ( Alt+124 by default)

 

 

Ø      The list delimiter

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘SETDELIM’, ‘char_delimiter’ ) ;

 

By default, the delimiter is | in the jar file

 

 

Ø     The text of the alert box

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘SETTEXT’, ‘the_text’ ) ;

 

 

 

6.    The properties that can be read from the bean

 

 

 

Ø      The returned string

 

:BLK.ITEM := Get_Custom_Property( ' BLOCK.BEAN_ITEM', 1, 'GETSTRING' ) ;

 

 

 

7.    The sample dialog

 

Ø      Download the bigalert.zip file

 

Ø      Unzip the bigalert.zip file

 

Ø      Copy the inputdialog.jar file in your /forms/java/ directory

 

Ø      Edit your /forms/server/formsweb.cfg file

 

Ø      Open the bigalert.fmb module (Oracle Forms 9.0.2)

 

Ø      Compile all and run the module

 

 

 

This dialog allows to enter the title, the question and the option list of the alert box

 

The code that shows the alert dialog box is located in the When-Button-Pressed trigger

 

-- Set the title --

Set_Custom_Property( 'CTRL.DIALOG', 1, 'SETTITLE', :CTRL.TITLE ) ;

-- Set the option list --

Set_Custom_Property( 'CTRL.DIALOG', 1, 'SETLIST',  :CTRL.LIST ) ;

-- Set the text and show the input dialog box --

Set_Custom_Property( 'CTRL.DIALOG', 1, 'SETTEXT',  :CTRL.QUESTION ) ;

-- Get the input string --

:CTRL.TEXT := Get_Custom_Property( 'CTRL.DIALOG', 1, 'GETSTRING' ) ;