生産スケジューラのフレクシェ > サポート > 開発者向け情報 > FSFのサンプルコード
下のフォームはFSFの利用方法のデモンストレーションを目的としたものです。フォームの構築、イベント処理、シリアライズなど、さまざまな要素が詰め込まれています。フォームの取り扱い方を習得するにあたって、このコードを参考にしてください。

このモーダルダイアログは以下のJScriptで実装されています。
Exercise.wsc (右クリックで保存してください)
function SelfRegistration( addIns )
{
//// この部分を変更した場合は「アドイン再登録」を実行してください
addin = addIns.AddAddIn( "Exercise.ShowPanel", "Exercise.Manager",
"ShowPanel", FLEXSCHE.AddInKeyMenuView );
addin.MenuString = "サンプルフォーム";
}
function _ShowPanel( keyEntity )
{
env = keyEntity.ParamObject( FLEXSCHE.ParamIDEnvironment );
if( env.Project != null )
Show_SamplePanel( env.Project );
return true;
}
////フォームSamplePanelを開きます
function Show_SamplePanel( project )
{
form = new ActiveXObject( "SDLib.Form" );
form.Setup( "SamplePanel", "_ok","Exercise.Manager" );
form.ShowForm( project );
}
//フォームSamplePanelの構築と初期設定
function SamplePanel_Initialize( form )
{
form.FormCaption = "サンプル";
form.AddControl( "listLeft", "list:10:100" );
form.AddControl( "btnRight", "button:→:50" );
form.AddControl( "btnLeft", "button:←:50", "down" );
form.AddControl( "listRight", "list:10:100" );
form.NextRow( "listLeft" );
combo = form.AddControl( "itemEdit", "combo_edit:10", "align_right:listLeft" );
form.AddControl( "btnAdd", "button:追加(&A):50" );
itemSet = form.Project.DataSpace.ItemSet;
c = itemSet.CountOfRecords;
for( i = 0; i < c; i++ )
{
itemRec = itemSet.Record( i );
if( itemRec.IsBound ) combo.Command( "add_string", itemRec.Code );
}
UpdateControls( form );
}
function UpdateControls( form )
{
index = form.Property( "listRight", "cur_sel" );
form.Property( "btnLeft", "enabled" ) = index >= 0;
index = form.Property( "listLeft", "cur_sel" );
form.Property( "btnRight", "enabled" ) = index >= 0;
s = form.Value( "itemEdit" );
index1 = form.Command( "listLeft", "find_string", s );
index2 = form.Command( "listRight", "find_string", s );
form.Property( "btnAdd", "enabled" ) = s != "" && index1 < 0 && index1 < 0;
}
// ここでフォームSamplePanelのイベントを処理してください
function SamplePanel_Event( form, ctrl, evnt, param )
{
if( ctrl == "btnAdd" )
{
s = form.Value( "itemEdit" )
if( evnt == "clicked" && s != "" )
{
form.Command( "listLeft", "add_string", s );
UpdateControls( form );
}
}
else if( ctrl == "btnLeft" )
{
index = form.Property( "listRight", "cur_sel" );
if( evnt == "clicked" && index >= 0 )
{
form.Command( "listLeft", "add_string", form.Property( "listRight", "string" ) );
form.Command( "listRight", "delete", index );
UpdateControls( form );
}
}
else if( ctrl == "btnRight" )
{
index = form.Property( "listLeft", "cur_sel" );
if( evnt == "clicked" && index >= 0 )
{
form.Command( "listRight", "add_string", form.Property( "listLeft", "string" ) );
form.Command( "listLeft", "delete", index );
UpdateControls( form );
}
}
else if( ( ctrl == "listLeft" || ctrl == "listRight" ) && evnt == "sel_change" )
UpdateControls( form );
else if( ctrl == "itemEdit" && evnt == "change" )
UpdateControls( form );
return true;
}
// フォームSamplePanelの設定の読み書き
function SamplePanel_Load( form, xmlElem )
{
list = form.Control( "listLeft" );
codeAttrs = xmlElem.selectNodes( "items[@pos='left']/item/@code" );
c = codeAttrs.length;
for( i = 0; i < c; i++ )
list.Command( "add_string", codeAttrs.item( i ).value );
list = form.Control( "listRight" );
codeAttrs = xmlElem.selectNodes( "items[@pos='right']/item/@code" );
c = codeAttrs.length;
for( i = 0; i < c; i++ )
list.Command( "add_string", codeAttrs.item( i ).value );
}
function SamplePanel_Save( form, xmlElem )
{
doc = xmlElem.ownerDocument;
list = form.Control( "listLeft" );
c = list.Property( "count" );
if( c > 0 )
{
itemsElem = doc.createElement( "items" );
itemsElem.setAttribute( "pos", "left" );
xmlElem.appendChild( itemsElem );
for( i = 0; i < c; i++ )
{
itemElem = doc.createElement( "item" );
itemElem.setAttribute( "code", list.Property( "string:" + i ) );
itemsElem.appendChild( itemElem );
}
}
list = form.Control( "listRight" );
c = list.Property( "count" );
if( c > 0 )
{
itemsElem = doc.createElement( "items" );
itemsElem.setAttribute( "pos", "right" );
xmlElem.appendChild( itemsElem );
for( i = 0; i < c; i++ )
{
itemElem = doc.createElement( "item" );
itemElem.setAttribute( "code", list.Property( "string:" + i ) );
itemsElem.appendChild( itemElem );
}
}
}