~ubuntu-branches/ubuntu/wily/389-ds-console/wily-proposed

« back to all changes in this revision

Viewing changes to src/com/netscape/admin/dirserv/panel/BckListPanel.java

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-03-15 19:58:37 UTC
  • Revision ID: package-import@ubuntu.com-20120315195837-296zyft51thld8q7
Tags: upstream-1.2.6
ImportĀ upstreamĀ versionĀ 1.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** BEGIN COPYRIGHT BLOCK
 
2
 * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
 
3
 * Copyright (C) 2005 Red Hat, Inc.
 
4
 * All rights reserved.
 
5
 * 
 
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.
 
9
 * 
 
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.
 
14
 * 
 
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 **/
 
19
 
 
20
package com.netscape.admin.dirserv.panel;
 
21
 
 
22
import java.awt.*;
 
23
import java.util.Vector;
 
24
import javax.swing.*;
 
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;
 
32
 
 
33
/**
 
34
 * BckListPanel
 
35
 * 
 
36
 *
 
37
 * @version 1.0
 
38
 * @author rweltman
 
39
 **/
 
40
public class BckListPanel extends BlankPanel {
 
41
        public BckListPanel( IDSModel model,
 
42
                                                 String[] bckList,
 
43
                                                 String[] inAlready,
 
44
                                                 String helpToken ) {
 
45
                super( model, _section, false );
 
46
                // setTitle( title );
 
47
                _bList = bckList;
 
48
                _bIn = inAlready;
 
49
                _helpToken = helpToken;
 
50
        }
 
51
 
 
52
 
 
53
        public void init() {
 
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 );
 
61
                        _myPanel.add(
 
62
                                Box.createVerticalStrut(UIFactory.getComponentSpace()), gbc);
 
63
                }
 
64
                gbc.fill = gbc.BOTH;
 
65
                gbc.weightx = 1.0;
 
66
                gbc.weighty = 1.0;
 
67
 
 
68
                String[] BAList =  getBckAvailable() ;
 
69
                if (BAList != null) {
 
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 );
 
76
                }
 
77
        }
 
78
 
 
79
        /**
 
80
         * Some list component changed
 
81
         *
 
82
         * @param e Event indicating what changed
 
83
         */
 
84
    public void valueChanged(ListSelectionEvent e) {
 
85
        Debug.println(7, "BckListPanel.valueChanged: " +
 
86
                                          _list.getSelectedValue());
 
87
                AbstractDialog dlg = getAbstractDialog();
 
88
                if ( dlg != null ) {
 
89
                        dlg.setOKButtonEnabled( _list.getSelectedValue() != null );
 
90
                }
 
91
    }
 
92
 
 
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] );
 
99
                        }
 
100
                }
 
101
                String[] nL = new String[v.size()];
 
102
                v.toArray( nL );
 
103
                return ( nL );
 
104
        }
 
105
        
 
106
        protected boolean notIn( String BName ) {
 
107
                if ( _bIn == null ) {
 
108
                        return( true );
 
109
                }
 
110
                Debug.println("BckListPanel.notIn()");
 
111
                Debug.println("------------------->" + BName );
 
112
                boolean b = true;
 
113
                for(int i =0; (i < _bIn.length) && b ; i++ ) {
 
114
                        Debug.println("------------------->" + _bIn[i] );
 
115
                        b =  BName.compareToIgnoreCase( _bIn[i] ) != 0;
 
116
                }
 
117
                return ( b );
 
118
        }
 
119
                
 
120
 
 
121
    public void resetCallback() {
 
122
                /* No state to preserve */
 
123
                clearDirtyFlag();
 
124
                hideDialog();
 
125
    }
 
126
 
 
127
    public void okCallback() {
 
128
                /* No state to preserve */
 
129
                Object OVals[] = _list.getSelectedValues();
 
130
                Vector v = new Vector(1);
 
131
 
 
132
                if (( OVals == null ) || (OVals.length == 0)) {
 
133
                        _item = null;
 
134
                }
 
135
 
 
136
                String[] bcList = new String[OVals.length];
 
137
                int i=0;
 
138
                
 
139
 
 
140
                for(i =0; i <  OVals.length; i++) {                     
 
141
                        v.addElement( OVals[i].toString() );
 
142
                }
 
143
            v.toArray(bcList);                          
 
144
                _item = (String[])bcList;
 
145
                if ( _item == null ) {
 
146
                        return;
 
147
                }
 
148
                clearDirtyFlag();
 
149
                hideDialog();
 
150
    }
 
151
 
 
152
    public Object getSelectedItem () {
 
153
                return _item;
 
154
        }
 
155
 
 
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.
 
159
                
 
160
                public Component getListCellRendererComponent(
 
161
                                                                                                          JList list,
 
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
 
166
                        {
 
167
                                AbstractDialog dlg = getAbstractDialog();
 
168
                                if ( dlg != null ) {
 
169
                                        if (list.isSelectionEmpty()) {
 
170
                                                dlg.setOKButtonEnabled( false );
 
171
                                        } else {
 
172
                                                dlg.setOKButtonEnabled( true );
 
173
                                        }
 
174
                                }
 
175
 
 
176
                                return super.getListCellRendererComponent(list,
 
177
                                                                                                                  value,
 
178
                                                                                                                  index,
 
179
                                                                                                                  isSelected,
 
180
                                                                                                                  cellHasFocus);
 
181
                        }
 
182
        }
 
183
 
 
184
        private JList _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";
 
190
}