この付録では、このガイド全体の項で参照されている、完全な長さのコード・サンプルを示します。
この付録の内容は次のとおりです。
次に、ADF Facesアーキテクチャを使用する場合のコード例を示します。
ADF Facesのデフォルトのadf-js-partitions.xmlファイルには、独自のパーティション・ファイルを作成することでオーバーライドできるパーティションがあります。詳細は、第4.9項「JavaScriptライブラリのパーティション化」を参照してください。例F-1に、デフォルトのADF Facesのadf-js-partitions.xmlファイルを示します。
例F-1 デフォルトのadf-js-partitions.xmlファイル
<?xml version="1.0" encoding="utf-8"?>
<partitions xmlns="http://xmlns.oracle.com/adf/faces/partition">
<partition>
<partition-name>boot</partition-name>
<feature>AdfBootstrap</feature>
</partition>
<partition>
<partition-name>core</partition-name>
<feature>AdfCore</feature>
<!-- Behavioral component super classes -->
<feature>AdfUIChoose</feature>
<feature>AdfUICollection</feature>
<feature>AdfUICommand</feature>
<feature>AdfUIDialog</feature>
<feature>AdfUIDocument</feature>
<feature>AdfUIEditableValue</feature>
<feature>AdfUIForm</feature>
<feature>AdfUIGo</feature>
<feature>AdfUIInput</feature>
<feature>AdfUIObject</feature>
<feature>AdfUIOutput</feature>
<feature>AdfUIPanel</feature>
<feature>AdfUIPopup</feature>
<feature>AdfUISelectBoolean</feature>
<feature>AdfUISelectInput</feature>
<feature>AdfUISelectOne</feature>
<feature>AdfUISelectMany</feature>
<feature>AdfUIShowDetail</feature>
<feature>AdfUISubform</feature>
<feature>AdfUIValue</feature>
<!-- These are all so common that we group them with core -->
<feature>AdfRichDocument</feature>
<feature>AdfRichForm</feature>
<feature>AdfRichPopup</feature>
<feature>AdfRichSubform</feature>
<feature>AdfRichCommandButton</feature>
<feature>AdfRichCommandLink</feature>
<!--
Dialog is currently on every page for messaging. No use
in putting these in a separate partition.
-->
<feature>AdfRichPanelWindow</feature>
<feature>AdfRichDialog</feature>
<!-- af:showPopupBehavior is so small/common, belongs in core -->
<feature>AdfShowPopupBehavior</feature>
</partition>
<partition>
<partition-name>accordion</partition-name>
<feature>AdfRichPanelAccordion</feature>
</partition>
<partition>
<partition-name>border</partition-name>
<feature>AdfRichPanelBorderLayout</feature>
</partition>
<partition>
<partition-name>box</partition-name>
<feature>AdfRichPanelBox</feature>
</partition>
<partition>
<partition-name>calendar</partition-name>
<feature>AdfUICalendar</feature>
<feature>AdfRichCalendar</feature>
<feature>AdfCalendarDragSource</feature>
<feature>AdfCalendarDropTarget</feature>
</partition>
<partition>
<partition-name>collection</partition-name>
<feature>AdfUIDecorateCollection</feature>
<feature>AdfRichPanelCollection</feature>
</partition>
<partition>
<partition-name>color</partition-name>
<feature>AdfRichChooseColor</feature>
<feature>AdfRichInputColor</feature>
</partition>
<partition>
<partition-name>date</partition-name>
<feature>AdfRichChooseDate</feature>
<feature>AdfRichInputDate</feature>
</partition>
<partition>
<partition-name>declarativeComponent</partition-name>
<feature>AdfUIInclude</feature>
<feature>AdfUIDeclarativeComponent</feature>
<feature>AdfRichDeclarativeComponent</feature>
</partition>
<partition>
<partition-name>detail</partition-name>
<feature>AdfRichShowDetail</feature>
</partition>
<partition>
<partition-name>dnd</partition-name>
<feature>AdfDragAndDrop</feature>
<feature>AdfCollectionDragSource</feature>
<feature>AdfStampedDropTarget</feature>
<feature>AdfCollectionDropTarget</feature>
<feature>AdfAttributeDragSource</feature>
<feature>AdfAttributeDropTarget</feature>
<feature>AdfComponentDragSource</feature>
<feature>AdfDropTarget</feature>
</partition>
<partition>
<partition-name>detailitem</partition-name>
<feature>AdfRichShowDetailItem</feature>
</partition>
<partition>
<partition-name>file</partition-name>
<feature>AdfRichInputFile</feature>
</partition>
<partition>
<partition-name>form</partition-name>
<feature>AdfRichPanelFormLayout</feature>
<feature>AdfRichPanelLabelAndMessage</feature>
</partition>
<partition>
<partition-name>format</partition-name>
<feature>AdfRichOutputFormatted</feature>
</partition>
<partition>
<partition-name>frame</partition-name>
<feature>AdfRichInlineFrame</feature>
</partition>
<partition>
<partition-name>header</partition-name>
<feature>AdfRichPanelHeader</feature>
<feature>AdfRichShowDetailHeader</feature>
</partition>
<partition>
<partition-name>imagelink</partition-name>
<feature>AdfRichCommandImageLink</feature>
</partition>
<partition>
<partition-name>iedit</partition-name>
<feature>AdfInlineEditing</feature>
</partition>
<partition>
<partition-name>input</partition-name>
<feature>AdfRichInputText</feature>
<feature>AdfInsertTextBehavior</feature>
</partition>
<partition>
<partition-name>label</partition-name>
<feature>AdfRichOutputLabel</feature>
</partition>
<partition>
<partition-name>list</partition-name>
<feature>AdfRichPanelList</feature>
</partition>
<partition>
<partition-name>lov</partition-name>
<feature>AdfUIInputPopup</feature>
<feature>AdfRichInputComboboxListOfValues</feature>
<feature>AdfRichInputListOfValues</feature>
</partition>
<partition>
<partition-name>media</partition-name>
<feature>AdfRichMedia</feature>
</partition>
<partition>
<partition-name>message</partition-name>
<feature>AdfUIMessage</feature>
<feature>AdfUIMessages</feature>
<feature>AdfRichMessage</feature>
<feature>AdfRichMessages</feature>
</partition>
<partition>
<partition-name>menu</partition-name>
<feature>AdfRichCommandMenuItem</feature>
<feature>AdfRichGoMenuItem</feature>
<feature>AdfRichMenuBar</feature>
<feature>AdfRichMenu</feature>
</partition>
<partition>
<partition-name>nav</partition-name>
<feature>AdfUINavigationPath</feature>
<feature>AdfUINavigationLevel</feature>
<feature>AdfRichBreadCrumbs</feature>
<feature>AdfRichCommandNavigationItem</feature>
<feature>AdfRichNavigationPane</feature>
</partition>
<partition>
<partition-name>note</partition-name>
<feature>AdfRichNoteWindow</feature>
</partition>
<partition>
<partition-name>poll</partition-name>
<feature>AdfUIPoll</feature>
<feature>AdfRichPoll</feature>
</partition>
<partition>
<partition-name>progress</partition-name>
<feature>AdfUIProgress</feature>
<feature>AdfRichProgressIndicator</feature>
</partition>
<partition>
<partition-name>print</partition-name>
<feature>AdfShowPrintablePageBehavior</feature>
</partition>
<partition>
<partition-name>scrollComponentIntoView</partition-name>
<feature>AdfScrollComponentIntoViewBehavior</feature>
</partition>
<partition>
<partition-name>query</partition-name>
<feature>AdfUIQuery</feature>
<feature>AdfRichQuery</feature>
<feature>AdfRichQuickQuery</feature>
</partition>
<partition>
<partition-name>region</partition-name>
<feature>AdfUIRegion</feature>
<feature>AdfRichRegion</feature>
</partition>
<partition>
<partition-name>reset</partition-name>
<feature>AdfUIReset</feature>
<feature>AdfRichResetButton</feature>
</partition>
<partition>
<partition-name>rte</partition-name>
<feature>AdfRichTextEditor</feature>
<feature>AdfRichTextEditorInsertBehavior</feature>
</partition>
<partition>
<partition-name>select</partition-name>
<feature>AdfRichSelectBooleanCheckbox</feature>
<feature>AdfRichSelectBooleanRadio</feature>
<feature>AdfRichSelectManyCheckbox</feature>
<feature>AdfRichSelectOneRadio</feature>
</partition>
<partition>
<partition-name>selectmanychoice</partition-name>
<feature>AdfRichSelectManyChoice</feature>
</partition>
<partition>
<partition-name>selectmanylistbox</partition-name>
<feature>AdfRichSelectManyListbox</feature>
</partition>
<partition>
<partition-name>selectonechoice</partition-name>
<feature>AdfRichSelectOneChoice</feature>
</partition>
<partition>
<partition-name>selectonelistbox</partition-name>
<feature>AdfRichSelectOneListbox</feature>
</partition>
<partition>
<partition-name>shuttle</partition-name>
<feature>AdfUISelectOrder</feature>
<feature>AdfRichSelectManyShuttle</feature>
<feature>AdfRichSelectOrderShuttle</feature>
</partition>
<partition>
<partition-name>slide</partition-name>
<feature>AdfRichInputNumberSlider</feature>
<feature>AdfRichInputRangeSlider</feature>
</partition>
<partition>
<partition-name>spin</partition-name>
<feature>AdfRichInputNumberSpinbox</feature>
</partition>
<partition>
<partition-name>status</partition-name>
<feature>AdfRichStatusIndicator</feature>
</partition>
<partition>
<partition-name>stretch</partition-name>
<feature>AdfRichDecorativeBox</feature>
<feature>AdfRichPanelSplitter</feature>
<feature>AdfRichPanelStretchLayout</feature>
<feature>AdfRichPanelDashboard</feature>
<feature>AdfPanelDashboardBehavior</feature>
<feature>AdfDashboardDropTarget</feature>
</partition>
<partition>
<partition-name>tabbed</partition-name>
<feature>AdfUIShowOne</feature>
<feature>AdfRichPanelTabbed</feature>
</partition>
<partition>
<partition-name>table</partition-name>
<feature>AdfUIIterator</feature>
<feature>AdfUITable</feature>
<feature>AdfUITable2</feature>
<feature>AdfUIColumn</feature>
<feature>AdfRichColumn</feature>
<feature>AdfRichTable</feature>
</partition>
<partition>
<partition-name>toolbar</partition-name>
<feature>AdfRichCommandToolbarButton</feature>
<feature>AdfRichToolbar</feature>
</partition>
<partition>
<partition-name>toolbox</partition-name>
<feature>AdfRichToolbox</feature>
</partition>
<partition>
<partition-name>train</partition-name>
<feature>AdfUIProcess</feature>
<feature>AdfRichCommandTrainStop</feature>
<feature>AdfRichTrainButtonBar</feature>
<feature>AdfRichTrain</feature>
</partition>
<partition>
<partition-name>tree</partition-name>
<feature>AdfUITree</feature>
<feature>AdfUITreeTable</feature>
<feature>AdfRichTree</feature>
<feature>AdfRichTreeTable</feature>
</partition>
<!--
Some components which typically do have client-side representation,
but small enough that we might as well download in a single partition
in the event that any of these are needed.
-->
<partition>
<partition-name>uncommon</partition-name>
<feature>AdfRichGoButton</feature>
<feature>AdfRichIcon</feature>
<feature>AdfRichImage</feature>
<feature>AdfRichOutputText</feature>
<feature>AdfRichPanelGroupLayout</feature>
<feature>AdfRichSeparator</feature>
<feature>AdfRichSpacer</feature>
<feature>AdfRichGoLink</feature>
</partition>
<partition>
<partition-name>eum</partition-name>
<feature>AdfEndUserMonitoring</feature>
</partition>
<partition>
<partition-name>ads</partition-name>
<feature>AdfActiveDataService</feature>
</partition>
<partition>
<partition-name>automation</partition-name>
<feature>AdfAutomationTest</feature>
</partition>
</partitions>
次は、ツリーマップとサンバースト・コンポーネントを作成するサンプル・コードです。
ツリーマップあるいはサンバーストをUI優先開発を使用して作成するには、クラスとマネージドBeanを使用してツリー・ノードとツリー・モデルを定義し、ツリーにデータを移入し、かつツリーマップあるいはサンバースト構成の必要に応じ、追加のメソッドを追加します。
例F-2に、国勢調査のデータ例でのツリー・ノードを定義するコードのサンプルを示します。ラベル、サイズ、および色についての必要な設定は、パラメータとしてツリー・ノードに渡されます。
例F-2 ツリーマップあるいはサンバーストのツリー・ノードを作成するコード・サンプル
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
public class TreeNode {
private final String m_text;
private final Number m_size;
private final Color m_color;
private final List<TreeNode> m_children = new ArrayList<TreeNode>();
public TreeNode(String text, Number size, Color color) {
m_text = text;
m_size = size;
m_color = color;
}
public String getText() {
return m_text;
}
public Number getSize() {
return m_size;
}
public Color getColor() {
return m_color;
}
public void addChild(TreeNode child) {
m_children.add(child);
}
public void addChildren(List<TreeNode> children) {
m_children.addAll(children);
}
public List<TreeNode> getChildren() {
return m_children;
}
@Override
public String toString() {
return m_text + ": " + m_color + " " + Math.round(m_size.doubleValue());
}
}
UI優先開発におけるツリーマップあるいはサンバーストにデータを供給するには、クラスあるいはマネージドBeanをユーザーのアプリケーションに追加します。アプリケーションは例F-2のツリー・ノードを展開し、そこにデータを移入します。ツリー・モデルを設定するクラスは、org.apache.myfaces.trinidad.model.TreeModelクラスの実装にする必要があります。ツリー・モデルを定義したら、org.apache.myfaces.trinidad.model.ChildPropertyTreeModelを実装するメソッドを作成してツリー・モデルを完成させます。
例F-3は、国勢データの例において、ルートと子ノードの構造を設定し、子レベルにデータを移入し、色およびノードのサイズを定義するサンプル・クラスを示します。
例F-3 ツリーマップおよびサンバースト用に国勢調査データ・モデルを作成するコード・サンプル
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
import org.apache.myfaces.trinidad.model.TreeModel;
public class CensusData {
public static TreeModel getUnitedStatesData() {
return getModel(ROOT);
}
public static TreeModel getRegionWestData() {
return getModel(REGION_W);
}
public static TreeModel getRegionNortheastData() {
return getModel(REGION_NE);
}
public static TreeModel getRegionMidwestData() {
return getModel(REGION_MW);
}
public static TreeModel getRegionSouthData() {
return getModel(REGION_S);
}
public static TreeModel getDivisionPacificData() {
return getModel(DIVISION_P);
}
private static TreeModel getModel(DataItem rootItem) {
TreeNode root = getTreeNode(rootItem);
return new ChildPropertyTreeModel(root, "children");
}
private static TreeNode getTreeNode(DataItem dataItem)
{
// Create the node itself
TreeNode node = new CensusTreeNode(dataItem.getName(),
dataItem.getPopulation(),
getColor(dataItem.getIncome(), MIN_INCOME, MAX_INCOME),
dataItem.getIncome());
// Create its children
List<TreeNode> children = new ArrayList<TreeNode>();
for(DataItem childItem : dataItem.children) {
children.add(getTreeNode(childItem));
}
// Add the children and return
node.addChildren(children);
return node;
}
private static Color getColor(double value, double min, double max) {
double percent = Math.max((value - min) / max, 0);
if(percent > 0.5) {
double modifier = (percent - 0.5) * 2;
return new Color((int)(modifier*102), (int)(modifier*153), (int)(modifier*51));
}
else {
double modifier = percent *2;
return new Color((int)(modifier*204), (int)(modifier*51), 0);
}
}
public static class DataItem {
private final String name;
private final int population;
private final int income;
private final List<DataItem> children;
public DataItem(String name, int population, int income) {
this.name = name;
this.population = population;
this.income = income;
this.children = new ArrayList<DataItem>();
}
public void addChild(DataItem child) {
this.children.add(child);
}
public String getName() {
return name;
}
public int getPopulation() {
return population;
}
public int getIncome() {
return income;
}
public List<CensusData.DataItem> getChildren() {
return children;
}
}
private static final int MIN_INCOME = 0;
private static final int MAX_INCOME = 70000;
private static final DataItem ROOT = new DataItem("United States", 301461533, 51425);
private static final DataItem REGION_NE = new DataItem("Northeast Region", 54906297, 57208);
private static final DataItem REGION_MW = new DataItem("Midwest Region", 66336038, 49932);
private static final DataItem REGION_S = new DataItem("South Region", 110450832, 47204);
private static final DataItem REGION_W = new DataItem("West Region", 69768366, 56171);
private static final DataItem DIVISION_NE = new DataItem("New England", 14315257, 61511);
private static final DataItem DIVISION_MA = new DataItem("Middle Atlantic", 40591040, 55726);
private static final DataItem DIVISION_ENC = new DataItem("East North Central", 46277998, 50156);
private static final DataItem DIVISION_WNC = new DataItem("West North Central", 20058040, 49443);
private static final DataItem DIVISION_SA = new DataItem("South Atlantic", 57805475, 50188);
private static final DataItem DIVISION_ESC = new DataItem("East South Central", 17966553, 41130);
private static final DataItem DIVISION_WSC = new DataItem("West South Central", 34678804, 45608);
private static final DataItem DIVISION_M = new DataItem("Mountain", 21303294, 51504);
private static final DataItem DIVISION_P = new DataItem("Pacific", 48465072, 58735);
static {
// Set up the regions
ROOT.addChild(REGION_NE);
ROOT.addChild(REGION_MW);
ROOT.addChild(REGION_S);
ROOT.addChild(REGION_W);
// Set up the divisions
REGION_NE.addChild(DIVISION_NE);
REGION_NE.addChild(DIVISION_MA);
REGION_MW.addChild(DIVISION_ENC);
REGION_MW.addChild(DIVISION_WNC);
REGION_S.addChild(DIVISION_SA);
REGION_S.addChild(DIVISION_ESC);
REGION_S.addChild(DIVISION_WSC);
REGION_W.addChild(DIVISION_M);
REGION_W.addChild(DIVISION_P);
// Set up the states
DIVISION_NE.addChild(new DataItem("Connecticut", 3494487, 67721));
DIVISION_NE.addChild(new DataItem("Maine", 1316380, 46541));
DIVISION_NE.addChild(new DataItem("Massachusetts", 6511176, 64496));
DIVISION_NE.addChild(new DataItem("New Hampshire", 1315419, 63033));
DIVISION_NE.addChild(new DataItem("Rhode Island", 1057381, 55569));
DIVISION_NE.addChild(new DataItem("Vermont", 620414, 51284));
DIVISION_MA.addChild(new DataItem("New Jersey", 8650548, 68981));
DIVISION_MA.addChild(new DataItem("New York", 19423896, 55233));
DIVISION_MA.addChild(new DataItem("Pennsylvania", 12516596, 49737));
DIVISION_ENC.addChild(new DataItem("Indiana", 6342469, 47465));
DIVISION_ENC.addChild(new DataItem("Illinois", 12785043, 55222));
DIVISION_ENC.addChild(new DataItem("Michigan", 10039208, 48700));
DIVISION_ENC.addChild(new DataItem("Ohio", 11511858, 47144));
DIVISION_ENC.addChild(new DataItem("Wisconsin", 5599420, 51569));
DIVISION_WNC.addChild(new DataItem("Iowa", 2978880, 48052));
DIVISION_WNC.addChild(new DataItem("Kansas", 2777835, 48394));
DIVISION_WNC.addChild(new DataItem("Minnesota", 5188581, 57007));
DIVISION_WNC.addChild(new DataItem("Missouri", 5904382, 46005));
DIVISION_WNC.addChild(new DataItem("Nebraska", 1772124, 47995));
DIVISION_WNC.addChild(new DataItem("North Dakota", 639725, 45140));
DIVISION_WNC.addChild(new DataItem("South Dakota", 796513, 44828));
DIVISION_SA.addChild(new DataItem("Delaware", 863832, 57618));
DIVISION_SA.addChild(new DataItem("District of Columbia", 588433, 56519));
DIVISION_SA.addChild(new DataItem("Florida", 18222420, 47450));
DIVISION_SA.addChild(new DataItem("Georgia", 9497667, 49466));
DIVISION_SA.addChild(new DataItem("Maryland", 5637418, 69475));
DIVISION_SA.addChild(new DataItem("North Carolina", 9045705, 45069));
DIVISION_SA.addChild(new DataItem("South Carolina", 4416867, 43572));
DIVISION_SA.addChild(new DataItem("Virginia", 7721730, 60316));
DIVISION_SA.addChild(new DataItem("West Virginia", 1811403, 37356));
DIVISION_ESC.addChild(new DataItem("Alabama", 4633360, 41216));
DIVISION_ESC.addChild(new DataItem("Kentucky", 4252000, 41197));
DIVISION_ESC.addChild(new DataItem("Mississippi", 2922240, 36796));
DIVISION_ESC.addChild(new DataItem("Tennessee", 6158953, 42943));
DIVISION_WSC.addChild(new DataItem("Arkansas", 2838143, 38542));
DIVISION_WSC.addChild(new DataItem("Louisiana", 4411546, 42167));
DIVISION_WSC.addChild(new DataItem("Oklahoma", 3610073, 41861));
DIVISION_WSC.addChild(new DataItem("Texas", 23819042, 48199));
DIVISION_M.addChild(new DataItem("Arizona", 6324865, 50296));
DIVISION_M.addChild(new DataItem("Colorado", 4843211, 56222));
DIVISION_M.addChild(new DataItem("Idaho", 1492573, 46183));
DIVISION_M.addChild(new DataItem("Montana", 956257, 43089));
DIVISION_M.addChild(new DataItem("Nevada", 2545763, 55585));
DIVISION_M.addChild(new DataItem("New Mexico", 1964860, 42742));
DIVISION_M.addChild(new DataItem("Utah", 2651816, 55642));
DIVISION_M.addChild(new DataItem("Wyoming", 523949, 51990));
DIVISION_P.addChild(new DataItem("Alaska", 683142, 64635));
DIVISION_P.addChild(new DataItem("California", 36308527, 60392));
DIVISION_P.addChild(new DataItem("Hawaii", 1280241, 64661));
DIVISION_P.addChild(new DataItem("Oregon", 3727407, 49033));
DIVISION_P.addChild(new DataItem("Washington", 6465755, 56384));
}
public static class CensusTreeNode extends TreeNode {
private int income;
public CensusTreeNode(String text, Number size, Color color, int income) {
super(text, size, color);
this.income = income;
}
public int getIncome() {
return income;
}
}
}
最後に、UI-first開発におけるツリー・モデルを完成するには、マネージドBeanを、データを含むクラスまたはBeanを参照するユーザーのアプリケーションに加え、オプションとして、ツリーマップあるいはサンバーストのカスタマイズのために他のメソッドを追加します。
例F-4に、国勢調査のツリーマップをインスタンス化し、それに国勢調査データを移入するコードのサンプルを示します。この例はまた、ツリーマップのノードの行データをラベル表示のための文字列に変換するサンプル・メソッド(convertToString)を含んでいます。
例F-4 国勢調査データのツリーマップ設定のためのマネージドBeanの例
import org.apache.myfaces.trinidad.component.UIXHierarchy;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.TreeModel;
import oracle.adf.view.faces.bi.component.treemap.UITreemap;
public class SampleTreemap {
// Data Model Attrs
private TreeModel currentModel;
private final CensusData censusData = new CensusData();
private String censusRoot = "United States";
private UITreemap treemap;
public TreeModel getCensusRootData() {
return censusData.getUnitedStatesData();
}
public TreeModel getCensusData() {
if ("West Region".equals(censusRoot))
return censusData.getRegionWestData();
else if ("South Region".equals(censusRoot))
return censusData.getRegionSouthData();
else if ("Midwest Region".equals(censusRoot))
return censusData.getRegionMidwestData();
else if ("Northeast Region".equals(censusRoot))
return censusData.getRegionNortheastData();
else if ("Pacific Division".equals(censusRoot))
return censusData.getDivisionPacificData();
else
return censusData.getUnitedStatesData();
}
public TreeModel getData() {
// Return cached data model if available
if(currentModel != null)
return currentModel;
currentModel = getCensusData();
return currentModel;
}
public void setCensusRoot(String censusRoot) {
this.censusRoot = censusRoot;
}
public String getCensusRoot() {
return censusRoot;
}
//Converts the rowKeySet into a string of node text labels.
public static String convertToString(RowKeySet rowKeySet, UIXHierarchy hierarchy) {
StringBuilder s = new StringBuilder();
if (rowKeySet != null) {
for (Object rowKey : rowKeySet) {
TreeNode rowData = (TreeNode)hierarchy.getRowData(rowKey);
s.append(rowData.getText()).append(", ");
}
// Remove the trailing comma
if (s.length() > 0)
s.setLength(s.length() - 2);
}
return s.toString();
}
public void setTreemap(UITreemap treemap) {
this.treemap = treemap;
}
public UITreemap getTreemap() {
return treemap;
}
}
両方のコンポーネントは同じツリー・モデルを使用するため、サンバースト国勢調査の例を設定するコードはほとんど同一です。例は、F.2.2項「サンバースト・マネージドBeanのサンプル・コード」を参照してください。
次のサンプル・コードは、国勢調査サンバーストをインスタンス化し、それに国勢調査データを移入します。この例はまた、サンバーストのノードの行データをラベル表示のための文字列に変換するサンプル・メソッド(convertToString)を含んでいます。
例F-5 国勢調査データのサンバースト設定のためのマネージドBeanの例
import oracle.adf.view.faces.bi.component.sunburst.UISunburst;
import org.apache.myfaces.trinidad.component.UIXHierarchy;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.TreeModel;
public class SunburstSample {
// Components
private UISunburst sunburst;
// Attributes
private TreeModel currentModel;
private final CensusData censusData = new CensusData();
private String censusRoot = "United States";
public TreeModel getCensusRootData() {
return censusData.getUnitedStatesData();
}
public TreeModel getCensusData() {
if ("West Region".equals(censusRoot))
return censusData.getRegionWestData();
else if ("South Region".equals(censusRoot))
return censusData.getRegionSouthData();
else if ("Midwest Region".equals(censusRoot))
return censusData.getRegionMidwestData();
else if ("Northeast Region".equals(censusRoot))
return censusData.getRegionNortheastData();
else if ("Pacific Division".equals(censusRoot))
return censusData.getDivisionPacificData();
else
return censusData.getUnitedStatesData();
}
public TreeModel getData() {
// Return cached data model if available
if(currentModel != null)
return currentModel;
currentModel = getCensusData();
return currentModel;
}
public void setCensusRoot(String censusRoot) {
this.censusRoot = censusRoot;
}
public String getCensusRoot() {
return censusRoot;
}
public static String convertToString(RowKeySet rowKeySet, UIXHierarchy hierarchy) {
StringBuilder s = new StringBuilder();
if (rowKeySet != null) {
for (Object rowKey : rowKeySet) {
TreeNode rowData = (TreeNode)hierarchy.getRowData(rowKey);
s.append(rowData.getText()).append(", ");
}
// Remove the trailing comma
if (s.length() > 0)
s.setLength(s.length() - 2);
}
return s.toString();
}
public void setSunburst(UISunburst sunburst) {
this.sunburst = sunburst;
}
public UISunburst getSunburst() {
return sunburst;
}
}