SelectOptionDialog.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.
*/
/**
* Dialog to select an option for inclusion in a macro.
*/
public class SelectOptionDialog extends JComponent
implements ButtonPanelListener {
private AutosizingTable optionTable;
private ButtonPanel buttonPanel;
private OptionTableModel optionTableModel;
private TableSorter sortedModel;
private OptionContext [] categories = {
};
// Model for the table displaying option descriptions
class OptionTableModel extends AbstractTableModel {
private ResourceBundle bundle;
public OptionTableModel() {
super();
// Locate the resource bundle containing the localized descriptions
"com.sun.dhcpmgr.client.OptionDescriptions",
Locale.getDefault());
}
try {
// Get all locally defined options from DataManager
// Now filter by the selected type
v.addElement(allOptions[i]);
}
}
// Convert to an array
} catch (Exception e) {
}
}
// Tell the sorter things changed
}
public int getRowCount() {
}
public int getColumnCount() {
return 2;
}
if (column == 0) {
} else {
try {
/**
* Look up descriptions in the properties file indexed by
* option name
*/
} catch (Exception e) {
// Ignore; we just don't have a description for this one
return null;
}
}
}
return String.class;
}
if (column == 0) {
} else {
}
}
return false;
}
}
// Generate the dialog
public void createDialog() {
// Label and combo box for selecting option category
category.setEditable(false);
// Table for selecting the options in the given category
optionTableModel = new OptionTableModel();
// Sort options by name, alphabetically
// Use an auto-sizing table so descriptions get the space they need
// Put in usual separator and buttons
buttonPanel = new ButtonPanel(false, false);
/*
* As user changes category selected, update table to view category
* contents
*/
public void itemStateChanged(ItemEvent e) {
updateTable();
}
});
// Only enable OK when there is an option selected in the table
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
buttonPanel.setOkEnabled(false);
} else {
buttonPanel.setOkEnabled(true);
}
}
});
// Ensure table displays data for initial selection
updateTable();
}
/**
* Update the table to the current category selection.
*/
private void updateTable() {
}
public void buttonPressed(int buttonId) {
switch (buttonId) {
case OK:
break;
case CANCEL:
break;
}
}
/**
* Here's the way to display this dialog modally and retrieve the value
* selected
* @param c a component relative to which the dialog should be displayed
*/
SelectOptionDialog d = new SelectOptionDialog();
d.createDialog();
/*
* When user presses OK or Cancel, retrieve the value and kill the
* dialog
*/
public void propertyChange(PropertyChangeEvent e) {
dialog.setVisible(false);
}
});
dialog.setVisible(true);
return value;
}
}