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.util.Vector;
25
import javax.swing.event.ListSelectionEvent;
26
import com.netscape.management.client.util.ResourceSet;
27
import com.netscape.management.client.util.Debug;
28
import com.netscape.management.client.util.UITools;
29
import com.netscape.management.client.util.AbstractDialog;
30
import com.netscape.admin.dirserv.IDSModel;
31
import com.netscape.admin.dirserv.DefaultResourceModel;
40
public class BckListPanel extends BlankPanel {
41
public BckListPanel( IDSModel model,
45
super( model, _section, false );
49
_helpToken = helpToken;
54
_myPanel.setLayout( new GridBagLayout() );
55
GridBagConstraints gbc = (GridBagConstraints)getGBC().clone();
56
gbc.insets = new Insets( 0, 0, 0, 0 );
57
gbc.fill = gbc.HORIZONTAL;
58
gbc.gridwidth = gbc.REMAINDER;
59
if ( _label != null ) {
60
_myPanel.add( new JLabel( _label ), gbc );
62
Box.createVerticalStrut(UIFactory.getComponentSpace()), gbc);
68
String[] BAList = getBckAvailable() ;
70
_list = new JList( BAList );
71
_list.setCellRenderer( new BackendCellRenderer() );
72
_list.setSelectedIndex( 0 );
73
JScrollPane scroll = new JScrollPane(_list);
74
scroll.setBorder( UITools.createLoweredBorder() );
75
_myPanel.add( scroll, gbc );
80
* Some list component changed
82
* @param e Event indicating what changed
84
public void valueChanged(ListSelectionEvent e) {
85
Debug.println(7, "BckListPanel.valueChanged: " +
86
_list.getSelectedValue());
87
AbstractDialog dlg = getAbstractDialog();
89
dlg.setOKButtonEnabled( _list.getSelectedValue() != null );
93
protected String[] getBckAvailable() {
94
Vector v = new Vector(1);
95
for(int i=0; i < _bList.length; i++) {
96
Debug.println("BckListPanel.getBckAvailable() bck = " + _bList[i]);
97
if( notIn( _bList[i])){
98
v.addElement( _bList[i] );
101
String[] nL = new String[v.size()];
106
protected boolean notIn( String BName ) {
107
if ( _bIn == null ) {
110
Debug.println("BckListPanel.notIn()");
111
Debug.println("------------------->" + BName );
113
for(int i =0; (i < _bIn.length) && b ; i++ ) {
114
Debug.println("------------------->" + _bIn[i] );
115
b = BName.compareToIgnoreCase( _bIn[i] ) != 0;
121
public void resetCallback() {
122
/* No state to preserve */
127
public void okCallback() {
128
/* No state to preserve */
129
Object OVals[] = _list.getSelectedValues();
130
Vector v = new Vector(1);
132
if (( OVals == null ) || (OVals.length == 0)) {
136
String[] bcList = new String[OVals.length];
140
for(i =0; i < OVals.length; i++) {
141
v.addElement( OVals[i].toString() );
144
_item = (String[])bcList;
145
if ( _item == null ) {
152
public Object getSelectedItem () {
156
class BackendCellRenderer extends DefaultListCellRenderer {
157
// This is the only method defined by ListCellRenderer. We just
158
// reconfigure the Jlabel each time we're called.
160
public Component getListCellRendererComponent(
162
Object value, // value to display
163
int index, // cell index
164
boolean isSelected, // is the cell selected
165
boolean cellHasFocus) // the list and the cell have the focus
167
AbstractDialog dlg = getAbstractDialog();
169
if (list.isSelectionEmpty()) {
170
dlg.setOKButtonEnabled( false );
172
dlg.setOKButtonEnabled( true );
176
return super.getListCellRendererComponent(list,
185
private String[] _bList;
186
private String[] _bIn;
187
private String _label = null;
188
private String[] _item = null;
189
private final static String _section = "mappingtree-bcklist";