DhcpmgrApplet.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* Main class for DHCP Manager. It is theoretically possible to run this
* application as a command managing the local system, a command managing a
* remote system using RMI, or as an applet managing the system from which it
* was downloaded. We presently only support the first option, but there is
* vestigial code here from when the other options were supported as they may
* be again. That's why we extend JApplet.
*/
public class DhcpmgrApplet extends JApplet {
public static boolean modeIsRelay;
private AddressView addressView;
private RestartAction restartAction;
private StopAction stopAction;
private StartAction startAction;
private DisableAction disableAction;
private EnableAction enableAction;
// Handler for Help->Overview menu item
class OverviewAction extends MnemonicAction {
public OverviewAction() {
}
public void actionPerformed(ActionEvent e) {
showHelp("overview");
}
}
// Handler for Help->How To menu item
class HowToAction extends MnemonicAction {
public HowToAction() {
}
public void actionPerformed(ActionEvent e) {
showHelp("howto");
}
}
// Handler for Help->Index menu item
class IndexAction extends MnemonicAction {
public IndexAction() {
}
public void actionPerformed(ActionEvent e) {
showHelp("index");
}
}
// Handler for Help->On Service menu item
class ServiceAction extends MnemonicAction {
public ServiceAction() {
}
public void actionPerformed(ActionEvent e) {
showHelp("service_reference");
}
}
// Handler for the Service->Restart menu item
class RestartAction extends MnemonicAction {
public RestartAction() {
}
public void actionPerformed(ActionEvent e) {
try {
} catch (NotRunningException ex) {
// Server not running, ignore the error and just start it
} catch (Throwable t) {
}
}
}
// Handler for the Service->Stop menu item
class StopAction extends MnemonicAction {
public StopAction() {
}
public void actionPerformed(ActionEvent e) {
try {
startAction.setEnabled(true);
restartAction.setEnabled(false);
setEnabled(false);
} catch (Throwable t) {
}
}
}
// Handler for the Service->Restart menu item
class StartAction extends MnemonicAction {
public StartAction() {
}
public void actionPerformed(ActionEvent e) {
try {
stopAction.setEnabled(true);
restartAction.setEnabled(true);
setEnabled(false);
} catch (Throwable t) {
}
}
}
// handler for the Service->Disable service menu item
class DisableAction extends MnemonicAction {
public DisableAction() {
}
public void actionPerformed(ActionEvent e) {
d.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Update menu item state once we've disabled it
enableAction.setEnabled(true);
disableAction.setEnabled(false);
stopAction.setEnabled(false);
startAction.setEnabled(false);
restartAction.setEnabled(false);
}
});
d.pack();
d.setVisible(true);
}
}
// handler for the Service->Enable service menu item
class EnableAction extends MnemonicAction {
public EnableAction() {
}
public void actionPerformed(ActionEvent e) {
d.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Update menu item state once we've enabled it
disableAction.setEnabled(true);
enableAction.setEnabled(false);
stopAction.setEnabled(true);
startAction.setEnabled(false);
restartAction.setEnabled(true);
}
});
d.pack();
d.setVisible(true);
}
}
// handler for the Service->Modify service menu item
class ModifyServiceAction extends MnemonicAction {
public ModifyServiceAction() {
}
public void actionPerformed(ActionEvent e) {
try {
d.pack();
d.setVisible(true);
} catch (BridgeException ex) {
// Error reading options
}
}
}
// handler for the Service->Convert service menu item
class ConvertAction extends MnemonicAction {
public ConvertAction() {
}
public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
showFrame();
}
}
});
wiz.setVisible(true);
}
public void setEnabled(boolean b) {
if (!modeIsRelay) {
super.setEnabled(b);
} else {
super.setEnabled(false);
}
}
}
// handler for the Service->Unconfigure service menu item
class UnconfigureServiceAction extends MnemonicAction {
public UnconfigureServiceAction() {
}
public void actionPerformed(ActionEvent e) {
d.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*
* User unconfigured the service; there's nothing
* else to do so just get rid of the frame which
* will as a side effect shut us down.
*/
frame.setVisible(false);
}
}
});
d.pack();
d.setVisible(true);
}
}
// Action for Service->Export data
class ExportAction extends MnemonicAction {
public ExportAction() {
}
public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
showFrame();
}
}
});
wiz.setVisible(true);
}
}
// Action for Service->Import data
class ImportAction extends MnemonicAction {
public ImportAction() {
}
public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
showFrame();
}
}
});
wiz.setVisible(true);
}
}
/*
* This class provides a transition dialog which allows the user
* to initiate the address wizard immediately upon startup. It's
* done this way so that the startMeUp() method can use invokeLater()
* to cause it to be displayed after the config wizard exit event
* has been processed rather than during that event's processing;
* otherwise the wizard doesn't disappear until after the user presses
* Yes or No in this dialog.
*/
class WizardTransition implements Runnable {
public void run() {
// Now transition to configuring addresses
}
}
}
/*
* This class provides a transition dialog which allows the user
* to initiate the conversion wizard immediately upon startup if a
* version mismatch exists (a data store upgrade is necessary).
*/
class ConversionTransition implements Runnable {
public void run() {
try {
while (!svcMgr.isVersionCurrent()) {
ActionEvent e = new ActionEvent(this,
} else {
requestExit();
}
}
} catch (Throwable e) {
requestExit();
}
}
}
// Create the frame within which the UI will live
private void createFrame() {
// Create the views for this tool
if (modeIsRelay) {
} else {
addressView = new AddressView();
}
// Set up the services menu
(restartAction = new RestartAction()));
(stopAction = new StopAction()));
(startAction = new StartAction()));
(disableAction = new DisableAction()));
(enableAction = new EnableAction()));
new ModifyServiceAction());
if (!modeIsRelay) {
new ExportAction());
new ImportAction());
new ConvertAction());
}
new UnconfigureServiceAction());
// Set up the Help menu
// In relay mode, let it size itself (quite small)
if (modeIsRelay) {
} else {
/*
* Normal mode set it to a reasonable size. This ought to be
* a user preference, but until we run as something other than
* root it's not really a useful idea.
*/
}
// Listen for closing events
public void windowClosing(WindowEvent e) {
/*
* This is here to work around the Close selection frame
* menu on Solaris not causing the closed function to be
* called
*/
windowClosed(e);
}
public void windowClosed(WindowEvent e) {
// Dispose of all data and exit when window goes away.
requestExit();
}
});
}
}
// Show the frame
private void showFrame() {
createFrame();
}
frame.initialize();
if (modeIsRelay) {
// Disable edit & view menus in the relay case
}
try {
// Set status of service menu options based on server state
boolean running =
} catch (Throwable e) {
// Enable all the menu items, as something went wrong
restartAction.setEnabled(true);
stopAction.setEnabled(true);
startAction.setEnabled(true);
enableAction.setEnabled(true);
disableAction.setEnabled(true);
}
frame.setVisible(true);
}
/*
* main startup code; checks whether server is already configured, and if
* not runs through the config wizard sequence in order to get the server
* configured.
*/
private void startMeUp() {
try {
}
// See if server is already configured, and start up
// If server mode, ensure RESOURCE and PATH were set
if (!modeIsRelay) {
requestExit();
}
}
showFrame();
// Check to make sure that the data store version is up to date.
// If not, inform the user and present them with the conversion
// wizard so that they can upgrade.
}
} catch (BridgeException e) {
// Let user select which type of service to configure
// DHCP; run the wizard
public void actionPerformed(ActionEvent e) {
// Service config completed, start up
modeIsRelay = false;
showFrame();
// Now transition to configuring addresses
} else {
// User cancelled the wizard, exit
requestExit();
}
}
});
wiz.setVisible(true);
// Wants to configure a relay, show the dialog for that
d.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Relay configuration completed, start up
modeIsRelay = true;
showFrame();
} else {
// User cancelled, exit
requestExit();
}
}
});
d.pack();
d.setVisible(true);
} else {
// User cancelled; exit
requestExit();
}
} catch (Throwable e) {
// Couldn't really get started, dump the stack and exit
e.printStackTrace();
requestExit();
}
}
// Show a help file referenced by tag
// If help tag mapping table not loaded yet, then load it
try {
} catch (Throwable e) {
// Error initializing help system
return;
}
}
// Ask browser to display
try {
}
}
// Exit the application
private void requestExit() {
}
// Main function when we're run as an application
// Ensure that we're running as root; exit if not
}
}
}