AddressWizard.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.
*/
/**
* A wizard to configure a group of addresses.
*/
public class AddressWizard extends Wizard {
private int number = 10;
private IPAddress startAddress;
private boolean generateNames = false;
private boolean unusable = false;
private boolean dynamic = true;
private WizardTableModel addressTableModel;
class Address {
public Address() {
name = "";
}
name = n;
setAddr(a);
}
name = n;
setAddr(a);
}
public void setAddr(int a) {
}
try {
} catch (ValidationException e) {
// Do nothing
}
}
return addr.getHostAddress();
}
}
class WizardTableModel extends AbstractTableModel {
public int getRowCount() {
}
public int getColumnCount() {
return 2;
}
if (column == 0) {
} else {
}
}
if (column == 0) {
return IPAddress.class;
} else {
return String.class;
}
}
if (column == 0) {
} else {
}
}
public long generateAddresses() {
return 0;
}
int count = 0;
if (index == 0) {
// Don't try allocating the network address as a client address
++index;
}
try {
/*
* Sort the data so we can generate the list of addresses
* with a minimal number of comparisons here. First, though,
* clone the array so that sorting won't affect the original
* data set and throw off the main display.
*/
} catch (Throwable e) {
// XXX What to do here???
e.printStackTrace();
}
int base = 0;
long searchAddress = 0;
// We finished searching before satisfying the request
break;
}
/*
* If clients == null then this is an empty network,
* so searching for holes is unnecessary
*/
// Advance search pointer past lower-numbered addresses
&& ((searchAddress =
++base;
}
}
if (searchAddress != address) {
// found an empty slot; create the address
if (generateNames) {
} else {
}
++count;
}
++index;
}
// Inform UI that the data is ready.
return count;
}
}
}
// This step selects the number of addresses and a comment
class NumberStep implements WizardStep {
private IntegerField addressCount;
private JTextField commentField;
public NumberStep() {
// Explanatory text at the top
// Get the number of addresses to create
// Let user supply a comment
"add_wiz_comment_label"));
/*
* This listener ensures that the forward button is enabled only
* when there is a count of addresses in the addressCount field.
*/
new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
}
public boolean setInactive(int direction) {
if (number == 0) {
/*
* Going forward with 0 addresses makes no sense,
* display error and veto the move.
*/
return false;
}
return true;
}
}
// This step selects the server and starting address
class ServerStep implements WizardStep {
private IPAddressField startField;
private HostnameField baseNameField;
private JCheckBox generateNamesBox;
private HostnameField serverField;
public ServerStep() {
// Explanatory text at the top
// Server to own these addresses
// Add some spacing
// Starting address
// Add some more spacing, and an explanation of generating names
// Control to indicate whether names should be generated
generateNamesBox = new JCheckBox(
generateNamesBox.setEnabled(true);
try {
generateNamesBox.setEnabled(false);
}
} catch (BridgeException e) {
// Assume set
}
baseNameField = new HostnameField();
baseNameField.setEnabled(false);
"add_wiz_rootname_label"));
// Only enable the text input if name generation is requested
public void actionPerformed(ActionEvent e) {
}
});
public void insertUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
};
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
}
public boolean setInactive(int direction) {
// Validate that address is on the network we're working on
if (a == null) {
// Not a valid address at all
return false;
} else if (!network.containsAddress(a)) {
// Address is not on network
return false;
}
try {
} catch (Throwable e) {
/*
* Unknown hostname, probably, so put up the message and
* decline to continue
*/
return false;
}
}
return true;
}
}
// This step confirms the list of addresses to be generated
class ConfirmStep implements WizardStep {
private JTable addressTable;
public ConfirmStep() {
// Explanatory text at the top
// Label the table
"add_wiz_confirm_label"));
// Display the addresses in a table
new ExtendedCellRenderer());
// Table is not selectable in any way
addressTable.setRowSelectionAllowed(false);
addressTable.setCellSelectionEnabled(false);
// Wrap in a scroll pane so column headings display
}
public String getDescription() {
}
public Component getComponent() {
return stepPanel;
}
/*
* If we're activating coming from the previous step,
* generate the address list
*/
// Error if no addresses could be generated
if (count == 0) {
setForwardEnabled(false);
} else {
/*
* Warn if we couldn't generate the number of addresses
* requested
*/
"generate_addresses_warning"));
}
setForwardEnabled(true);
}
} else {
setForwardEnabled(true);
}
}
public boolean setInactive(int direction) {
return true; // Nothing to do when leaving
}
}
// This step selects the macro and flags
class ConfigureStep implements WizardStep {
// Model class for the macro list
class MacroListModel extends AbstractListModel
implements ComboBoxModel {
private Object currentValue;
public int getSize() {
try {
// If we don't have data yet, grab currently cached list
} catch (NoTableException e) {
// can function without table
} catch (Throwable e) {
e.printStackTrace();
}
}
return 1;
} else {
}
}
try {
// If we don't have data yet, grab currently cached list
} catch (NoTableException e) {
// can function without table
} catch (Throwable e) {
e.printStackTrace();
}
}
if (index == 0) {
} else {
}
}
}
}
}
public Object getSelectedItem() {
return currentValue;
}
if (index == 0) {
return noMacro;
} else {
}
}
}
private MacroListModel macroBoxModel;
private JButton viewButton;
private JCheckBox unusableBox;
public ConfigureStep() {
// Start with some explanatory text
// Add some spacing
// Let 'em select the macro to use
macroBoxModel = new MacroListModel();
// Button to view the contents of the selected macro
// Give the option to mark them unusable for now
unusableBox = new JCheckBox(
// When user presses View, show the macro's contents
public void actionPerformed(ActionEvent e) {
/*
* viewButton is passed as component relative to which the
* dialog should be displayed, keeping user more in
* context with the task.
*/
ViewMacroDialog d = new ViewMacroDialog(
AddressWizard.this, viewButton,
d.pack();
d.setVisible(true);
}
});
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
}
public boolean setInactive(int direction) {
return true;
}
}
// This step selects the lease type
class LeaseStep implements WizardStep {
private ButtonGroup buttonGroup;
public LeaseStep() {
// Start with explanatory text
// User has choice of dynamic or permanent leases
buttonGroup = new ButtonGroup();
dynamicButton = new JRadioButton(
permanentButton = new JRadioButton(
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
}
public boolean setInactive(int direction) {
return true;
}
}
// Last chance to check work before committing to it
class ReviewStep implements WizardStep {
private JTable addressTable;
private JLabel numberLabel;
private JLabel commentLabel;
private JLabel serverLabel;
private JLabel macroLabel;
private JLabel leaseLabel;
public ReviewStep() {
"add_wiz_confirm_label"));
new ExtendedCellRenderer());
// Table should not be selectable in any way
addressTable.setRowSelectionAllowed(false);
addressTable.setCellSelectionEnabled(false);
d.height = 50;
}
return l;
}
return l;
}
return l;
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
// Use number of addresses actually generated, not requested
if (unusable) {
} else {
}
if (dynamic) {
} else {
}
setFinishEnabled(true);
}
public boolean setInactive(int direction) {
// Nothing to do
return true;
}
}
super(owner, "");
try {
} catch (ValidationException e) {
// this should never happen!
}
addressTableModel = new WizardTableModel();
// Create steps in order of appearance
addStep(new NumberStep());
addStep(new ServerStep());
addStep(new ConfirmStep());
addStep(new ConfigureStep());
addStep(new ReviewStep());
}
public void doFinish() {
/*
* Method here is as follows:
* 1. Create a ProgressManager which will apprise user of our progress
* 2. Create a background thread to execute the add operations
* 3. Within the background thread, update the progress monitor
* as each address is created.
* 4. At completion, the background thread displays the error
* output, if any, before it invokes one last runnable which pops
* down and cleans up.
*/
// final so that ProgressUpdater can access it
public void run() {
reallyFinish();
}
};
// Here's the thread which does the adds
public void run() {
// Create a template object which we'll use for all the adds
try {
} catch (ValidationException e) {
// Should never happen as we have a valid IP already
}
} else {
}
// This is final so it can be used in the errorDisplay Runnable
IPAddress.class);
/*
* For each address, create a client record and possibly a
* hosts record, log any errors for later consumption.
*/
try {
} catch (InterruptedException e) {
return;
} catch (Throwable e) {
// Pick the best message for the exception thrown
if (e instanceof ExistsException) {
} else if (e instanceof HostExistsException) {
} else {
msg = e.getMessage();
}
}
}
// If any errors occurred, display them all at once.
if (!failedTable.isEmpty()) {
public void run() {
objs[0] =
new JScrollPane(failedTable);
// Resize the table to something kind of small
Dimension d =
d.height = 80;
objs,
}
};
try {
} catch (Throwable e) {
e.printStackTrace();
}
}
}
};
}
protected void reallyFinish() {
super.doFinish();
}
public void doHelp() {
}
}