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