Overblog
Suivre ce blog
Editer l'article Administration Créer mon blog
2 février 2006 4 02 /02 /février /2006 12:32

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





The java code


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 ;     

    }    

}


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


Implementation Class property

    oracle.forms.fd.ShowMessage


Properties that can be set

Clear the text

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

Set the title of the message box

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

Set the icon style

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

Where icon_type could be: 
 
  • I   Information
  • E   Error
  • P   Plain (no icon)
  • W   Warning
 


Set the maximum length of a line

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

Set the text of the message box

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

Display the message box

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



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

Partager cet article

Published by Oracle Forms community - dans Bean - JoptionPane
commenter cet article

commentaires