]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/GenAprioriFileDialog.java
Provide UI for generating Apriori file of PEI or DXE phase. The module order informat...
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / GenAprioriFileDialog.java
1 /**
2 *
3 */
4 package org.tianocore.frameworkwizard.platform.ui;
5
6 import java.awt.BorderLayout;
7 import java.awt.Dimension;
8 import java.awt.Toolkit;
9
10 import javax.swing.JPanel;
11
12 import java.awt.event.ActionEvent;
13 import java.awt.event.ActionListener;
14 import java.util.Vector;
15
16 import javax.swing.JDialog;
17 import javax.swing.JLabel;
18 import javax.swing.JComboBox;
19 import javax.swing.JTabbedPane;
20
21 import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformType;
22 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
23 import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;
24
25 /**
26 * @author jlin16
27 *
28 */
29 public class GenAprioriFileDialog extends JDialog implements ActionListener {
30
31 /**
32 *
33 */
34 private static final long serialVersionUID = 3627991301208644354L;
35 private JPanel jContentPane = null;
36 private JPanel jPanelN = null;
37 private JLabel jLabelFvName = null;
38 private JComboBox jComboBoxFvNames = null;
39 private JTabbedPane jTabbedPane = null;
40 private FpdFileContents ffc = null;
41 private OpeningPlatformType docConsole = null;
42
43 /**
44 * This is the default constructor
45 */
46 public GenAprioriFileDialog(FpdFileContents inputFfc, OpeningPlatformType dc) {
47 super();
48 ffc = inputFfc;
49 docConsole = dc;
50 initialize();
51 }
52
53 /**
54 * This method initializes this
55 *
56 * @return void
57 */
58 private void initialize() {
59 this.setSize(670, 670);
60 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
61 this.setTitle("Apriori Files");
62 this.setContentPane(getJContentPane());
63 this.setResizable(false);
64 this.setModal(true);
65
66 String fvName = jComboBoxFvNames.getSelectedItem()+"";
67 if (fvName.length() > 0) {
68 jTabbedPane.removeAll();
69 AprioriModuleOrderPane peiPane = new AprioriModuleOrderPane(fvName, "", GenAprioriFileDialog.this, true);
70 peiPane.showModulesInFv(fvName);
71 peiPane.showAllModulesInPlatform();
72 jTabbedPane.addTab("PEIMs", peiPane);
73 AprioriModuleOrderPane dxePane = new AprioriModuleOrderPane(fvName, "", GenAprioriFileDialog.this, false);
74 dxePane.showModulesInFv(fvName);
75 dxePane.showAllModulesInPlatform();
76 jTabbedPane.addTab("DXE Drivers", dxePane);
77 }
78 this.centerWindow();
79 }
80
81 /**
82 * This method initializes jContentPane
83 *
84 * @return javax.swing.JPanel
85 */
86 private JPanel getJContentPane() {
87 if (jContentPane == null) {
88 jContentPane = new JPanel();
89 jContentPane.setLayout(new BorderLayout());
90 jContentPane.add(getJPanelN(), java.awt.BorderLayout.NORTH);
91 jContentPane.add(getJTabbedPane(), java.awt.BorderLayout.CENTER);
92 }
93 return jContentPane;
94 }
95
96 public void actionPerformed(ActionEvent arg0) {
97 // TODO Auto-generated method stub
98 if (arg0.getActionCommand().equals("ModuleOrderPaneOk")) {
99 docConsole.setSaved(false);
100 return;
101 }
102 if (arg0.getActionCommand().equals("ModuleOrderPaneCancel")) {
103 this.dispose();
104 }
105 }
106
107 /**
108 Start the window at the center of screen
109
110 **/
111 protected void centerWindow(int intWidth, int intHeight) {
112 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
113 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
114 }
115
116 /**
117 Start the window at the center of screen
118
119 **/
120 protected void centerWindow() {
121 centerWindow(this.getSize().width, this.getSize().height);
122 }
123
124 /**
125 * This method initializes jPanelN
126 *
127 * @return javax.swing.JPanel
128 */
129 private JPanel getJPanelN() {
130 if (jPanelN == null) {
131 jLabelFvName = new JLabel();
132 jLabelFvName.setText("FV Name");
133 jPanelN = new JPanel();
134 jPanelN.add(jLabelFvName, null);
135 jPanelN.add(getJComboBoxFvNames(), null);
136 }
137 return jPanelN;
138 }
139
140 /**
141 * This method initializes jComboBoxFvNames
142 *
143 * @return javax.swing.JComboBox
144 */
145 private JComboBox getJComboBoxFvNames() {
146 if (jComboBoxFvNames == null) {
147 jComboBoxFvNames = new JComboBox();
148 jComboBoxFvNames.setPreferredSize(new java.awt.Dimension(200,20));
149 Vector<String> vFvNames = new Vector<String>();
150 ffc.getFvImagesFvImageFvImageNames(vFvNames);
151 for (int i = 0; i < vFvNames.size(); ++i) {
152 jComboBoxFvNames.addItem(vFvNames.get(i));
153 }
154 // if (jComboBoxFvNames.getItemCount() > 0) {
155 // jComboBoxFvNames.setSelectedIndex(0);
156 //
157 // }
158 jComboBoxFvNames.addItemListener(new java.awt.event.ItemListener() {
159 public void itemStateChanged(java.awt.event.ItemEvent e) {
160 String fvName = jComboBoxFvNames.getSelectedItem()+"";
161 if (fvName.length() > 0) {
162 jTabbedPane.removeAll();
163 AprioriModuleOrderPane peiPane = new AprioriModuleOrderPane(fvName, "", GenAprioriFileDialog.this, true);
164 peiPane.showModulesInFv(fvName);
165 peiPane.showAllModulesInPlatform();
166 jTabbedPane.addTab("PEIMs", peiPane);
167 AprioriModuleOrderPane dxePane = new AprioriModuleOrderPane(fvName, "", GenAprioriFileDialog.this, false);
168 dxePane.showModulesInFv(fvName);
169 dxePane.showAllModulesInPlatform();
170 jTabbedPane.addTab("DXE Drivers", dxePane);
171 }
172
173 }
174 });
175 }
176 return jComboBoxFvNames;
177 }
178
179 /**
180 * This method initializes jTabbedPane
181 *
182 * @return javax.swing.JTabbedPane
183 */
184 private JTabbedPane getJTabbedPane() {
185 if (jTabbedPane == null) {
186 jTabbedPane = new JTabbedPane();
187 }
188 return jTabbedPane;
189 }
190
191 private class AprioriModuleOrderPane extends ModuleOrderPane {
192 /**
193 *
194 */
195 private static final long serialVersionUID = -7952853414833230546L;
196 private boolean forPEI = false;
197 private String fvName = null;
198
199 AprioriModuleOrderPane (String fvName, String file, ActionListener action, boolean b) {
200
201 super(fvName, file, ffc, action);
202 this.fvName = fvName;
203 forPEI = b;
204 getJTableModInFv().getColumnModel().getColumn(0).setHeaderValue("Modules in Apriori File");
205 getJButtonOk().setText("Save");
206 getJButtonCancel().setText("Close");
207 }
208
209 public void showModulesInFv (String fvName) {
210 int id = 1;
211 if (forPEI) {
212 id = 0;
213 }
214 int size = ffc.getUserExtsIncModCount(fvName, "APRIORI", id);
215
216 if (size != -1) {
217 String[][] saa = new String[size][5];
218 ffc.getUserExtsIncMods(fvName, "APRIORI", id, saa);
219
220 for (int i = 0; i < size; ++i) {
221 String moduleKey = saa[i][0] + " " + saa[i][1] + " " + saa[i][2] + " " + saa[i][3];
222 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
223 String name = "N/A";
224 if (mi != null) {
225 name = mi.getName();
226 }
227
228 String[] row = { name, saa[i][0] , saa[i][1], saa[i][2] , saa[i][3], saa[i][4] };
229 getModInFvTableModel().addRow(row);
230 }
231 }
232 }
233
234 public void actionPerformed(ActionEvent arg0) {
235 if (arg0.getActionCommand().equals("ModuleOrderPaneOk")) {
236 int id = 1;
237 if (forPEI) {
238 id = 0;
239 }
240
241 Vector<String[]> vModInFv = new Vector<String[]>();
242 for (int i = 0; i < getJTableModInFv().getRowCount(); ++i) {
243 String moduleName = getModInFvTableModel().getValueAt(i, 0)+"";
244 if (moduleName.length() == 0 || moduleName.equals("N/A")) {
245 continue;
246 }
247
248 String mg = getModInFvTableModel().getValueAt(i, 1)+"";
249 String mv = getModInFvTableModel().getValueAt(i, 2)+"";
250 String pg = getModInFvTableModel().getValueAt(i, 3)+"";
251 String pv = getModInFvTableModel().getValueAt(i, 4)+"";
252 String arch = getModInFvTableModel().getValueAt(i, 5)+"";
253
254 String[] sa = { mg, mv, pg, pv, arch};
255 vModInFv.add(sa);
256
257 }
258
259 ffc.removeBuildOptionsUserExtensions(fvName, "APRIORI", id);
260 ffc.genBuildOptionsUserExtensions(fvName, "APRIORI", id+"", "", vModInFv);
261
262 }
263 }
264 }
265 } // @jve:decl-index=0:visual-constraint="10,10"