X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FFrameworkWizard%2Fsrc%2Forg%2Ftianocore%2Fframeworkwizard%2Fmodule%2Fui%2FModuleLibraryClassDefinitions.java;h=1decd0fa32b87e8bed4a98f885f84a3da9b4f7e7;hp=a815c8549bd43eee0199a2454d6fd4ee698fb809;hb=623db5caebe9ecf6ef8f78a46a0495761fe1912b;hpb=79cb6fdbc073e47380880d84c3eef43bef0c0826 diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleLibraryClassDefinitions.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleLibraryClassDefinitions.java index a815c8549b..1decd0fa32 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleLibraryClassDefinitions.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleLibraryClassDefinitions.java @@ -17,16 +17,15 @@ package org.tianocore.frameworkwizard.module.ui; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ComponentEvent; -import java.awt.event.ItemEvent; +import java.awt.event.MouseEvent; import java.util.Vector; import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; import org.tianocore.LibraryClassDefinitionsDocument; import org.tianocore.LibraryUsage; @@ -34,17 +33,15 @@ import org.tianocore.ModuleSurfaceAreaDocument; import org.tianocore.LibraryClassDefinitionsDocument.LibraryClassDefinitions; import org.tianocore.LibraryClassDocument.LibraryClass; import org.tianocore.frameworkwizard.common.DataType; -import org.tianocore.frameworkwizard.common.DataValidation; -import org.tianocore.frameworkwizard.common.EnumerationData; +import org.tianocore.frameworkwizard.common.IDefaultTableModel; import org.tianocore.frameworkwizard.common.Log; import org.tianocore.frameworkwizard.common.Tools; import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType; +import org.tianocore.frameworkwizard.common.ui.IFrame; import org.tianocore.frameworkwizard.common.ui.IInternalFrame; -import org.tianocore.frameworkwizard.common.ui.StarLabel; -import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList; import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassIdentification; import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassVector; -import org.tianocore.frameworkwizard.workspace.WorkspaceTools; +import org.tianocore.frameworkwizard.module.ui.dialog.LibraryClassDefsDlg; /** The class is used to create, update Library Class Definition of MSA/MBD file @@ -63,61 +60,17 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { // private JPanel jContentPane = null; - private JComboBox jComboBoxLibraryClassName = null; - - private JLabel jLabelUsage = null; - - private JComboBox jComboBoxUsage = null; - - private JComboBox jComboBoxList = null; - private JButton jButtonAdd = null; private JButton jButtonRemove = null; private JButton jButtonUpdate = null; - private JLabel jLabelLibraryClassName = null; - - private JScrollPane jScrollPaneList = null; - private JScrollPane jScrollPane = null; - private JTextArea jTextAreaList = null; - - private StarLabel jStarLabel1 = null; - - private StarLabel jStarLabel2 = null; - - private ICheckBoxList iCheckBoxListArch = null; - - private JScrollPane jScrollPaneArch = null; - - private JLabel jLabelRecommendedInstanceVersion = null; - - private JTextField jTextFieldRecommendedInstanceVersion = null; - - private JLabel jLabelRecommendedInstanceGuid = null; - - private JTextField jTextFieldRecommendedInstanceGuid = null; - - private JButton jButtonGenerateGuid = null; - - private JLabel jLabelFeatureFlag = null; + private JScrollPane jScrollPaneTable = null; - private JTextField jTextFieldFeatureFlag = null; - - private JLabel jLabelArch = null; - - private JLabel jLabelModuleList = null; - - private JScrollPane jScrollPaneModuleList = null; - - private ICheckBoxList iCheckBoxListModule = null; - - private JLabel jLabelHelpText = null; - - private JTextField jTextFieldHelpText = null; + private JTable jTable = null; // // Not for UI @@ -128,65 +81,11 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { private LibraryClassVector vLibraryClass = new LibraryClassVector(); - private EnumerationData ed = new EnumerationData(); - - private Vector vLib = new Vector(); - - private int intSelectedItemId = 0; - - private WorkspaceTools wt = new WorkspaceTools(); - - private LibraryClassIdentification lcid = null; - private OpeningModuleType omt = null; - /** - This method initializes jComboBoxSelect - - @return javax.swing.JComboBox jComboBoxSelect - - **/ - private JComboBox getJComboBoxLibraryClassName() { - if (jComboBoxLibraryClassName == null) { - jComboBoxLibraryClassName = new JComboBox(); - jComboBoxLibraryClassName.setBounds(new java.awt.Rectangle(160, 10, 320, 20)); - jComboBoxLibraryClassName.setPreferredSize(new Dimension(320, 20)); - jComboBoxLibraryClassName.setEnabled(true); - } - return jComboBoxLibraryClassName; - } - - /** - This method initializes jComboBoxUsage - - @return javax.swing.JComboBox jComboBoxUsage - - **/ - private JComboBox getJComboBoxUsage() { - if (jComboBoxUsage == null) { - jComboBoxUsage = new JComboBox(); - jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20)); - jComboBoxUsage.setPreferredSize(new Dimension(320, 20)); - } - return jComboBoxUsage; - } + private IDefaultTableModel model = null; - /** - This method initializes jComboBoxFileList - - @return javax.swing.JComboBox jComboBoxFileList - - **/ - private JComboBox getJComboBoxList() { - if (jComboBoxList == null) { - jComboBoxList = new JComboBox(); - jComboBoxList.setBounds(new java.awt.Rectangle(15, 330, 210, 20)); - jComboBoxList.setPreferredSize(new Dimension(210, 20)); - jComboBoxList.addItemListener(this); - jComboBoxList.addActionListener(this); - } - return jComboBoxList; - } + private int selectedRow = -1; /** This method initializes jButtonAdd @@ -232,28 +131,13 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { if (jButtonUpdate == null) { jButtonUpdate = new JButton(); jButtonUpdate.setBounds(new java.awt.Rectangle(315, 330, 80, 20)); - jButtonUpdate.setText("Update"); + jButtonUpdate.setText("Edit"); jButtonUpdate.setPreferredSize(new Dimension(80, 20)); jButtonUpdate.addActionListener(this); } return jButtonUpdate; } - /** - This method initializes jScrollPane - - @return javax.swing.JScrollPane - */ - private JScrollPane getJScrollPaneList() { - if (jScrollPaneList == null) { - jScrollPaneList = new JScrollPane(); - jScrollPaneList.setBounds(new java.awt.Rectangle(15, 355, 465, 100)); - jScrollPaneList.setPreferredSize(new Dimension(465, 260)); - jScrollPaneList.setViewportView(getJTextAreaList()); - } - return jScrollPaneList; - } - /** This method initializes jScrollPane @@ -268,147 +152,41 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { } /** - * This method initializes jTextAreaList - * - * @return javax.swing.JTextArea - */ - private JTextArea getJTextAreaList() { - if (jTextAreaList == null) { - jTextAreaList = new JTextArea(); - jTextAreaList.setEditable(false); - } - return jTextAreaList; - } - - /** - * This method initializes jTextFieldRecommendedInstanceVersion - * - * @return javax.swing.JTextField - */ - private JTextField getJTextFieldRecommendedInstanceVersion() { - if (jTextFieldRecommendedInstanceVersion == null) { - jTextFieldRecommendedInstanceVersion = new JTextField(); - jTextFieldRecommendedInstanceVersion.setPreferredSize(new java.awt.Dimension(260, 20)); - jTextFieldRecommendedInstanceVersion.setSize(new java.awt.Dimension(260, 20)); - jTextFieldRecommendedInstanceVersion.setLocation(new java.awt.Point(220, 85)); - } - return jTextFieldRecommendedInstanceVersion; - } - - /** - * This method initializes jTextFieldRecommendedInstanceGuid - * - * @return javax.swing.JTextField - */ - private JTextField getJTextFieldRecommendedInstanceGuid() { - if (jTextFieldRecommendedInstanceGuid == null) { - jTextFieldRecommendedInstanceGuid = new JTextField(); - jTextFieldRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(220, 110, 190, 20)); - jTextFieldRecommendedInstanceGuid.setPreferredSize(new java.awt.Dimension(190, 20)); - } - return jTextFieldRecommendedInstanceGuid; - } - - /** - * This method initializes jButtonGenerateGuid - * - * @return javax.swing.JButton - */ - private JButton getJButtonGenerateGuid() { - if (jButtonGenerateGuid == null) { - jButtonGenerateGuid = new JButton(); - jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 110, 65, 20)); - jButtonGenerateGuid.setPreferredSize(new java.awt.Dimension(65, 20)); - jButtonGenerateGuid.setText("GEN"); - jButtonGenerateGuid.addActionListener(this); - } - return jButtonGenerateGuid; - } - - /** - * This method initializes jTextFieldFeatureFlag - * - * @return javax.swing.JTextField - */ - private JTextField getJTextFieldFeatureFlag() { - if (jTextFieldFeatureFlag == null) { - jTextFieldFeatureFlag = new JTextField(); - jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 135, 320, 20)); - jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20)); - } - return jTextFieldFeatureFlag; - } - - /** - This method initializes iCheckBoxListArch + This method initializes jScrollPaneTable - @return ICheckBoxList + @return javax.swing.JScrollPane **/ - private ICheckBoxList getICheckBoxListSupportedArchitectures() { - if (iCheckBoxListArch == null) { - iCheckBoxListArch = new ICheckBoxList(); - iCheckBoxListArch.addFocusListener(this); + private JScrollPane getJScrollPaneTable() { + if (jScrollPaneTable == null) { + jScrollPaneTable = new JScrollPane(); + jScrollPaneTable.setBounds(new java.awt.Rectangle(15, 10, 470, 420)); + jScrollPaneTable.setPreferredSize(new Dimension(470, 420)); + jScrollPaneTable.setViewportView(getJTable()); } - return iCheckBoxListArch; + return jScrollPaneTable; } /** - This method initializes iCheckBoxListArch + This method initializes jTable - @return ICheckBoxList + @return javax.swing.JTable **/ - private ICheckBoxList getICheckBoxListSupModuleList() { - if (iCheckBoxListModule == null) { - iCheckBoxListModule = new ICheckBoxList(); - } - return iCheckBoxListModule; - } + private JTable getJTable() { + if (jTable == null) { + jTable = new JTable(); + model = new IDefaultTableModel(); + jTable = new JTable(model); + jTable.setRowHeight(20); - /** - This method initializes jScrollPaneArch - - @return javax.swing.JScrollPane - - **/ - private JScrollPane getJScrollPaneArch() { - if (jScrollPaneArch == null) { - jScrollPaneArch = new JScrollPane(); - jScrollPaneArch.setBounds(new java.awt.Rectangle(160, 160, 320, 80)); - jScrollPaneArch.setPreferredSize(new java.awt.Dimension(320, 80)); - jScrollPaneArch.setViewportView(getICheckBoxListSupportedArchitectures()); - } - return jScrollPaneArch; - } - - /** - This method initializes jScrollPaneModuleList - - @return javax.swing.JScrollPane - - **/ - private JScrollPane getJScrollPaneModuleList() { - if (jScrollPaneModuleList == null) { - jScrollPaneModuleList = new JScrollPane(); - jScrollPaneModuleList.setBounds(new java.awt.Rectangle(160, 245, 320, 80)); - jScrollPaneModuleList.setPreferredSize(new java.awt.Dimension(320, 80)); - jScrollPaneModuleList.setViewportView(getICheckBoxListSupModuleList()); - } - return jScrollPaneModuleList; - } + model.addColumn("Library Class Name"); + model.addColumn("Usage"); - /** - This method initializes jTextFieldHelpText - - @return javax.swing.JTextField - - **/ - private JTextField getJTextFieldHelpText() { - if (jTextFieldHelpText == null) { - jTextFieldHelpText = new JTextField(); - jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 60, 320, 20)); - jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20)); + jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + jTable.getSelectionModel().addListSelectionListener(this); + jTable.getModel().addTableModelListener(this); + jTable.addMouseListener(this); } - return jTextFieldHelpText; + return jTable; } public static void main(String[] args) { @@ -435,39 +213,10 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { super(); this.omt = inOmt; this.msa = omt.getXmlMsa(); - initLibraryClass(); init(msa.getLibraryClassDefinitions()); this.setVisible(true); } - // private void initLibraryClass(MsaHeaderDocument.MsaHeader msaHeader) { - // Enum e = msaHeader.getModuleType(); - // if (e == ModuleTypeDef.BASE) { - // vLib = ed.getVLibClassDefBase(); - // } else if (e == ModuleTypeDef.PEI_CORE) { - // vLib = ed.getVLibClassDefPei(); - // } else if (e == ModuleTypeDef.PEIM) { - // vLib = ed.getVLibClassDefPeim(); - // } else if (e == ModuleTypeDef.DXE_CORE) { - // vLib = ed.getVLibClassDefDxeCore(); - // } else if (e == ModuleTypeDef.DXE_DRIVER) { - // vLib = ed.getVLibClassDefDxeDriver(); - // } else if (e == ModuleTypeDef.DXE_SMM_DRIVER) { - // vLib = ed.getVLibClassDefDxeSmmDriver(); - // } else if (e == ModuleTypeDef.UEFI_DRIVER) { - // vLib = ed.getVLibClassDefUefiDriver(); - // } else { - // //vLib = ed.getVLibClassDef(); - // } - // } - - /** - - **/ - private void initLibraryClass() { - vLib = wt.getAllLibraryClassDefinitionsFromWorkspace(); - } - /** This method initializes this Fill values to all fields if these values are not empty @@ -484,7 +233,7 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { String name = lcd.getLibraryClassList().get(index).getKeyword(); String usage = null; if (lcd.getLibraryClassList().get(index).getUsage() != null) { - usage = lcd.getLibraryClassList().get(index).getUsage().toString(); + usage = lcd.getLibraryClassList().get(index).getUsage().toString(); } String version = lcd.getLibraryClassList().get(index).getRecommendedInstanceVersion(); String guid = lcd.getLibraryClassList().get(index).getRecommendedInstanceGuid(); @@ -503,8 +252,7 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { // // Update the list // - Tools.generateComboBoxByVector(jComboBoxList, vLibraryClass.getLibraryClassName()); - reloadListArea(); + showTable(); } /** @@ -515,21 +263,6 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { this.setContentPane(getJScrollPane()); this.setTitle("Library Class Definitions"); this.setBounds(new java.awt.Rectangle(0, 0, 500, 515)); - initFrame(); - this.setViewMode(false); - } - - /** - Disable all components when the mode is view - - @param isView true - The view mode; false - The non-view mode - - **/ - public void setViewMode(boolean isView) { - if (isView) { - this.jComboBoxLibraryClassName.setEnabled(!isView); - this.jComboBoxUsage.setEnabled(!isView); - } } /** @@ -540,159 +273,18 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { **/ private JPanel getJContentPane() { if (jContentPane == null) { - jLabelHelpText = new JLabel(); - jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 140, 20)); - jLabelHelpText.setText("Help Text"); - jLabelModuleList = new JLabel(); - jLabelModuleList.setBounds(new java.awt.Rectangle(15, 245, 140, 20)); - jLabelModuleList.setText("Sup Module List"); - jLabelArch = new JLabel(); - jLabelArch.setBounds(new java.awt.Rectangle(15, 160, 140, 20)); - jLabelArch.setText("Sup Arch List"); - jLabelFeatureFlag = new JLabel(); - jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 135, 140, 20)); - jLabelFeatureFlag.setText("Feature Flag"); - jLabelRecommendedInstanceGuid = new JLabel(); - jLabelRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(15, 110, 200, 20)); - jLabelRecommendedInstanceGuid.setText("Recommended Instance Guid"); - jLabelRecommendedInstanceVersion = new JLabel(); - jLabelRecommendedInstanceVersion.setBounds(new java.awt.Rectangle(15, 85, 200, 20)); - jLabelRecommendedInstanceVersion.setText("Recommended Instance Version"); - jLabelLibraryClassName = new JLabel(); - jLabelLibraryClassName.setBounds(new java.awt.Rectangle(15, 10, 140, 20)); - jLabelLibraryClassName.setText("Library Class Name"); - jLabelUsage = new JLabel(); - jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 140, 20)); - jLabelUsage.setText("Usage"); jContentPane = new JPanel(); jContentPane.setLayout(null); - jContentPane.setPreferredSize(new java.awt.Dimension(490, 465)); - - jContentPane.add(getJComboBoxLibraryClassName(), null); - jContentPane.add(jLabelUsage, null); - jContentPane.add(getJComboBoxUsage(), null); - jContentPane.add(jLabelLibraryClassName, null); - jContentPane.add(getJScrollPaneList(), null); - jContentPane.add(getJComboBoxList(), null); + jContentPane.setPreferredSize(new java.awt.Dimension(490, 490)); + jContentPane.add(getJButtonAdd(), null); jContentPane.add(getJButtonRemove(), null); jContentPane.add(getJButtonUpdate(), null); - jContentPane.add(jLabelRecommendedInstanceVersion, null); - jContentPane.add(getJTextFieldRecommendedInstanceVersion(), null); - jContentPane.add(jLabelRecommendedInstanceGuid, null); - jContentPane.add(getJTextFieldRecommendedInstanceGuid(), null); - jContentPane.add(getJButtonGenerateGuid(), null); - jContentPane.add(jLabelFeatureFlag, null); - jContentPane.add(getJTextFieldFeatureFlag(), null); - jContentPane.add(jLabelArch, null); - jContentPane.add(getJScrollPaneArch(), null); - jStarLabel1 = new StarLabel(); - jStarLabel1.setLocation(new java.awt.Point(0, 10)); - jStarLabel2 = new StarLabel(); - jStarLabel2.setLocation(new java.awt.Point(0, 35)); - - jContentPane.add(jStarLabel1, null); - jContentPane.add(jStarLabel2, null); - jContentPane.add(jLabelModuleList, null); - jContentPane.add(getJScrollPaneModuleList(), null); - jContentPane.add(jLabelHelpText, null); - jContentPane.add(getJTextFieldHelpText(), null); + jContentPane.add(getJScrollPaneTable(), null); } return jContentPane; } - /** - This method initializes all existing libraries and usage types - - **/ - private void initFrame() { - Tools.generateComboBoxByVector(jComboBoxLibraryClassName, vLib); - Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVLibraryUsage()); - this.iCheckBoxListArch.setAllItems(ed.getVSupportedArchitectures()); - this.iCheckBoxListModule.setAllItems(ed.getVFrameworkModuleTypes()); - } - - /* (non-Javadoc) - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - * - * Override actionPerformed to listen all actions - * - */ - public void actionPerformed(ActionEvent arg0) { - if (arg0.getSource() == jButtonAdd) { - if (!checkAdd()) { - return; - } - addToList(); - } - if (arg0.getSource() == jButtonRemove) { - removeFromList(); - } - if (arg0.getSource() == jButtonUpdate) { - updateForList(); - } - if (arg0.getSource() == jButtonGenerateGuid) { - this.jTextFieldRecommendedInstanceGuid.setText(Tools.generateUuidString()); - } - } - - /** - Data validation for all fields - - @retval true - All datas are valid - @retval false - At least one data is invalid - - **/ - public boolean checkAdd() { - // - // Check LibraryClass - // - if (this.jComboBoxLibraryClassName.getSelectedItem() == null) { - Log.err("No Library Class can be added"); - return false; - } - if (!DataValidation.isLibraryClass(this.jComboBoxLibraryClassName.getSelectedItem().toString())) { - Log.err("Incorrect data type for Library Class"); - return false; - } - - // - // Check RecommendedInstanceVersion - // - if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) { - if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) { - Log.err("Incorrect data type for Recommended Instance Version"); - return false; - } - } - - // - // Check RecommendedInstanceGuid - // - if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) { - if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) { - Log.err("Incorrect data type for Recommended Instance Guid"); - return false; - } - } - - // - // Check FeatureFlag - // - if (!isEmpty(this.jTextFieldFeatureFlag.getText())) { - if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) { - Log.err("Incorrect data type for Feature Flag"); - return false; - } - } - - if (this.vLibraryClass.findLibraryClass(this.jComboBoxLibraryClassName.getSelectedItem().toString()) > -1) { - Log.err("The Library Class has been added already!"); - return false; - } - return true; - } - /** Save all components of Mbd Header if exists mbdHeader, set the value directly @@ -742,179 +334,116 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { this.omt.setSaved(false); } catch (Exception e) { + Log.wrn("Update Library Class Definitions", e.getMessage()); Log.err("Update Library Class Definitions", e.getMessage()); } } - private LibraryClassIdentification getCurrentLibraryClass() { - String name = this.jComboBoxLibraryClassName.getSelectedItem().toString(); - String usage = this.jComboBoxUsage.getSelectedItem().toString(); - String version = this.jTextFieldRecommendedInstanceVersion.getText(); - String guid = this.jTextFieldRecommendedInstanceGuid.getText(); - String featureFlag = this.jTextFieldFeatureFlag.getText(); - Vector arch = this.iCheckBoxListArch.getAllCheckedItemsString(); - Vector module = this.iCheckBoxListModule.getAllCheckedItemsString(); - String help = this.jTextFieldHelpText.getText(); - lcid = new LibraryClassIdentification(name, usage, version, guid, arch, featureFlag, module, help); - return lcid; - } - - /** - Add current item to Vector - - **/ - private void addToList() { - intSelectedItemId = vLibraryClass.size(); - - vLibraryClass.addLibraryClass(getCurrentLibraryClass()); - - jComboBoxList.addItem(lcid.getLibraryClassName()); - jComboBoxList.setSelectedItem(lcid.getLibraryClassName()); - - // - // Reset select item index - // - intSelectedItemId = vLibraryClass.size(); - - // - // Reload all fields of selected item - // - reloadFromList(); - - // - // Save to memory - // - save(); + private void showEdit(int index) { + LibraryClassDefsDlg mcdd = new LibraryClassDefsDlg(vLibraryClass.getLibraryClass(index), new IFrame()); + int result = mcdd.showDialog(); + if (result == DataType.RETURN_TYPE_OK) { + if (index == -1) { + this.vLibraryClass.addLibraryClass(mcdd.getLcid()); + } else { + this.vLibraryClass.setLibraryClass(mcdd.getLcid(), index); + } + this.showTable(); + this.save(); + mcdd.dispose(); + } + if (result == DataType.RETURN_TYPE_CANCEL) { + mcdd.dispose(); + } } - /** - Remove current item from Vector - - **/ - private void removeFromList() { - // - // Check if exist items - // - if (this.vLibraryClass.size() < 1) { - return; + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + * + * Override actionPerformed to listen all actions + * + */ + public void actionPerformed(ActionEvent arg0) { + if (arg0.getSource() == jButtonAdd) { + showEdit(-1); + } + if (arg0.getSource() == jButtonUpdate) { + if (this.selectedRow < 0) { + Log.wrn("Update Library Class Definitions", "Please select one record first."); + return; + } + showEdit(selectedRow); } - int intTempIndex = intSelectedItemId; - - jComboBoxList.removeItemAt(intSelectedItemId); - - vLibraryClass.removeLibraryClass(intTempIndex); - - // - // Reload all fields of selected item - // - reloadFromList(); - - // - // Save to memory - // - save(); + if (arg0.getSource() == jButtonRemove) { + if (jTable.isEditing()) { + jTable.getCellEditor().stopCellEditing(); + } + if (selectedRow > -1) { + this.model.removeRow(selectedRow); + this.vLibraryClass.removeLibraryClass(selectedRow); + selectedRow = -1; + this.save(); + } + } } /** - Update current item of Vector + Clear all table rows **/ - private void updateForList() { - // - // Check if exist items - // - if (this.vLibraryClass.size() < 1) { - return; - } - - // - // Backup selected item index - // - int intTempIndex = intSelectedItemId; - - vLibraryClass.updateLibraryClass(getCurrentLibraryClass(), intTempIndex); - - jComboBoxList.removeAllItems(); - for (int index = 0; index < vLibraryClass.size(); index++) { - jComboBoxList.addItem(vLibraryClass.getLibraryClass(index).getLibraryClassName()); + private void clearAll() { + if (model != null) { + for (int index = model.getRowCount() - 1; index >= 0; index--) { + model.removeRow(index); + } } - - // - // Restore selected item index - // - intSelectedItemId = intTempIndex; - - // - // Reset select item index - // - jComboBoxList.setSelectedIndex(intSelectedItemId); - - // - // Reload all fields of selected item - // - reloadFromList(); - - // - // Save to memory - // - save(); } /** - Refresh all fields' values of selected item of Vector + Read content of vector and put then into table **/ - private void reloadFromList() { + private void showTable() { + clearAll(); + if (vLibraryClass.size() > 0) { - // - // Get selected item index - // - intSelectedItemId = jComboBoxList.getSelectedIndex(); - - this.jComboBoxLibraryClassName.setSelectedItem(vLibraryClass.getLibraryClass(intSelectedItemId) - .getLibraryClassName()); - this.jComboBoxUsage.setSelectedItem(vLibraryClass.getLibraryClass(intSelectedItemId).getUsage()); - this.jTextFieldRecommendedInstanceVersion.setText(vLibraryClass.getLibraryClass(intSelectedItemId) - .getRecommendedInstanceVersion()); - this.jTextFieldRecommendedInstanceGuid.setText(vLibraryClass.getLibraryClass(intSelectedItemId) - .getRecommendedInstanceGuid()); - this.jTextFieldFeatureFlag.setText(vLibraryClass.getLibraryClass(intSelectedItemId).getFeatureFlag()); - this.iCheckBoxListArch.setAllItemsUnchecked(); - this.iCheckBoxListArch.initCheckedItem(true, vLibraryClass.getLibraryClass(intSelectedItemId) - .getSupArchList()); - this.iCheckBoxListModule.setAllItemsUnchecked(); - this.iCheckBoxListModule.initCheckedItem(true, vLibraryClass.getLibraryClass(intSelectedItemId) - .getSupModuleList()); - this.jTextFieldHelpText.setText(vLibraryClass.getLibraryClass(intSelectedItemId).getHelp()); - } else { + for (int index = 0; index < vLibraryClass.size(); index++) { + model.addRow(vLibraryClass.toStringVector(index)); + } } - - reloadListArea(); + this.jTable.repaint(); + this.jTable.updateUI(); + //this.jScrollPane.setViewportView(this.jTable); } - /** - Update list area pane via the elements of Vector - - **/ - private void reloadListArea() { - String strListItem = ""; - for (int index = 0; index < vLibraryClass.size(); index++) { - strListItem = strListItem + vLibraryClass.getLibraryClass(index).getLibraryClassName() - + DataType.UNIX_LINE_SEPARATOR; + /* (non-Javadoc) + * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) + * + */ + public void valueChanged(ListSelectionEvent arg0) { + if (arg0.getValueIsAdjusting()) { + return; + } + ListSelectionModel lsm = (ListSelectionModel) arg0.getSource(); + if (lsm.isSelectionEmpty()) { + return; + } else { + selectedRow = lsm.getMinSelectionIndex(); } - this.jTextAreaList.setText(strListItem); } /* (non-Javadoc) - * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) + * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) * - * Reflesh the frame when selected item changed - * */ - public void itemStateChanged(ItemEvent arg0) { - if (arg0.getStateChange() == ItemEvent.SELECTED) { - reloadFromList(); + public void mouseClicked(MouseEvent arg0) { + if (arg0.getClickCount() == 2) { + if (this.selectedRow < 0) { + return; + } else { + showEdit(selectedRow); + } } } @@ -929,24 +458,16 @@ public class ModuleLibraryClassDefinitions extends IInternalFrame { int intPreferredWidth = this.getJContentPane().getPreferredSize().width; int intPreferredHeight = this.getJContentPane().getPreferredSize().height; - resizeComponentWidth(this.jComboBoxLibraryClassName, intCurrentWidth, intPreferredWidth); - resizeComponentWidth(this.jComboBoxUsage, intCurrentWidth, intPreferredWidth); - resizeComponentWidth(this.jTextFieldHelpText, intCurrentWidth, intPreferredWidth); - resizeComponentWidth(this.jTextFieldRecommendedInstanceVersion, intCurrentWidth, intPreferredWidth); - resizeComponentWidth(this.jTextFieldRecommendedInstanceGuid, intCurrentWidth, intPreferredWidth); - resizeComponentWidth(this.jTextFieldFeatureFlag, intCurrentWidth, intPreferredWidth); - resizeComponentWidth(this.jScrollPaneArch, intCurrentWidth, intPreferredWidth); - resizeComponentWidth(this.jScrollPaneModuleList, intCurrentWidth, intPreferredWidth); - - relocateComponentX(this.jButtonGenerateGuid, intCurrentWidth, intPreferredWidth, - DataType.SPACE_TO_RIGHT_FOR_GENERATE_BUTTON); - - resizeComponentWidth(this.jComboBoxList, intCurrentWidth, intPreferredWidth); - resizeComponent(this.jScrollPaneList, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight); - relocateComponentX(this.jButtonAdd, intCurrentWidth, intPreferredWidth, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON); - relocateComponentX(this.jButtonRemove, intCurrentWidth, intPreferredWidth, - DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON); - relocateComponentX(this.jButtonUpdate, intCurrentWidth, intPreferredWidth, - DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON); + Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth, + intPreferredHeight); + Tools.relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth, + intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON, + DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON); + Tools.relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth, + intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON, + DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON); + Tools.relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth, + intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON, + DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON); } }