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