ExportWizard.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 2001-2002 by Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* ExportWizard provides an easy-to-use interface for exporting the data
* from one DHCP server to be later imported by another DHCP server, typically
* because the administrator wishes to repartition the workload among DHCP
* servers.
*/
public class ExportWizard extends Wizard {
// Step to collect the networks to be exported
class NetworkStep implements WizardStep {
public NetworkStep() {
try {
networkLists = new ListPair(
} catch (Throwable t) {
t.printStackTrace();
}
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
}
public boolean setInactive(int direction) {
networks =
return true;
}
}
// Step to collect the macros to be exported
class MacroStep implements WizardStep {
public MacroStep() {
try {
}
macroLists = new ListPair(
} catch (Throwable t) {
t.printStackTrace();
}
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
}
public boolean setInactive(int direction) {
return true;
}
}
// Step to collect the options to be exported
class OptionStep implements WizardStep {
public OptionStep() {
try {
}
optionLists = new ListPair(
} catch (Throwable t) {
t.printStackTrace();
}
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
}
public boolean setInactive(int direction) {
return true;
}
}
// Step to collect the name of the file to which data is exported
class FileStep implements WizardStep {
public FileStep() {
l.setLabelFor(stepPanel);
l.setLabelFor(pathField);
c = Wizard.createTextArea(
c = Box.createVerticalGlue();
// Enable forward only if something is entered in the file field
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 stepPanel;
}
}
public boolean setInactive(int direction) {
return true;
}
}
// Review everything before doing it
class ReviewStep implements WizardStep {
public ReviewStep() {
networkList = new JList();
"exp_wiz_review_macros"));
"exp_wiz_review_options"));
optionList = new JList();
exportLabel = new JLabel();
"exp_wiz_delete_label"));
deleteLabel = new JLabel();
}
public String getDescription() {
}
public Component getComponent() {
return mainPanel;
}
if (deleteData) {
} else {
}
setFinishEnabled(true);
}
public boolean setInactive(int direction) {
// Nothing to do here
return true;
}
}
/*
* Display an error message in its own thread. This allows a task running
* in a non-GUI thread to get the message displayed by the toolkit.
*/
class ErrorDisplay implements Runnable {
}
public void run() {
}
}
/*
* Display a warning message in its own thread. This allows a task running
* in a non-GUI thread to get the message displayed by the toolkit.
*/
class WarningDisplay implements Runnable {
}
public void run() {
}
}
/*
* Class to ask the user whether the export file should be forcibly
* overwritten if it already exists. We default to not overwriting
* export files. This is a Runnable in order to allow it to be displayed
* by the export thread, which is a non-GUI thread.
*/
class OverwritePrompter implements Runnable {
/*
* overwrite member is public so we can access it directly since run()
* can't return the user's input.
*/
public boolean overwrite;
public OverwritePrompter() {
overwrite = false;
}
public void run() {
ExportWizard.this,
// Return true if the user clicked Yes
}
}
private boolean deleteData = false;
super(owner, "");
// Insert steps in order of execution
addStep(new NetworkStep());
addStep(new OptionStep());
addStep(new ReviewStep());
}
/*
* Execute the export. This is relatively complicated because we want to
* run the actual export in a background thread so that the whole GUI isn't
* tied up during the export. Also, the actual export logic is implemented
* by the ExportController, and we provide an Exporter implementation
* which allows it to interact with the user. So, the ExportController is
* executed in a background thread, and the callbacks implemented in the
* Exporter must each use SwingUtilities.invoke* methods to ask for the
* UI updates to happen. In the case of the progress display, the
* ProgressManager class already implements that logic so it's simpler
* than the rest of the interactions.
*/
public void doFinish() {
/*
* This runnable serves merely to allow the background thread used for
* export to tell the GUI that it's done.
*/
public void run() {
reallyFinish();
}
};
/*
* Create callback interface used by ExportController to interact with
* the user.
*/
""
};
// Set up the progress display
public void initializeProgress(int length) {
length);
}
// Update progress to current point, updating message
throws InterruptedException {
}
// Display an error message
try {
} catch (InvocationTargetException ex2) {
// ErrorDisplay threw an exception; give up!
} catch (InterruptedException ex2) {
// ErrorDisplay was interrupted; give up!
}
}
// Display a bunch of error messages in a table
ActionError [] errs) {
try {
} catch (InvocationTargetException e) {
// WarningDisplay threw an exception; just dump it
e.printStackTrace();
} catch (InterruptedException e) {
// WarningDisplay was interrupted; just dump it
e.printStackTrace();
}
}
};
/*
* Create the export controller and set parameters. Use final so
* that the exportThread can reference it.
*/
// Now create the thread that does the exporting
public void run() {
while (true) {
try {
/*
* Controller will return true if it completed
* successfully, in which case we want to exit the
* wizard; if it returns false, just exit this
* thread but leave the wizard up.
*/
}
return;
} catch (ExistsException e) {
// Export file already existed and overwrite was false
try {
/*
* If user said not to overwrite, then exit
* this thread but leave wizard up. Otherwise just
* let the while loop try the export again.
*/
return;
}
} catch (Throwable t) {
/*
* We can get an interrupt or prompter could
* throw an exception; the only reasonable
* thing to do at this point is just display
* the stack and return.
*/
t.printStackTrace();
return;
}
}
}
}
};
// Now run the export thread
}
protected void reallyFinish() {
super.doFinish();
}
public void doHelp() {
}
}