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;
24
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.Debug;
30
import com.netscape.management.client.util.ResourceSet;
31
import com.netscape.admin.dirserv.*;
34
* Panel for Directory Server resource page
39
* @see com.netscape.admin.dirserv
41
abstract public class FilePanel extends BlankPanel {
42
public FilePanel(IDSModel model, String section) {
43
super(model, section);
48
public FilePanel(IDSModel model, String section, boolean onlyLocal, boolean onlyRemote) {
49
super(model, section);
51
_onlyLocal = onlyLocal;
52
_onlyRemote = onlyRemote;
56
protected void createFileArea( JPanel grid ) {
57
GridBagConstraints gbc = getGBC();
58
gbc.gridwidth = gbc.REMAINDER;
60
/* File selection group */
61
JPanel panel = new JPanel( new GridBagLayout() );
62
gbc.gridwidth = gbc.REMAINDER;
63
gbc.fill = gbc.HORIZONTAL;
68
ButtonGroup group = new ButtonGroup();
69
_rbLocal = makeJRadioButton( _section, "local-file", true );
73
_rbRemote = makeJRadioButton( _section, "remote-file", false );
79
if (!super.isLocal()) {
80
label = makeJLabel( _section, "filename-onlylocal" );
82
label = makeJLabel( _section, "filename" );
84
} else if (_onlyRemote) {
86
label = makeJLabel( _section, "filename-onlyremote" );
88
label = makeJLabel( _section, "filename" );
91
label = makeJLabel( _section, "filename" );
94
gbc.fill = gbc.HORIZONTAL;
96
panel.add( label, gbc );
99
_tfExport = new DSFileField((BlankPanel)this, _section, "filename",
100
"", 25, DSFileField.FILE);
101
label.setLabelFor(_tfExport);
103
panel.add(_tfExport,gbc);
105
_bExport = makeJButton( _section, "browse-file" );
106
gbc.gridwidth = gbc.REMAINDER;
108
panel.add(_bExport,gbc);
113
JPanel buttonPanel = new JPanel(new GridBagLayout());
116
buttonPanel.add( _rbLocal, gbc );
118
buttonPanel.add( _rbRemote, gbc );
120
gbc.fill = gbc.HORIZONTAL;
121
gbc.gridwidth = gbc.REMAINDER;
122
buttonPanel.add(Box.createHorizontalGlue(), gbc);
123
gbc.insets = new Insets(0,0,0,0);
124
panel.add(buttonPanel, gbc);
128
protected void createSeparator( JPanel grid ) {
129
GridBagConstraints gbc = getGBC();
130
gbc.gridwidth = gbc.REMAINDER;
131
gbc.fill = gbc.HORIZONTAL;
133
grid.add(new JSeparator(), gbc);
136
protected boolean isLocal() {
137
return (super.isLocal() || _onlyLocal);
140
protected void checkOkay() {
143
protected String getFilename() {
144
return _tfExport.getText().trim();
147
protected void setFilename( String name ) {
148
_tfExport.setText( name.trim() );
151
protected boolean validateFilename() {
152
return _tfExport.dsValidate();
155
protected boolean getLocalState() {
156
return !_rbRemote.isSelected();
159
protected void setLocalState( boolean state ) {
160
if ( _bExport != null ) {
161
_bExport.setEnabled( state );
166
public void changedUpdate(DocumentEvent e) {
167
super.changedUpdate( e );
171
public void removeUpdate(DocumentEvent e) {
172
super.removeUpdate( e );
176
public void insertUpdate(DocumentEvent e) {
177
super.insertUpdate( e );
182
* handle incoming event
186
public void actionPerformed(ActionEvent e) {
187
if ( e.getSource().equals( _rbLocal ) ) {
188
setLocalState( true );
189
} else if ( e.getSource().equals( _rbRemote ) ) {
190
setLocalState( false );
192
super.actionPerformed(e);
196
public void resetCallback() {
197
/* No state to preserve */
201
protected String getDefaultPath(IDSModel model ) {
202
return DSUtil.getDefaultLDIFPath(model.getServerInfo());
205
protected DSFileField _tfExport;
206
protected JButton _bExport;
207
protected JButton _browseButton;
208
protected JRadioButton _rbLocal;
209
protected JRadioButton _rbRemote;
210
protected ResourceSet _resource = DSUtil._resource;
211
protected String _section = null;
212
protected boolean _onlyLocal = false;
213
protected boolean _onlyRemote = false;