CreateMacroDialog.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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
*/
// Model for the table that displays the macro's contents
class MacroTableModel extends AbstractTableModel {
public MacroTableModel() {
}
public MacroTableModel(Macro m) {
super();
setMacro(m);
}
macro = m;
}
public int getRowCount() {
return macro.optionCount();
}
public int getColumnCount() {
return 2;
}
OptionValue v = null;
try {
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
if (v == null) {
return null;
}
switch (column) {
case 0:
return v.getName();
case 1:
return v.getValue();
default:
return null;
}
}
switch (column) {
case 0:
case 1:
return String.class;
default:
return super.getColumnClass(column);
}
}
switch (column) {
case 0:
case 1:
default:
super.getColumnName(column);
}
return null;
}
return false;
}
}
public void moveRowDown(int row) {
}
}
}
for (int i = 0; i < getRowCount(); ++i) {
return i;
}
}
return -1;
}
}
public static final int CREATE = 0;
public static final int EDIT = 1;
public static final int DUPLICATE = 2;
private MacroNameField name;
private JTextField optionName;
private JTextField optionValue;
private AutosizingTable macroTable;
private MacroTableModel macroTableModel;
private ButtonPanel buttonPanel;
private DownButton downButton;
/*
* Listener for the editing buttons which are used to manipulate the
* table's contents
*/
public void actionPerformed(ActionEvent e) {
if (row == 0) {
return; // Can't move the first row up
}
/*
* Keep the row we moved selected so that repeated move up's
* affect the same data
*/
} else if (src == downButton) {
return; // Can't move the last row down
}
/*
* Keep the row we moved selected so that repeated move down's
* affect the same data
*/
} else if (src == deleteButton) {
/*
* Keep the same row selected so that repeated delete presses
* can be used to delete a series of options
*/
}
}
modifyButton.setEnabled(false);
}
} else if (src == selectButton) {
// Show dialog that allows selection of options
/*
* User selected something, put it in the name field
* set the focus to the value field
*/
if (s != null) {
optionName.setText(s);
}
// Update the table from the field contents
OptionValue v = null;
if (v instanceof BogusOptionValue) {
// bad option name
form = new MessageFormat(
return;
}
try {
/*
* Catch an empty value field, which is only legal for
* a boolean option
*/
throw new ValidationException();
}
v.setValue(s);
} catch (ValidationException ex) {
// bad option value
form = new MessageFormat(
return;
}
/*
* Don't allow a second instance of any option other than
* Include in a macro, but only check if we're doing an add
* or if it's a modify and the name has changed.
*/
if ((!(v instanceof IncludeOptionValue)
|| ((src == modifyButton)
return;
}
}
// If adding, append it at the end
}
}
}
};
super(f);
switch (mode) {
case CREATE:
break;
case EDIT:
break;
case DUPLICATE:
break;
default:
break;
}
// Name cannot have blanks in it so use a control which disallows them
// Put a titled border on the contents panel
/*
* Create a panel using a couple of text fields to edit the options
* included in the macro
*/
// Field for option name
// Field for option value
optionValue = new JTextField();
addButton.setEnabled(false);
modifyButton.setEnabled(false);
// Use a table to display the contents of the macro
macroTableModel = new MacroTableModel();
// Resize table as otherwise it asks for a huge area
d.height = 100;
d.width = 300;
// Create buttons for controlling table
upButton.setEnabled(false);
downButton = new DownButton();
downButton.setEnabled(false);
deleteButton.setEnabled(false);
true);
buttonPanel = new ButtonPanel(true);
// Listen to table selection state and set state of buttons accordingly
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (index == -1) {
// Nothing selected, disable all
upButton.setEnabled(false);
downButton.setEnabled(false);
deleteButton.setEnabled(false);
// Clear the option name we saved
savedOptionName = "";
} else {
/*
* Only allow deleteButton to be activated when
* the table is not empty regardless of selection
* method, mouse or keyboard
*/
deleteButton.setEnabled(true);
}
if (index == 0) {
// First row can't move up
upButton.setEnabled(false);
} else {
upButton.setEnabled(true);
}
// Last row can't move down
downButton.setEnabled(false);
} else {
/*
* Only allow downButton to be activated when the
* table is not empty regardless of selection
* method, mouse or keyboard
*/
downButton.setEnabled(true);
}
}
// Save editing name so we can detect name change
}
}
});
// Only enable OK if the name is not empty
public void insertUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
public void insertUpdate(DocumentEvent e) {
if (state == false) {
}
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
buttonPanel.setOkEnabled(true);
}
}
/**
* Display this dialog, and auto-validate its contents to start with
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
/*
* If we're being hidden, then just return
*/
if (!visible)
return;
/*
* Validate the current contents of the macro so we can tell the user
* about any syntax errors in the existing definition.
*/
try {
} catch (ValidationException e) {
// Errors; advise user by putting up a dialog
} else {
}
if (row != -1) {
}
}
}
}
}
public void buttonPressed(int buttonId) {
switch (buttonId) {
case OK:
// A macro with no options is not useful, so don't allow it
JOptionPane.showMessageDialog(this,
return;
}
try {
} catch (ValidationException e) {
// Not a valid macro name
return;
}
try {
// Validate the macro
signalBox.isSelected());
signalBox.isSelected());
}
setVisible(false);
dispose();
} catch (ValidationException ve) {
} else {
}
} 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_macro";
break;
case DUPLICATE:
helpTag = "duplicate_macro";
break;
case EDIT:
helpTag = "modify_macro";
break;
}
break;
case RESET:
signalBox.setSelected(true);
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);
}
}
}