From a88ddd993f1f44f4d383649bdcf30b8b4df76e8d Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Feb 22 2011 23:02:10 +0000 Subject: Bug 450016 - RFE- Console display values in KB/MB/GB https://bugzilla.redhat.com/show_bug.cgi?id=450016 Description: Entry cache size in Database Settings as well as DB cache size and Import cache size in LDBM Plug-in Settings allow users to choose display unit from bytes, KB, MB, and GB. The value in the text area is recalculated based upon the unit. Note: The size value sent to the server is in bytes regardless of the unit selection. Also, the selected unit is not stored. Every time, the Console is started, the default unit "bytes" is selected and the size is displayed in bytes. --- diff --git a/src/com/netscape/admin/dirserv/dirserv.properties b/src/com/netscape/admin/dirserv/dirserv.properties index 3c045c1..14e9eca 100644 --- a/src/com/netscape/admin/dirserv/dirserv.properties +++ b/src/com/netscape/admin/dirserv/dirserv.properties @@ -1467,7 +1467,11 @@ CreateVLVIndex-deleteIndex-title=Delete Browsing Index # pldbmsetting-title=LDBM Plug-in Settings pldbmsetting-maxCacheSize-label=Maximum cache size: -pldbmsetting-maxCacheSize-unit-label=bytes +pldbmsetting-maxCacheSizeUnits-default=bytes +pldbmsetting-maxCacheSizeUnits-1=bytes +pldbmsetting-maxCacheSizeUnits-2=KB +pldbmsetting-maxCacheSizeUnits-3=MB +pldbmsetting-maxCacheSizeUnits-4=GB pldbmsetting-maxCacheSize-ttip=Memory available for all indexes pldbmsetting-maxCacheSize-default=1000000 pldbmsetting-maxCacheSize-columns=15 @@ -1486,7 +1490,11 @@ pldbmsetting-RootDatabaseLoc-ttip= Full path to the database location on the ser pldbmsetting-RootDatabaseLoc-columns=15 pldbmsetting-importCacheSize-label=Import cache size: pldbmsetting-importCacheSize-ttip= Size of cache used for import -pldbmsetting-importCacheSize-unit-label=bytes +pldbmsetting-importCacheSizeUnits-default=bytes +pldbmsetting-importCacheSizeUnits-1=bytes +pldbmsetting-importCacheSizeUnits-2=KB +pldbmsetting-importCacheSizeUnits-3=MB +pldbmsetting-importCacheSizeUnits-4=GB pldbmsetting-importCacheSize-columns=15 pldbmsetting-autoCacheSize-label=Use Import Cache Auto-Size pldbmsetting-autoCacheSize-ttip=If import cache auto-size is used, the server will automatically figure out the optimal amount of memory to use @@ -1525,7 +1533,11 @@ dbsettings-confirm-delete-msg=Delete suffix(es) %0? dbsettings-suffix-label=Suffix: dbsettings-suffix-ttip=Suffix maintained by this database. dbsettings-cachememsize-label=Memory available for cache -dbsettings-cachememsize-unit-label=bytes +dbsettings-cachememsizeunits-default=bytes +dbsettings-cachememsizeunits-1=bytes +dbsettings-cachememsizeunits-2=KB +dbsettings-cachememsizeunits-3=MB +dbsettings-cachememsizeunits-4=GB dbsettings-cachememsize-ttip=Maximum memory available to the database for storing cached entries # # SNMP setting panel diff --git a/src/com/netscape/admin/dirserv/panel/BlankPanel.java b/src/com/netscape/admin/dirserv/panel/BlankPanel.java index dc0a67e..e7f3d72 100644 --- a/src/com/netscape/admin/dirserv/panel/BlankPanel.java +++ b/src/com/netscape/admin/dirserv/panel/BlankPanel.java @@ -952,6 +952,54 @@ public class BlankPanel extends JPanel * Add a label and a textfield to a panel, assumed to be using * GridBagLayout. */ + protected void addEntryField( JPanel panel, JComponent label, + JComponent field, JComponent unit ) { + Component endGlue = STRETCH_FIELDS ? null : Box.createGlue(); + Component lastItem = + STRETCH_FIELDS ? ((unit != null) ? unit : field) : endGlue; + GridBagConstraints gbc = getGBC(); + gbc.fill = gbc.NONE; + gbc.weightx = 0.0; + gbc.gridwidth = 1; + gbc.gridx = 0; + gbc.anchor = gbc.EAST; + int space = UIFactory.getComponentSpace(); + gbc.insets = new Insets( space, space, 0, space/2 ); + panel.add( label, gbc ); + + gbc.gridx++; + gbc.anchor = gbc.WEST; + gbc.insets = new Insets( space, 0, 0, 0 ); + if ( STRETCH_FIELDS ) { + gbc.fill = gbc.HORIZONTAL; + gbc.weightx = 1.0; + } + gbc.gridwidth = (lastItem == field) ? gbc.REMAINDER : 1; + panel.add( field, gbc ); + + if ( unit != null ) { + gbc.gridx++; + gbc.fill = gbc.NONE; + gbc.weightx = 0.0; + gbc.insets = new Insets( space, space/2, 0, 0 ); + gbc.gridwidth = (lastItem == unit) ? gbc.REMAINDER : 1; + panel.add( unit, gbc ); + } + + if ( !STRETCH_FIELDS ) { + gbc.gridx++; + gbc.anchor = gbc.EAST; + gbc.fill = gbc.HORIZONTAL; + gbc.weightx = 1.0; + gbc.gridwidth = gbc.REMAINDER; + panel.add( endGlue, gbc ); + } + } + + /** + * Add a label and a textfield to a panel, assumed to be using + * GridBagLayout. + */ protected void addEntryField( JPanel panel, JComponent label, JComponent field ) { addEntryField( panel, label, field, null ); diff --git a/src/com/netscape/admin/dirserv/panel/DSEntryLong.java b/src/com/netscape/admin/dirserv/panel/DSEntryLong.java index d5fa5a9..048e39f 100644 --- a/src/com/netscape/admin/dirserv/panel/DSEntryLong.java +++ b/src/com/netscape/admin/dirserv/panel/DSEntryLong.java @@ -322,6 +322,24 @@ public class DSEntryLong extends DSEntry { return _maxValue; } + /** + * Set the scale factor. + * + * @param scaleFactor scale factor for this field + */ + public void setScaleFactor( long scaleFactor ) { + _scaleFactor = scaleFactor; + } + + /** + * Report the scale factor. + * + * @returns Scale factor for this field + */ + public long getScaleFactor() { + return _scaleFactor; + } + protected long _minValue; protected long _maxValue; protected long _scaleFactor = 1; diff --git a/src/com/netscape/admin/dirserv/panel/LDBMInstancePanel.java b/src/com/netscape/admin/dirserv/panel/LDBMInstancePanel.java index aacb24a..48e5004 100644 --- a/src/com/netscape/admin/dirserv/panel/LDBMInstancePanel.java +++ b/src/com/netscape/admin/dirserv/panel/LDBMInstancePanel.java @@ -42,7 +42,7 @@ public class LDBMInstancePanel extends DSTabbedPanel { addTab( _settingsTab = new LDBMSettingsPanel( model, dbEntry )); - addTab( _attrEnc = new LDBMAttrEncPanel( model, dbEntry.getDN())); + addTab( _attrEnc = new LDBMAttrEncPanel( model, dbEntry.getDN())); _tabbedPane.setSelectedIndex( 0 ); } @@ -51,5 +51,5 @@ public class LDBMInstancePanel extends DSTabbedPanel { private BlankPanel _passwordTab; private BlankPanel _performanceTab; private BlankPanel _settingsTab; - private BlankPanel _attrEnc; + private BlankPanel _attrEnc; } diff --git a/src/com/netscape/admin/dirserv/panel/LDBMPluginSettingPanel.java b/src/com/netscape/admin/dirserv/panel/LDBMPluginSettingPanel.java index 08b478b..c9972f8 100644 --- a/src/com/netscape/admin/dirserv/panel/LDBMPluginSettingPanel.java +++ b/src/com/netscape/admin/dirserv/panel/LDBMPluginSettingPanel.java @@ -46,17 +46,16 @@ public class LDBMPluginSettingPanel extends BlankPanel { _refreshWhenSelect = false; } - public void init() { - - if (_isInitialized) { - return; - } - /* Memory available for all indexes */ + public void init() { + + if (_isInitialized) { + return; + } + /* DB cache memory available for all entries/indexes */ _tfMaxCacheSize = makeNumericalJTextField( _section, "maxCacheSize" ); _lMaxCacheSize = makeJLabel( _section,"maxCacheSize" ); _lMaxCacheSize.setLabelFor(_tfMaxCacheSize); - JLabel lMaxCacheSizeUnit = makeJLabel( _section,"maxCacheSize-unit" ); - lMaxCacheSizeUnit.setLabelFor(_tfMaxCacheSize); + _cbMaxCacheSizeUnit = makeJComboBox(_section, "maxCacheSizeUnits", null); /* Max entries the server checks in response to a search */ _tfLookLimit = makeNumericalJTextField( _section, "lookLimit" ); @@ -84,21 +83,19 @@ public class LDBMPluginSettingPanel extends BlankPanel { _tfImportCacheSize = makeJTextField(_section,"importCacheSize"); _lImportCacheSize = makeJLabel( _section,"importCacheSize" ); _lImportCacheSize.setLabelFor(_tfImportCacheSize); - JLabel lImportCacheSizeUnit = makeJLabel( _section,"importCacheSize-unit" ); - lImportCacheSizeUnit.setLabelFor(_tfImportCacheSize); + _cbImportCacheSizeUnit = makeJComboBox(_section, + "importCacheSizeUnits", null); Debug.println("LDBMPluginSettingPanel.init() _dnEntry :" + _dnEntry); DSEntrySet entries = getDSEntrySet(); - - DSEntryLong sizeDSEntry = new DSEntryLong(null, - _tfMaxCacheSize, _lMaxCacheSize, - CACHE_SIZE_NUM_MIN_VAL, CACHE_SIZE_NUM_MAX_VAL, 1); - entries.add(_dnEntry, PLUGINDB_CACHE_SIZE_ATTR_NAM, - sizeDSEntry); - setComponentTable(_tfMaxCacheSize, sizeDSEntry); + // Pull down menu for the dbcache size unit + _cacheSizeDSEntry = new DSEntryLong(null, _tfMaxCacheSize, _lMaxCacheSize, + CACHE_SIZE_NUM_MIN_VAL, CACHE_SIZE_NUM_MAX_VAL, 1); + entries.add(_dnEntry, PLUGINDB_CACHE_SIZE_ATTR_NAM, _cacheSizeDSEntry); + setComponentTable(_tfMaxCacheSize, _cacheSizeDSEntry); DSEntryLong lookDSEntry = new DSEntryLong(null, _tfLookLimit, _lLookLimit, @@ -121,24 +118,26 @@ public class LDBMPluginSettingPanel extends BlankPanel { entries.add(_dnEntry, IMPORT_AUTO_CACHE_SIZE_ATTR_NAME, autoDSEntry); setComponentTable(_cbAutoCacheSize, autoDSEntry); - DSEntryLong importsizeDSEntry = new DSEntryLong(null, - _tfImportCacheSize, _lImportCacheSize, - CACHE_SIZE_NUM_MIN_VAL, CACHE_SIZE_NUM_MAX_VAL, 1); - entries.add(_dnEntry, DB_IMPORT__CACHE_SIZE_ATTR_NAM, - importsizeDSEntry); - setComponentTable(_tfImportCacheSize, importsizeDSEntry); - + // Pull down menu for the import cache size unit + _importCacheSizeDSEntry = new DSEntryLong(null, + _tfImportCacheSize, _lImportCacheSize, + CACHE_SIZE_NUM_MIN_VAL, + CACHE_SIZE_NUM_MAX_VAL, 1); + entries.add(_dnEntry, DB_IMPORT_CACHE_SIZE_ATTR_NAM, + _importCacheSizeDSEntry); + setComponentTable(_tfImportCacheSize, _importCacheSizeDSEntry); JPanel panel = _myPanel; panel.setLayout( new GridBagLayout() ); - addEntryField( panel, _lMaxCacheSize, _tfMaxCacheSize, lMaxCacheSizeUnit ); + addEntryField( panel, _lMaxCacheSize, _tfMaxCacheSize, + _cbMaxCacheSizeUnit ); addEntryField( panel, _lLookLimit, _tfLookLimit, lLookLimitUnit ); addEntryField( panel, _lModeFile, _tfModeFile, lModeFileUnit ); addEntryField( panel, new JLabel(""), _cbAutoCacheSize, new JLabel("") ); addEntryField( panel, _lImportCacheSize, _tfImportCacheSize, - lImportCacheSizeUnit); - addBottomGlue(); + _cbImportCacheSizeUnit ); + addBottomGlue(); _isInitialized = true; } @@ -147,6 +146,29 @@ public class LDBMPluginSettingPanel extends BlankPanel { _tfImportCacheSize.setEnabled(enabled); _lImportCacheSize.setEnabled(enabled); } + + private void setCacheSizeUnit(JComboBox unit, DSEntryLong dsentry) { + String selectedUnit = (String)unit.getSelectedItem(); + Debug.println("actionPerformed: selected MaxCacheSizeUnit: " + + selectedUnit); + if (selectedUnit.equalsIgnoreCase("bytes")) { + dsentry.setScaleFactor(1); + dsentry.show(); + } else if (selectedUnit.equalsIgnoreCase("KB")) { + dsentry.setScaleFactor(1024); + dsentry.show(); + } else if (selectedUnit.equalsIgnoreCase("MB")) { + dsentry.setScaleFactor(1024*1024); + dsentry.show(); + } else if (selectedUnit.equalsIgnoreCase("GB")) { + dsentry.setScaleFactor(1024*1024*1024); + dsentry.show(); + } else { + Debug.println("actionPerformed: ignore unknown unit: " + + selectedUnit); + } + } + /* (non-Javadoc) * @see com.netscape.admin.dirserv.panel.BlankPanel#refresh() */ @@ -163,13 +185,20 @@ public class LDBMPluginSettingPanel extends BlankPanel { public void actionPerformed(ActionEvent e) { if (e.getSource().equals(_cbAutoCacheSize)) { enableCacheSize(); + } else if (e.getSource().equals(_cbMaxCacheSizeUnit)) { + setCacheSizeUnit(_cbMaxCacheSizeUnit, _cacheSizeDSEntry); + } else if (e.getSource().equals(_cbImportCacheSizeUnit)) { + setCacheSizeUnit(_cbImportCacheSizeUnit, _importCacheSizeDSEntry); } super.actionPerformed(e); } private JTextField _tfMaxCacheSize; private JLabel _lMaxCacheSize; - + private JComboBox _cbMaxCacheSizeUnit; + private static final String[] UCOMBO_ENTRIES = { "bytes", "KB", "MB", "GB" }; + private DSEntryLong _cacheSizeDSEntry; + private JTextField _tfLookLimit; private JLabel _lLookLimit; @@ -183,22 +212,18 @@ public class LDBMPluginSettingPanel extends BlankPanel { private JTextField _tfImportCacheSize; private JLabel _lImportCacheSize; - - private static final String PLUGINDB_CACHE_SIZE_ATTR_NAM = - "nsslapd-dbcachesize"; - private static final String LOOK_LIMIT_ATTR_NAM = - "nsslapd-lookthroughlimit"; - private static final String FILE_MODE_ATTR_NAME = - "nsslapd-mode"; - private static final String DB_FILE_LOC_ATTR_NAME = - "nsslapd-directory"; - private static final String DB_IMPORT__CACHE_SIZE_ATTR_NAM = - "nsslapd-import-cachesize"; - private static final String IMPORT_AUTO_CACHE_SIZE_ATTR_NAME = - "nsslapd-import-cache-autosize"; + private JComboBox _cbImportCacheSizeUnit; + private DSEntryLong _importCacheSizeDSEntry; + + private static final String PLUGINDB_CACHE_SIZE_ATTR_NAM = "nsslapd-dbcachesize"; + private static final String LOOK_LIMIT_ATTR_NAM = "nsslapd-lookthroughlimit"; + private static final String FILE_MODE_ATTR_NAME = "nsslapd-mode"; + private static final String DB_FILE_LOC_ATTR_NAME = "nsslapd-directory"; + private static final String DB_IMPORT_CACHE_SIZE_ATTR_NAM = "nsslapd-import-cachesize"; + private static final String IMPORT_AUTO_CACHE_SIZE_ATTR_NAME = "nsslapd-import-cache-autosize"; private static final long LIMIT_MIN_VAL = -1; private static final long LIMIT_MAX_VAL = Long.MAX_VALUE; - private static final long CACHE_SIZE_NUM_MIN_VAL = 500000; + private static final long CACHE_SIZE_NUM_MIN_VAL = 1; // e.g., 1MB private static final long CACHE_SIZE_NUM_MAX_VAL = LIMIT_MAX_VAL; private static final int MODE_MIN_VAL = 0; private static final int MODE_MAX_VAL = 777; diff --git a/src/com/netscape/admin/dirserv/panel/LDBMSettingsPanel.java b/src/com/netscape/admin/dirserv/panel/LDBMSettingsPanel.java index f52fc63..010f0bf 100644 --- a/src/com/netscape/admin/dirserv/panel/LDBMSettingsPanel.java +++ b/src/com/netscape/admin/dirserv/panel/LDBMSettingsPanel.java @@ -20,7 +20,7 @@ package com.netscape.admin.dirserv.panel; import java.awt.*; -//import java.awt.event.*; +import java.awt.event.*; import java.util.*; import java.io.File; import javax.swing.*; @@ -152,22 +152,21 @@ public class LDBMSettingsPanel extends BlankPanel implements SuiConstants{ DSEntryBoolean roDSEntry = new DSEntryBoolean("off", _cbIsReadOnly); - entries.add(_dnEntry, READ_ONLY_ATTR_NAM, - roDSEntry); + entries.add(_dnEntry, READ_ONLY_ATTR_NAM, roDSEntry); setComponentTable(_cbIsReadOnly, roDSEntry); - + /* Cache info */ + _cbcachememsizeUnits = makeJComboBox(_section, "cachememsizeunits", null); _tfcachememsize = makeNumericalJTextField( _section, "cachememsize" ); _lcachememsize = makeJLabel(_section, "cachememsize"); _lcachememsize.setLabelFor(_tfcachememsize); - JLabel lcachememsizeUnit = makeJLabel(_section, "cachememsize-unit"); - lcachememsizeUnit.setLabelFor(_tfcachememsize); - DSEntryLong cachememsizeDSEntry = new DSEntryLong(null, - _tfcachememsize, _lcachememsize, - CACHEMEM_SIZE_NUM_MIN_VAL, CACHEMEM_SIZE_NUM_MAX_VAL, 1); - entries.add(_dnEntry, DB_CACHEMEMSIZE_ATTR_NAM, cachememsizeDSEntry); - setComponentTable(_tfcachememsize, cachememsizeDSEntry); + _cachememsizeDSEntry = new DSEntryLong(null, + _tfcachememsize, _lcachememsize, + CACHEMEM_SIZE_NUM_MIN_VAL, + CACHEMEM_SIZE_NUM_MAX_VAL, 1); + entries.add(_dnEntry, DB_CACHEMEMSIZE_ATTR_NAM, _cachememsizeDSEntry); + setComponentTable(_tfcachememsize, _cachememsizeDSEntry); /* Now let's build this */ GridBagLayout Mabag = new GridBagLayout(); @@ -222,7 +221,7 @@ public class LDBMSettingsPanel extends BlankPanel implements SuiConstants{ gbc.gridx = 2; gbc.fill = gbc.NONE; gbc.anchor = gbc.WEST; - grid.add( lcachememsizeUnit, gbc); + grid.add(_cbcachememsizeUnits, gbc); gbc.gridy++; gbc.gridx = 0; @@ -241,21 +240,28 @@ public class LDBMSettingsPanel extends BlankPanel implements SuiConstants{ * * @param e event */ - /* public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(_bLDBMLoc)) { - String file = DSFileDialog.getDirectoryName( - _tfLDBMLoc.getText(), false, this ); - if (file != null) - _tfLDBMLoc.setText(file); - else - return; // don't set dirty flag if nothing done - - super.actionPerformed(e); - } else - super.actionPerformed(e); + if (e.getSource().equals(_cbcachememsizeUnits)) { + String selectedUnit = (String)_cbcachememsizeUnits.getSelectedItem(); + Debug.println("actionPerformed: selected cachememsizeUnit: " + selectedUnit); + if (selectedUnit.equalsIgnoreCase("bytes")) { + _cachememsizeDSEntry.setScaleFactor(1); + _cachememsizeDSEntry.show(); + } else if (selectedUnit.equalsIgnoreCase("KB")) { + _cachememsizeDSEntry.setScaleFactor(1024); + _cachememsizeDSEntry.show(); + } else if (selectedUnit.equalsIgnoreCase("MB")) { + _cachememsizeDSEntry.setScaleFactor(1024*1024); + _cachememsizeDSEntry.show(); + } else if (selectedUnit.equalsIgnoreCase("GB")) { + _cachememsizeDSEntry.setScaleFactor(1024*1024*1024); + _cachememsizeDSEntry.show(); + } else { + Debug.println("actionPerformed: ignore unknown unit: " + selectedUnit); + } + } + super.actionPerformed(e); } - */ private JCheckBox _cbIsReadOnly; private JLabel _tfLDBMLoc; @@ -269,8 +275,10 @@ public class LDBMSettingsPanel extends BlankPanel implements SuiConstants{ private JTextField _tfcachememsize; private JLabel _lcachememsize; + private DSEntryLong _cachememsizeDSEntry; + private JComboBox _cbcachememsizeUnits; - private static final long CACHEMEM_SIZE_NUM_MIN_VAL = 200000; + private static final long CACHEMEM_SIZE_NUM_MIN_VAL = 1; // e.g., allow 1GB private static final long CACHEMEM_SIZE_NUM_MAX_VAL = Long.MAX_VALUE; private static final String DB_CACHEMEMSIZE_ATTR_NAM = "nsslapd-cachememsize"; @@ -286,6 +294,5 @@ public class LDBMSettingsPanel extends BlankPanel implements SuiConstants{ final static int DEFAULT_PADDING = 6; final static Insets DEFAULT_EMPTY_INSETS = new Insets(0,0,0,0); final static Insets BOTTOM_INSETS = new Insets(6,6,6,6); - }