summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/security/CRLDeleteCertDialog.java
blob: 6b1132ced15930a08685c4e31bf169388793e222 (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
// --- 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.security;

import javax.swing.*;
import javax.swing.border.*;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

import com.netscape.management.client.console.ConsoleInfo;


import com.netscape.management.client.util.*;
import com.netscape.management.nmclf.*;

class CRLDeleteCertDialog extends AbstractDialog implements SuiConstants {



    ConsoleInfo _consoleInfo;

    KeyCertTaskInfo _taskInfo;
    static boolean delete = false;

    String _sie;

    JButton bClose;
    JButton bDelete;
    JButton bHelp;

    CertInfo _certInfo;
    ResourceSet _resource;
    String _crlname;
    String _listtype;

    CRLCertInfoPane _crlCertInfoPane;


    class CRLDeleteCertActionListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("DELETE")) {
                //call delete cert cgi
                _taskInfo.clear();
                _taskInfo.put("formop", "D");
                _taskInfo.put("crlname", _crlname);
                _taskInfo.put("sie", _sie);
                _taskInfo.put("list_type", _listtype);

                Response response = null;
                try {
                    response = _taskInfo.exec(_taskInfo.SEC_ECRL);
                } catch (Exception error) {
                    SuiOptionPane.showMessageDialog(
                            UtilConsoleGlobals.getActivatedFrame(),
                            error.getMessage());
                    return;
                }
                if (!(((Message)(response.getMessages().elementAt(0))).
                        isFailure())) {
                    delete = true;
                    setVisible(false);
                } else {
                    try {
                        MessageDialog.messageDialog( (Message)
                                (response.getMessages().elementAt(0)));
                    } catch (Exception e2) {
                        //shouldn't even be here in the first place.  if cgi fail or return nothing
                        //then it should be handle right after KeyCertTaskInfo.exec(...) is called
                        //If exception occure here here then something is really mess up.
                        Debug.println("Error in decoding server messages");
                    }
                }
            } else if (e.getActionCommand().equals("CLOSE")) {
                setVisible(false);
            } else if (e.getActionCommand().equals("HELP")) {
                Help help = new Help(_resource);
                help.help("CRLDeleteCertDialog", "help");
            }
        }
    }

    public boolean isDeleted() {
        return delete;
    }

    protected void show(String crlname, String list_type) {
        delete = false;
        _crlname = crlname;
        _listtype = list_type;

        _taskInfo.clear();
        _taskInfo.put("sie", _sie);
        _taskInfo.put("crlname", crlname);
        _taskInfo.put("list_type", list_type);
        try {
            _taskInfo.exec(_taskInfo.SEC_ECRL);
        } catch (Exception e) {
            SuiOptionPane.showMessageDialog(
                    UtilConsoleGlobals.getActivatedFrame(), e.getMessage());
            return;
        }

        if (_taskInfo.getResponse().hasCertInfo()) {
            setInfo(_taskInfo.getResponse().getCertInfo());
            super.show();
        } else {
            Object[] message = new Object[2];
            message[0] = _resource.getString("CRLDeleteCertDialog", "error");
            SuiOptionPane.showMessageDialog(
                    UtilConsoleGlobals.getActivatedFrame(), message);
        }
    }

    private void setInfo(CertInfo certInfo) {
        _certInfo = certInfo;

        _crlCertInfoPane.setCertInfo(certInfo);
    }


    public CRLDeleteCertDialog(ConsoleInfo consoleInfo,
            ResourceSet resource) {
        super(null, "", true, NO_BUTTONS);

        _consoleInfo = consoleInfo;
        _sie = KeyCertUtility.createTokenName(_consoleInfo);
        _resource = resource;
        _taskInfo = new KeyCertTaskInfo(consoleInfo);

        _crlCertInfoPane = new CRLCertInfoPane(resource);

        Container mainPane = getContentPane();
        mainPane.setLayout(new GridBagLayout());

        GridBagUtil.constrain(mainPane, _crlCertInfoPane, 0, 0, 4, 1,
                1.0, 1.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0,
                SuiConstants.DIFFERENT_COMPONENT_SPACE, 0);


        CRLDeleteCertActionListener listener =
                new CRLDeleteCertActionListener();

        bClose = JButtonFactory.createCloseButton(listener);
        GridBagUtil.constrain(mainPane, bClose, 1, 1, 1, 1, 1.0, 0.0,
                GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE,
                0, 0, 0, SuiConstants.COMPONENT_SPACE);


        bDelete = JButtonFactory.createDeleteButton(listener);
        GridBagUtil.constrain(mainPane, bDelete, 2, 1, 1, 1, 0.0, 0.0,
                GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE,
                0, 0, 0, SuiConstants.SEPARATED_COMPONENT_SPACE);


        bHelp = JButtonFactory.createHelpButton(listener);
        GridBagUtil.constrain(mainPane, bHelp, 3, 1, 1, 1, 0.0, 0.0,
                GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE,
                0, 0, 0, 0);



        JButtonFactory.resizeGroup(bHelp, bClose, bDelete);

        setSize(400, 225);
        setResizable(false);
    }

    /*public static void main(String arg[]) {
     JFrame f = new JFrame();
     f.setSize(400,400);
     f.show();

     try {
      UIManager.setLookAndFeel("javax.swing.plaf.windows.WindowsLookAndFeel");
      SwingUtilities.updateComponentTreeUI(f.getContentPane());
     } catch (Exception e) {}


     CRLDeleteCertDialog d = new CRLDeleteCertDialog(new ConsoleInfo(), new ResourceSet("com.netscape.admin.certsrv.security.CertManagementResource"));
     d.show();
     }*/
}