Add Fv option value edit support;
authorjlin16 <jlin16@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 31 Oct 2006 08:14:22 +0000 (08:14 +0000)
committerjlin16 <jlin16@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 31 Oct 2006 08:14:22 +0000 (08:14 +0000)
Give hover hint why some Fv options are not editable.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1874 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFlash.java
Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFvOptions.java

index bc472480732078223a42f3fe1018ab6e41be5d93..a59b2d4f792b5f6078ab37ac623fafade111942a 100644 (file)
@@ -1531,7 +1531,10 @@ public class FpdFileContents {
                 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
                     \r
                     if (getDynamicPcdBuildDataCount() == 1) {\r
-                        cursor.toParent();\r
+                        cursor.dispose();\r
+                        removeElement(o);\r
+                        fpdDynPcdBuildDefs = null;\r
+                        return;\r
                     }\r
                     cursor.removeXml();\r
                     cursor.dispose();\r
@@ -1548,6 +1551,8 @@ public class FpdFileContents {
     public int getDynamicPcdSkuInfoCount(int i){\r
         if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null \r
                         || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {\r
+            removeElement(getfpdDynPcdBuildDefs());\r
+            fpdDynPcdBuildDefs = null;\r
             return 0;\r
         }\r
         \r
@@ -1716,9 +1721,11 @@ public class FpdFileContents {
     \r
     public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r
                                                  String hiiDefault, String vpdOffset, String value, int i){\r
-//        if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
-//            return;\r
-//        }\r
+        if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
+            removeElement(getfpdDynPcdBuildDefs());\r
+            fpdDynPcdBuildDefs = null;\r
+            return;\r
+        }\r
         \r
         XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
         if (cursor.toFirstChild()) {\r
@@ -3278,32 +3285,31 @@ public class FpdFileContents {
      * @param name\r
      * @param value\r
      */\r
-    public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) {\r
+    public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value, String newName) {\r
         boolean fvImageExists = false;\r
-        if (getfpdFlash().getFvImages() == null) {\r
-            return;\r
-        }\r
-        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
-        if (l == null) {\r
-            return;\r
-        }\r
-        ListIterator li = l.listIterator();\r
-        while(li.hasNext()) {\r
-            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
-            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
-                continue;\r
-            }\r
-            if (!fi.getFvImageNamesList().contains(fvName)) {\r
-                continue;\r
+        if (getfpdFlash().getFvImages() != null) {\r
+\r
+            List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+            if (l != null) {\r
+                ListIterator li = l.listIterator();\r
+                while (li.hasNext()) {\r
+                    FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage) li.next();\r
+                    if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                        continue;\r
+                    }\r
+                    if (!fi.getFvImageNamesList().contains(fvName)) {\r
+                        continue;\r
+                    }\r
+                    fvImageExists = true;\r
+                    setFvImagesFvImageNameValue(fi, name, value, newName);\r
+                }\r
             }\r
-            fvImageExists = true;\r
-            setFvImagesFvImageNameValue (fi, name, value, null);\r
         }\r
-        \r
+\r
         if (!fvImageExists) {\r
             HashMap<String, String> map = new HashMap<String, String>();\r
             map.put(name, value);\r
-            genFvImagesFvImage(new String[]{fvName}, type, map);\r
+            genFvImagesFvImage(new String[] { fvName }, type, map);\r
         }\r
     }\r
     \r
@@ -3359,7 +3365,7 @@ public class FpdFileContents {
             FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue();\r
             nv.setName(name);\r
             nv.setValue(value);\r
-            if (newName != null) {\r
+            if (newName != null && !newName.equals(name)) {\r
                 nv.setName(newName);\r
             }\r
             return;\r
@@ -3371,7 +3377,7 @@ public class FpdFileContents {
                 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject();\r
                 if (nv.getName().equals(name)) {\r
                     nv.setValue(value);\r
-                    if (newName != null) {\r
+                    if (newName != null && !newName.equals(name)) {\r
                         nv.setName(newName);\r
                     }\r
                     cursor.dispose();\r
@@ -3383,7 +3389,7 @@ public class FpdFileContents {
         FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();\r
         nv.setName(name);\r
         nv.setValue(value);\r
-        if (newName != null) {\r
+        if (newName != null && !newName.equals(name)) {\r
             nv.setName(newName);\r
         }\r
         cursor.dispose();\r
index 8a8af51ec9f6ee2f7b2234faa8ee71ae4c7c58eb..a880ae41f24e4c061de311c12c65ee2c3eabd493 100644 (file)
@@ -1055,9 +1055,16 @@ public class FpdFlash extends IInternalFrame {
                         jButtonFdfBrowse.setEnabled(true);\r
                     }\r
                     else {\r
-                        \r
+                        getFvInFdfTableModel().setRowCount(0);\r
                         jTextFieldFdf.setEnabled(false);\r
+                        jTextFieldFdf.setText("");\r
                         jButtonFdfBrowse.setEnabled(false);\r
+                        ffc.genFlashDefinitionFile("");\r
+                        docConsole.setSaved(false);\r
+                        int selectedBackup = selectedRowInFvAdditionalTable;\r
+                        selectedRowInFvAdditionalTable = -1;\r
+                        initFvAdditionalTable();\r
+                        selectedRowInFvAdditionalTable = selectedBackup;\r
                     }\r
                 }\r
             });\r
@@ -1194,9 +1201,16 @@ public class FpdFlash extends IInternalFrame {
         determinedFvBlockSize = blkSize;\r
         \r
         getFvInFdfTableModel().setRowCount(0);\r
+        Vector<String> vExistingFvNameInFpd = new Vector<String>();\r
+        ffc.getFvImagesFvImageFvImageNames(vExistingFvNameInFpd);\r
         for (int j = 0; j < vFvInfo.size(); ++j) {\r
             FvInfoFromFdf fvInfo = vFvInfo.get(j);\r
             String[] row = {fvInfo.getFvName(), fvInfo.getSize(), fvInfo.getEfiFileName()};\r
+            \r
+            if (row[0].length() > 0 && !vExistingFvNameInFpd.contains(row[0])) {\r
+                ffc.addFvImageFvImageNames(new String[]{row[0]});\r
+            }\r
+            \r
             // if FV addtional table contains the same FV from fdf file, remove that row.\r
             for (int k = 0; k < jTableFvAdditional.getRowCount(); ++k) {\r
                 if (fvAdditionalTableModel.getValueAt(k, 0).equals(row[0])) {\r
@@ -1221,15 +1235,15 @@ public class FpdFlash extends IInternalFrame {
                 else {\r
                     ffc.getFvImagesFvImageOptions(row[0], mOptions);\r
                     if (mOptions.get("EFI_BLOCK_SIZE") == null || !mOptions.get("EFI_BLOCK_SIZE").equalsIgnoreCase(blkSize)) {\r
-                        ffc.setTypedNamedFvImageNameValue(row[0], "Options", "EFI_BLOCK_SIZE", blkSize);\r
+                        ffc.setTypedNamedFvImageNameValue(row[0], "Options", "EFI_BLOCK_SIZE", blkSize, null);\r
                         memModified = true;\r
                     }\r
                     if (mOptions.get("EFI_NUM_BLOCKS") == null || Integer.decode(mOptions.get("EFI_NUM_BLOCKS")) != numBlocks) {\r
-                        ffc.setTypedNamedFvImageNameValue(row[0], "Options", "EFI_NUM_BLOCKS", numBlocks + "");\r
+                        ffc.setTypedNamedFvImageNameValue(row[0], "Options", "EFI_NUM_BLOCKS", numBlocks + "", null);\r
                         memModified = true;\r
                     }\r
                     if (mOptions.get("EFI_FILE_NAME") == null || !mOptions.get("EFI_FILE_NAME").equals(row[2])) {\r
-                        ffc.setTypedNamedFvImageNameValue(row[0], "Options", "EFI_FILE_NAME", row[2]);\r
+                        ffc.setTypedNamedFvImageNameValue(row[0], "Options", "EFI_FILE_NAME", row[2], null);\r
                         memModified = true;\r
                     }\r
                     \r
@@ -1810,20 +1824,20 @@ public class FpdFlash extends IInternalFrame {
                                 else {\r
                                     blkSize = defaultBlkSize;\r
                                 }\r
-                                ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_BLOCK_SIZE", blkSize);\r
+                                ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_BLOCK_SIZE", blkSize, null);\r
                                 int fs = Integer.decode(fvSize);\r
                                 int bs = Integer.decode(blkSize);\r
-                                ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_NUM_BLOCKS", (fs/bs)+"");\r
+                                ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_NUM_BLOCKS", (fs/bs)+"", null);\r
                                 docConsole.setSaved(false);\r
                             }\r
                             else {\r
                                 if (!DataValidation.isInt(blkSize) && !DataValidation.isHexDoubleWordDataType(blkSize)) {\r
                                     int retVal = JOptionPane.showConfirmDialog(frame, "Confirm", "FPD file contains error block size format. Would you like to replace it with a default value?", JOptionPane.YES_NO_OPTION);\r
                                     if (retVal == JOptionPane.YES_OPTION) {\r
-                                        ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_BLOCK_SIZE", defaultBlkSize);\r
+                                        ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_BLOCK_SIZE", defaultBlkSize, null);\r
                                         int fs = Integer.decode(fvSize);\r
                                         int bs = Integer.decode(defaultBlkSize);\r
-                                        ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_NUM_BLOCKS", (fs/bs)+"");\r
+                                        ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_NUM_BLOCKS", (fs/bs)+"", null);\r
                                         docConsole.setSaved(false);\r
                                         return;\r
                                     }\r
@@ -1834,13 +1848,13 @@ public class FpdFlash extends IInternalFrame {
                                 }\r
                                 int fs = Integer.decode(fvSize);\r
                                 int bs = Integer.decode(blkSize);\r
-                                ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_NUM_BLOCKS", (fs/bs)+"");\r
+                                ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_NUM_BLOCKS", (fs/bs)+"", null);\r
                                 docConsole.setSaved(false);\r
                             }\r
                         }\r
                         \r
                         if (col == 2 && !fileFromOptionDlg) {\r
-                            ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_FILE_NAME", m.getValueAt(row, col)+"");\r
+                            ffc.setTypedNamedFvImageNameValue(oldFvName, "Options", "EFI_FILE_NAME", m.getValueAt(row, col)+"", null);\r
                             docConsole.setSaved(false);\r
                         }\r
                         \r
@@ -2269,6 +2283,7 @@ public class FpdFlash extends IInternalFrame {
         jTextFieldFdf.setText("");\r
         String fdfFile = ffc.getFlashDefinitionFile();\r
         if (fdfFile != null && fdfFile.length() > 0) {\r
+            jCheckBoxFdf.setSelected(true);\r
             jTextFieldFdf.setText(fdfFile);\r
             String fdfPath = System.getenv("WORKSPACE") + File.separator + fdfFile;\r
             initFvInFdfTable(fdfPath);\r
@@ -3181,6 +3196,7 @@ class FvOptsTableModel extends DefaultTableModel {
     private Vector<Object> vKeyWords = new Vector<Object>();\r
     \r
     public boolean isCellEditable(int row, int col) {\r
+\r
         if (vNonEditableName.size() > 0 || vKeyWords.size() > 0) {\r
             if (vKeyWords.contains(getValueAt(row, 0))) {\r
                 return false;\r
@@ -3188,7 +3204,11 @@ class FvOptsTableModel extends DefaultTableModel {
             if (vNonEditableName.contains(getValueAt(row, 0)) && col == 0) {\r
                 return false;\r
             }\r
-        }  \r
+        }\r
+        \r
+        if (col == 0 && getValueAt(row, 0) != null && getValueAt(row, 0).toString().length() > 0) {\r
+            return false;\r
+        }\r
        \r
         return true;\r
     }\r
index 1a2123ca723af6dc3257776d93f9ebd953c271e4..00ecad69a12466351177d49d806d8b764d6d13f1 100644 (file)
@@ -15,14 +15,21 @@ package org.tianocore.frameworkwizard.platform.ui;
 import java.awt.BorderLayout;\r
 import java.awt.Dimension;\r
 import java.awt.Toolkit;\r
-import java.util.HashMap;\r
+import java.awt.event.MouseEvent;\r
+import java.awt.event.WindowEvent;\r
 import java.util.Iterator;\r
+import java.util.LinkedHashMap;\r
 import java.util.Set;\r
 \r
+import javax.swing.JFrame;\r
+import javax.swing.JOptionPane;\r
 import javax.swing.JPanel;\r
 import javax.swing.JDialog;\r
 import javax.swing.JScrollPane;\r
 import javax.swing.JTable;\r
+import javax.swing.ListSelectionModel;\r
+import javax.swing.event.ListSelectionEvent;\r
+import javax.swing.event.ListSelectionListener;\r
 import javax.swing.event.TableModelEvent;\r
 import javax.swing.event.TableModelListener;\r
 import javax.swing.table.DefaultTableModel;\r
@@ -41,6 +48,7 @@ public class FpdFvOptions extends JDialog {
      * \r
      */\r
     private static final long serialVersionUID = 1L;\r
+    private static JFrame frame;\r
     private JPanel jContentPane = null;\r
     private JPanel jPanelN = null;\r
     private JPanel jPanelS = null;\r
@@ -53,6 +61,9 @@ public class FpdFvOptions extends JDialog {
     private OpeningPlatformType docConsole = null;\r
     private JButton jButtonNew = null;\r
     private JButton jButtonDelete = null;\r
+    private String oldOptionName = "";\r
+    private int selectedRow = -1;\r
+    private TableModelListener tableModelListener = null;\r
 \r
     /**\r
      * This is the default constructor\r
@@ -67,10 +78,20 @@ public class FpdFvOptions extends JDialog {
         initialize();\r
         \r
     }\r
+    \r
+    protected void processWindowEvent (WindowEvent e) {\r
+        if (e.getID() == WindowEvent.WINDOW_CLOSING) {\r
+            if (jTableFvOptions.isEditing()) {\r
+                jTableFvOptions.getCellEditor().stopCellEditing();\r
+            }\r
+            tableModel.removeTableModelListener(tableModelListener);\r
+            this.dispose();\r
+        }\r
+    }\r
 \r
     private void initOptions() {\r
         tableModel.setRowCount(0);\r
-        HashMap<String, String> mOpts = new HashMap<String, String>();\r
+        LinkedHashMap<String, String> mOpts = new LinkedHashMap<String, String>();\r
         ffc.getFvImagesFvImageOptions(fvName, mOpts);\r
         Set<String> sKey = mOpts.keySet();\r
         Iterator<String> iter = sKey.iterator();\r
@@ -80,6 +101,19 @@ public class FpdFvOptions extends JDialog {
             tableModel.addRow(new String[]{name, value});\r
         }\r
     }\r
+    \r
+    private boolean fvOptionNameExists (String name) {\r
+        int count = 0;\r
+        for (int i = 0; i < jTableFvOptions.getRowCount(); ++i) {\r
+            if (getTableModel().getValueAt(i, 0).equals(name)) {\r
+                ++count;\r
+            }\r
+        }\r
+        if (count > 1) {\r
+            return true;\r
+        }\r
+        return false;\r
+    }\r
     /**\r
      * This method initializes this\r
      * \r
@@ -87,12 +121,13 @@ public class FpdFvOptions extends JDialog {
      */\r
     private void initialize() {\r
         this.setSize(650, 400);\r
-        this.setModal(true);\r
+//        this.setModal(true);\r
         this.setTitle("FV Options");\r
-        this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);\r
+        this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);\r
         this.setContentPane(getJContentPane());\r
         this.centerWindow();\r
         this.setVisible(true);\r
+        \r
     }\r
 \r
     /**\r
@@ -171,26 +206,81 @@ public class FpdFvOptions extends JDialog {
      */\r
     private JTable getJTableFvOptions() {\r
         if (jTableFvOptions == null) {\r
-            jTableFvOptions = new JTable();\r
+            jTableFvOptions = new JTable(getTableModel()) {\r
+                /**\r
+                 * \r
+                 */\r
+                private static final long serialVersionUID = -1941328952828651192L;\r
+\r
+                public String getToolTipText(MouseEvent e) {\r
+                    String tip = null;\r
+                    java.awt.Point p = e.getPoint();\r
+                    int rowIndex = rowAtPoint(p);\r
+//                    int colIndex = columnAtPoint(p);\r
+//                    int realColumnIndex = convertColumnIndexToModel(colIndex);\r
+\r
+                    TableModel model = getModel();\r
+                    String optName = (String) model.getValueAt(rowIndex, 0);\r
+                    if (((FvOptsTableModel)model).getVKeyWords().contains(optName)){\r
+                        tip = optName + " is from Flash Definition File and it is NOT editable.";\r
+                    }\r
+                         \r
+                    return tip;\r
+                }\r
+\r
+            };\r
\r
             jTableFvOptions.setRowHeight(20);\r
-            jTableFvOptions.setModel(getTableModel());\r
             \r
-            jTableFvOptions.getModel().addTableModelListener(new TableModelListener() {\r
+            jTableFvOptions.getSelectionModel().addListSelectionListener(new ListSelectionListener() {\r
+                public void valueChanged(ListSelectionEvent e) {\r
+                    if (e.getValueIsAdjusting()) {\r
+                        return;\r
+                    }\r
+                    ListSelectionModel lsm = (ListSelectionModel) e.getSource();\r
+                    if (lsm.isSelectionEmpty()) {\r
+                        return;\r
+                    } else {\r
+                        selectedRow = lsm.getMinSelectionIndex();\r
+                        oldOptionName = getTableModel().getValueAt(selectedRow, 0)+"";\r
+                    }\r
+                }\r
+            });\r
+            \r
+            tableModelListener = new TableModelListener() {\r
                 public void tableChanged(TableModelEvent arg0) {\r
                     // TODO Auto-generated method stub\r
                     int row = arg0.getFirstRow();\r
-//                    int col = arg0.getColumn();\r
+                    int col = arg0.getColumn();\r
                     TableModel m = (TableModel) arg0.getSource();\r
                     \r
                     if (arg0.getType() == TableModelEvent.UPDATE) {\r
-                        if (m.getValueAt(row, 0).equals("")) {\r
-                            return;\r
+                        String newOptionName = m.getValueAt(row, 0) + "";\r
+                        if (col == 0) {\r
+                            if (newOptionName.equals(oldOptionName)) {\r
+                                return;\r
+                            }\r
+                            if (fvOptionNameExists(newOptionName)) {\r
+                                JOptionPane.showMessageDialog(frame, "This Option already exists. Please choose another Option name.");\r
+                                m.setValueAt(oldOptionName, row, 0);\r
+                                return;\r
+                            }\r
+                            \r
+                            ffc.setTypedNamedFvImageNameValue(fvName, "Options", oldOptionName, m.getValueAt(row, 1)+"", newOptionName);\r
+                            docConsole.setSaved(false);\r
+                            oldOptionName = newOptionName;\r
                         }\r
-                        ffc.setTypedNamedFvImageNameValue(fvName, "Options", m.getValueAt(row, 0)+"", m.getValueAt(row, 1)+"");\r
-                        docConsole.setSaved(false);\r
+                        \r
+                        if (col == 1) {\r
+                            ffc.setTypedNamedFvImageNameValue(fvName, "Options", oldOptionName, m.getValueAt(row, 1)+"", newOptionName);\r
+                            docConsole.setSaved(false);    \r
+                        }\r
+                                            \r
                     }\r
                 }\r
-            });\r
+            };\r
+            \r
+            jTableFvOptions.getModel().addTableModelListener(tableModelListener);\r
         }\r
         return jTableFvOptions;\r
     }\r
@@ -235,6 +325,7 @@ private JButton getJButtonNew() {
         jButtonNew.addActionListener(new java.awt.event.ActionListener() {\r
             public void actionPerformed(java.awt.event.ActionEvent e) {\r
                 tableModel.addRow(new String[]{"", ""});\r
+                oldOptionName = "";\r
             }\r
         });\r
     }\r