~ubuntu-branches/ubuntu/utopic/389-admin-console/utopic

« back to all changes in this revision

Viewing changes to src/com/netscape/management/admserv/panel/LoggingConfigPanel.java

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2011-10-12 11:05:09 UTC
  • Revision ID: package-import@ubuntu.com-20111012110509-ybd1jr5xeat2ug1i
Tags: upstream-1.1.8
ImportĀ upstreamĀ versionĀ 1.1.8

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
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; version 2
 
9
 * of the License.
 
10
 * 
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 * 
 
20
 * END COPYRIGHT BLOCK **/
 
21
package com.netscape.management.admserv.panel;
 
22
 
 
23
import java.awt.*;
 
24
import javax.swing.*;
 
25
import javax.swing.event.*;
 
26
import com.netscape.management.client.util.*;
 
27
import com.netscape.management.client.console.ConsoleInfo;
 
28
import com.netscape.management.admserv.config.*;
 
29
import com.netscape.management.nmclf.SuiConstants;
 
30
 
 
31
/**
 
32
  *
 
33
  * @version 0.1 11/23/97
 
34
  * @author miodrag@netscape.com
 
35
  */
 
36
public class LoggingConfigPanel extends PluginConfigPanel {
 
37
 
 
38
    IConfigDataModel _configData;
 
39
 
 
40
    static ResourceSet _resource;
 
41
    static String _i18nLogPath, _i18nLogFile, _i18nErrorLogGroupbox,
 
42
    _i18nAccessLogGroupbox;
 
43
 
 
44
    static {
 
45
        _resource = new ResourceSet("com.netscape.management.admserv.panel.panel");
 
46
        _i18nLogPath = _resource.getString("logging","LogPath");
 
47
        _i18nLogFile = _resource.getString("logging","LogFile");
 
48
        _i18nAccessLogGroupbox = _resource.getString("logging","AccessLogGroupbox");
 
49
        _i18nErrorLogGroupbox = _resource.getString("logging","ErrorLogGroupbox");
 
50
    }
 
51
 
 
52
    Help _help;
 
53
 
 
54
    public static final int topInset =
 
55
            SuiConstants.SEPARATED_COMPONENT_SPACE;
 
56
    public static final int rghtColInset = SuiConstants.COMPONENT_SPACE;
 
57
 
 
58
    JLabel _lblAccessPath, _lblErrorPath;
 
59
    JTextField _txtAccessPath, _txtErrorPath;
 
60
 
 
61
    JLabel _lblAccessFile, _lblErrorFile;
 
62
    JTextField _txtAccessFile, _txtErrorFile;
 
63
 
 
64
 
 
65
    public LoggingConfigPanel(String title, ConsoleInfo consoleInfo) {
 
66
        super(title);
 
67
        _configData = new CGILoggingSetup(consoleInfo);
 
68
 
 
69
        setLayout(new BorderLayout());
 
70
        add(makeConfigPanel(), BorderLayout.NORTH);
 
71
        _help = new Help(_resource);
 
72
    }
 
73
 
 
74
    public void showHelp() {
 
75
        _help.contextHelp("loggingHelp");
 
76
    }
 
77
 
 
78
    public IConfigDataModel getDataModel() {
 
79
        return _configData;
 
80
    }
 
81
 
 
82
    public void setDataModel(IConfigDataModel data) {
 
83
        _configData = data;
 
84
        if (_configData.isLoaded()) {
 
85
            setPanelContent(_configData);
 
86
        }
 
87
    }
 
88
 
 
89
    public void initialize() throws ConfigPanelException {
 
90
        try {
 
91
            if (!_configData.isLoaded()) {
 
92
                _configData.load();
 
93
            }
 
94
            setPanelContent(_configData);
 
95
        } catch (ConfigPanelException e) {
 
96
            throw e;
 
97
        }
 
98
    }
 
99
 
 
100
    public void resetContent() {
 
101
        setPanelContent(_configData);
 
102
    }
 
103
 
 
104
    public void applyChanges() throws ValidationException {
 
105
        try {
 
106
            getPanelContent(_configData);
 
107
        } catch (ValidationException e) {
 
108
            throw e;
 
109
        }
 
110
    }
 
111
 
 
112
    public void registerEditComponents(EditMonitor editMonitor) {
 
113
        editMonitor.monitor(_txtAccessFile);
 
114
        editMonitor.monitor(_txtErrorFile);
 
115
    }
 
116
 
 
117
    public void setPanelContent(IConfigDataModel data) {
 
118
System.out.println("LoggingConfigPanel.setPanelContent: data: "+data.getClass().getName());
 
119
        String value;
 
120
        value = (String) data.getAttribute(AttrNames.CONFIG_ACCESSLOG);
 
121
        if (value == null) {
 
122
            _txtAccessPath.setText("");
 
123
            _txtAccessFile.setText("");
 
124
        } else {
 
125
            int i = value.lastIndexOf('/');
 
126
            _txtAccessPath.setText(value.substring(0, i));
 
127
            _txtAccessFile.setText(value.substring(i+1));
 
128
        }
 
129
 
 
130
        value = (String) data.getAttribute(AttrNames.CONFIG_ERRORLOG);
 
131
        if (value == null) {
 
132
            _txtErrorPath.setText("");
 
133
            _txtErrorFile.setText("");
 
134
        } else {
 
135
            int i = value.lastIndexOf('/');
 
136
            _txtErrorPath.setText(value.substring(0, i));
 
137
            _txtErrorFile.setText(value.substring(i+1));
 
138
        }
 
139
    }
 
140
 
 
141
    public void getPanelContent(IConfigDataModel data)
 
142
            throws ValidationException {
 
143
        try {
 
144
            data.setAttribute(AttrNames.CONFIG_ACCESSLOG,
 
145
                    _txtAccessPath.getText()+"/"+_txtAccessFile.getText());
 
146
            data.setAttribute(AttrNames.CONFIG_ERRORLOG,
 
147
                    _txtErrorPath.getText()+"/"+_txtErrorFile.getText());
 
148
        } catch (ValidationException e) {
 
149
            throw e;
 
150
        }
 
151
    }
 
152
 
 
153
 
 
154
    private JPanel makeConfigPanel() {
 
155
 
 
156
        JPanel p = new JPanel();
 
157
        GBC gbc = new GBC();
 
158
        GridBagLayout gbl;
 
159
        JPanel ctrlGroup;
 
160
 
 
161
        p.setLayout(gbl = new GridBagLayout());
 
162
 
 
163
        _lblAccessPath = new JLabel(_i18nLogPath);
 
164
        _txtAccessPath = new SingleByteTextField(16);
 
165
        _lblAccessFile = new JLabel(_i18nLogFile);
 
166
        _txtAccessFile = new SingleByteTextField(16); // 324429
 
167
 
 
168
        _txtAccessPath.setEditable(false);
 
169
 
 
170
        //gbc.setInsets(0,leftColInset,0,0);
 
171
        gbc.setGrid(0, 0, 1, 1);
 
172
        gbc.setSpace(1.0, 0.0, GBC.WEST, //anchor
 
173
                GBC.HORIZONTAL); //fill
 
174
        p.add(createLogGroup(_i18nAccessLogGroupbox,
 
175
                _lblAccessPath, _txtAccessPath,
 
176
                _lblAccessFile, _txtAccessFile), gbc);
 
177
 
 
178
        _lblErrorPath = new JLabel(_i18nLogPath);
 
179
        _txtErrorPath = new SingleByteTextField(16);
 
180
        _lblErrorFile = new JLabel(_i18nLogFile);
 
181
        _txtErrorFile = new SingleByteTextField(16); // 324429
 
182
 
 
183
        _txtErrorPath.setEditable(false);
 
184
 
 
185
        //gbc.setInsets(0,leftColInset,0,0);
 
186
        gbc.setGrid(0, 1, 1, 1);
 
187
        gbc.setSpace(1.0, 0.0, GBC.WEST, //anchor
 
188
                GBC.HORIZONTAL); //fill
 
189
        p.add(createLogGroup(_i18nErrorLogGroupbox,
 
190
                _lblErrorPath, _txtErrorPath,
 
191
                _lblErrorFile, _txtErrorFile), gbc);
 
192
 
 
193
        return p;
 
194
    }
 
195
 
 
196
    private JPanel createLogGroup(String groupTitle,
 
197
            JLabel lblPath, JTextField txtPath,
 
198
            JLabel lblFile, JTextField txtFile) {
 
199
        GridBagLayout gbl;
 
200
        GBC gbc = new GBC();
 
201
        JPanel group = new JPanel(gbl = new GridBagLayout());
 
202
        group.setBorder(BaseConfigPanel.createGroupBorder(groupTitle));
 
203
 
 
204
        lblPath.setFont(BaseConfigPanel.getLabelFont());
 
205
        gbc.setInsets(0, 0, 0, 0);
 
206
        gbc.setGrid(0, 0, 1, 1);
 
207
        gbc.setSpace(0.0, 0.0, GBC.WEST, //anchor
 
208
                GBC.NONE); //fill
 
209
        group.add(lblPath, gbc);
 
210
 
 
211
        gbc.setInsets(0, rghtColInset, 0, 0);
 
212
        gbc.setGrid(1, 0, 1, 1);
 
213
        gbc.setSpace(1.0, 0.0, GBC.WEST, // anchor
 
214
                GBC.HORIZONTAL); //fill
 
215
        group.add(txtPath, gbc);
 
216
 
 
217
        lblFile.setFont(BaseConfigPanel.getLabelFont());
 
218
        gbc.setInsets(0, 0, 0, 0);
 
219
        gbc.setGrid(0, 1, 1, 1);
 
220
        gbc.setSpace(0.0, 0.0, GBC.WEST, //anchor
 
221
                GBC.NONE); //fill
 
222
        group.add(lblFile, gbc);
 
223
 
 
224
        gbc.setInsets(0, rghtColInset, 0, 0);
 
225
        gbc.setGrid(1, 1, 1, 1);
 
226
        gbc.setSpace(1.0, 0.0, GBC.WEST, // anchor
 
227
                GBC.HORIZONTAL); //fill
 
228
        group.add(txtFile, gbc);
 
229
 
 
230
        return group;
 
231
    }
 
232
}