独自のカスタム・タグ・インサイト・エディタを作成して、JSP 1.1および1.2のカスタム・タグ・テクノロジで使用できます。独自のカスタム・タグ・インサイト・エディタを実装する手順は、次のとおりです。
次の手順では、単純なDate Picker Insight Editorの作成方法を説明します。この手順では、ワークスペース、プロジェクト、およびファイルの作成など、基本的なJDeveloperの機能を理解していることを前提としています。
単純なDate Picker Insight EditorのUIを作成するには、次のようにします。
DateInsight
という名前を付けます。
.jpr
)をダブルクリックして、「プロジェクトの設定」ダイアログを開きます。 ツリーで「構成」を開き、「開発」を開いて「ライブラリ」を選択し、プロジェクトの選択済のライブラリのリストに「JDeveloper」ライブラリを追加します。
DateInsight.java
に、次のコードを追加します。 package package1;
import java.util.ArrayList;
import javax.swing.Icon;
import javax.swing.JComponent;
import oracle.ide.addin.Context;
import oracle.ideimpl.resource.PaletteArb;
import oracle.jdevimpl.jsp.tags.insight.AttributeEditor;
import oracle.jdevimpl.jsp.tags.insight.TagCompletion;
import oracle.jdevimpl.jsp.tags.insight.WebTags;
import oracle.jdevimpl.jsp.tags.insight.model.WebTag;
public class DateInsight implements TagCompletion
{
private String _value;
private WebTags _webTags;
/**
* Set the context and "active" tag.
*/
public void setTagInfo( Context context, WebTags webTags )
{
_webTags = webTags;
}
/**
* Sets String Value
*/
public void setValue( String value )
{
_value = value;
}
/**
* Returns String Value
*/
public String getValue()
{
return _value;
}
/**
* Returns a GUI. The AttributeEditor and TagCompletion are used to
* easily insert attribute values and close the dialog from inside your
* UI. However, you can also write your own listener and do this yourself
* since it is not the most elegant code.
*/
public JComponent createPanel( AttributeEditor dlg, TagCompletion editor )
{
/* To not invoke a dialog, just setIsInvokable to false.
Ex. dlg.setIsInvokable( false );
otherwise, just return the UI to display.
return yourUI();
Note: You can pass the AttributeEditor and TagCompletion to your UI
to allow you to insert values into CodeEditor and close the dialog.
Ex. return new DateUI( dlg, editor );
*/
return null;
}
/**
* Returns a List of Default Values
* The first name added to the List should be the editor name.
* Important: If you return an empty ArrayList, insight will not appear.
* @return ArrayList of values
*/
public ArrayList getValueList()
{
ArrayList list = new ArrayList();
if( false )
{
// To display a UI, you must return an empty list.
}
else // return an list of items for insight to display
{
// Show your own value list
list.add("Date Picker");
list.add("Today");
list.add("Tomorrow");
list.add("The Next Day");
}
return list;
}
/**
* Retrieves the name of the editor
* Note: This will be as the title in your UI */
public String getName()
{
return "Date Chooser";
}
/**
* Retrieves Icon to use in code insight
*/
public Icon getIcon()
{
return PaletteArb.getIcon( PaletteArb.JSP_ICON );
}
/**
* Specify whether there is an associated editor to use.
* @return true or false If there is an associated editor.
*/
public boolean hasEditor()
{
return true;
}
/**
* Called whenver a new Tag Library has been added in the Java Code Editor
*/
public void tagAdded( WebTag tag )
{
// Implementation needed.
}
/**
* Call Help for certain Tag.
*/
public void showTagHelp( WebTag tag )
{
// Implementation needed.
}
}
DateInsightAddin
という名前を付けます。
DateInsightAddin.java
に、次のコードを追加します。 package package2;
import oracle.ide.addin.Addin;
import oracle.jdevimpl.jsp.tags.insight.*;
public class DateInsightAddin implements Addin
{
private final TagInsightManager _mgr = TagInsightManager.getInstance();
private final DateInsight _dateInsight = new DateInsight();
public DateInsightAddin()
{
}
public void initialize()
{
// To register your TagCompletion, you must specify the tag prefix to listen for.
// Ex. for a simple utilities tag with prefix utils ( <utils:foo use
_mgr.register( "utils", _dateInsight );
}
public void shutdown()
{
}
public float version()
{
return 0;
}
public float ideVersion()
{
return 0;
}
public boolean canShutdown()
{
return false;
}
}
<JDEV_HOME\jdev\lib\ext>
へデプロイします。「ファイル」->「新規」を選択して「General」を開き、「Deployment Profiles」を選択して「JARファイル - シンプル・アーカイブ」をダブルクリックします。 次に、アプリケーション・ナビゲータで.deploy
ファイルを右クリックし、「JARファイルにデプロイ」を選択します。
<utils:foo test="
getValueList
に指定した値のリストが表示されます。リスト・ボックスではなくエディタを表示するには、次のようにします。
DatePicker
というクラスを作成します。
DatePicker.java
に、次のコードを追加します。 package package2;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import oracle.jdeveloper.layout.XYConstraints;
import oracle.jdeveloper.layout.XYLayout;
import oracle.jdevimpl.jsp.tags.insight.AttributeEditor;
import oracle.jdevimpl.jsp.tags.insight.TagCompletion;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JLabel;
import java.awt.event.*;
/**
* A Simple Swing-based panel to select a date. This is truly trivial.
*/
public class DatePicker extends JPanel implements ActionListener
{
private final JTextField _dateFld = new JTextField();
private final JButton _okBtn = new JButton();
private final GridBagLayout gridBagLayout1 = new GridBagLayout();
private final JLabel _dateLbl = new JLabel();
private AttributeEditor _dlg = null;
private TagCompletion _editor = null;
/**
* Constructs a new instance.
*/
public DatePicker( AttributeEditor dlg, TagCompletion editor )
{
_dlg = dlg;
_editor = editor;
try
{
jbInit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
*
*/
private void jbInit() throws Exception
{
setLayout( gridBagLayout1 );
_okBtn.setText("Ok");
_okBtn.addActionListener( this );
_dateLbl.setText("Create Date:");
_dateFld.setText(new java.util.Date().toString());
this.add(_dateFld, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
this.add(_okBtn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
this.add(_dateLbl, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
}
public void actionPerformed( ActionEvent e )
{
// Insert Attribute Value into Java Code Editor
_editor.setValue("<%= new java.util.Date(\""+_dateFld.getText()+"\") %>\"");
// Close Dialog.
_dlg.close();
}
}
DateInsight.java
で、次の変更を加えます。 createPanel
メソッドにおいて
return new DatePicker( dlg, editor );
getValueList
メソッドにおいて
return new ArrayList();
単純なDate Picker Insight EditorのUIが表示されます。
JDeveloperのJSPカスタム・タグ・ライブラリについて
カスタムJSPタグ・ライブラリの作成
カスタム・タグ・エディタの作成
詳細は、次のURLでJavaServer Pages仕様を参照してください。http://java.sun.com/products/jsp/index.html
Copyright © 1997, 2004, Oracle. All rights reserved.