I always wanted to learn to use java in Oracle Forms. Oracle form is very limited on a client side and you often need to expand your possibilities by use java code.
And I have, at last, a task that can not be solved without the java usage.
There is my target: I need to write a form for a text template creating, where I can create such a template for example:
..........
Dear <<Client Name>>
Please accept this purchase order <<Order number>>
Once it has shipped, you will receive a Shipping Confirmation email <<Email address>>.
..........
Our dictionary of tags is:
I have few tags in my dictionary and I need to pass a tag from the dictionary to a multi-lined text item as easily as possible.
Our tags list is a multi-record block. I write the template and I want to insert a tag value at the position where I am now. I want to click the row with a necessary tag and the tag will be inserted programmatically in a current position in the editable item.
What's a difficulty of this action? Oracle form does not be able to insert text into an inner place of a multi-lined item if you navigate from/to the item.
To pass the tag to the template I want to do:
The actions (1) and (3) I intend to process by Java Bean.
Java:
I create Java class CopyPasteClipBoard.java
There's its code:
package com.metro.beans;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.KeyEvent;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.VBean;
public class CopyPasteClipBoard extends VBean implements ClipboardOwner{
static IHandler handler;
static String COPY_PROPERTY_NAME = "COPY_TO_CLIPBOARD";
static String PASTE_PROPERTY_NAME = "PASTE_FROM_CLIPBOARD";
static String selectedText;
protected static final ID CopyText = ID.registerProperty(COPY_PROPERTY_NAME);
protected static final ID PasteText = ID.registerProperty(PASTE_PROPERTY_NAME);
public CopyPasteClipBoard(){
super();
}
public void init(IHandler hand){
super.init(hand);
handler = hand;
}
public boolean setProperty(ID property, Object value){
boolean rc = true;
if (property == CopyText){
selectedText = (String)value;
StringSelection stringSelection = new StringSelection( selectedText );
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents( stringSelection, this );
} else if (property == PasteText){
try {
Robot r = new Robot();
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_V);
}catch(Exception e){
e.printStackTrace();
}
}else{
return super.setProperty(property, value);
}
return rc;
}
public void lostOwnership(Clipboard arg0, Transferable arg1) {
}
public static void main(String[] args) {
CopyPasteClipBoard obj = new CopyPasteClipBoard();
obj.setProperty(CopyText, "tratata");
obj.setProperty(PasteText, "");
}
}
v_dummy := ' <<'||:TEMPLATE_TAGS.TAG_LABEL||'>> ';
set_custom_item_property('CONTROL.COPY_PASTE_BEAN','COPY_TO_CLIPBOARD',v_dummy);
go_item('TEMPLATES.TEMPLATE_EDIT');
synchronize;
set_custom_item_property('CONTROL.COPY_PASTE_BEAN','PASTE_FROM_CLIPBOARD',v_dummy);
else
go_item(:CONTROL.CURRENT_FIELD);
end if;
There are steps and problems you need to solve:
And I have, at last, a task that can not be solved without the java usage.
There is my target: I need to write a form for a text template creating, where I can create such a template for example:
..........
Dear <<Client Name>>
Please accept this purchase order <<Order number>>
Once it has shipped, you will receive a Shipping Confirmation email <<Email address>>.
..........
Our dictionary of tags is:
- Client Name
- Order number
- Email address
I have few tags in my dictionary and I need to pass a tag from the dictionary to a multi-lined text item as easily as possible.
Our tags list is a multi-record block. I write the template and I want to insert a tag value at the position where I am now. I want to click the row with a necessary tag and the tag will be inserted programmatically in a current position in the editable item.
What's a difficulty of this action? Oracle form does not be able to insert text into an inner place of a multi-lined item if you navigate from/to the item.
To pass the tag to the template I want to do:
- to edit the template item and to place a cursor to a position where I'd like to insert a tag;
- to click the tag;
- to copy the tag value into system clipboard(Copy);
- to navigate to the template item(a focus navigates to the current position);
- to simulate Cntrl-V pressing(Paste).
The actions (1) and (3) I intend to process by Java Bean.
Java:
I create Java class CopyPasteClipBoard.java
There's its code:
package com.metro.beans;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.KeyEvent;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.VBean;
public class CopyPasteClipBoard extends VBean implements ClipboardOwner{
static IHandler handler;
static String COPY_PROPERTY_NAME = "COPY_TO_CLIPBOARD";
static String PASTE_PROPERTY_NAME = "PASTE_FROM_CLIPBOARD";
static String selectedText;
protected static final ID CopyText = ID.registerProperty(COPY_PROPERTY_NAME);
protected static final ID PasteText = ID.registerProperty(PASTE_PROPERTY_NAME);
public CopyPasteClipBoard(){
super();
}
public void init(IHandler hand){
super.init(hand);
handler = hand;
}
public boolean setProperty(ID property, Object value){
boolean rc = true;
if (property == CopyText){
selectedText = (String)value;
StringSelection stringSelection = new StringSelection( selectedText );
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents( stringSelection, this );
} else if (property == PasteText){
try {
Robot r = new Robot();
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_V);
}catch(Exception e){
e.printStackTrace();
}
}else{
return super.setProperty(property, value);
}
return rc;
}
public void lostOwnership(Clipboard arg0, Transferable arg1) {
}
public static void main(String[] args) {
CopyPasteClipBoard obj = new CopyPasteClipBoard();
obj.setProperty(CopyText, "tratata");
obj.setProperty(PasteText, "");
}
}
In Form:
I add a new "Bean Area" item to control block, visible on some canvas with width=0 and height=0.
I set the "Implementation class" property value com.metro.beans.CopyPasteClipBoard(the package and class name).
I create a multi-record block TEMPLATE_TAGS with an item TAG_LABEL.
There's the "WHEN-MOUSE-UP" trigger's code of the tag item :RM_TEMPLATE_TAGS.TAG_LABEL
I add a new "Bean Area" item to control block, visible on some canvas with width=0 and height=0.
I set the "Implementation class" property value com.metro.beans.CopyPasteClipBoard(the package and class name).
I create an item TEMPLATES.TEMPLATE_EDIT for a template editing.
You need to switch the template item property "Keep Cursor Position" to "Yes".(Oracle, thanks for think about). This gives us to navigate to a same position if I leave and I enter to the template item.
There's the "WHEN-MOUSE-UP" trigger's code of the tag item :RM_TEMPLATE_TAGS.TAG_LABEL
v_dummy := ' <<'||:TEMPLATE_TAGS.TAG_LABEL||'>> ';
set_custom_item_property('CONTROL.COPY_PASTE_BEAN','COPY_TO_CLIPBOARD',v_dummy);
go_item('TEMPLATES.TEMPLATE_EDIT');
synchronize;
set_custom_item_property('CONTROL.COPY_PASTE_BEAN','PASTE_FROM_CLIPBOARD',v_dummy);
else
go_item(:CONTROL.CURRENT_FIELD);
end if;
There are steps and problems you need to solve:
- To export our java project with CopyPaste bean to CopyPasteJbeans.jar and to place one in
c:\Oracle\Middleware\Oracle_FRHome1\forms\java\;
(Forms 11 for me, development web logic installation) c:\Oracle\Middleware\user_projects\domains\FormsReports\servers\AdminServer\tmp\_WL_user\formsapp_11.1.2\7tyy89\war\metro_java\
- For Oracle*Forms 11 version you need ORACLE signature for this JAR by jarsigner. In addition you must create directory maping in the file(for server web logic installation):
- To add the jar file name to the parameter archive_jini in an appropriate section of formsweb.cfg
- For Forms 11 you must create
- For example:
archive_jini = frmall_jinit.jar, CopyPasteJbeans.jar - To solve java permissions. You search the c:\Program Files\Oracle\JInitiator 1.3.1.26\lib\security\java.policy
(this location for 10 version, for 11 version you need to search in %JAVA_HOME% path a file with same name) and after row
to add two rows
permission java.awt.AWTPermission "accessClipboard";
permission java.awt.AWTPermission "createRobot";
I see one problem only: where do you place your JARs. I've give directory pathes, this can help...
I wish you success
I wish you success
Yuri