]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java
f9eb19409bb956f9d9c1d07d1b84d4014c0ecfe0
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFrameworkModules.java
1 package org.tianocore.frameworkwizard.platform.ui;
2
3 import java.awt.BorderLayout;
4
5 import javax.swing.JFrame;
6 import javax.swing.JOptionPane;
7 import javax.swing.JPanel;
8 import javax.swing.JSplitPane;
9 import javax.swing.JLabel;
10 import javax.swing.JScrollPane;
11 import javax.swing.JTable;
12 import javax.swing.JButton;
13 import javax.swing.ListSelectionModel;
14 import javax.swing.table.DefaultTableModel;
15
16 import org.tianocore.PlatformSurfaceAreaDocument;
17 import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformType;
18 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
19 import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;
20 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
21 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
22
23 import java.awt.FlowLayout;
24 import java.io.File;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.Map;
29 import java.util.Set;
30
31 public class FpdFrameworkModules extends IInternalFrame {
32
33 /**
34 *
35 */
36 private static final long serialVersionUID = 1L;
37 static JFrame frame;
38 private JSplitPane jSplitPane = null;
39 private JPanel jPanel = null;
40 private JPanel jPanel1 = null;
41 private JLabel jLabel = null;
42 private JScrollPane jScrollPane = null;
43 private JTable jTable = null;
44 private JPanel jPanel2 = null;
45 private JButton jButton = null;
46 private JLabel jLabel1 = null;
47 private JPanel jPanel3 = null;
48 private JScrollPane jScrollPane1 = null;
49 private JTable jTable1 = null;
50 private JButton jButton1 = null;
51 private JButton jButton2 = null;
52 private NonEditableTableModel model = null;
53 private NonEditableTableModel model1 = null;
54
55 private FpdModuleSA settingDlg = null;
56
57 private FpdFileContents ffc = null;
58 private OpeningPlatformType docConsole = null;
59 private Map<String, String> fpdMsa = null;
60
61 private ArrayList<ModuleIdentification> miList = null;
62
63 /**
64 * This method initializes jSplitPane
65 *
66 * @return javax.swing.JSplitPane
67 */
68 private JSplitPane getJSplitPane() {
69 if (jSplitPane == null) {
70 jSplitPane = new JSplitPane();
71 jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
72 jSplitPane.setDividerLocation(250);
73 jSplitPane.setBottomComponent(getJPanel1());
74 jSplitPane.setTopComponent(getJPanel());
75 }
76 return jSplitPane;
77 }
78
79 /**
80 * This method initializes jPanel
81 *
82 * @return javax.swing.JPanel
83 */
84 private JPanel getJPanel() {
85 if (jPanel == null) {
86 jLabel = new JLabel();
87 jLabel.setText("Modules in Workspace");
88 jPanel = new JPanel();
89 jPanel.setLayout(new BorderLayout());
90 jPanel.add(jLabel, java.awt.BorderLayout.NORTH);
91 jPanel.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
92 jPanel.add(getJPanel2(), java.awt.BorderLayout.SOUTH);
93 }
94 return jPanel;
95 }
96
97 /**
98 * This method initializes jPanel1
99 *
100 * @return javax.swing.JPanel
101 */
102 private JPanel getJPanel1() {
103 if (jPanel1 == null) {
104 jLabel1 = new JLabel();
105 jLabel1.setText("Modules Added");
106 jPanel1 = new JPanel();
107 jPanel1.setLayout(new BorderLayout());
108 jPanel1.add(jLabel1, java.awt.BorderLayout.NORTH);
109 jPanel1.add(getJPanel3(), java.awt.BorderLayout.SOUTH);
110 jPanel1.add(getJScrollPane1(), java.awt.BorderLayout.CENTER);
111 }
112 return jPanel1;
113 }
114
115 /**
116 * This method initializes jScrollPane
117 *
118 * @return javax.swing.JScrollPane
119 */
120 private JScrollPane getJScrollPane() {
121 if (jScrollPane == null) {
122 jScrollPane = new JScrollPane();
123 jScrollPane.setPreferredSize(new java.awt.Dimension(600,200));
124 jScrollPane.setViewportView(getJTable());
125 }
126 return jScrollPane;
127 }
128
129 /**
130 * This method initializes jTable
131 *
132 * @return javax.swing.JTable
133 */
134 private JTable getJTable() {
135 if (jTable == null) {
136 model = new NonEditableTableModel();
137 jTable = new JTable(model);
138 jTable.setRowHeight(20);
139 model.addColumn("ModuleName");
140 model.addColumn("ModuleGUID");
141 model.addColumn("ModuleVersion");
142 model.addColumn("PackageGUID");
143 model.addColumn("PackageVersion");
144
145 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
146 }
147 return jTable;
148 }
149
150 /**
151 * This method initializes jPanel2
152 *
153 * @return javax.swing.JPanel
154 */
155 private JPanel getJPanel2() {
156 if (jPanel2 == null) {
157 FlowLayout flowLayout = new FlowLayout();
158 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
159 jPanel2 = new JPanel();
160 jPanel2.setLayout(flowLayout);
161 jPanel2.add(getJButton(), null);
162 }
163 return jPanel2;
164 }
165
166 /**
167 * This method initializes jButton
168 *
169 * @return javax.swing.JButton
170 */
171 private JButton getJButton() {
172 if (jButton == null) {
173 jButton = new JButton();
174 jButton.setPreferredSize(new java.awt.Dimension(130,20));
175 jButton.setText("Add a Module");
176 jButton.addActionListener(new java.awt.event.ActionListener() {
177 public void actionPerformed(java.awt.event.ActionEvent e) {
178 int selectedRow = jTable.getSelectedRow();
179 if (selectedRow < 0){
180 return;
181 }
182
183 String mg = (String)model.getValueAt(selectedRow, 1);
184 String mv = (String)model.getValueAt(selectedRow, 2);
185 String pg = (String)model.getValueAt(selectedRow, 3);
186 String pv = (String)model.getValueAt(selectedRow, 4);
187 if (fpdMsa.containsKey(mg + mv + pg + pv)) {
188 JOptionPane.showMessageDialog(frame, "This Module Already Added.");
189 return;
190 }
191 //ToDo put Arch instead of null
192 fpdMsa.put(mg + mv + pg + pv, null);
193
194 String[] row = {" ", mg, mv, pg, pv};
195 ModuleIdentification mi = getModuleId(mg + " " + mv + " " + pg + " " + pv);
196 if (mi != null) {
197 row[0] = mi.getName();
198 row[2] = mi.getVersion();
199 row[4] = mi.getPackage().getVersion();
200 }
201 model1.addRow(row);
202 docConsole.setSaved(false);
203 ffc.addFrameworkModulesPcdBuildDefs(miList.get(selectedRow), null);
204 }
205 });
206 }
207 return jButton;
208 }
209
210 /**
211 * This method initializes jPanel3
212 *
213 * @return javax.swing.JPanel
214 */
215 private JPanel getJPanel3() {
216 if (jPanel3 == null) {
217 FlowLayout flowLayout1 = new FlowLayout();
218 flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
219 jPanel3 = new JPanel();
220 jPanel3.setLayout(flowLayout1);
221 jPanel3.add(getJButton1(), null);
222 jPanel3.add(getJButton2(), null);
223 }
224 return jPanel3;
225 }
226
227 /**
228 * This method initializes jScrollPane1
229 *
230 * @return javax.swing.JScrollPane
231 */
232 private JScrollPane getJScrollPane1() {
233 if (jScrollPane1 == null) {
234 jScrollPane1 = new JScrollPane();
235 jScrollPane1.setPreferredSize(new java.awt.Dimension(453,200));
236 jScrollPane1.setViewportView(getJTable1());
237 }
238 return jScrollPane1;
239 }
240
241 /**
242 * This method initializes jTable1
243 *
244 * @return javax.swing.JTable
245 */
246 private JTable getJTable1() {
247 if (jTable1 == null) {
248 model1 = new NonEditableTableModel();
249 jTable1 = new JTable(model1);
250 jTable1.setRowHeight(20);
251 model1.addColumn("ModuleName");
252 model1.addColumn("ModuleGUID");
253 model1.addColumn("ModuleVersion");
254 model1.addColumn("PackageGUID");
255 model1.addColumn("PackageVersion");
256 // model1.addColumn("SupportedArch");
257
258 jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
259 }
260 return jTable1;
261 }
262
263 /**
264 * This method initializes jButton1
265 *
266 * @return javax.swing.JButton
267 */
268 private JButton getJButton1() {
269 if (jButton1 == null) {
270 jButton1 = new JButton();
271 jButton1.setPreferredSize(new java.awt.Dimension(130,20));
272 jButton1.setText("Settings");
273 jButton1.addActionListener(new java.awt.event.ActionListener() {
274 public void actionPerformed(java.awt.event.ActionEvent e) {
275 int selectedRow = jTable1.getSelectedRow();
276 if (selectedRow < 0){
277 return;
278 }
279 if (settingDlg == null) {
280 settingDlg = new FpdModuleSA(ffc);
281 }
282 docConsole.setSaved(false);
283 String mg = model1.getValueAt(selectedRow, 1)+"";
284 String mv = model1.getValueAt(selectedRow, 2)+"";
285 String pg = model1.getValueAt(selectedRow, 3)+"";
286 String pv = model1.getValueAt(selectedRow, 4)+"";
287 settingDlg.setKey(mg + " " + mv + " " + pg + " " + pv);
288 settingDlg.setVisible(true);
289 }
290 });
291 }
292 return jButton1;
293 }
294
295 /**
296 * This method initializes jButton2
297 *
298 * @return javax.swing.JButton
299 */
300 private JButton getJButton2() {
301 if (jButton2 == null) {
302 jButton2 = new JButton();
303 jButton2.setPreferredSize(new java.awt.Dimension(130,20));
304 jButton2.setText("Remove Module");
305 jButton2.addActionListener(new java.awt.event.ActionListener() {
306 public void actionPerformed(java.awt.event.ActionEvent e) {
307 int selectedRow = jTable1.getSelectedRow();
308 if (selectedRow < 0){
309 return;
310 }
311 String mg = model1.getValueAt(selectedRow, 1).toString();
312 String mv = model1.getValueAt(selectedRow, 2).toString();
313 String pg = model1.getValueAt(selectedRow, 3).toString();
314 String pv = model1.getValueAt(selectedRow, 4).toString();
315 model1.removeRow(selectedRow);
316 fpdMsa.remove(mg+mv+pg+pv);
317 docConsole.setSaved(false);
318 ffc.removeModuleSA(selectedRow);
319 }
320 });
321 }
322 return jButton2;
323 }
324
325 /**
326 * @param args
327 */
328 public static void main(String[] args) {
329 // TODO Auto-generated method stub
330 new FpdFrameworkModules().setVisible(true);
331 }
332
333 /**
334 * This is the default constructor
335 */
336 public FpdFrameworkModules() {
337 super();
338 initialize();
339 }
340
341 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd){
342 this();
343 init(fpd);
344
345 }
346
347 public FpdFrameworkModules(OpeningPlatformType opt) {
348 this(opt.getXmlFpd());
349 docConsole = opt;
350 }
351
352 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
353 try {
354 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", System.getenv("WORKSPACE"));
355 }
356 catch(Exception e){
357 JOptionPane.showMessageDialog(frame, "FrameworkDatabase Corrupted.");
358 }
359
360 if (ffc == null){
361 ffc = new FpdFileContents(fpd);
362 ffc.initDynPcdMap();
363 }
364
365 if (fpdMsa == null) {
366 fpdMsa = new HashMap<String, String>();
367 }
368
369 if (ffc.getFrameworkModulesCount() > 0) {
370 String[][] saa = new String[ffc.getFrameworkModulesCount()][5];
371 ffc.getFrameworkModulesInfo(saa);
372 for (int i = 0; i < saa.length; ++i) {
373 ModuleIdentification mi = getModuleId(saa[i][1]+ " "+saa[i][2]+" "+saa[i][3]+" "+saa[i][4]);
374 if (mi != null) {
375 saa[i][0] = mi.getName();
376 saa[i][2] = mi.getVersion();
377 saa[i][4] = mi.getPackage().getVersion();
378 }
379 model1.addRow(saa[i]);
380 fpdMsa.put(saa[i][1]+saa[i][2]+saa[i][3]+saa[i][4], saa[i][0]);
381 }
382 }
383
384 showAllModules();
385
386 }
387
388 private void showAllModules() {
389
390 if (miList == null) {
391 miList = new ArrayList<ModuleIdentification>();
392 }
393 Set<PackageIdentification> spi = GlobalData.getPackageList();
394 Iterator ispi = spi.iterator();
395
396 while(ispi.hasNext()) {
397 PackageIdentification pi = (PackageIdentification)ispi.next();
398 String[] s = {"", "", "", "", ""};
399 s[3] = pi.getGuid();
400 s[4] = pi.getVersion();
401 Set<ModuleIdentification> smi = GlobalData.getModules(pi);
402 Iterator ismi = smi.iterator();
403 while(ismi.hasNext()) {
404 ModuleIdentification mi = (ModuleIdentification)ismi.next();
405 s[0] = mi.getName();
406 s[1] = mi.getGuid();
407 s[2] = mi.getVersion();
408 model.addRow(s);
409 miList.add(mi);
410 }
411 }
412 }
413 /**
414 * This method initializes this
415 *
416 * @return void
417 */
418 private void initialize() {
419 this.setSize(633, 533);
420 this.setTitle("Framework Modules");
421 this.setContentPane(getJSplitPane());
422 this.setVisible(true);
423
424 }
425
426 private ModuleIdentification getModuleId(String key){
427 //
428 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.
429 //
430 String[] keyPart = key.split(" ");
431 Set<PackageIdentification> spi = GlobalData.getPackageList();
432 Iterator ispi = spi.iterator();
433
434 while(ispi.hasNext()) {
435 PackageIdentification pi = (PackageIdentification)ispi.next();
436 if ( !pi.getGuid().equals(keyPart[2])){
437 // || !pi.getVersion().equals(keyPart[3])){
438 continue;
439 }
440 Set<ModuleIdentification> smi = GlobalData.getModules(pi);
441 Iterator ismi = smi.iterator();
442 while(ismi.hasNext()) {
443 ModuleIdentification mi = (ModuleIdentification)ismi.next();
444 if (mi.getGuid().equals(keyPart[0])){
445 // && mi.getVersion().equals(keyPart[1])){
446
447 return mi;
448 }
449 }
450 }
451 return null;
452 }
453
454 } // @jve:decl-index=0:visual-constraint="10,10"
455
456 class NonEditableTableModel extends DefaultTableModel {
457 /**
458 *
459 */
460 private static final long serialVersionUID = 1L;
461
462 public boolean isCellEditable(int row, int col) {
463 return false;
464 }
465 }