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