1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 package com.sun.dhcpmgr.client; 29 30 import java.awt.*; 31 import java.awt.event.*; 32 import java.text.MessageFormat; 33 import java.util.*; 34 import javax.swing.*; 35 36 import com.sun.dhcpmgr.server.*; 37 import com.sun.dhcpmgr.data.*; 38 import com.sun.dhcpmgr.ui.*; 39 import com.sun.dhcpmgr.bridge.NotRunningException; 40 41 /** 42 * This dialog allows the user to delete an option definition 43 */ 44 public class DeleteOptionDialog extends DhcpmgrDialog { 45 private JCheckBox signalBox; 46 private Option option; 47 private JLabel message; 48 49 public DeleteOptionDialog(Frame f, Option o) { 50 super(f, false); 51 setTitle(ResourceStrings.getString("delete_option_title")); 52 option = o; 53 message.setText(MessageFormat.format( 54 ResourceStrings.getString("delete_option_confirm"), o.getKey())); 55 message.setToolTipText(MessageFormat.format( 56 ResourceStrings.getString("delete_option_confirm"), o.getKey())); 57 } 58 59 protected JPanel getMainPanel() { 60 JPanel mainPanel = new JPanel(new BorderLayout()); 61 JPanel flowPanel = new JPanel(); 62 63 message = new JLabel(); 64 flowPanel.add(message); 65 mainPanel.add(flowPanel, BorderLayout.NORTH); 66 67 flowPanel = new JPanel(); 68 signalBox = new JCheckBox(ResourceStrings.getString("signal_server"), 69 true); 70 signalBox.setToolTipText( 71 ResourceStrings.getString("signal_server")); 72 flowPanel.add(signalBox); 73 mainPanel.add(flowPanel, BorderLayout.CENTER); 74 75 buttonPanel.setOkEnabled(true); 76 return mainPanel; 77 } 78 79 protected void doOk() { 80 try { 81 DhcptabMgr server = DataManager.get().getDhcptabMgr(); 82 server.deleteRecord(option, signalBox.isSelected()); 83 fireActionPerformed(); 84 setVisible(false); 85 dispose(); 86 } catch (NotRunningException e) { 87 // Server not running, put up a warning 88 JOptionPane.showMessageDialog(this, 89 ResourceStrings.getString("server_not_running"), 90 ResourceStrings.getString("warning"), 91 JOptionPane.WARNING_MESSAGE); 92 fireActionPerformed(); 93 setVisible(false); 94 dispose(); 95 } catch (Exception e) { 96 MessageFormat form = null; 97 Object [] args = new Object[2]; 98 form = new MessageFormat( 99 ResourceStrings.getString("delete_option_error")); 100 args[0] = option.getKey(); 101 args[1] = e.getMessage(); 102 JOptionPane.showMessageDialog(this, form.format(args), 103 ResourceStrings.getString("server_error_title"), 104 JOptionPane.ERROR_MESSAGE); 105 } 106 } 107 108 protected String getHelpKey() { 109 return "delete_option"; 110 } 111 112 protected void fireActionPerformed() { 113 fireActionPerformed(this, DialogActions.DELETE); 114 } 115 }