]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/ui/PCDDatabaseFrame.java
Initial import.
[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
21 import javax.swing.*;
22 import javax.swing.tree.DefaultMutableTreeNode;
23
24 import org.tianocore.build.pcd.action.ActionMessage;
25 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
26 import org.tianocore.build.pcd.entity.Token;
27 import org.tianocore.build.pcd.entity.UsageInstance;
28
29 /**
30 The class is the frame class for displaying PCD database in tree method.
31 **/
32 public class PCDDatabaseFrame extends JFrame {
33 static final long serialVersionUID = -7034897190740068939L;
34 ///
35 /// Database instance
36 ///
37 private MemoryDatabaseManager dbManager;
38 ///
39 /// The token and module tree
40 ///
41 private JTree databaseTree;
42
43 /**
44 Constructure function.
45
46 Create the UI component and display frame.
47
48 @param dbManager databaase manager instance.
49 **/
50 public PCDDatabaseFrame(MemoryDatabaseManager dbManager) {
51 if (dbManager != null) {
52 this.dbManager = dbManager;
53 }
54 //
55 // Put the frame into center of desktop.
56 //
57 setLocation(100, 100);
58 initializeComponent();
59
60 setTitle("PCD View Tool");
61 pack();
62 setVisible(true);
63 }
64
65 /**
66 Initliaze the UI component in Display frame.
67 **/
68 public void initializeComponent() {
69 JScrollPane scrollPane = new JScrollPane();
70 Container contentPane = getContentPane();
71
72 contentPane.setLayout(new BorderLayout());
73 scrollPane.setViewportView(initializeTree());
74 contentPane.add(scrollPane);
75
76 addWindowListener(new PCDDatabaseFrameAdapter());
77 }
78
79 /**
80 Initiliaze the TREE control.
81 **/
82 public JTree initializeTree() {
83 Token[] tokenArray = null;
84 Token token = null;
85 DefaultMutableTreeNode root = new DefaultMutableTreeNode(dbManager.getLogFileName());
86 DefaultMutableTreeNode rootByPCD = new DefaultMutableTreeNode("By PCD");
87 DefaultMutableTreeNode rootByModule = new DefaultMutableTreeNode("By Module");
88 DefaultMutableTreeNode tokenNode = null;
89 DefaultMutableTreeNode usageNode = null;
90 DefaultMutableTreeNode moduleNode = null;
91 java.util.List<String> moduleNames = null;
92 int index = 0;
93 int usageIndex = 0;
94 int moduleIndex = 0;
95 java.util.List<UsageInstance> usageArray = null;
96 UsageInstance usageInstance = null;
97
98 root.add(rootByPCD);
99 //
100 // By PCD Node
101 //
102
103 tokenArray = dbManager.getRecordArray();
104 for (index = 0; index < tokenArray.length; index ++) {
105 token = tokenArray[index];
106 ActionMessage.debug(this, token.cName);
107 tokenNode = new DefaultMutableTreeNode(token.cName);
108 tokenNode.add(new DefaultMutableTreeNode(String.format("TOKEN NUMBER: 0x%08x", token.tokenNumber)));
109 tokenNode.add(new DefaultMutableTreeNode(String.format("ASSIGNED TOKEN NUMBER: 0x%08x", token.assignedtokenNumber)));
110 tokenNode.add(new DefaultMutableTreeNode("TOKEN SPACE NAME: " + token.tokenSpaceName.toString()));
111 tokenNode.add(new DefaultMutableTreeNode("ASSIGNED TOKEN SPACE NAME: " + token.assignedtokenSpaceName.toString()));
112 tokenNode.add(new DefaultMutableTreeNode("PCD TYPE: " + Token.getStringOfpcdType(token.pcdType)));
113 tokenNode.add(new DefaultMutableTreeNode("DATUM TYPE: " +Token.getStringOfdatumType(token.datumType)));
114 tokenNode.add(new DefaultMutableTreeNode("DATUM: " + token.datum.toString()));
115 tokenNode.add(new DefaultMutableTreeNode("HIIENABLE: " +(token.hiiEnabled?"true":"false")));
116 tokenNode.add(new DefaultMutableTreeNode("VARIABLE NAME: " + token.variableName));
117 tokenNode.add(new DefaultMutableTreeNode("VARIABLE GUID: " + token.variableGuid.toString()));
118 tokenNode.add(new DefaultMutableTreeNode("SKUENABLE: " +(token.skuEnabled?"true":"false")));
119 tokenNode.add(new DefaultMutableTreeNode("SKUDATA ARRAY ENABLE: " +(token.skuDataArrayEnabled?"true":"false")));
120 tokenNode.add(new DefaultMutableTreeNode(String.format("SKUID: %d", token.skuId)));
121 tokenNode.add(new DefaultMutableTreeNode(String.format("MAX SKU COUNT: %d", token.maxSkuCount)));
122 tokenNode.add(new DefaultMutableTreeNode("VPDENABLE: " +(token.vpdEnabled?"true":"false")));
123
124 usageNode = new DefaultMutableTreeNode("PRODUCER");
125 tokenNode.add(usageNode);
126
127 //
128 // Prepare producer's leaf node
129 //
130
131 for (usageIndex = 0; usageIndex < token.producers.size(); usageIndex ++) {
132 usageNode.add(new DefaultMutableTreeNode(token.producers.get(usageIndex).moduleName));
133 }
134
135 //
136 // Prepare consumer's leaf node
137 //
138 usageNode = new DefaultMutableTreeNode("CONSUMER");
139 tokenNode.add(usageNode);
140
141 for (usageIndex = 0; usageIndex < token.consumers.size(); usageIndex ++) {
142 usageNode.add(new DefaultMutableTreeNode(token.consumers.get(usageIndex).moduleName));
143 }
144
145 rootByPCD.add(tokenNode);
146 }
147
148 //
149 // BY MODULE Node
150 //
151 root.add(rootByModule);
152 moduleNames = dbManager.getAllModuleArray();
153 for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) {
154 ActionMessage.debug(this, "ModuleName:" + moduleNames.get(moduleIndex));
155 }
156 for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) {
157 moduleNode = new DefaultMutableTreeNode(moduleNames.get(moduleIndex));
158 usageArray = dbManager.getUsageInstanceArrayByModuleName(moduleNames.get(moduleIndex));
159 for (usageIndex = 0; usageIndex < usageArray.size(); usageIndex ++) {
160 usageInstance = usageArray.get(usageIndex);
161 usageNode = new DefaultMutableTreeNode(usageInstance.parentToken.cName);
162 usageNode.add(new DefaultMutableTreeNode("MODULE PCD TYPE: " + Token.getStringOfpcdType(usageInstance.modulePcdType)));
163 usageNode.add(new DefaultMutableTreeNode("HELP TEXT: " + usageInstance.helpTextInMSA));
164 usageNode.add(new DefaultMutableTreeNode("IS INHERIT: " +(usageInstance.isInherit?"true":"false")));
165 usageNode.add(new DefaultMutableTreeNode("USAGE: " + Token.getStringOfUsage(usageInstance.usage)));
166 moduleNode.add(usageNode);
167 }
168 rootByModule.add(moduleNode);
169 }
170
171 databaseTree = new JTree(root);
172 return databaseTree;
173 }
174 }
175
176 /**
177 The adatper class for PCDDatabaseFrame. This class instance many windows message
178 callback function.
179 **/
180 class PCDDatabaseFrameAdapter extends WindowAdapter {
181 public void windowClosing(WindowEvent e) {
182 System.exit(0);
183 }
184 }