]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/ui/PCDDatabaseFrame.java
PCD tools update:
[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("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(String.format("SKUID: %d", token.skuId)));
120 tokenNode.add(new DefaultMutableTreeNode(String.format("MAX SKU COUNT: %d", token.maxSkuCount)));
121 tokenNode.add(new DefaultMutableTreeNode("VPDENABLE: " +(token.vpdEnabled?"true":"false")));
122
123 usageNode = new DefaultMutableTreeNode("PRODUCER");
124 tokenNode.add(usageNode);
125
126
127 //
128 // Prepare consumer's leaf node
129 //
130 usageNode = new DefaultMutableTreeNode("CONSUMER");
131 tokenNode.add(usageNode);
132 objectArray = token.consumers.entrySet().toArray();
133 for (usageIndex = 0; usageIndex < token.consumers.size(); usageIndex ++) {
134 usageInstance = (UsageInstance) ((Map.Entry)objectArray[usageIndex]).getValue();
135 usageNode.add(new DefaultMutableTreeNode(usageInstance.getPrimaryKey()));
136 }
137
138 rootByPCD.add(tokenNode);
139 }
140
141 //
142 // BY MODULE Node
143 //
144 root.add(rootByModule);
145 moduleNames = dbManager.getAllModuleArray();
146 for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) {
147 ActionMessage.debug(this, "ModuleName:" + moduleNames.get(moduleIndex));
148 }
149 for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) {
150 moduleNode = new DefaultMutableTreeNode(moduleNames.get(moduleIndex));
151 usageArray = dbManager.getUsageInstanceArrayByKeyString(moduleNames.get(moduleIndex));
152 for (usageIndex = 0; usageIndex < usageArray.size(); usageIndex ++) {
153 usageInstance = usageArray.get(usageIndex);
154 usageNode = new DefaultMutableTreeNode(usageInstance.parentToken.cName);
155 usageNode.add(new DefaultMutableTreeNode("MODULE PCD TYPE: " + Token.getStringOfpcdType(usageInstance.modulePcdType)));
156 moduleNode.add(usageNode);
157 }
158 rootByModule.add(moduleNode);
159 }
160
161 databaseTree = new JTree(root);
162 return databaseTree;
163 }
164 }
165
166 /**
167 The adatper class for PCDDatabaseFrame. This class instance many windows message
168 callback function.
169 **/
170 class PCDDatabaseFrameAdapter extends WindowAdapter {
171 public void windowClosing(WindowEvent e) {
172 System.exit(0);
173 }
174 }