AddressView.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.
*/
/**
* Address View displays the networks currently under DHCP management, and
* as a network is selected from the list its addresses are displayed.
*/
public class AddressView implements View {
private JPanel displayPanel;
protected static AutosizingTable addressTable;
private JScrollPane addressPane;
private boolean firstActivation = true;
private NetworkListModel networkListModel;
private JList networkList;
private TableSorter sortedTableModel;
private JCheckBoxMenuItem showGrid;
private JCheckBoxMenuItem showAddresses;
private JMenuItem releaseAddrs;
private JMenuItem deleteNets;
private JMenuItem addressHelp;
private int sortModelIndex = -1;
private static final String NO_NETWORKS =
// Model class for the network list
class NetworkListModel extends AbstractListModel {
private Object currentValue;
public void load() {
try {
} catch (Throwable e) {
e.printStackTrace();
} finally {
int len = 0;
}
}
}
public void reload() {
load();
}
public int getSize() {
load();
}
return 0;
} else {
}
}
load();
}
return "";
} else {
}
}
return null;
} else {
}
}
}
// Container class for the address data
class AddressTableModel extends AbstractTableModel {
private DhcpClientRecord [] data;
private boolean showAddresses;
private boolean firstLoad;
public AddressTableModel() {
network = "";
showAddresses = false;
firstLoad = true;
}
// No network number supplied, so can't load
return;
}
// Update the status line
// Kick off background loading of addresses
}
// Loading is done, re-sort and tell the view to repaint
protected void doneLoading() {
if (firstLoad) {
firstLoad = false;
}
}
protected String getNetwork() {
return network;
}
}
public void setShowAddresses(boolean state) {
}
public int getRowCount() {
return 0;
} else {
}
}
public int getColumnCount() {
return 7;
}
switch (column) {
case 0:
if (showAddresses) {
} else {
}
case 1:
} else {
}
case 2:
case 3:
if (showAddresses) {
} else {
}
case 4:
case 5:
case 6:
default:
return null;
}
}
switch (column) {
case 0:
case 3:
if (showAddresses) {
return IPAddress.class;
} else {
return String.class;
}
case 2:
return Date.class;
case 1:
case 4:
case 5:
case 6:
return String.class;
default:
return super.getColumnClass(column);
}
}
switch (column) {
case 0:
if (showAddresses) {
} else {
}
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
default:
return super.getColumnName(column);
}
}
}
}
// Background loader for addresses.
class AddressLoader 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() {
}
}
// Renderer class used to make unusable addresses bold in the display
class AddressTableCellRenderer extends ExtendedCellRenderer {
int column) {
if (modelRow != -1) {
}
}
return c;
}
}
// Recipient of update messages sent when the editing dialogs exit
class DialogListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// Don't reload if cancel happened
AddressView.this.reload();
}
}
}
public AddressView() {
// Create network selection list, tie it to table
networkListModel = new NetworkListModel();
public void valueChanged(ListSelectionEvent e) {
// Ignore all but the last in a series of these events
if (e.getValueIsAdjusting()) {
return;
}
if (index != -1) {
}
/*
* No networks are selected; disable menu items
*/
deleteNets.setEnabled(false);
addAddrs.setEnabled(false);
showAddresses.setEnabled(false);
showGrid.setEnabled(false);
} else {
deleteNets.setEnabled(true);
addAddrs.setEnabled(true);
showAddresses.setEnabled(true);
showGrid.setEnabled(true);
}
}
});
// Use a prototype value as a performance enhancement
// Create table to display in data area
addressTableModel = new AddressTableModel();
private SortedHeaderRenderer sortedRenderer =
private TableCellRenderer savedRenderer;
public void actionPerformed(ActionEvent e) {
// Clear the selection when sorting is changed
/*
* Change the header rendering to show which column is
* being used for sorting of the data.
*/
int viewIndex =
if (sortModelIndex != -1) {
int sortViewIndex =
}
/*
* Save the column currently being sorted so we can restore
* the renderer later. We save model columns rather than
* view columns because model columns are invariant while
* view columns can be reordered with confusion resulting.
*/
TableColumn c =
savedRenderer = c.getHeaderRenderer();
}
});
// Make double-clicks the same as Edit->Properties
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
}
}
});
// Install custom renderer to bold the entries which are unusable
// Wrap it in a scroll pane
// Create menu items
false);
public void actionPerformed(ActionEvent e) {
}
});
true);
public void actionPerformed(ActionEvent e) {
}
});
public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
reload();
}
}
});
wiz.setVisible(true);
}
});
public void actionPerformed(ActionEvent e) {
d.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reload();
}
}
});
d.pack();
d.setVisible(true);
}
});
public void actionPerformed(ActionEvent e) {
wiz.setVisible(true);
}
});
public void actionPerformed(ActionEvent e) {
return;
}
}
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
});
public void actionPerformed(ActionEvent e) {
}
});
/*
* Construct the menu lists
*/
}
// Listen for selections events, manipulate menu item state as needed
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
// Disable menu items
releaseAddrs.setEnabled(false);
} else {
// Enable menu items
releaseAddrs.setEnabled(true);
}
// Notify listeners that our selection state may have changed
}
});
}
}
// Return custom menus for this view, which is nothing at this time
public Enumeration menus() {
return null;
}
// Return custom menu items for each menu as requested.
}
public Component getDisplay() {
return displayPanel;
}
if (state) {
if (firstActivation) {
// Find frame we're in for use when creating dialogs
MainFrame.class, addressTable);
}
firstActivation = false;
} else {
// Clear any messages left from other views
}
}
}
// Handle a find
return;
}
}
// Got to the end, wrap around
for (int i = 0; i < startRow; ++i) {
return;
}
}
}
public void handleCreate() {
// Tell user to use Network Wizard
} else {
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
}
public void handleDelete() {
return;
}
}
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
public void handleDuplicate() {
if (row == -1) {
return;
}
return;
}
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
public void handleProperties() {
return;
}
recs[i] =
}
// Edit a single address
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
} else {
// Edit a group of addresses
d.addActionListener(new DialogListener());
d.pack();
d.setVisible(true);
}
}
public void handleUpdate() {
reload();
}
protected void reload() {
// Didn't get selected, must be gone. Select first item in list
}
}
}
}
private void notifySelectionListeners() {
while (en.hasMoreElements()) {
l.valueChanged();
}
}
public boolean isSelectionEmpty() {
}
public boolean isSelectionMultiple() {
}
public void startAddressWizard() {
}
}