ed282e1b768e72b8d228a2d25b295b85907a169b
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / ui / PCDDatabaseFrame.java
1 /** @file
2 PCDDatabaseFrame class.
3
4 The class is the frame class for displaying PCD database in tree method.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16 package org.tianocore.build.pcd.ui;
17
18 import java.awt.*;
19 import java.awt.event.*;
20 import java.util.Map;
21
22 import javax.swing.*;
23 import javax.swing.tree.DefaultMutableTreeNode;
24
25 import org.tianocore.build.pcd.action.ActionMessage;
26 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
27 import org.tianocore.build.pcd.entity.Token;
28 import org.tianocore.build.pcd.entity.UsageInstance;
29
30 /**
31 The class is the frame class for displaying PCD database in tree method.
32 **/
33 public class PCDDatabaseFrame extends JFrame {
34 static final long serialVersionUID = -7034897190740068939L;
35 ///
36 /// Database instance
37 ///
38 private MemoryDatabaseManager dbManager;
39 ///
40 /// The token and module tree
41 ///
42 private JTree databaseTree;
43
44 /**
45 Constructure function.
46
47 Create the UI component and display frame.
48
49 @param dbManager databaase manager instance.
50 **/
51 public PCDDatabaseFrame(MemoryDatabaseManager dbManager) {
52 if (dbManager != null) {
53 this.dbManager = dbManager;
54 }
55 //
56 // Put the frame into center of desktop.
57 //
58 setLocation(100, 100);
59 initializeComponent();
60
61 setTitle("PCD View Tool");
62 pack();
63 setVisible(true);
64 }
65
66 /**
67 Initliaze the UI component in Display frame.
68 **/
69 public void initializeComponent() {
70 JScrollPane scrollPane = new JScrollPane();
71 Container contentPane = getContentPane();
72
73 contentPane.setLayout(new BorderLayout());
74 scrollPane.setViewportView(initializeTree());
75 contentPane.add(scrollPane);
76
77 addWindowListener(new PCDDatabaseFrameAdapter());
78 }
79
80 /**
81 Initiliaze the TREE control.
82 **/
83 public JTree initializeTree() {
84 Token[] tokenArray = null;
85 Token token = null;
86 DefaultMutableTreeNode root = new DefaultMutableTreeNode("PCDTreeRoot");
87 DefaultMutableTreeNode rootByPCD = new DefaultMutableTreeNode("By PCD");
88 DefaultMutableTreeNode rootByModule = new DefaultMutableTreeNode("By Module");
89 DefaultMutableTreeNode tokenNode = null;
90 DefaultMutableTreeNode usageNode = null;
91 DefaultMutableTreeNode moduleNode = null;
92 java.util.List<String> moduleNames = null;
93 int index = 0;
94 int usageIndex = 0;
95 int moduleIndex = 0;
96 Object[] objectArray = null;
97 java.util.List<UsageInstance> usageArray = null;
98 UsageInstance usageInstance = null;
99
100 root.add(rootByPCD);
101 //
102 // By PCD Node
103 //
104
105 tokenArray = dbManager.getRecordArray();
106 for (index = 0; index < tokenArray.length; index ++) {
107 token = tokenArray[index];
108 ActionMessage.debug(this, token.cName);
109 tokenNode = new DefaultMutableTreeNode(token.cName);
110 tokenNode.add(new DefaultMutableTreeNode(String.format("TOKEN NUMBER: 0x%08x", token.tokenNumber)));
111 tokenNode.add(new DefaultMutableTreeNode("TOKEN SPACE NAME: " + token.tokenSpaceName.toString()));
112 tokenNode.add(new DefaultMutableTreeNode("DATUM TYPE: " +Token.getStringOfdatumType(token.datumType)));
113 //tokenNode.add(new DefaultMutableTreeNode("VARIABLE GUID: " + token.variableGuid.toString()));
114
115 usageNode = new DefaultMutableTreeNode("PRODUCER");
116 tokenNode.add(usageNode);
117
118
119 //
120 // Prepare consumer's leaf node
121 //
122 usageNode = new DefaultMutableTreeNode("CONSUMER");
123 tokenNode.add(usageNode);
124 objectArray = token.consumers.entrySet().toArray();
125 for (usageIndex = 0; usageIndex < token.consumers.size(); usageIndex ++) {
126 usageInstance = (UsageInstance) ((Map.Entry)objectArray[usageIndex]).getValue();
127 usageNode.add(new DefaultMutableTreeNode(usageInstance.getPrimaryKey()));
128 }
129
130 rootByPCD.add(tokenNode);
131 }
132
133 //
134 // BY MODULE Node
135 //
136 root.add(rootByModule);
137 moduleNames = dbManager.getAllModuleArray();
138 for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) {
139 ActionMessage.debug(this, "ModuleName:" + moduleNames.get(moduleIndex));
140 }
141 for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) {
142 moduleNode = new DefaultMutableTreeNode(moduleNames.get(moduleIndex));
143 usageArray = dbManager.getUsageInstanceArrayByKeyString(moduleNames.get(moduleIndex));
144 for (usageIndex = 0; usageIndex < usageArray.size(); usageIndex ++) {
145 usageInstance = usageArray.get(usageIndex);
146 usageNode = new DefaultMutableTreeNode(usageInstance.parentToken.cName);
147 usageNode.add(new DefaultMutableTreeNode("MODULE PCD TYPE: " + Token.getStringOfpcdType(usageInstance.modulePcdType)));
148 moduleNode.add(usageNode);
149 }
150 rootByModule.add(moduleNode);
151 }
152
153 databaseTree = new JTree(root);
154 return databaseTree;
155 }
156 }
157
158 /**
159 The adatper class for PCDDatabaseFrame. This class instance many windows message
160 callback function.
161 **/
162 class PCDDatabaseFrameAdapter extends WindowAdapter {
163 public void windowClosing(WindowEvent e) {
164 System.exit(0);
165 }
166 }