~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/FilePanel.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.io.File;
 
23
import java.awt.*;
 
24
import java.awt.event.*;
 
25
import javax.swing.*;
 
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.*;
 
32
 
 
33
/**
 
34
 * Panel for Directory Server resource page
 
35
 *
 
36
 * @author  rweltman
 
37
 * @version %I%, %G%
 
38
 * @date                9/15/97
 
39
 * @see     com.netscape.admin.dirserv
 
40
 */
 
41
abstract public class FilePanel extends BlankPanel {
 
42
        public FilePanel(IDSModel model, String section) {
 
43
                super(model, section);
 
44
                _section = section;
 
45
        }
 
46
 
 
47
 
 
48
        public FilePanel(IDSModel model, String section, boolean onlyLocal, boolean onlyRemote) {
 
49
                super(model, section);
 
50
                _section = section;
 
51
                _onlyLocal = onlyLocal;
 
52
                _onlyRemote = onlyRemote;
 
53
        }
 
54
 
 
55
 
 
56
    protected void createFileArea( JPanel grid ) {
 
57
        GridBagConstraints gbc = getGBC();
 
58
        gbc.gridwidth = gbc.REMAINDER;
 
59
 
 
60
                /* File selection group */
 
61
        JPanel panel = new JPanel( new GridBagLayout() );
 
62
        gbc.gridwidth = gbc.REMAINDER;
 
63
                gbc.fill = gbc.HORIZONTAL;
 
64
                gbc.weightx = 1.0;      
 
65
        grid.add(panel, gbc);
 
66
        
 
67
                gbc.weightx = 0.0;
 
68
        ButtonGroup group = new ButtonGroup();
 
69
        _rbLocal = makeJRadioButton( _section, "local-file", true );
 
70
        group.add(_rbLocal);
 
71
                gbc.fill = gbc.NONE;
 
72
                gbc.gridwidth = 3;
 
73
        _rbRemote = makeJRadioButton( _section, "remote-file", false );
 
74
        group.add(_rbRemote);
 
75
 
 
76
                JLabel label;
 
77
                
 
78
                if (_onlyLocal) {
 
79
                        if (!super.isLocal()) {
 
80
                                label = makeJLabel( _section, "filename-onlylocal" );
 
81
                        } else {
 
82
                                label = makeJLabel( _section, "filename" );
 
83
                        }
 
84
                } else if (_onlyRemote) {
 
85
                        if (!isLocal()) {
 
86
                                label = makeJLabel( _section, "filename-onlyremote" );
 
87
                        } else {
 
88
                                label = makeJLabel( _section, "filename" );
 
89
                        }
 
90
                } else {                
 
91
                        label = makeJLabel( _section, "filename" );
 
92
                }
 
93
                gbc.gridwidth = 3;
 
94
                gbc.fill = gbc.HORIZONTAL;
 
95
                gbc.weightx = 0.0;      
 
96
        panel.add( label, gbc );
 
97
 
 
98
                gbc.gridwidth--;
 
99
                _tfExport = new DSFileField((BlankPanel)this, _section, "filename",
 
100
                                                                        "", 25, DSFileField.FILE);
 
101
                label.setLabelFor(_tfExport);
 
102
                gbc.weightx = 1.0;
 
103
        panel.add(_tfExport,gbc);
 
104
 
 
105
                _bExport = makeJButton( _section, "browse-file" );
 
106
        gbc.gridwidth = gbc.REMAINDER;
 
107
                gbc.weightx = 0.0;      
 
108
        panel.add(_bExport,gbc);
 
109
                                
 
110
                if ( !isLocal() && 
 
111
                         !_onlyRemote &&
 
112
                         !_onlyLocal) {
 
113
                        JPanel buttonPanel = new JPanel(new GridBagLayout());                   
 
114
                        gbc.fill = gbc.NONE;
 
115
                        gbc.gridwidth = 3;
 
116
                        buttonPanel.add( _rbLocal, gbc );
 
117
                        gbc.gridwidth--;
 
118
                        buttonPanel.add( _rbRemote, gbc );
 
119
                        gbc.weightx = 1.0;
 
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);
 
125
                }
 
126
        }
 
127
 
 
128
        protected void createSeparator( JPanel grid ) {
 
129
        GridBagConstraints gbc = getGBC();        
 
130
                gbc.gridwidth = gbc.REMAINDER;
 
131
                gbc.fill = gbc.HORIZONTAL;
 
132
                gbc.weightx = 1.0;      
 
133
        grid.add(new JSeparator(), gbc);
 
134
        }
 
135
 
 
136
        protected boolean isLocal() {
 
137
                return (super.isLocal() || _onlyLocal);
 
138
        }
 
139
        
 
140
    protected void checkOkay() {
 
141
        }
 
142
 
 
143
    protected String getFilename() {
 
144
            return _tfExport.getText().trim();
 
145
        }
 
146
 
 
147
    protected void setFilename( String name ) {
 
148
            _tfExport.setText( name.trim() );
 
149
        }
 
150
 
 
151
    protected boolean validateFilename() {
 
152
            return _tfExport.dsValidate();
 
153
        }
 
154
 
 
155
    protected boolean getLocalState() {
 
156
        return !_rbRemote.isSelected();
 
157
    }
 
158
    
 
159
    protected void setLocalState( boolean state ) {
 
160
                if ( _bExport != null ) {
 
161
                        _bExport.setEnabled( state );
 
162
                        repaint();
 
163
                }
 
164
    }
 
165
    
 
166
    public void changedUpdate(DocumentEvent e) {
 
167
                super.changedUpdate( e );
 
168
                checkOkay();
 
169
        }
 
170
 
 
171
    public void removeUpdate(DocumentEvent e) {
 
172
                super.removeUpdate( e );
 
173
                checkOkay();
 
174
        }
 
175
 
 
176
    public void insertUpdate(DocumentEvent e) {
 
177
                super.insertUpdate( e );
 
178
                checkOkay();
 
179
        }
 
180
 
 
181
    /**
 
182
     *  handle incoming event
 
183
     *
 
184
     * @param e event
 
185
     */
 
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 );
 
191
        } else {
 
192
                        super.actionPerformed(e);
 
193
                }
 
194
    }
 
195
 
 
196
    public void resetCallback() {
 
197
                /* No state to preserve */
 
198
                clearDirtyFlag();
 
199
    }
 
200
 
 
201
        protected String getDefaultPath(IDSModel model ) {
 
202
                return DSUtil.getDefaultLDIFPath(model.getServerInfo());
 
203
        }
 
204
 
 
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;
 
214
}