// --- 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 java.util.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import javax.swing.text.*; import javax.swing.event.*; import com.netscape.management.client.util.*; import com.netscape.admin.certsrv.connection.*; import com.netscape.certsrv.common.*; import com.netscape.admin.certsrv.*; /** * Display the auto recovery dialog box. * @author chrisho * @version $Revision$, $Date$ */ public class CMSAutoRecovery extends JDialog implements ActionListener, ListSelectionListener, MouseListener { private final static String PREFIX = "AUTORECOVERYDIALOG"; private AdminConnection mAdmin; private JFrame mParentFrame; private ResourceBundle mResource; private JButton mOK; private JButton mCancel; private JButton mEnable; private String mDisableLabel; private String mDisableTip; private JTable mTable; private AutoRecoveryModel mDataModel; protected JScrollPane mScrollPane; public CMSAutoRecovery(JFrame parent, AdminConnection conn, JButton button) { super(parent, true); mParentFrame = parent; mAdmin = conn; mEnable = button; mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); mDisableLabel = mResource.getString(PREFIX + "_BUTTON_"+"DISABLEAUTO_LABEL"); mDisableTip = mResource.getString(PREFIX + "_BUTTON_"+"DISABLEAUTO_TTIP"); setSize(360, 216); setTitle(mResource.getString(PREFIX+"_TITLE")); setLocationRelativeTo(parent); getRootPane().setDoubleBuffered(true); setDisplay(); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("ok")) { Component component = mTable.getEditorComponent(); if(component!= null) { int col = mTable.getEditingColumn(); int row = mTable.getEditingRow(); if ((col>-1)&&(row>-1)) { String str = ((JTextComponent)component).getText(); mTable.setValueAt(str, row, col); } } String val = getUIDPassword(); // check empty user id and password if (val.equals("")) { CMSAdminUtil.showMessageDialog(mParentFrame, mResource, PREFIX, "EMPTYFIELD", CMSAdminUtil.ERROR_MESSAGE); return; } else { NameValuePairs nvps = new NameValuePairs(); nvps.put(Constants.PR_RECOVERY_AGENT, val); nvps.put(Constants.PR_AUTO_RECOVERY_ON, Constants.TRUE); try { mAdmin.modify(DestDef.DEST_KRA_ADMIN, ScopeDef.SC_AUTO_RECOVERY, Constants.RS_ID_CONFIG, nvps); } catch (EAdminException ex) { CMSAdminUtil.showErrorDialog(mParentFrame, mResource, ex.getMessage(), CMSAdminUtil.ERROR_MESSAGE); } } mEnable.setText(mDisableLabel); mEnable.setToolTipText(mDisableTip); mEnable.repaint(); cleanup(); this.dispose(); } else if (e.getActionCommand().equals("cancel")) { cleanup(); this.dispose(); } } //Set the first column's cellrender as label cell protected void setLabelCellRenderer(JTable table, int index) { table.getColumnModel().getColumn(index).setCellRenderer( new DefaultTableCellRenderer()); } //Set the first column's cellrender as label cell protected void setLabelCellEditor(JTable table, int index) { table.getColumnModel().getColumn(index).setCellRenderer( new PasswordCellRenderer()); table.getColumnModel().getColumn(index).setCellEditor( new DefaultCellEditor(new JPasswordField())); } private String getUIDPassword() { String result = ""; for (int i=0; i