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 a macro. 43 */ 44 public class DeleteMacroDialog extends DhcpmgrDialog { 45 private JCheckBox signalBox; 46 private Macro macro; 47 private JLabel message; 48 49 public DeleteMacroDialog(Frame f, Macro m) { 50 super(f, false); 51 setTitle(ResourceStrings.getString("delete_macro_title")); 52 macro = m; 53 message.setText(MessageFormat.format( 54 ResourceStrings.getString("delete_macro_confirm"), macro.getKey())); 55 message.setToolTipText(MessageFormat.format( 56 ResourceStrings.getString("delete_macro_confirm"), macro.getKey())); 57 } 58 59 public JPanel getMainPanel() { 60 JPanel mainPanel = new JPanel(new BorderLayout()); 61 62 JPanel flowPanel = new JPanel(); 63 64 message = new JLabel(); 65 flowPanel.add(message); 66 mainPanel.add(flowPanel, BorderLayout.NORTH); 67 68 flowPanel = new JPanel(); 69 signalBox = new JCheckBox(ResourceStrings.getString("signal_server"), 70 true); 71 signalBox.setToolTipText( 72 ResourceStrings.getString("signal_server")); 73 flowPanel.add(signalBox); 74 mainPanel.add(flowPanel, BorderLayout.CENTER); 75 76 buttonPanel.setOkEnabled(true); 77 return mainPanel; 78 } 79 80 protected void doOk() { 81 try { 82 DhcptabMgr server = DataManager.get().getDhcptabMgr(); 83 server.deleteRecord(macro, signalBox.isSelected()); 84 fireActionPerformed(); 85 setVisible(false); 86 dispose(); 87 } catch (NotRunningException e) { 88 // Server not running, put up a warning 89 JOptionPane.showMessageDialog(this, 90 ResourceStrings.getString("server_not_running"), 91 ResourceStrings.getString("warning"), 92 JOptionPane.WARNING_MESSAGE); 93 fireActionPerformed(); 94 setVisible(false); 95 dispose(); 96 } catch (Exception e) { 97 MessageFormat form = null; 98 Object [] args = new Object[2]; 99 form = new MessageFormat( 100 ResourceStrings.getString("delete_macro_error")); 101 args[0] = macro.getKey(); 102 args[1] = e.getMessage(); 103 JOptionPane.showMessageDialog(this, form.format(args), 104 ResourceStrings.getString("server_error_title"), 105 JOptionPane.ERROR_MESSAGE); 106 } 107 } 108 109 protected String getHelpKey() { 110 return "delete_macro"; 111 } 112 113 protected void fireActionPerformed() { 114 fireActionPerformed(this, DialogActions.DELETE); 115 } 116 }