MacroView.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.
*/
// Background thread for doing retrieval while keeping GUI live
class MacroLoader extends SwingWorker {
try {
} catch (final BridgeException e) {
// Since we're in a background thread, ask Swing to run ASAP.
public void run() {
}
});
}
return null;
}
public void finished() {
}
}
}
/**
* Implements a display of the macro hierarchy contained in the dhcptab
*/
// A node in the tree of macros
class MacroTreeNode extends DefaultMutableTreeNode {
private boolean scannedIncludes = false;
private boolean isScanning = false;
public MacroTreeNode(Object o) {
super(o);
}
return m.getKey();
}
public int getChildCount() {
/*
* scannedIncludes is used so that we only build the tree once;
* isScanning prevents us from recursing infinitely because add()
* ends up coming right back here
*/
if (!scannedIncludes && !isScanning) {
isScanning = true;
Enumeration e = m.elements();
while (e.hasMoreElements()) {
if (o instanceof IncludeOptionValue) {
}
}
}
scannedIncludes = true;
isScanning = false;
}
return super.getChildCount();
}
return (Macro)getUserObject();
}
}
/*
* Special class for the root node; this handles retrieving the data from
* the server
*/
class MacroTreeRootNode extends MacroTreeNode {
public MacroTreeRootNode() {
super(new Macro());
}
public MacroTreeRootNode(Object o) {
super(o);
}
}
}
}
}
public int getChildCount() {
return 0;
}
return super.getChildCount();
}
public void load() {
// Display starting message and clear tree
// Kick off background loader
}
return null;
}
// Find a particular macro by name
return macros[i];
}
}
}
return null;
}
}
// Model for data contained in macro tree
class MacroTreeModel extends DefaultTreeModel {
public MacroTreeModel(MacroTreeRootNode n) {
super(n);
}
public void load() {
getRootNode().load();
}
}
public MacroTreeRootNode getRootNode() {
return (MacroTreeRootNode)super.getRoot();
}
}
// Model for table displaying contents of a macro
class MacroTableModel extends AbstractTableModel {
public MacroTableModel() {
super();
}
macro = m;
}
public int getRowCount() {
return 0;
} else {
return macro.optionCount();
}
}
public int getColumnCount() {
return 2;
}
return null;
}
switch (column) {
case 0:
case 1:
default:
return null;
}
}
switch (column) {
case 0:
case 1:
return String.class;
default:
super.getColumnClass(column);
}
return null;
}
switch (column) {
case 0:
case 1:
default:
super.getColumnName(column);
}
return null;
}
}
// Recipient of update messages sent when the macro editing dialogs exit
class DialogListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
reload();
}
}
}
private AutosizingTable macroTable;
private JScrollPane treePane;
private JScrollPane macroTablePane;
private JSplitPane splitPane;
private boolean firstActivation = true;
private MacroTableModel macroTableModel;
private JCheckBoxMenuItem showGrid;
private boolean firstview = true;
public MacroView() {
// Create tree for macro display
// Listen for selection events, load selected macro into table
public void valueChanged(TreeSelectionEvent e) {
if (node instanceof MacroTreeNode) {
} else {
}
} else {
}
// Notify listeners that our selection state may have changed
}
});
// Single selection for now
// Make a scroll pane for it
treePane = new JScrollPane();
// Make double-clicks the same as Edit->Properties
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
// Don't do anything if it's the root node
}
}
}
});
// Create table to display in data area
macroTableModel = new MacroTableModel();
// Can't mess with the column order, or select any data
macroTable.setRowSelectionAllowed(false);
macroTable.setColumnSelectionAllowed(false);
// Now wrap it with scrollbars
// Create split pane containing the tree & table, side-by-side
// Create menu items
true);
public void actionPerformed(ActionEvent e) {
}
});
public void actionPerformed(ActionEvent e) {
}
});
/*
* Construct lists of menu items custom to this view.
*/
}
}
}
// Return menus that we wish to add to MainFrame, in our case none
public Enumeration menus() {
return null;
}
// Return menu items for each menu as requested by MainFrame
}
public Component getDisplay() {
return splitPane;
}
private void reload() {
}
// Callback from model when loading completed to update display
private void reloadCompleted() {
// Doesn't display correctly without this
/*
* Check for syntax errors.
*/
try {
} catch (ValidationException e) {
}
}
// Found some errors; warn user
}
}
if (state) {
// We only do an automatic load the first time we're displayed
if (firstview) {
reload();
firstview = false;
}
}
}
/*
* Handle a find operation.
* Algorithm used here searches nodes in the order they appear in the
* displayed tree. This requires traversing the entire tree starting at
* an arbitrary point with some special twists.
*/
// Clear status if we had an old message lying there
// Nothing selected so start at root
}
// Start by searching children of selected node
return;
}
// Get all ancestor nodes of selected
// Walk up towards root of tree, at each level search all children
return;
}
// Move up a level
/*
* If it's not the root node and it matches, remember it. We don't
* return immediately because this is actually about last in the
* display order.
*/
}
}
}
// We found one on the path to the root, select and return
return;
}
// Nothing found; show an error
args[0] = s;
}
// Search a particular level of a tree in the order a user would expect
// Skip all children prior to the startNode in display order
Enumeration e = n.children();
while (e.hasMoreElements()) {
break;
}
}
// Now search those after the startNode in the display order
while (e.hasMoreElements()) {
return result;
}
}
// Got to the end of this level and didn't find it, so wrap to beginning
e = n.children();
while (e.hasMoreElements()) {
break;
}
return result;
}
}
return null;
}
// Search a node and all its children for a particular string
return n;
}
return searchUnderNode(n, s);
}
// Search all children, recursively, of a node for a particular string
Enumeration e = n.children();
while (e.hasMoreElements()) {
return cn;
}
return result;
}
}
return null;
}
// Select a node and make sure it's visible
private void selectNode(MacroTreeNode n) {
}
// Return the macro currently selected
private Macro getSelectedMacro() {
if (node instanceof MacroTreeNode) {
}
}
return null;
}
public void handleCreate() {
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
public void handleDelete() {
Macro m = getSelectedMacro();
if (m == null) {
return;
}
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
public void handleDuplicate() {
Macro m = getSelectedMacro();
if (m == null) {
return;
}
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
public void handleProperties() {
Macro m = getSelectedMacro();
if (m == null) {
return;
}
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
public void handleUpdate() {
reload();
}
}
}
private void notifySelectionListeners() {
while (en.hasMoreElements()) {
l.valueChanged();
}
}
public boolean isSelectionEmpty() {
// If empty or the root of the tree is selected, then we call it empty
}
public boolean isSelectionMultiple() {
return false; // We don't allow multiple selection
}
}