+/**\r
+ * \r
+ */\r
+package org.tianocore.frameworkwizard.platform.ui;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Dimension;\r
+import java.awt.Toolkit;\r
+\r
+import javax.swing.JPanel;\r
+\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.util.Vector;\r
+\r
+import javax.swing.JDialog;\r
+import javax.swing.JLabel;\r
+import javax.swing.JComboBox;\r
+import javax.swing.JTabbedPane;\r
+\r
+import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformType;\r
+import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
+import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;\r
+\r
+/**\r
+ * @author jlin16\r
+ *\r
+ */\r
+public class GenAprioriFileDialog extends JDialog implements ActionListener {\r
+\r
+ /**\r
+ * \r
+ */\r
+ private static final long serialVersionUID = 3627991301208644354L;\r
+ private JPanel jContentPane = null;\r
+ private JPanel jPanelN = null;\r
+ private JLabel jLabelFvName = null;\r
+ private JComboBox jComboBoxFvNames = null;\r
+ private JTabbedPane jTabbedPane = null;\r
+ private FpdFileContents ffc = null;\r
+ private OpeningPlatformType docConsole = null;\r
+\r
+ /**\r
+ * This is the default constructor\r
+ */\r
+ public GenAprioriFileDialog(FpdFileContents inputFfc, OpeningPlatformType dc) {\r
+ super();\r
+ ffc = inputFfc;\r
+ docConsole = dc;\r
+ initialize();\r
+ }\r
+\r
+ /**\r
+ * This method initializes this\r
+ * \r
+ * @return void\r
+ */\r
+ private void initialize() {\r
+ this.setSize(670, 670);\r
+ this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);\r
+ this.setTitle("Apriori Files");\r
+ this.setContentPane(getJContentPane());\r
+ this.setResizable(false);\r
+ this.setModal(true);\r
+ \r
+ String fvName = jComboBoxFvNames.getSelectedItem()+"";\r
+ if (fvName.length() > 0) {\r
+ jTabbedPane.removeAll();\r
+ AprioriModuleOrderPane peiPane = new AprioriModuleOrderPane(fvName, "", GenAprioriFileDialog.this, true);\r
+ peiPane.showModulesInFv(fvName);\r
+ peiPane.showAllModulesInPlatform();\r
+ jTabbedPane.addTab("PEIMs", peiPane);\r
+ AprioriModuleOrderPane dxePane = new AprioriModuleOrderPane(fvName, "", GenAprioriFileDialog.this, false);\r
+ dxePane.showModulesInFv(fvName);\r
+ dxePane.showAllModulesInPlatform();\r
+ jTabbedPane.addTab("DXE Drivers", dxePane);\r
+ }\r
+ this.centerWindow();\r
+ }\r
+\r
+ /**\r
+ * This method initializes jContentPane\r
+ * \r
+ * @return javax.swing.JPanel\r
+ */\r
+ private JPanel getJContentPane() {\r
+ if (jContentPane == null) {\r
+ jContentPane = new JPanel();\r
+ jContentPane.setLayout(new BorderLayout());\r
+ jContentPane.add(getJPanelN(), java.awt.BorderLayout.NORTH);\r
+ jContentPane.add(getJTabbedPane(), java.awt.BorderLayout.CENTER);\r
+ }\r
+ return jContentPane;\r
+ }\r
+\r
+ public void actionPerformed(ActionEvent arg0) {\r
+ // TODO Auto-generated method stub\r
+ if (arg0.getActionCommand().equals("ModuleOrderPaneOk")) {\r
+ docConsole.setSaved(false);\r
+ return;\r
+ }\r
+ if (arg0.getActionCommand().equals("ModuleOrderPaneCancel")) {\r
+ this.dispose();\r
+ }\r
+ }\r
+ \r
+ /**\r
+ Start the window at the center of screen\r
+ \r
+ **/\r
+ protected void centerWindow(int intWidth, int intHeight) {\r
+ Dimension d = Toolkit.getDefaultToolkit().getScreenSize();\r
+ this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);\r
+ }\r
+\r
+ /**\r
+ Start the window at the center of screen\r
+ \r
+ **/\r
+ protected void centerWindow() {\r
+ centerWindow(this.getSize().width, this.getSize().height);\r
+ }\r
+\r
+/**\r
+ * This method initializes jPanelN \r
+ * \r
+ * @return javax.swing.JPanel \r
+ */\r
+private JPanel getJPanelN() {\r
+ if (jPanelN == null) {\r
+ jLabelFvName = new JLabel();\r
+ jLabelFvName.setText("FV Name");\r
+ jPanelN = new JPanel();\r
+ jPanelN.add(jLabelFvName, null);\r
+ jPanelN.add(getJComboBoxFvNames(), null);\r
+ }\r
+ return jPanelN;\r
+}\r
+\r
+/**\r
+ * This method initializes jComboBoxFvNames \r
+ * \r
+ * @return javax.swing.JComboBox \r
+ */\r
+private JComboBox getJComboBoxFvNames() {\r
+ if (jComboBoxFvNames == null) {\r
+ jComboBoxFvNames = new JComboBox();\r
+ jComboBoxFvNames.setPreferredSize(new java.awt.Dimension(200,20));\r
+ Vector<String> vFvNames = new Vector<String>();\r
+ ffc.getFvImagesFvImageFvImageNames(vFvNames);\r
+ for (int i = 0; i < vFvNames.size(); ++i) {\r
+ jComboBoxFvNames.addItem(vFvNames.get(i));\r
+ }\r
+// if (jComboBoxFvNames.getItemCount() > 0) {\r
+// jComboBoxFvNames.setSelectedIndex(0);\r
+// \r
+// }\r
+ jComboBoxFvNames.addItemListener(new java.awt.event.ItemListener() {\r
+ public void itemStateChanged(java.awt.event.ItemEvent e) {\r
+ String fvName = jComboBoxFvNames.getSelectedItem()+"";\r
+ if (fvName.length() > 0) {\r
+ jTabbedPane.removeAll();\r
+ AprioriModuleOrderPane peiPane = new AprioriModuleOrderPane(fvName, "", GenAprioriFileDialog.this, true);\r
+ peiPane.showModulesInFv(fvName);\r
+ peiPane.showAllModulesInPlatform();\r
+ jTabbedPane.addTab("PEIMs", peiPane);\r
+ AprioriModuleOrderPane dxePane = new AprioriModuleOrderPane(fvName, "", GenAprioriFileDialog.this, false);\r
+ dxePane.showModulesInFv(fvName);\r
+ dxePane.showAllModulesInPlatform();\r
+ jTabbedPane.addTab("DXE Drivers", dxePane);\r
+ }\r
+ \r
+ }\r
+ });\r
+ }\r
+ return jComboBoxFvNames;\r
+}\r
+\r
+/**\r
+ * This method initializes jTabbedPane \r
+ * \r
+ * @return javax.swing.JTabbedPane \r
+ */\r
+private JTabbedPane getJTabbedPane() {\r
+ if (jTabbedPane == null) {\r
+ jTabbedPane = new JTabbedPane();\r
+ }\r
+ return jTabbedPane;\r
+}\r
+\r
+private class AprioriModuleOrderPane extends ModuleOrderPane {\r
+ /**\r
+ * \r
+ */\r
+ private static final long serialVersionUID = -7952853414833230546L;\r
+ private boolean forPEI = false;\r
+ private String fvName = null;\r
+\r
+ AprioriModuleOrderPane (String fvName, String file, ActionListener action, boolean b) {\r
+ \r
+ super(fvName, file, ffc, action);\r
+ this.fvName = fvName;\r
+ forPEI = b;\r
+ getJTableModInFv().getColumnModel().getColumn(0).setHeaderValue("Modules in Apriori File");\r
+ getJButtonOk().setText("Save");\r
+ getJButtonCancel().setText("Close");\r
+ }\r
+ \r
+ public void showModulesInFv (String fvName) {\r
+ int id = 1;\r
+ if (forPEI) {\r
+ id = 0;\r
+ }\r
+ int size = ffc.getUserExtsIncModCount(fvName, "APRIORI", id);\r
+ \r
+ if (size != -1) {\r
+ String[][] saa = new String[size][5];\r
+ ffc.getUserExtsIncMods(fvName, "APRIORI", id, saa);\r
+\r
+ for (int i = 0; i < size; ++i) {\r
+ String moduleKey = saa[i][0] + " " + saa[i][1] + " " + saa[i][2] + " " + saa[i][3];\r
+ ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);\r
+ String name = "N/A";\r
+ if (mi != null) {\r
+ name = mi.getName();\r
+ }\r
+ \r
+ String[] row = { name, saa[i][0] , saa[i][1], saa[i][2] , saa[i][3], saa[i][4] };\r
+ getModInFvTableModel().addRow(row);\r
+ }\r
+ }\r
+ }\r
+ \r
+ public void actionPerformed(ActionEvent arg0) {\r
+ if (arg0.getActionCommand().equals("ModuleOrderPaneOk")) {\r
+ int id = 1;\r
+ if (forPEI) {\r
+ id = 0;\r
+ }\r
+ \r
+ Vector<String[]> vModInFv = new Vector<String[]>();\r
+ for (int i = 0; i < getJTableModInFv().getRowCount(); ++i) {\r
+ String moduleName = getModInFvTableModel().getValueAt(i, 0)+"";\r
+ if (moduleName.length() == 0 || moduleName.equals("N/A")) {\r
+ continue;\r
+ }\r
+ \r
+ String mg = getModInFvTableModel().getValueAt(i, 1)+"";\r
+ String mv = getModInFvTableModel().getValueAt(i, 2)+"";\r
+ String pg = getModInFvTableModel().getValueAt(i, 3)+"";\r
+ String pv = getModInFvTableModel().getValueAt(i, 4)+"";\r
+ String arch = getModInFvTableModel().getValueAt(i, 5)+"";\r
+ \r
+ String[] sa = { mg, mv, pg, pv, arch};\r
+ vModInFv.add(sa);\r
+ \r
+ }\r
+ \r
+ ffc.removeBuildOptionsUserExtensions(fvName, "APRIORI", id);\r
+ ffc.genBuildOptionsUserExtensions(fvName, "APRIORI", id+"", "", vModInFv);\r
+ \r
+ }\r
+ }\r
+}\r
+} // @jve:decl-index=0:visual-constraint="10,10"\r