CreateOptionDialog.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 1998-2002 by Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
*/
public static final int CREATE = 0;
public static final int EDIT = 1;
public static final int DUPLICATE = 2;
private OptionNameField name;
private IntegerField code;
private JTextField clientClass;
private IntegerField granularity;
private IntegerField maximum;
private ButtonPanel buttonPanel;
private ClassListModel classListModel;
private DownButton moveDown;
private OptionContext [] categories = {
};
// Model for the list of vendor classes
class ClassListModel extends AbstractListModel {
public ClassListModel() {
super();
}
public int getSize() {
return option.getVendorCount();
}
}
}
public void removeElementAt(int index) {
}
}
}
public void reset() {
}
}
super(f);
switch (mode) {
case CREATE:
break;
case EDIT:
break;
case DUPLICATE:
break;
default:
break;
}
// Initialize constraints
GridBagConstraints c = new GridBagConstraints();
// Label and text field for name
bag.setConstraints(l, c);
fieldPanel.add(l);
l.setLabelFor(name);
l.setLabelFor(name);
++c.gridx;
// Label and combo box for category
c.gridx = 0;
++c.gridy;
bag.setConstraints(l, c);
fieldPanel.add(l);
l.setLabelFor(category);
category.setEditable(false);
++c.gridx;
// Label and text field for code
c.gridx = 0;
++c.gridy;
bag.setConstraints(l, c);
fieldPanel.add(l);
code = new IntegerField();
l.setLabelFor(code);
++c.gridx;
// Label and combo box for data type
c.gridx = 0;
++c.gridy;
bag.setConstraints(l, c);
fieldPanel.add(l);
l.setLabelFor(type);
type.setEditable(false);
++c.gridx;
// Label and text field for granularity
c.gridx = 0;
++c.gridy;
bag.setConstraints(l, c);
fieldPanel.add(l);
++c.gridx;
// Label and text field for maximum
c.gridx = 0;
++c.gridy;
bag.setConstraints(l, c);
fieldPanel.add(l);
l.setLabelFor(maximum);
++c.gridx;
// Editing controls for client classes
bag = new GridBagLayout();
c = new GridBagConstraints();
c.gridheight = 1;
c.gridwidth = 1;
// Field to type in new classes
// Button for Add operation
++c.gridx;
c.weightx = 0.5;
// List for classes
classListModel = new ClassListModel();
// Make sure it's approximately wide enough for our purposes, 20 chars
c.gridx = 0;
++c.gridy;
c.weightx = 1.0;
// Buttons to manipulate the list contents
moveDown = new DownButton();
++c.gridx;
c.weightx = 0.5;
/*
* Disable all buttons to start; selection changes will adjust button
* state as necessary
*/
add.setEnabled(false);
delete.setEnabled(false);
moveUp.setEnabled(false);
moveDown.setEnabled(false);
// Create listener for button presses, take action as needed
public void actionPerformed(ActionEvent e) {
try {
} catch (ValidationException ex) {
// Something wrong with class name
return;
}
/*
* Need to sort them so that the delete's don't
* interfere with each other
*/
int k = indices[i];
indices[j] = k;
}
}
}
}
// Now delete from high index to low
}
// Clear selection if multiple deleted
/*
* XXX We don't get a selection event for some reason,
* make it work for now
*/
delete.setEnabled(false);
} else {
// Make sure to select something in the list
// List is empty, so disable delete
delete.setEnabled(false);
// Select last one if we're off the end
} else {
// Select next one in list
}
}
int i = classList.getSelectedIndex();
classListModel.moveUp(i);
// Keep item selected so repeated moveUp's affect same item
int i = classList.getSelectedIndex();
// Keep item selected so repeated moveDowns affect same item
}
}
};
// Put a selection listener on the list to enable buttons appropriately
public void valueChanged(ListSelectionEvent e) {
case 0:
// Nothing selected; disable them all
delete.setEnabled(false);
moveUp.setEnabled(false);
moveDown.setEnabled(false);
break;
case 1:
delete.setEnabled(true);
// Can't move first one up
// Can't move last one down
moveDown.setEnabled(false);
} else {
moveDown.setEnabled(true);
}
break;
default:
// More than one; only delete is allowed
delete.setEnabled(true);
moveUp.setEnabled(false);
moveDown.setEnabled(false);
}
}
});
// Enable Add when class is not empty.
public void insertUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
true);
buttonPanel = new ButtonPanel(true);
buttonPanel.setOkEnabled(true);
}
// Enable OK when there is data in the name field
public void insertUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
// If category != VENDOR you can't mess with the client class data
public void itemStateChanged(ItemEvent e) {
boolean isVendor =
if (!isVendor) {
}
}
});
// Update state of granularity & maximum depending on data type selected
public void itemStateChanged(ItemEvent e) {
// Set granularity to correct minimum for type
}
// Now set editability of the granularity and max fields
granularity.setEditable(false);
maximum.setEditable(true);
granularity.setEditable(false);
// Also reset maximum value in this case
maximum.setEditable(false);
granularity.setEditable(true);
maximum.setEditable(true);
}
}
});
}
originalOption = o; // Keep a copy so reset will work
resetValues();
}
private void resetValues() {
} else {
}
break;
}
}
type.setSelectedIndex(i);
break;
}
}
signalBox.setSelected(true);
}
public void buttonPressed(int buttonId) {
switch (buttonId) {
case OK:
try {
JOptionPane.showMessageDialog(this,
return;
}
signalBox.isSelected());
}
setVisible(false);
dispose();
} catch (NotRunningException e) {
// Server not running, put up a warning
JOptionPane.showMessageDialog(this,
setVisible(false);
dispose();
} catch (Exception e) {
switch (mode) {
case CREATE:
case DUPLICATE:
form = new MessageFormat(
break;
case EDIT:
form = new MessageFormat(
break;
}
}
break;
case CANCEL:
setVisible(false);
dispose();
break;
case HELP:
switch (mode) {
case CREATE:
helpTag = "create_option";
break;
case DUPLICATE:
helpTag = "duplicate_option";
break;
case EDIT:
helpTag = "modify_option";
break;
}
break;
case RESET:
break;
}
}
public void addActionListener(ActionListener l) {
listeners.addElement(l);
}
public void removeActionListener(ActionListener l) {
}
protected void fireActionPerformed() {
switch (mode) {
case CREATE:
case DUPLICATE:
break;
case EDIT:
break;
}
command);
while (en.hasMoreElements()) {
l.actionPerformed(e);
}
}
}