Oracle Forms – Javabean

 

A java popup dialog

 

Home page

 

 

1.    Purpose

 

The Show_Alert() Forms built-in allows to display any message in a popup modal window.

This built-in is limited to a maximum of 255 characters displayed.

This limitation cannot allow to display huge messages like trace/log message.

 

This is a Javabean component that allow to display messages with thousands of characters

 

 

 

 

2.    The Javabean

 

 

package oracle.forms.fd;

 

import oracle.forms.handler.IHandler;

import oracle.forms.properties.ID;

import oracle.forms.ui.CustomEvent;

import oracle.forms.ui.VBean;

import javax.swing.JOptionPane;

 

/**

 * A dialog box for Forms that allow to output 1 up to 32767 characters

 *

 * @author Francois Degrelle

 * @version 1.0

 */

 

public class ShowMessage extends VBean {

 

    static String title = "" ;

    static String text  = "" ;

    static String icone = "" ;   

    static int    max   = 150 ;

    static int    icon  = JOptionPane.INFORMATION_MESSAGE ;

 

    private IHandler mHandler;

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

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

    private static final ID pSetIcon  = ID.registerProperty("SETICON");

    private static final ID pSetSize  = ID.registerProperty("SETLINESIZE");

    private static final ID pShow     = ID.registerProperty("SHOW");   

    private static final ID pClear    = ID.registerProperty("CLEAR");       

 

    public ShowMessage() {

        super();

    }

 

    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 == pSetText) { /** Set the message **/

            text += (String)value ;

            return true;

        }

        else if (id == pClear) { /** Clear the text **/

            text = "" ;

            return true;

        }       

        else if (id == pSetSize) { /** Set max line size **/       

            max = new Integer((String)value).intValue() ;

            return true;

        }

        else if (id == pSetIcon) { /** Set the dialog box icon **/

            icone = (String)value ;

            if( icone.equals("I") )      icon = JOptionPane.INFORMATION_MESSAGE ;

            else if( icone.equals("E") ) icon = JOptionPane.ERROR_MESSAGE ;

            else if( icone.equals("P") ) icon = JOptionPane.PLAIN_MESSAGE ;

            else if( icone.equals("W") ) icon = JOptionPane.WARNING_MESSAGE ;

            return true;

        }       

        else if (id == pShow) { /** Display the dialog box **/

            text = Wrap_Text( text ) ;

            ShowDialog();

            return true;

        }               

        else {

            return true;

        }

    }

 

    /**

     * Display the dialog box

     */

    public static void ShowDialog() {

 

        JOptionPane.showMessageDialog(null, text, title, icon);

 

    }

   

     /**

     * Wrap the text if lines are too long

     */

    private String Wrap_Text( String sText )

    {

      String sWraped = "" ;

      String s1 = sText ;

      String s2 = "" ;

      int    l, x = 0 ;

     

      l = s1.length() ;

      if( l <= max ) sWraped = s1 ;

      else

      {

        while( l > 0 )

        {

          x = s1.indexOf("\n") ;

          if( (x > 0) && (x <= max))

          {

            sWraped += s1.substring(0,x) ;

            s1 = s1.substring(x) ;

          }

          else

          {

            s2 = s1.substring(0, max-1) ;

            sWraped += s2 + "\n" ;

            s1 = s1.substring(max-1) ;

          }

          l = s1.length() ;

 

          if( l <= max )

          {

            sWraped += s1 ;

            l = 0 ;

          }

        }

       

      }

     

      return sWraped ;     

    }

       

}

 

3.    Forms configuration

 

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

 

Ø      Sign the showmessage.jar file with your own certificate

 

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

 

archive_jini=f90all_jinit.jar,……,showmessage.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.ShowMessage

 

 

 

5.    The properties that can be sent to the bean

 

 

Ø      Clear the text

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘CLEAR’, ‘’ ) ;

 

 

Ø      The title of the message box

 

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

 

 

Ø     The icon style of the message box

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘SETICON’, ‘icon_type’ ) ;

 

Where icon_type can be one of the following:

 

I           Information

E         Error

P         Plain (no icon)

W        Warning

 

The default value is I (Information)

 

 

Ø     The maximum size of a line of the message box

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘SETLINESIZE’, ‘max_size’ ) ;

 

The default value for LINESIZE is 150 characters

 

 

Ø     The text of the message box

 

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

 

 

Ø      Show the message box

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘SHOW’, ‘’ ) ;

 

 

 

6.    The sample dialog

 

Ø      Download the showmessage.zip file

 

Ø      Unzip the showmessage.zip file

 

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

 

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

 

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

 

Ø      Compile all and run the module

 

 

 

This dialog allows to enter the title, the text of the message, an icon style and the max size of lines

 

All these functions are encapsulated in the Show_Message() program unit procedure

 

PROCEDURE Show_Message

 (

   PC$Bean  IN Varchar2,

   PC$Text  IN Varchar2,

   PC$Title IN Varchar2  DEFAULT NULL,

   PC$Icon  IN Varchar2  DEFAULT 'P',

   PN$Max   IN NUMBER    DEFAULT 150

 ) IS

 

       LN$Slices  Pls_Integer := 1 ;

       LN$Rest    Pls_Integer ;

       LN$Pos     Pls_Integer := 1 ;

 

BEGIN

 

  -- Clear text --

  Set_Custom_Property( PC$Bean, 1, 'CLEAR',  '' ) ; 

 

  -- Set Title --

  If PC$Title IS NOT NULL Then

     Set_Custom_Property( PC$Bean, 1, 'SETTITLE', PC$Title ) ;

  End if ;

  -- Set icon --

  If Upper( PC$Icon ) IN ('I','E','P','W') Then

     Set_Custom_Property( PC$Bean, 1, 'SETICON', Upper( PC$Icon ) ) ;

  End if ; 

  -- Set max line size --

  If PN$Max IS NOT NULL Then

     Set_Custom_Property( PC$Bean, 1, 'SETLINESIZE', To_Char( PN$Max ) ) ;    

  End if ;

  -- Set text --

  If PC$Text IS NOT NULL Then

If LENGTH( PC$Text ) > 1000 Then

            LN$Slices := LENGTH( PC$Text ) / 1000 ;

            LN$Rest   := MOD( LENGTH( PC$Text ), 1000 ) ;

            IF LN$Rest > 0 THEN LN$Slices := LN$Slices + 1 ; END IF ;

      End if ;

      FOR i IN 1..LN$Slices LOOP

            message('.', no_acknowledge);

            Set_Custom_Property( PC$Bean, 1, 'SETTEXT',  SUBSTR( PC$Text, LN$Pos, 1000 ) ) ; 

            LN$Pos := LN$Pos + 1000 ;

END LOOP ;

  End if ;

  -- Show text --

  If PC$Text IS NOT NULL Then

       Set_Custom_Property( PC$Bean, 1, 'SHOW',  '' ) ; 

  End if ; 

 

END;

 

Explanation:

 

Set_Custom_Property() does not allow to pass an argument greater than 1000 characters.

That is why, the text is cut into bits of 1000 characters, as many as required.

 

 

Assume your bean is located in the SHOW item of the CTRL block and you want to display the text located in the  CTRL.TEXT item:

 

Show_Message( ‘CTRL.SHOW’, :CTRL.TEXT ) ;