+++ /dev/null
-/** @file\r
- \r
- The file is used to create, update Variable of MSA/MBD file\r
- \r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
- \r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
- \r
- **/\r
-\r
-package org.tianocore.frameworkwizard.module.ui;\r
-\r
-import java.awt.Dimension;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ComponentEvent;\r
-import java.awt.event.MouseEvent;\r
-import java.util.Vector;\r
-\r
-import javax.swing.JButton;\r
-import javax.swing.JPanel;\r
-import javax.swing.JScrollPane;\r
-import javax.swing.JTable;\r
-import javax.swing.ListSelectionModel;\r
-import javax.swing.event.ListSelectionEvent;\r
-\r
-import org.tianocore.VariableUsage;\r
-import org.tianocore.VariablesDocument;\r
-import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
-import org.tianocore.VariablesDocument.Variables;\r
-import org.tianocore.VariablesDocument.Variables.Variable;\r
-import org.tianocore.frameworkwizard.common.DataType;\r
-import org.tianocore.frameworkwizard.common.IDefaultTableModel;\r
-import org.tianocore.frameworkwizard.common.Log;\r
-import org.tianocore.frameworkwizard.common.Tools;\r
-import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r
-import org.tianocore.frameworkwizard.common.ui.IFrame;\r
-import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r
-import org.tianocore.frameworkwizard.module.Identifications.Variables.VariablesIdentification;\r
-import org.tianocore.frameworkwizard.module.Identifications.Variables.VariablesVector;\r
-import org.tianocore.frameworkwizard.module.ui.dialog.VariablesDlg;\r
-\r
-/**\r
- The class is used to create, update Variable of MSA/MBD file\r
- It extends IInternalFrame\r
- \r
- **/\r
-public class ModuleVariables extends IInternalFrame {\r
-\r
- ///\r
- /// Define class Serial Version UID\r
- ///\r
- private static final long serialVersionUID = -6998982978030439446L;\r
-\r
- //\r
- //Define class members\r
- //\r
- private JPanel jContentPane = null;\r
-\r
- private JButton jButtonAdd = null;\r
-\r
- private JButton jButtonRemove = null;\r
-\r
- private JButton jButtonUpdate = null;\r
-\r
- private JScrollPane jScrollPane = null;\r
-\r
- private JScrollPane jScrollPaneTable = null;\r
-\r
- private JTable jTable = null;\r
-\r
- //\r
- // Not used by UI\r
- //\r
- private OpeningModuleType omt = null;\r
-\r
- private ModuleSurfaceArea msa = null;\r
-\r
- private VariablesDocument.Variables variables = null;\r
-\r
- private VariablesIdentification id = null;\r
-\r
- private VariablesVector vid = new VariablesVector();\r
-\r
- private IDefaultTableModel model = null;\r
-\r
- private int selectedRow = -1;\r
- \r
- private IFrame parentFrame = null;\r
-\r
- /**\r
- This method initializes jButtonAdd \r
- \r
- @return javax.swing.JButton jButtonAdd\r
- \r
- **/\r
- private JButton getJButtonAdd() {\r
- if (jButtonAdd == null) {\r
- jButtonAdd = new JButton();\r
- jButtonAdd.setBounds(new java.awt.Rectangle(230, 220, 90, 20));\r
- jButtonAdd.setText("Add");\r
- jButtonAdd.addActionListener(this);\r
- jButtonAdd.setPreferredSize(new java.awt.Dimension(90, 20));\r
- }\r
- return jButtonAdd;\r
- }\r
-\r
- /**\r
- This method initializes jButtonRemove \r
- \r
- @return javax.swing.JButton jButtonRemove\r
- \r
- **/\r
- private JButton getJButtonRemove() {\r
- if (jButtonRemove == null) {\r
- jButtonRemove = new JButton();\r
- jButtonRemove.setBounds(new java.awt.Rectangle(400, 220, 90, 20));\r
- jButtonRemove.setText("Remove");\r
- jButtonRemove.addActionListener(this);\r
- jButtonRemove.setPreferredSize(new java.awt.Dimension(90, 20));\r
- }\r
- return jButtonRemove;\r
- }\r
-\r
- /**\r
- This method initializes jButtonUpdate \r
- \r
- @return javax.swing.JButton jButtonUpdate\r
- \r
- **/\r
- private JButton getJButtonUpdate() {\r
- if (jButtonUpdate == null) {\r
- jButtonUpdate = new JButton();\r
- jButtonUpdate.setBounds(new java.awt.Rectangle(315, 220, 90, 20));\r
- jButtonUpdate.setPreferredSize(new java.awt.Dimension(90, 20));\r
- jButtonUpdate.setText("Edit");\r
- jButtonUpdate.addActionListener(this);\r
- }\r
- return jButtonUpdate;\r
- }\r
-\r
- /**\r
- This method initializes jScrollPane \r
- \r
- @return javax.swing.JScrollPane \r
- */\r
- private JScrollPane getJScrollPane() {\r
- if (jScrollPane == null) {\r
- jScrollPane = new JScrollPane();\r
- jScrollPane.setViewportView(getJContentPane());\r
- }\r
- return jScrollPane;\r
- }\r
-\r
- /**\r
- This method initializes jScrollPaneTable \r
- \r
- @return javax.swing.JScrollPane \r
- **/\r
- private JScrollPane getJScrollPaneTable() {\r
- if (jScrollPaneTable == null) {\r
- jScrollPaneTable = new JScrollPane();\r
- jScrollPaneTable.setBounds(new java.awt.Rectangle(15, 10, 470, 420));\r
- jScrollPaneTable.setPreferredSize(new Dimension(470, 420));\r
- jScrollPaneTable.setViewportView(getJTable());\r
- }\r
- return jScrollPaneTable;\r
- }\r
-\r
- /**\r
- This method initializes jTable \r
- \r
- @return javax.swing.JTable \r
- **/\r
- private JTable getJTable() {\r
- if (jTable == null) {\r
- jTable = new JTable();\r
- model = new IDefaultTableModel();\r
- jTable = new JTable(model);\r
- jTable.setRowHeight(20);\r
-\r
- model.addColumn("Name");\r
- model.addColumn("Guid C_Name");\r
- model.addColumn("Usage");\r
-\r
- jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);\r
- jTable.getSelectionModel().addListSelectionListener(this);\r
- jTable.getModel().addTableModelListener(this);\r
- jTable.addMouseListener(this);\r
- }\r
- return jTable;\r
- }\r
-\r
- public static void main(String[] args) {\r
-\r
- }\r
-\r
- /**\r
- This method initializes this\r
- \r
- **/\r
- private void init() {\r
- this.setSize(500, 515);\r
- this.setContentPane(getJScrollPane());\r
- this.setTitle("Variables");\r
- }\r
-\r
- /**\r
- This method initializes this\r
- Fill values to all fields if these values are not empty\r
- \r
- @param inPackageDependencies\r
-\r
- **/\r
- private void init(Variables inVariables) {\r
- init();\r
- this.variables = inVariables;\r
-\r
- if (this.variables != null) {\r
- if (this.variables.getVariableList().size() > 0) {\r
- for (int index = 0; index < this.variables.getVariableList().size(); index++) {\r
- String arg0 = Tools.convertUnicodeHexStringToString(variables.getVariableList().get(index)\r
- .getVariableName());\r
- String arg1 = variables.getVariableList().get(index).getGuidCName();\r
- String arg2 = null;\r
- if (variables.getVariableList().get(index).getUsage() != null) {\r
- arg2 = variables.getVariableList().get(index).getUsage().toString();\r
- }\r
-\r
- String arg3 = variables.getVariableList().get(index).getFeatureFlag();\r
- Vector<String> arg4 = Tools.convertListToVector(variables.getVariableList().get(index)\r
- .getSupArchList());\r
- String arg5 = variables.getVariableList().get(index).getHelpText();\r
- id = new VariablesIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
- vid.addVariables(id);\r
- }\r
- }\r
- }\r
- showTable();\r
- }\r
-\r
- /**\r
- This is the default constructor\r
- \r
- **/\r
- public ModuleVariables() {\r
- super();\r
- init();\r
- this.setVisible(true);\r
- }\r
-\r
- /**\r
- This is the override edit constructor\r
- \r
- @param inVariables The input data of VariablesDocument.Variables\r
- \r
- **/\r
- public ModuleVariables(OpeningModuleType inOmt, IFrame iFrame) {\r
- super();\r
- this.omt = inOmt;\r
- this.msa = omt.getXmlMsa();\r
- this.parentFrame = iFrame;\r
- init(msa.getVariables());\r
- this.setVisible(true);\r
- }\r
-\r
- /**\r
- This method initializes jContentPane\r
- \r
- @return javax.swing.JPanel jContentPane\r
- \r
- **/\r
- private JPanel getJContentPane() {\r
- if (jContentPane == null) {\r
- jContentPane = new JPanel();\r
- jContentPane.setLayout(null);\r
- jContentPane.setPreferredSize(new java.awt.Dimension(490, 490));\r
-\r
- jContentPane.add(getJButtonAdd(), null);\r
- jContentPane.add(getJButtonRemove(), null);\r
- jContentPane.add(getJButtonUpdate(), null);\r
- jContentPane.add(getJScrollPaneTable(), null);\r
- }\r
- return jContentPane;\r
- }\r
-\r
- private void showEdit(int index) {\r
- VariablesDlg dlg = new VariablesDlg(vid.getVariables(index), this.parentFrame, omt.getId());\r
- int result = dlg.showDialog();\r
- if (result == DataType.RETURN_TYPE_OK) {\r
- if (index == -1) {\r
- this.vid.addVariables(dlg.getId());\r
- } else {\r
- this.vid.setVariables(dlg.getId(), index);\r
- }\r
- this.showTable();\r
- this.save();\r
- dlg.dispose();\r
- }\r
- if (result == DataType.RETURN_TYPE_CANCEL) {\r
- dlg.dispose();\r
- }\r
- }\r
-\r
- /**\r
- Clear all table rows\r
- \r
- **/\r
- private void clearAll() {\r
- if (model != null) {\r
- for (int index = model.getRowCount() - 1; index >= 0; index--) {\r
- model.removeRow(index);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Read content of vector and put then into table\r
- \r
- **/\r
- private void showTable() {\r
- clearAll();\r
-\r
- if (vid.size() > 0) {\r
- for (int index = 0; index < vid.size(); index++) {\r
- model.addRow(vid.toStringVector(index));\r
- }\r
- }\r
- this.jTable.repaint();\r
- this.jTable.updateUI();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
- *\r
- * Override actionPerformed to listen all actions\r
- * \r
- */\r
- public void actionPerformed(ActionEvent arg0) {\r
- if (arg0.getSource() == jButtonAdd) {\r
- showEdit(-1);\r
- }\r
- if (arg0.getSource() == jButtonUpdate) {\r
- if (this.selectedRow < 0) {\r
- Log.wrn("Update Variables", "Please select one record first.");\r
- return;\r
- }\r
- showEdit(selectedRow);\r
- }\r
-\r
- if (arg0.getSource() == jButtonRemove) {\r
- if (jTable.isEditing()) {\r
- jTable.getCellEditor().stopCellEditing();\r
- }\r
- \r
- int selectedRows[] = this.jTable.getSelectedRows();\r
- \r
- if (selectedRows != null) {\r
- for (int index = selectedRows.length - 1; index > -1; index--) {\r
- this.model.removeRow(selectedRows[index]);\r
- this.vid.removeVariables(selectedRows[index]);\r
- }\r
- selectedRow = -1;\r
- this.save();\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Save all components of Variables\r
- if exists variables, set the value directly\r
- if not exists variables, new an instance first\r
- \r
- **/\r
- public void save() {\r
- try {\r
- int count = this.vid.size();\r
-\r
- this.variables = Variables.Factory.newInstance();\r
- if (count > 0) {\r
- for (int index = 0; index < count; index++) {\r
- Variable p = Variable.Factory.newInstance();\r
- if (!isEmpty(vid.getVariables(index).getName())) {\r
- p.setVariableName(Tools.convertStringToUnicodeHexString(vid.getVariables(index).getName()));\r
- }\r
- if (!isEmpty(vid.getVariables(index).getGuid())) {\r
- p.setGuidCName(vid.getVariables(index).getGuid());\r
- }\r
- if (!isEmpty(vid.getVariables(index).getUsage())) {\r
- p.setUsage(VariableUsage.Enum.forString(vid.getVariables(index).getUsage()));\r
- }\r
- if (!isEmpty(vid.getVariables(index).getFeatureFlag())) {\r
- p.setFeatureFlag(vid.getVariables(index).getFeatureFlag());\r
- }\r
- if (vid.getVariables(index).getSupArchList() != null\r
- && vid.getVariables(index).getSupArchList().size() > 0) {\r
- p.setSupArchList(vid.getVariables(index).getSupArchList());\r
- }\r
- if (!isEmpty(vid.getVariables(index).getHelp())) {\r
- p.setHelpText(vid.getVariables(index).getHelp());\r
- }\r
- this.variables.addNewVariable();\r
- this.variables.setVariableArray(variables.getVariableList().size() - 1, p);\r
- }\r
- }\r
-\r
- this.msa.setVariables(variables);\r
- this.omt.setSaved(false);\r
- } catch (Exception e) {\r
- Log.wrn("Update Variables", e.getMessage());\r
- Log.err("Update Variables", e.getMessage());\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r
- *\r
- */\r
- public void valueChanged(ListSelectionEvent arg0) {\r
- if (arg0.getValueIsAdjusting()) {\r
- return;\r
- }\r
- ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r
- if (lsm.isSelectionEmpty()) {\r
- return;\r
- } else {\r
- selectedRow = lsm.getMinSelectionIndex();\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r
- *\r
- */\r
- public void mouseClicked(MouseEvent arg0) {\r
- if (arg0.getClickCount() == 2) {\r
- if (this.selectedRow < 0) {\r
- return;\r
- } else {\r
- showEdit(selectedRow);\r
- }\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r
- * \r
- * Override componentResized to resize all components when frame's size is changed\r
- */\r
- public void componentResized(ComponentEvent arg0) {\r
- int intCurrentWidth = this.getJContentPane().getWidth();\r
- int intCurrentHeight = this.getJContentPane().getHeight();\r
- int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r
- int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r
-\r
- Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
- intPreferredHeight);\r
- Tools.relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
- intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON,\r
- DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r
- Tools.relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
- intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON,\r
- DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r
- Tools.relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
- intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON,\r
- DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r
- }\r
-}\r