StatusPanelDialog.java revision a395dd575518d9e5280fc5d5d5ef47c61b174647
/*
* 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
* 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
* trunk/opends/resource/legal-notices/OpenDS.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
*
*
* Copyright 2008 Sun Microsystems, Inc.
*/
/**
* This panel is used to display basic information about the server status.
*
*/
public class StatusPanelDialog extends JFrame
{
private static final long serialVersionUID = 6832422469078074151L;
private ServerStatusDescriptor lastDescriptor;
private ServerStatusDescriptor lastPackDescriptor;
new HashSet<StatusPanelButtonListener>();
private JButton quitButton;
private JButton authenticateButton;
private JLabel lServerStatus;
private JLabel lCurrentConnections;
private JLabel lAdministrativeUsers;
private JLabel lInstallPath;
private JLabel lOpenDSVersion;
private JLabel lJavaVersion;
private JLabel lDbTableEmpty;
private JLabel lListenersTableEmpty;
private JEditorPane lError;
private JButton stopButton;
private JButton startButton;
private JButton restartButton;
private HtmlProgressMessageFormatter formatter =
new HtmlProgressMessageFormatter();
private JTable dbTableWithReplication;
private JTable dbTableWithoutReplication;
private ListenersTableModel listenersTableModel;
private JTable listenersTable;
/**
* ProgressDialog constructor.
*/
public StatusPanelDialog()
{
super();
createLayout();
{
public void windowClosing(WindowEvent e)
{
quitClicked();
}
});
Utilities.setFrameIcon(this);
}
/**
* Packs and displays this dialog.
*
*/
public void packAndShow()
{
pack();
{
pack();
}
Utilities.centerOnScreen(this);
setVisible(true);
}
/**
* Updates the contents displaying with what is specified in the provided
* ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
boolean mustRepack;
if (lastPackDescriptor == null)
{
mustRepack = true;
}
else
{
boolean lastSmall =
boolean currentBig =
}
if (mustRepack)
{
pack();
{
pack();
}
}
}
/**
* Adds a StatusPanelButtonListener that will be notified of clicks in
* the control panel dialog.
* @param l the StatusPanelButtonListener to be added.
*/
public void addButtonListener(StatusPanelButtonListener l)
{
}
/**
* Removes a StatusPanelButtonListener.
* @param l the StatusPanelButtonListener to be removed.
*/
public void removeButtonListener(StatusPanelButtonListener l)
{
}
/**
* Sets the enable state of the authenticate button.
* @param enable whether to enable or disable the button.
*/
public void setAuthenticateButtonEnabled(boolean enable)
{
}
/**
* Sets the enable state of the start button.
* @param enable whether to enable or disable the button.
*/
public void setStartButtonEnabled(boolean enable)
{
}
/**
* Sets the enable state of the stop button.
* @param enable whether to enable or disable the button.
*/
public void setStopButtonEnabled(boolean enable)
{
}
/**
* Sets the enable state of the restart button.
* @param enable whether to enable or disable the button.
*/
public void setRestartButtonEnabled(boolean enable)
{
}
/**
* Creates the layout of the dialog panel.
*
*/
private void createLayout()
{
/* Create input panel. */
inputPanel.setOpaque(false);
lError.setEditable(false);
/* Create buttons panel */
buttonsPanel.setOpaque(false);
{
{
}
});
{
{
quitClicked();
}
});
getContentPane().add(p);
/* Update the preferred sizes of labels */
int maxWidth = 0;
for (JLabel l : subsectionLabels)
{
{
}
}
for (JLabel l : subsectionLabels)
{
}
}
/**
* Method called when start button is clicked.
*/
private void startClicked()
{
for (StatusPanelButtonListener l : listeners)
{
l.startClicked();
}
}
/**
* Method called when quit button is clicked.
*/
private void quitClicked()
{
for (StatusPanelButtonListener l : listeners)
{
l.quitClicked();
}
}
/**
* Method called when authenticate button is clicked.
*/
private void authenticateClicked()
{
for (StatusPanelButtonListener l : listeners)
{
l.authenticateClicked();
}
}
/**
* Method called when stop button is clicked.
*/
private void stopClicked()
{
for (StatusPanelButtonListener l : listeners)
{
l.stopClicked();
}
}
/**
* Method called when restart button is clicked.
*/
private void restartClicked()
{
for (StatusPanelButtonListener l : listeners)
{
l.restartClicked();
}
}
/**
* Method usedto create the subsection title with two decoration icons
* surrounding the text.
* @param title the title of the subsection.
*/
{
p.setOpaque(false);
subsectionLabels.add(l);
return p;
}
/**
* Creates the server status subsection panel.
* @return the server status subsection panel.
*/
private JPanel createServerStatusPanel()
{
p.setOpaque(false);
gbc);
statusPanel.setOpaque(false);
{
{
stopClicked();
}
});
{
{
startClicked();
}
});
{
{
}
});
int maxButtonHeight = 0;
gbc);
return p;
}
/**
* Creates the server details subsection panel.
* @return the server details subsection panel.
*/
private JPanel createServerDetailsPanel()
{
p.setOpaque(false);
JLabel[] leftLabels =
{
};
JLabel[] rightLabels =
{
};
{
if (i != 0)
{
}
}
return p;
}
/**
* Creates the server listeners subsection panel.
* @return the server listeners subsection panel.
*/
private JPanel createListenersPanel()
{
p.setOpaque(false);
listenersTableModel = new ListenersTableModel();
new ListenersCellRenderer(),
listenersTable.setFocusable(false);
int height = (int)
lListenersTableEmpty.setVisible(false);
return p;
}
/**
* Creates the server databases subsection panel.
* @return the server databases subsection panel.
*/
private JPanel createDatabasesPanel()
{
p.setOpaque(false);
dbTableModelWithReplication = new DatabasesTableModel(true);
dbTableModelWithoutReplication = new DatabasesTableModel(false);
new DatabasesCellRenderer(),
dbTableWithReplication.setFocusable(false);
new DatabasesCellRenderer(),
dbTableWithoutReplication.setVisible(false);
lDbTableEmpty.setVisible(false);
return p;
}
/**
* Sets the not available text to a label and associates a help icon and
* a tooltip explaining that the data is not available because the server is
* down.
* @param l the label.
*/
private void setNotAvailableBecauseServerIsDown(JLabel l)
{
}
/**
* Sets the not available text to a label and associates a help icon and
* a tooltip explaining that the data is not available because authentication
* is required.
* @param l the label.
*/
private void setNotAvailableBecauseAuthenticationIsRequired(JLabel l)
{
.toString());
}
/**
* Sets the not available text to a label with no icon nor tooltip.
* @param l the label.
*/
private void setNotAvailable(JLabel l)
{
l.setToolTipText(null);
}
/**
* Sets the a text to a label with no icon nor tooltip.
* @param l the label.
*/
{
l.setToolTipText(null);
}
/**
* Updates the status contents displaying with what is specified in the
* provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
{
case STARTED:
startButton.setVisible(false);
restartButton.setVisible(true);
stopButton.setVisible(true);
break;
case STOPPED:
startButton.setVisible(true);
restartButton.setVisible(false);
stopButton.setVisible(false);
break;
case STARTING:
startButton.setVisible(false);
restartButton.setVisible(false);
stopButton.setVisible(false);
break;
case STOPPING:
startButton.setVisible(false);
restartButton.setVisible(false);
stopButton.setVisible(false);
break;
case UNKNOWN:
startButton.setVisible(false);
restartButton.setVisible(true);
stopButton.setVisible(true);
break;
default:
}
/* Enable authenticate button only if the server is started AND we have
* no authentication (or the authentication we have does not seem to work
* because we get an error).
*/
}
/**
* Updates the current connection contents displaying with what is specified
* in the provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
{
if (nConn >= 0)
{
}
else
{
if (!desc.isAuthenticated())
{
}
else
{
}
}
}
else
{
}
}
/**
* Updates the host name contents displaying with what is specified
* in the provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
}
/**
* Updates the administrative user contents displaying with what is specified
* in the provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
{
{
}
}
else
{
{
if (!desc.isAuthenticated())
{
}
else
{
}
}
else
{
}
}
}
/**
* Updates the install path contents displaying with what is specified in the
* provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
}
/**
* Updates the server version contents displaying with what is specified in
* the provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
}
/**
* Updates the java version contents displaying with what is specified in
* the provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
{
if (javaVersion != null)
{
}
else
{
if (!desc.isAuthenticated())
{
}
else
{
}
}
}
else
{
}
}
/**
* Updates the listeners contents displaying with what is specified in
* the provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
{
{
}
}
{
listenersTable.setVisible(false);
lListenersTableEmpty.setVisible(true);
{
if (!desc.isAuthenticated())
{
}
else
{
}
}
else
{
}
}
else
{
listenersTable.setVisible(true);
lListenersTableEmpty.setVisible(false);
}
}
/**
* Updates the databases contents displaying with what is specified in
* the provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
{
}
{
dbTableWithoutReplication.setVisible(false);
dbTableWithReplication.setVisible(false);
lDbTableEmpty.setVisible(true);
{
if (!desc.isAuthenticated())
{
}
else
{
}
}
else
{
}
}
else
{
boolean replicated = false;
{
{
replicated = true;
}
}
lDbTableEmpty.setVisible(false);
}
}
/**
* Updates the error label contents displaying with what is specified in
* the provided ServerStatusDescriptor object.
* This method must be called from the event thread.
* @param desc the ServerStatusDescriptor object.
*/
{
{
lError.setVisible(false);
}
else
{
lError.setVisible(true);
}
}
/**
* Updates the size of the table rows according to the size of the
* rendered component.
* @param table the table to handle.
*/
{
/*
int totalWidth = 0;
int colMargin = table.getColumnModel().getColumnMargin();
int totalHeight = 0;
TableColumn tcol = table.getColumnModel().getColumn(0);
TableCellRenderer renderer = tcol.getHeaderRenderer();
Component comp = renderer.getTableCellRendererComponent(table,
table.getModel().getColumnName(0), false, false, 0, 0);
totalHeight = (int)comp.getPreferredSize().getHeight();
for (int row=0; row<table.getRowCount(); row++)
{
totalHeight += table.getRowHeight(row);
}
for (int col=0; col<table.getColumnCount(); col++)
{
tcol = table.getColumnModel().getColumn(col);
totalWidth += tcol.getPreferredWidth() + colMargin;
}
table.setPreferredScrollableViewportSize(
new Dimension(totalWidth, totalHeight));
*/
}
/**
* Updates the height of the table rows according to the size of the
* rendered component.
* @param table the table to handle.
*/
{
int headerMaxHeight = 0;
{
}
{
{
}
}
}
/**
* Updates the height of the table columns according to the size of the
* rendered component.
* @param table the table to handle.
*/
{
{
int colMaxWidth;
{
}
}
}
private int getMaximalWidth()
{
if (multipleScreen)
{
}
else
{
}
}
/**
* Returns the maximum height we allow this dialog to have after pack.
* @return the maximum height we allow this dialog to have after pack.
*/
private int getMaximalHeight()
{
}
/**
* Method written for testing purposes.
* @param args the arguments to be passed to the test program.
*/
{
try
{
dlg.packAndShow();
{
}
}
/**
* Class used to render the databases table cells.
*/
{
private static final long serialVersionUID = -256719167426289735L;
/**
* Default constructor.
*/
public DatabasesCellRenderer()
{
super();
}
/**
* {@inheritDoc}
*/
{
}
{
}
{
{
}
setTextValue(this, "<html>" +
baseDns, "<br>"),
}
else
{
/* Is the number of entries: check if it is available or not */
if (lastDescriptor.getStatus() ==
{
if (nEntries >= 0)
{
}
else
{
if (!lastDescriptor.isAuthenticated())
{
}
else
{
setNotAvailable(this);
}
}
}
else
{
}
}
if (column == 0)
{
}
else
{
}
return this;
}
}
/**
* Class used to render the listeners table cells.
*/
{
private static final long serialVersionUID = -256719167426289735L;
/**
* Default constructor.
*/
public ListenersCellRenderer()
{
super();
}
/**
* {@inheritDoc}
*/
if (column == 0)
{
}
else
{
}
return this;
}
}
}
/**
* This class is used to be able to have an instantaneous tooltip displayed
* in the 'not available' labels. It replaces the default ToolTipManager class.
*
*/
class InstantaneousToolTipManager extends MouseAdapter
implements MouseMotionListener
{
private boolean isVisible;
/**
* The default constructor.
*/
public InstantaneousToolTipManager()
{
}
/**
* Register a component that will use this tool tip manager to display tool
* tips.
* @param comp the component to be registered.
*/
{
comp.removeMouseListener(this);
comp.addMouseListener(this);
comp.removeMouseMotionListener(this);
comp.addMouseMotionListener(this);
}
/**
* Unregisters a component. Calling this method makes the component to be
* registered by the default tool tip manager.
* @param comp the component to be unregistered.
*/
{
comp.removeMouseListener(this);
comp.removeMouseMotionListener(this);
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
if (isVisible)
{
}
else
{
}
}
/**
* Displays a tooltip depending on the MouseEvent received.
* @param event the mouse event.
*/
{
if (toolTipText != null)
{
getBounds();
if(preferredLocation != null)
{
}
else
{
}
}
}
}
}
}
isVisible = true;
}
/**
* Hides the tooltip if we are displaying it.
* @param event the mouse event.
*/
{
{
}
isVisible = false;
}
}