1
/** BEGIN COPYRIGHT BLOCK
2
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
3
* Copyright (C) 2005 Red Hat, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
* END COPYRIGHT BLOCK **/
20
package com.netscape.admin.dirserv.panel;
23
import java.awt.event.*;
26
import javax.swing.table.*;
27
import com.netscape.management.nmclf.SuiTableHeaderRenderer;
28
import com.netscape.management.client.*;
29
import com.netscape.management.client.util.*;
30
import com.netscape.admin.dirserv.*;
31
import netscape.ldap.*;
34
* Panel for Directory Server resource page
39
* @see com.netscape.admin.dirserv
41
public class MonitorBasePanel extends RefreshablePanel {
43
public MonitorBasePanel(IDSModel model, String title) {
44
super( model, title, true );
48
/* Various methods used by subclasses */
51
* Called when the panel is selected.
53
public void select(IResourceObject parent, IPage viewInstance) {
54
if (!_isInitialized) { // first time called
56
_isInitialized = true;
59
if ( (_refreshCheckbox != null) &&
60
_refreshCheckbox.isSelected() ) {
66
* Called when the panel is deselected.
68
public void unselect(IResourceObject parent, IPage viewInstance) {
69
//Debug.println( "MonitorBasePanel: unselect" );
75
* This method is overridden in subclasses.
77
public boolean refresh() {
78
/* Have the data models notify listeners that they need updating */
79
Enumeration en = _tables.elements();
80
while( en.hasMoreElements() ) {
81
JTable table = (JTable)en.nextElement();
82
// ((PerfTableModel)table.getModel()).notifyChanges();
88
protected String getAttrValue( String attrName ) {
89
return DSUtil.getAttrValue( _entry, attrName );
92
protected void setColumnWidths( JTable table, int[] widths ) {
93
Enumeration en = table.getColumnModel().getColumns();
95
while( en.hasMoreElements() ) {
96
TableColumn col = (TableColumn)en.nextElement();
97
col.setPreferredWidth( widths[i] );
98
col.setResizable( true );
103
protected void setColumnHeaders( JTable table, String[] headers ) {
104
Enumeration en = table.getColumnModel().getColumns();
106
while( en.hasMoreElements() ) {
107
TableColumn col = (TableColumn)en.nextElement();
108
col.setHeaderValue( headers[i] );
113
protected int getTotalColumnWidth( JTable table ) {
114
Enumeration en = table.getColumnModel().getColumns();
116
while( en.hasMoreElements() ) {
117
TableColumn col = (TableColumn)en.nextElement();
118
width += col.getWidth();
123
private Dimension getOptimalDimension( JTable table,
124
JComponent container ) {
125
/* What is the initial total width of all columns? */
126
int width = getTotalColumnWidth( table );
127
/* Make the minimum and the current size of the table fit all
130
new Dimension( width,
131
(table.getRowMargin() + table.getRowHeight()) * table.getRowCount());
132
Insets ins = container.getInsets();
133
width = container.getWidth() - ins.left - ins.right;
134
//Debug.println( "getOptimalDimensionTable: " + d + ", container: " + width );
135
d.width = Math.max( d.width, width );
139
private void setupTable( JTable table,
140
JComponent container ) {
141
Dimension d = getOptimalDimension( table, container );
142
table.setMinimumSize( d );
144
table.getTableHeader().setReorderingAllowed(false);
145
table.setRowSelectionAllowed(false);
146
table.setColumnSelectionAllowed(false);
147
table.setAutoResizeMode( table.AUTO_RESIZE_NEXT_COLUMN );
148
table.setRequestFocusEnabled(false);
149
/* If necessary, adjust column widths */
150
table.sizeColumnsToFit( true );
153
protected void addTable( JTable table, JComponent myContainer,
155
/* The column headers only show up if I put this in a scrollpane
156
in Swing 0.7 or 1.0... */
157
// addTableInGroupPane( table, myContainer, key );
158
addTableInScrollPane( table, myContainer, key );
161
protected void addTableInScrollPane( JTable table,
162
JComponent container,
163
String titleString ) {
164
JScrollPane scrollpane = new JScrollPane( table );
165
JPanel outer = new GroupPanel(titleString);
166
scrollpane.setHorizontalScrollBarPolicy(
167
scrollpane.HORIZONTAL_SCROLLBAR_NEVER);
168
scrollpane.setVerticalScrollBarPolicy(
169
scrollpane.VERTICAL_SCROLLBAR_NEVER);
170
_gbc.gridwidth = _gbc.REMAINDER;
171
_gbc.fill = GridBagConstraints.BOTH;
172
// ((Container)container).add( scrollpane, _gbc );
173
outer.add( scrollpane, _gbc );
174
_gbc.fill = GridBagConstraints.HORIZONTAL;
175
((Container)container).add( outer, _gbc );
176
// ((Container)container).add( scrollpane, _gbc );
177
setupTable( table, container );
178
Dimension d = getOptimalDimension( table, container );
179
table.setPreferredScrollableViewportSize(new Dimension(10, d.height));
184
protected void addTableInGroupPane( JTable table,
185
JComponent container,
186
String titleString ) {
187
JPanel panel = new GroupPanel( titleString);
188
panel.add( table, _gbc );
189
setupTable( table, container );
190
_gbc.insets = new Insets(10,0,2,2);
191
_gbc.gridwidth = _gbc.REMAINDER;
192
_gbc.fill = GridBagConstraints.HORIZONTAL;
193
((Container)container).add( panel, _gbc );
196
protected void rightAlignColumns( JTable table,
197
int first, int last ) {
198
for( int i = first; i <= last; i++ ) {
199
table.getColumnModel().getColumn(i).setCellRenderer(
200
new RightAlignedCellRenderer() );
201
SuiTableHeaderRenderer renderer = (SuiTableHeaderRenderer)
202
table.getColumnModel().getColumn(i).getHeaderRenderer();
203
renderer.setHorizontalAlignment(SwingConstants.RIGHT);
204
renderer.setHorizontalTextPosition(SwingConstants.RIGHT);
208
class RightAlignedCellRenderer extends DefaultTableCellRenderer {
209
public Component getTableCellRendererComponent(
210
JTable table, Object value,
211
boolean isSelected, boolean hasFocus, int row, int column) {
212
setHorizontalAlignment(SwingConstants.RIGHT);
213
return super.getTableCellRendererComponent(
214
table, value, isSelected, hasFocus, row, column );
219
* Table model to provide data from the cached directory entry.
221
class PerfTableModel extends AbstractTableModel {
223
PerfTableModel( String[] labels, String[] headers,
224
String[] dataNames ) {
227
_dataNames = dataNames;
228
_monitorEntry = _entry;
231
PerfTableModel( String[] labels, String[] headers,
232
String[] dataNames, LDAPEntry monitorEntry ) {
235
_dataNames = dataNames;
236
_monitorEntry = monitorEntry;
239
public void updEntry( LDAPEntry updEntry ) {
240
updEntry( updEntry, true );
244
public void updEntry( LDAPEntry updEntry, boolean notifChanges ) {
245
_monitorEntry = updEntry;
246
if ( notifChanges) fireTableDataChanged();
249
public void updDataNames( String[] dataNames, boolean notifChanges ) {
250
_dataNames = dataNames;
251
if( notifChanges) fireTableDataChanged();
254
public void notifyChanges() {
255
fireTableDataChanged();
257
public int getColumnCount() {
258
return _headers.length;
260
public int getRowCount() {
261
return _labels.length;
263
public Object getValueAt(int row, int col) {
268
val = DSUtil.getAttrValue( _monitorEntry, _dataNames[row] );
269
if ( (val == null) || (val.length() < 1) ) {
273
// Debug.println( " table value " + row + "," +
274
// col + ": " + val );
277
public String getColumnName(int columnIndex) {
278
return _headers[columnIndex];
281
protected String[] _labels; // Row labels
282
protected String[] _headers; // Column labels
283
protected String[] _dataNames; // Attributes to provide data
284
protected LDAPEntry _monitorEntry = null;
287
protected LDAPEntry _entry;
288
protected LDAPConnection _ldc;
289
protected String _entryName = "cn=monitor";
290
protected Vector _tables = new Vector();
291
private boolean _isSelected = false;
292
protected static final int PREFERRED_WIDTH = 500;
294
static final ResourceSet _resource = DSUtil._resource;