summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/config/WMNSelection.java
blob: db7753b1dff44d60814dfdbb46ec386aef691929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.admin.certsrv.config;

import java.awt.*;
import javax.swing.*;
import com.netscape.admin.certsrv.*;
import com.netscape.admin.certsrv.wizard.*;
import com.netscape.management.client.util.*;
import com.netscape.certsrv.common.*;

/**
 * MNSelection page for reconfiguring the Recovery MN Scheme
 *
 * @author Jack Pan-Chen
 * @version $Revision$, $Date$
 * @see com.netscape.admin.certsrv.config
 */
class WMNSelection extends WizardBasePanel
    implements IWizardPanel
{

    /*==========================================================
     * variables
     *==========================================================*/
    private static final String PANELNAME = "WMNSELECTION";

    private JTextField mMField, mNField;
    private JLabel mMLabel, mNLabel;
    private int mRequired, mAvail;

    private MNSchemeWizardInfo mInfo;
    private static final String HELPINDEX =
      "configuration-kra-wizard-change-keyscheme-help";

	/*==========================================================
     * constructors
     *==========================================================*/
    WMNSelection() {
        super(PANELNAME);
        init();
    }

    public boolean isLastPage() {
        return false;
    }

    /*==========================================================
	 * public methods
     *==========================================================*/

    public boolean initializePanel(WizardInfo info) {
        //let's set the values
        mInfo = (MNSchemeWizardInfo)info;
        mMField.setText(mInfo.getNewM());
        mNField.setText(mInfo.getNewN());
        mMLabel.setText(mInfo.getM());
        mNLabel.setText(mInfo.getN());
        return true;
    }

    public boolean validatePanel() {
        if ((mMField.getText().trim().equals("")) ||
            (mNField.getText().trim().equals("")) ) {
            setErrorMessage("CANNOTBEBLANK");
            return false;    
        }

        String str = mMField.getText().trim();
        if (str.equals("")) {
            setErrorMessage("CANNOTBEBLANK");
            return false;
        }

        try {
            mRequired = Integer.parseInt(str);
            str = mNField.getText().trim();
            if (str.equals("")) {
                setErrorMessage("CANNOTBEBLANK");
                return false;
            }
            mAvail = Integer.parseInt(str);
        } catch (NumberFormatException e) {
            setErrorMessage("NOTINTEGER");
            return false;
        }

        if (mRequired <= 0 || mAvail <= 0) {
            setErrorMessage("NONZERO");
            return false;
        }

        if (mRequired > mAvail) {
            setErrorMessage("LARGER");
            return false;
        }
        return true;
    }

    public boolean concludePanel(WizardInfo info) {
        return true;
    }

    public void getUpdateInfo(WizardInfo info) {
        mInfo.add(Constants.PR_RECOVERY_M, mMField.getText().trim());
        mInfo.add(Constants.PR_RECOVERY_N, mNField.getText().trim());
    }

    public void callHelp() {
        CMSAdminUtil.help(HELPINDEX);
    }

    //base class take care of these
    //public String getTitle();
    //public String getErrorMessage();

    /*==========================================================
	 * private methods
     *==========================================================*/

    //initialize the panel
    protected void init() {
        GridBagLayout gb = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        setLayout(gb);

        //show icon
        JLabel iconLabel = new JLabel(CMSAdminUtil.getImage(CMSAdminResources.IMAGE_CERTICON_LARGE));
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.NORTHWEST;
        gbc.fill = gbc.NONE;
        gbc.gridwidth = gbc.REMAINDER;
        gb.setConstraints(iconLabel,gbc);
        add(iconLabel);

        //show wizard description
        JTextArea desc = new JTextArea(
            CMSAdminUtil.wrapText(
            mResource.getString("WMNSELECTION_TEXT_DESC_LABEL"),60),2,60);
        desc.setBackground(getBackground());
        desc.setEditable(false);
        desc.setCaretColor(getBackground());
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.weightx = 1.0;
        gbc.weighty = 0.1;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,
      		                   COMPONENT_SPACE,COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(desc, gbc);

        //current setting
        JPanel oldPanel = new JPanel();
        oldPanel.setBorder(makeTitledBorder("OLDSCHEME"));
        GridBagLayout gb1 = new GridBagLayout();
        oldPanel.setLayout(gb1);

        //m
        JLabel label1 = makeJLabel("M");
        mMLabel = new JLabel("");
        CMSAdminUtil.resetGBC(gbc);
        CMSAdminUtil.addEntryField(oldPanel, label1, mMLabel, gbc);

        //n
        JLabel label3 = makeJLabel("N");
        mNLabel = new JLabel("");
        CMSAdminUtil.resetGBC(gbc);
        gbc.gridheight = gbc.REMAINDER;
        CMSAdminUtil.addEntryField(oldPanel, label3, mNLabel, gbc);

        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.NORTH;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.weightx = 1.0;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,
      		                   COMPONENT_SPACE,COMPONENT_SPACE);
      	gb.setConstraints(oldPanel,gbc);
        add(oldPanel);

        //new setting
        JPanel newPanel = new JPanel();
        newPanel.setBorder(makeTitledBorder("NEWSCHEME"));
        GridBagLayout gb2 = new GridBagLayout();
        newPanel.setLayout(gb2);

        //m
        JLabel label5 = makeJLabel("M");
        mMField = new JTextField("");
        CMSAdminUtil.resetGBC(gbc);
        CMSAdminUtil.addEntryField(newPanel, label5, mMField, gbc);

        //n
        JLabel label6 = makeJLabel("N");
        mNField = new JTextField("");
        CMSAdminUtil.resetGBC(gbc);
        gbc.gridheight = gbc.REMAINDER;
        CMSAdminUtil.addEntryField(newPanel, label6, mNField, gbc);

        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.NORTH;
        gbc.gridwidth = gbc.REMAINDER;
        //gbc.gridheight = gbc.REMAINDER;
        gbc.weightx = 1.0;
        gbc.weighty = 0.9;
        gb.setConstraints(newPanel,gbc);
        add(newPanel);

        super.init();
    }

}