Trigger ou função para disparar ao digitar

Dicas do Oracle Forms Builder - Blocos, Itens, LOV, Canvas, Triggers, comandos, PLL, d2kwutil, FMB, Alert, menus, etc
Responder
roberta.baltazar
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Mensagens: 1
Registrado em: Ter, 06 Ago 2013 11:07 am

Trigger no momento da digitação

Estou desenvolvendo uma rotina de menu para um coletor, onde será apresentada uma lista com o número do menu e a descrição. A pessoa poderá navegar pelo menu através das setas (subindo e descendo) ou através da digitação do número do menu.

Alguém conhece uma forma de ao digitar disparar uma trigger/função no forms? Digo ao digitar mesmo, sem enter ou tab. Disparar a trigger logo que tiver uma digitação

Obrigada,
Roberta
diegoBenetti
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Mensagens: 4
Registrado em: Sex, 27 Set 2013 9:24 am

Bom dia!

não sei se atende a sua necessidade, mas você pode definir uma tecla de atalho para seus itens, se não me engano no menu também é possível.

Por exemplo: imagine um button com label "Cadastro". Se você quiser definir a letra "C" como atalho para esse button, basta alterar o label para "&Cadastro". ( o símbolo é um 'E' comercial). Se por acaso quisesse definir a letra 'D' como atalho, basta alterar o label para "Ca&dastro". Perceba que, quando você definir o atalho dessa forma, a letra imediatamente posterior ao 'E' comercial ficará sublinhada.

A propriedade "Access key" tem efeito semelhante, porém nessa propriedade você pode definir qualquer carácter como atalho, não é necessário que seja um carácter presente no label.

Para que acessar o item após ter definido o atalho basta segurar a tecla alt + a tecla de atalho definida

Espero que seja útil,
att. Diego
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Aqui foi dado uma idéia não muito elegante. Usando TIMER, talvez ajude:
http://glufke.net/oracle/viewtopic.php?f=4&t=411

Caso seja Forms WEB, é possível usando este método:
http://sheikyerbouti.developpez.com/for ... ceptor.htm
Purpose

This is a Javabean component that allows to intercept each key typed in a text field


Key Typed

Then, there is no need to use a Forms timer to intercept each key typed.

The java code

Get the Java code here


Forms configuration
. Copy the keytyped.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,……,keytyped.jar

Implementation Class property

oracle.forms.fd.KeyTyped


Properties that can be set

The text of the item

set_custom_property( 'BLOCK.BEAN_ITEM', 1, 'SETTEXT', 'the_text');


The cursor position

set_custom_property( 'BLOCK.BEAN_ITEM', 1, 'SETPOS', 'n');


The item colors

set_custom_property( 'BLOCK.BEAN_ITEM', 1, 'SETBG', 'rgb value');
set_custom_property( 'BLOCK.BEAN_ITEM', 1, 'SETFG', 'rgb value');

e.g.
set_custom_property( 'BLOCK.BEAN_ITEM', 1, 'SETBG', '200,10,0');


Properties that can be read

The text of the item

get_custom_property( 'BLOCK.BEAN_ITEM', 1, 'GETTEXT', '');


The last character typed

get_custom_property( 'BLOCK.BEAN_ITEM', 1, 'GETCHAR', '');



The keyboard state modifier

get_custom_property( 'BLOCK.BEAN_ITEM', 1, 'GETMODIFIER', '');



Events that can be raised by the bean

A character was typed

KEYTYPED


The sample dialog

Download the KeyTyped.zip file
Unzip the KeyTyped.zip file
Copy the keytyped.jar file in your /forms/java/ directory
Edit your /forms/server/formsweb.cfg file
Open the KEYTYPED.fmb module (Oracle Forms 9.0.2)
Compile all and run the module

Selecionar tudo

package oracle.forms.fd;

import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
import javax.swing.BorderFactory;
import javax.swing.JTextField;
import javax.swing.border.Border;
import oracle.forms.ui.CustomEvent;
import oracle.forms.ui.VBean;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;

  /**
   * A javabean that fires for each character pressed
   * in a JtextField
   *
   * @author Francois Degrelle
   * @version 1.2
   * return the correct modifier code (Ctrl, Alt, Shift, ...)
   * in the sModifier String via the GETMODIFIER property
   */

  public class KeyTyped   extends VBean implements FocusListener, KeyListener
  {
    public final static ID SETTEXT      = ID.registerProperty("SETTEXT"); 
    public final static ID SETPOS       = ID.registerProperty("SETPOS");   
    public final static ID SETBG        = ID.registerProperty("SETBG");   
    public final static ID SETFG        = ID.registerProperty("SETFG");       
    public final static ID GETTEXT      = ID.registerProperty("GETTEXT");   
    public final static ID GETCHAR      = ID.registerProperty("GETCHAR");       
    public final static ID GETMODIFIER  = ID.registerProperty("GETMODIFIER");           
    public final static ID KEYTYPED     = ID.registerProperty("KEYTYPED");   
    private   IHandler    m_handler; 
    protected JTextField  jText ;
    private   int         iStringLength = 0 ;
    private   char        cChar ;
    private   int         iModifier = 0 ;
    private   String      sModifier = "" ;
   
    public KeyTyped ()
    {
       super();
       jText = new JTextField() ;
       jText.addKeyListener(this);
       Border border = BorderFactory.createLoweredBevelBorder();
       jText.setBorder(border);
       add(jText) ;

    }
     
    public void init(IHandler handler)
    {
      m_handler = handler;
      super.init(handler);
      addFocusListener(this);
      jText.addFocusListener(this);
    }     
   
   
    public boolean setProperty(ID property, Object value)
    {
      if (property == SETTEXT)  // set the text of the JTextField
      {
        jText.setText(value.toString());
        jText.setCaretPosition(0);
        return true;
      }
      else if (property == SETPOS) // set the position of the cursor
      {
        int iPos = new Integer((String)value).intValue() ;
        jText.setCaretPosition(iPos);
        return true;
      }
      else if (property == SETBG) // set the background color
      {
        String color = value.toString().trim();
        int r=-1, g=-1, b=-1, c=0 ;
        StringTokenizer st = new StringTokenizer(color,",");
        while (st.hasMoreTokens()) {
                 c = new Integer((String)st.nextToken()).intValue()  ;
                 if( (c <0) || (c > 255) ) c = 0 ;
                 if( r == -1 ) r = c ;
                 else if( g == -1 ) g = c ;
                 else if( b == -1 ) b = c ;
               }
        jText.setBackground(new Color(r, g, b) );
        return true;
      }
      else if (property == SETFG) // set the foreground color
      {
        String color = value.toString().trim();
        int r=-1, g=-1, b=-1, c=0 ;
        StringTokenizer st = new StringTokenizer(color,",");
        while (st.hasMoreTokens()) {
                 c = new Integer((String)st.nextToken()).intValue()  ;
                 if( (c <0) || (c > 255) ) c = 0 ;
                 if( r == -1 ) r = c ;
                 else if( g == -1 ) g = c ;
                 else if( b == -1 ) b = c ;
               }
        jText.setForeground(new Color(r, g, b) );
        return true;
      }     
      else
      {
       return super.setProperty(property, value);
      }
    }

    /**
     * Get the result string from Forms
     **/
    public Object getProperty(ID pId) // get the whole string
    {
      if (pId == GETTEXT)
      {
        return "" + jText.getText();
      }
      else if (pId == GETCHAR) // get the last character typed
      {
        return "" + cChar;
      }     
      else if (pId == GETMODIFIER) // get the last character typed
      {
        return "" + sModifier;
      }           
      else
      {
        return super.getProperty(pId);
      }
    }
   
    /** Handle the key typed event from the text field. */
    public void keyTyped(KeyEvent e) {
          ;
        }
        
    /** Handle the key pressed event from the text field. */
    public void keyPressed(KeyEvent e) {
    }

    /** Handle the key released event from the text field. */
    public void keyReleased(KeyEvent e) {
       iStringLength = jText.getText().length();
       int iKey = (int)(e.getKeyChar()) ;
       // get the character
       cChar = e.getKeyChar() ;
       // get the modifier
       iModifier = e.getModifiers();
       sModifier = KeyEvent.getKeyModifiersText(iModifier);
       /*
        * Inform Forms that a character was typed
        */
       CustomEvent ce = new CustomEvent(m_handler, KEYTYPED);
       dispatchCustomEvent(ce);        
    }

    public void focusGained(FocusEvent e)
     {
         if (e.getComponent() == this)
         {
             // put the focus on the component
             jText.requestFocus();
         }
   
         try
         {
             m_handler.setProperty(FOCUS_EVENT, e);
         }
         catch ( Exception ex )
         {
           ;
         }
     }
   
   
     public void focusLost(FocusEvent e)
     {
     }
   
  }
  
gledson.veras
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Mensagens: 7
Registrado em: Ter, 10 Dez 2013 10:03 am

você já fez o teste colocando o código na trigger WHEN-BUTTON-PRESSED?
Responder
  • Informação
  • Quem está online

    Usuários navegando neste fórum: Nenhum usuário registrado e 14 visitantes