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.border.*;
27
import javax.swing.event.*;
28
import javax.swing.text.*;
29
import com.netscape.management.client.util.*;
30
import com.netscape.admin.dirserv.*;
31
import com.netscape.admin.dirserv.task.ListDB;
32
import com.netscape.admin.dirserv.panel.MappingUtils;
33
import com.netscape.management.nmclf.*;
34
import netscape.ldap.*;
35
import netscape.ldap.util.*;
39
* Panel for Directory Server resource page
42
* @see com.netscape.admin.dirserv
44
public class NewMappingNodePanel extends BlankPanel {
46
public NewMappingNodePanel(IDSModel model, LDAPEntry node) {
47
super( model, _section );
48
_helpToken = "configuration-new-mapping-node-dbox-help";
49
setTitle( DSUtil._resource.getString( _section, "new-title" ));
56
_myPanel.setLayout( new GridBagLayout() );
57
GridBagConstraints gbc = getGBC();
60
createTypeArea( _myPanel );
61
createValueArea( _myPanel );
62
AbstractDialog dlg = getAbstractDialog();
64
dlg.setOKButtonEnabled( false );
69
protected void createValueArea( JPanel grid ) {
71
GridBagConstraints gbc = getGBC();
72
JPanel Mapanel = new GroupPanel( DSUtil._resource.getString( _section, "bck-title" ),
74
gbc.gridwidth = gbc.REMAINDER;
75
gbc.fill = gbc.HORIZONTAL;
76
grid.add( Mapanel, gbc );
78
GridBagLayout Mabag = new GridBagLayout();
79
GridBagConstraints Magbc = new GridBagConstraints() ;
82
Magbc.gridwidth = Magbc.REMAINDER;
86
Magbc.fill = Magbc.BOTH;
87
Magbc.anchor = Magbc.CENTER;
88
Magbc.insets = new Insets(0, 0, 0, 0);
92
Mapanel.setLayout(Mabag);
94
/* Backends list label */
95
_bckListLabel = makeJLabel ( _section, "bck-list" );
96
Magbc.fill= Magbc.NONE;
97
Magbc.anchor = Magbc.WEST;
98
Mapanel.add( _bckListLabel,Magbc );
101
String BList[] = getBackendList();
102
_bckList = new JList( BList );
103
_bckList.setVisibleRowCount( ROWS );
104
_bckList.setCellRenderer( new ReferralCellRenderer() );
105
// _bckList.setSelectionMode( _bckList.MULTIPLE_INTERVAL_SELECTION );
106
JScrollPane scrollBck = new JScrollPane();
107
scrollBck.getViewport().setView(_bckList);
109
Magbc.fill= Magbc.BOTH;
112
Mapanel.add( scrollBck, Magbc );
114
/* Referrals Label */
115
_refListLabel = makeJLabel ( _section, "ref-list" );
119
Magbc.fill= Magbc.NONE;
120
Magbc.anchor = Magbc.WEST;
122
Mapanel.add( _refListLabel,Magbc);
125
/* New Referrals Line */
126
_refNewRefText = makeJTextField(_section, "ref-new");
131
Magbc.fill= Magbc.BOTH;
132
Magbc.insets = new Insets(0,
134
SuiLookAndFeel.COMPONENT_SPACE,
136
Magbc.anchor = Magbc.CENTER;
137
Mapanel.add( _refNewRefText,Magbc);
139
_bAdd = UIFactory.makeJButton(this, _section, "badd", (ResourceSet)null);
140
_bAdd.setActionCommand(ADD_REF);
141
_bAdd.setEnabled(false);
146
Magbc.insets = new Insets(0,
147
SuiLookAndFeel.DIFFERENT_COMPONENT_SPACE,
148
SuiLookAndFeel.COMPONENT_SPACE,
150
Magbc.fill= Magbc.NONE;
151
Magbc.anchor = Magbc.EAST;
152
Mapanel.add( _bAdd,Magbc);
154
/* just to make it nicer */
158
_refData = new DefaultListModel();
159
_refList = new JList( _refData );
160
_refList.setVisibleRowCount(ROWS);
161
_refList.setCellRenderer( new ReferralCellRenderer() );
162
JScrollPane scrollRef = new JScrollPane();
163
scrollRef.getViewport().setView(_refList);
167
Magbc.insets = new Insets(0, 0, 0, 0);
168
Magbc.fill= Magbc.BOTH;
171
Mapanel.add( scrollRef, Magbc);
173
_bDelete = UIFactory.makeJButton(this, _section, "bdelete", (ResourceSet)null);
174
_bDelete.setActionCommand(DELETE_REF);
175
_bDelete.setEnabled(false);
180
Magbc.fill= Magbc.NONE;
181
Magbc.insets = new Insets(0, SuiLookAndFeel.DIFFERENT_COMPONENT_SPACE, 0, 0);
182
Magbc.anchor = Magbc.NORTHEAST;
183
Mapanel.add( _bDelete,Magbc);
188
protected void createTypeArea( JPanel grid ) {
189
GridBagConstraints gbc = getGBC();
190
gbc.insets.bottom = _gbc.insets.top;
191
gbc.gridwidth = gbc.REMAINDER;
193
String[] mapList = MappingUtils.getMappingNode( _model.getServerInfo().getLDAPConnection() );
195
JPanel Mapanel = new GroupPanel(
196
DSUtil._resource.getString( _section, "new-mapping-title" ));
197
gbc.gridwidth = gbc.REMAINDER;
198
gbc.fill = gbc.HORIZONTAL;
199
grid.add( Mapanel, gbc );
202
_NewNodeLabel = makeJLabel( _section, "new-node-suffix" );
206
Mapanel.add( _NewNodeLabel, gbc );
208
_NewNodeText = makeJTextField( _section, "new-node-suffix" );
210
gbc.gridwidth = gbc.REMAINDER;
211
gbc.fill = gbc.HORIZONTAL;
212
Mapanel.add( _NewNodeText, gbc );
214
_comboNewNodeMapping = new JComboBox();
215
_comboNewNodeMapping.addItemListener(this);
216
_comboNewNodeMapping.addActionListener(this);
218
if ( mapList != null ) {
220
_comboNewNodeMapping.addItem( ROOT_MAPPING_NODE );
221
String suffix = null;
222
if (_entry != null) {
223
suffix = MappingUtils.getMappingNodeSuffix(_entry);
225
for( int i = 0; i < mapList.length; i++ ) {
226
_comboNewNodeMapping.addItem( mapList[i] );
227
if((suffix != null) &&
228
DSUtil.equalDNs(mapList[i], suffix)) {
233
if ( mapList.length > 0 )
234
_comboNewNodeMapping.setSelectedIndex( j );
237
_comboNewNodeLabel = makeJLabel( _section, "new-node-subordination" );
238
gbc.gridwidth = 3; // 2
241
Mapanel.add( _comboNewNodeLabel, gbc );
242
gbc.gridwidth = gbc.REMAINDER;
244
gbc.fill = gbc.HORIZONTAL;
245
Mapanel.add( _comboNewNodeMapping, gbc );
248
_comboStatus = new JComboBox();
249
_comboStatus.addItemListener(this);
250
_comboStatus.addActionListener(this);
252
_comboStatus.addItem( BACKEND );
253
_comboStatus.addItem( REFERRAL );
254
_comboStatus.addItem( REFERRAL_UPDATE );
255
_comboStatus.addItem( DISABLE );
257
_comboStatusLabel = makeJLabel( _section, "new-node-status" );
261
Mapanel.add( _comboStatusLabel, gbc );
262
gbc.gridwidth = gbc.REMAINDER;
264
gbc.fill = gbc.HORIZONTAL;
265
Mapanel.add( _comboStatus, gbc );
269
private String[] getBackendList() {
270
Vector v = new Vector(1);
273
LDAPConnection ldc = _model.getServerInfo().getLDAPConnection();
274
_model.setWaitCursor( true );
275
LDAPSearchResults res =
276
ldc.search( CONFIG_BASEDN,
278
"objectclass=nsBackendInstance",
281
while( res.hasMoreElements() ) {
282
LDAPEntry bentry = (LDAPEntry)res.nextElement();
283
String name = bentry.getDN();
284
Debug.println( "NewMappingNodePanel.getBackendList() {");
285
Debug.println( "*** backend : " + name );
286
v.addElement(LDAPDN.explodeDN(bentry.getDN(),true)[0]);
288
} catch ( LDAPException e ) {
289
Debug.println( "NewMappingNodePanel.getBackendList() " + e );
291
_model.setWaitCursor( false );
293
Debug.println( "*** Nb : " + v.size() + " Dir :" + v.toString());
294
String[] bckList = new String[v.size()];
299
private boolean isListEmpty(JList list){
300
boolean testlist = (list.getModel().getSize() == 0);
304
private String[] getReferralsInList() {
306
Vector v = new Vector();
309
i < _refList.getModel().getSize();
311
v.addElement( _refList.getModel().getElementAt( i ));
313
if( v.size() == 0 ) {
316
String referralList[] = new String[ v.size() ];
317
v.toArray( referralList );
318
return ( referralList );
322
private String[] getBackendsInList() {
323
Vector v = new Vector(1);
324
Object OVals[] = _bckList.getSelectedValues();
326
if (( OVals == null ) || (OVals.length == 0)) {
330
String[] bckList = new String[OVals.length];
334
for(i =0; i < OVals.length; i++) {
335
v.addElement( OVals[i].toString() );
336
Debug.println( "*** backends : " + OVals[i].toString() );
343
* Enable/disable OK button
345
* @param ok true to enable the OK button
347
private void setOkay( boolean ok ) {
348
AbstractDialog dlg = getAbstractDialog();
350
dlg.setOKButtonEnabled( ok );
355
private void checkOkay() {
356
String a = _NewNodeText.getText().trim();
357
boolean ok = ((a != null) && (a.length() > 0)) ;
358
ok = ok && _isNewMappingNodeValid &&
359
( !( _bckList.isSelectionEmpty() ) ||
360
!( isListEmpty( _refList ) ));
365
* handle incoming event
369
public void actionPerformed(ActionEvent e) {
370
if(e.getActionCommand().equals(ADD_REF)) {
371
_refData.addElement( _refNewRefText.getText());
372
_refNewRefText.setText("");
373
_bAdd.setEnabled( false );
374
} else if (e.getActionCommand().equals(DELETE_REF)) {
375
int[] indices = _refList.getSelectedIndices();
376
for (int i = indices.length - 1; i>= 0;i--) {
377
_refData.removeElementAt(indices[i]);
379
_bDelete.setEnabled( false );
385
public void resetCallback() {
386
/* No state to preserve */
392
public void okCallback() {
393
/* No state to preserve */
394
if(( _NewNodeText.getText() != null ) &&
395
( _NewNodeText.getText().trim().length() > 0 )) {
396
if( MappingUtils.addMappingNode(
397
_model.getServerInfo().getLDAPConnection(),
399
_NewNodeText.getText(),
400
(String) _comboNewNodeMapping.getSelectedItem(),
401
(String) _comboStatus.getSelectedItem(),
403
getReferralsInList())) return;
406
DSUtil.showErrorDialog( getModel().getFrame(),
407
"new-mapping-node","" );
413
public void changedUpdate(DocumentEvent e) {
414
if( e.getDocument() == _NewNodeText.getDocument() ) {
415
if ( DN.isDN ( _NewNodeText.getText() )) {
416
setChangeState( _NewNodeLabel, CHANGE_STATE_UNMODIFIED );
417
_isNewMappingNodeValid = true;
419
setChangeState( _NewNodeLabel, CHANGE_STATE_ERROR );
420
_isNewMappingNodeValid = false;
423
super.changedUpdate( e );
427
public void removeUpdate(DocumentEvent e) {
428
if( e.getDocument() == _NewNodeText.getDocument() ) {
429
if ( DN.isDN ( _NewNodeText.getText() )) {
430
setChangeState( _NewNodeLabel, CHANGE_STATE_UNMODIFIED );
431
_isNewMappingNodeValid = true;
433
setChangeState( _NewNodeLabel, CHANGE_STATE_ERROR );
434
_isNewMappingNodeValid = false;
437
super.removeUpdate( e );
441
public void insertUpdate(DocumentEvent e) {
442
if( e.getDocument() == _refNewRefText.getDocument() ) {
443
boolean bAdd_status = ( _refNewRefText.getText().trim().length() > 0 );
444
_bAdd.setEnabled( bAdd_status );
445
} else if( e.getDocument() == _NewNodeText.getDocument() ) {
446
if ( DN.isDN ( _NewNodeText.getText() )) {
447
setChangeState( _NewNodeLabel, CHANGE_STATE_UNMODIFIED );
448
_isNewMappingNodeValid = true;
450
setChangeState( _NewNodeLabel, CHANGE_STATE_ERROR );
451
_isNewMappingNodeValid = false;
454
super.insertUpdate( e );
459
class ReferralCellRenderer extends DefaultListCellRenderer {
460
// This is the only method defined by ListCellRenderer. We just
461
// reconfigure the Jlabel each time we're called.
463
public Component getListCellRendererComponent(
465
Object value, // value to display
466
int index, // cell index
467
boolean isSelected, // is the cell selected
468
boolean cellHasFocus) // the list and the cell have the focus
470
if ( list == _refList ){
471
if (list.isSelectionEmpty()) {
472
_bDelete.setEnabled(false);
474
_bDelete.setEnabled(true);
478
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
482
private JTextField _mappingNameText;
483
private JLabel _mappingNameLabel;
484
private JTextField _NewNodeText;
485
private JLabel _NewNodeLabel;
487
private JTextField _subordinationText;
488
private JLabel _subordinationLabel;
490
private IDSModel _model = null;
491
private JComboBox _comboNewNodeMapping;
492
private JLabel _comboNewNodeLabel;
493
private JComboBox _comboStatus;
494
private JLabel _comboStatusLabel;
495
private JLabel _bckListLabel;
497
private JList _bckList;
498
private JButton _bAdd;
499
private JButton _bDelete;
500
private JLabel _refListLabel;
501
private JTextField _refNewRefText;
503
private JLabel _refNewRefLabel;
504
private JList _refList;
505
private DefaultListModel _refData;
507
private boolean _isNewMappingNodeValid = false;
509
private final static String _section = "mappingtree";
510
static final String CONFIG_BASEDN = "cn=plugins, cn=config" ;
511
static final String CONFIG_MAPPING = "cn=mapping tree, cn=config" ;
512
static final String ROOT_MAPPING_NODE = "is root suffix";
513
static final String DISABLE = MappingUtils.DISABLE;
514
static final String BACKEND = MappingUtils.BACKEND;
515
static final String REFERRAL = MappingUtils.REFERRAL;
516
static final String REFERRAL_UPDATE = MappingUtils.REFERRAL_UPDATE;
517
static final String ADD_REF = "addReferral";
518
private final String DELETE_REF = "deleteReferral";
519
private final int ROWS = 4;
520
private LDAPEntry _entry = null;