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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
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 * pmDelete.java
29 * Delete Printer implementation
30 */
31
32package com.sun.admin.pm.client;
33
34import java.awt.*;
35import java.awt.event.*;
36import javax.swing.JPanel;
37import javax.swing.*;
38
39import com.sun.admin.pm.server.*;
40
41
42/*
43 * Window for Edit -> Delete
44 */
45
46// public class pmDelete extends JPanel {
47public class pmDelete {
48
49    Printer newpr = null;
50    pmTop mytop = null;
51
52    public pmDelete(pmTop mytop)
53    {
54        this.mytop = mytop;
55        newpr = new Printer(mytop.ns);
56
57        Debug.message("CLNT:  pmDelete");
58
59        if (mytop.selectedPrinter.equals("")) {
60            Debug.warning("CLNT:  pmDelete:error: selectedPrinter empty");
61            // Display error window
62            actioncancelButton();
63         }
64
65        pmOKCancelDialog d = new pmOKCancelDialog(
66            mytop.parentFrame,
67            pmUtility.getResource("SPM:Delete.Printer"),
68            pmUtility.getResource("Please.confirm.deletion.of.printer") +
69		mytop.selectedPrinter, false);
70        d.setVisible(true);
71
72        if (d.getValue() != JOptionPane.OK_OPTION)
73            actioncancelButton();
74        else {
75            try {
76                actionokButton();
77            } catch (pmUserCancelledException ce) {
78                Debug.message("CLNT:  pmDelete:okButton: Login cancelled");
79            } catch (pmLoginFailedException de) {
80                pmMessageDialog m = new pmMessageDialog(
81                    mytop.parentFrame,
82                    pmUtility.getResource("Error"),
83                    pmUtility.getResource("Required.login.failed."),
84                    mytop,
85                    "LoginFailed");
86                m.setVisible(true);
87            } catch (pmGuiException ge) {
88                pmMessageDialog m = new pmMessageDialog(
89                    mytop.parentFrame,
90                    pmUtility.getResource("Application.Error"),
91                    ge.toString());
92                m.setVisible(true);
93            }
94        }
95
96    }
97
98    public void actionokButton() throws pmGuiException {
99	int ret;
100        String cmd = null;
101        String warn = null;
102        String err = null;
103
104	Debug.message("CLNT:  pmDelete actionokButton()");
105
106	// handle authentication if needed
107	if (mytop.ns.getNameService().equals("nis") == true ||
108		mytop.ns.getNameService().equals("ldap") == true) {
109	    try {
110		if (!mytop.ns.isAuth()) {
111			pmUtility.doLogin(mytop, mytop.parentFrame);
112		}
113	    } catch (pmUserCancelledException e) {
114		Debug.message("CLNT:  pmDelete:User cancelled login");
115		throw new pmUserCancelledException(
116				pmUtility.getResource("User.Cancelled.Login"));
117	    } catch (pmGuiException e) {
118		Debug.warning("CLNT:  pmDelete:login for nis/ldap failed");
119		throw new pmLoginFailedException(
120			pmUtility.getResource("Login.Authorization.Failed"));
121	    } catch (Exception e) {
122		Debug.warning("CLNT:  pmDelete:login for nis/ldap failed");
123		throw new pmLoginFailedException(
124                  pmUtility.getResource("Login.Authorization.Failed"));
125	    }
126	}
127
128	newpr.setPrinterName(mytop.selectedPrinter);
129
130	// delete the printer
131	boolean failed = false;
132	try {
133		newpr.deletePrinter();
134        } catch (Exception e) {
135		Debug.warning("CLNT:  pmDelete:deletePrinter exception " + e);
136		failed = true;
137	}
138
139	cmd = newpr.getCmdLog();
140	warn = newpr.getWarnLog();
141	err = newpr.getErrorLog();
142
143	Debug.message("CLNT:  pmDelete: delete cmd = " + cmd);
144	Debug.message("CLNT:  pmDelete: delete err = " + err);
145	Debug.message("CLNT:  pmDelete: delete warn = " + warn);
146
147	if (failed) {
148		pmMessageDialog m = new pmMessageDialog(
149			mytop.parentFrame,
150			pmUtility.getResource("Error"),
151			((err == null) ?
152			   pmUtility.getResource(
153				"Printer.delete.operation.failed.") :
154			err),
155			mytop,
156			"DeletePrinterFailed");
157		m.setVisible(true);
158
159        } else {
160		Debug.message("CLNT: pmDelete return from deletePrinter ok");
161
162		// Deletion successful, change the table
163		if (mytop.selectedRow >= 0) {
164			// update table
165			mytop.pmsetPrinterList();
166			mytop.clearSelected();
167			mytop.listTable.clearSelection();
168			mytop.pmsetdefaultpLabel();
169		} else {
170			Debug.warning("CLNT:  pmDelete:selectedRow invalid: " +
171				   mytop.selectedRow);
172		}
173	}
174	mytop.setLogData(cmd, err, warn);
175	mytop.showLogData(pmUtility.getResource("Delete.Printer"));
176    }
177
178
179    public void actioncancelButton() {
180	Debug.message("CLNT:  pmDelete: actioncancelButton()");
181    }
182
183}
184