001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2009 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.guitools.controlpanel.ui;
028
029import static org.opends.messages.AdminToolMessages.*;
030
031import java.awt.CardLayout;
032import java.awt.Component;
033import java.awt.GridBagConstraints;
034
035import javax.swing.JPanel;
036
037import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
038import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
039import org.opends.guitools.controlpanel.util.Utilities;
040import org.forgerock.i18n.LocalizableMessage;
041
042
043/**
044 * The panel on the right of the 'General Information' panel.
045 *
046 */
047public class GeneralMonitoringRightPanel extends StatusGenericPanel
048{
049  private static final long serialVersionUID = -4197460101279681042L;
050
051  /**
052   * The panel with a CardLayout that contains all the panels.
053   */
054  protected JPanel mainPanel;
055
056  private RootMonitoringPanel rootPanel = new RootMonitoringPanel();
057  private WorkQueueMonitoringPanel workQueuePanel =
058    new WorkQueueMonitoringPanel();
059  private EntryCachesMonitoringPanel entryCachesPanel =
060    new EntryCachesMonitoringPanel();
061  private DBEnvironmentMonitoringPanel dbEnvironmentPanel =
062    new DBEnvironmentMonitoringPanel();
063  private SystemInformationMonitoringPanel systemInformationPanel =
064    new SystemInformationMonitoringPanel();
065  private JavaInformationMonitoringPanel javaInformationPanel =
066    new JavaInformationMonitoringPanel();
067
068  /**
069   * The panel used to update messages.
070   */
071  protected NoItemSelectedPanel noEntryPanel = new NoItemSelectedPanel();
072
073  private final StatusGenericPanel[] panels =
074  {
075      rootPanel,
076      workQueuePanel,
077      entryCachesPanel,
078      dbEnvironmentPanel,
079      systemInformationPanel,
080      javaInformationPanel
081  };
082
083  /**
084   * Default constructor.
085   *
086   */
087  public GeneralMonitoringRightPanel()
088  {
089    super();
090    createLayout();
091  }
092
093  /**
094   * Displays a panel containing a message.
095   * @param msg the message.
096   *
097   */
098  public void displayMessage(LocalizableMessage msg)
099  {
100    noEntryPanel.setMessage(msg);
101    ((CardLayout)mainPanel.getLayout()).show(mainPanel, getTitle(noEntryPanel));
102  }
103
104  /** {@inheritDoc} */
105  public void setInfo(ControlPanelInfo info)
106  {
107    super.setInfo(info);
108    for (StatusGenericPanel panel : panels)
109    {
110      panel.setInfo(info);
111    }
112  }
113
114  /**
115   * Creates the layout of the panel (but the contents are not populated here).
116   */
117  protected void createLayout()
118  {
119    GridBagConstraints gbc = new GridBagConstraints();
120    CardLayout cardLayout = new CardLayout();
121    mainPanel = new JPanel(cardLayout);
122    mainPanel.setOpaque(false);
123    noEntryPanel.setMessage(
124        INFO_CTRL_PANEL_GENERAL_MONITORING_NO_ITEM_SELECTED.get());
125    JPanel[] panelsWithScroll =
126    {
127        noEntryPanel,
128        rootPanel,
129        workQueuePanel,
130        entryCachesPanel,
131        systemInformationPanel,
132        javaInformationPanel
133    };
134    JPanel[] panelsWithNoScroll =
135    {
136        dbEnvironmentPanel
137    };
138    for (JPanel panel : panelsWithScroll)
139    {
140      mainPanel.add(Utilities.createBorderLessScrollBar(panel),
141          getTitle(panel));
142    }
143    for (JPanel panel : panelsWithNoScroll)
144    {
145      mainPanel.add(panel, getTitle(panel));
146    }
147    cardLayout.show(mainPanel, getTitle(noEntryPanel));
148    gbc.gridx = 0;
149    gbc.gridy = 0;
150    gbc.weightx = 1.0;
151    gbc.weighty = 1.0;
152    gbc.fill = GridBagConstraints.BOTH;
153    add(mainPanel, gbc);
154  }
155
156  /** {@inheritDoc} */
157  public void okClicked()
158  {
159    // No ok button
160  }
161
162  /** {@inheritDoc} */
163  public GenericDialog.ButtonType getButtonType()
164  {
165    return GenericDialog.ButtonType.NO_BUTTON;
166  }
167
168  /** {@inheritDoc} */
169  public LocalizableMessage getTitle()
170  {
171    return LocalizableMessage.EMPTY;
172  }
173
174  /** {@inheritDoc} */
175  public Component getPreferredFocusComponent()
176  {
177    return null;
178  }
179
180  /** {@inheritDoc} */
181  public void configurationChanged(ConfigurationChangeEvent ev)
182  {
183  }
184
185  /**
186   * Updates the contents of the panel with the root monitoring information.
187   */
188  public void updateRoot()
189  {
190    rootPanel.updateContents();
191    ((CardLayout)mainPanel.getLayout()).show(mainPanel,
192        getTitle(rootPanel));
193  }
194
195  /**
196   * Updates the contents of the panel with the system information monitoring.
197   */
198  public void updateSystemInformation()
199  {
200    systemInformationPanel.updateContents();
201    ((CardLayout)mainPanel.getLayout()).show(mainPanel,
202        getTitle(systemInformationPanel));
203  }
204
205  /** Updates the contents of the panel with the work queue monitoring information. */
206  public void updateWorkQueue()
207  {
208    workQueuePanel.updateContents();
209    ((CardLayout)mainPanel.getLayout()).show(mainPanel,
210        getTitle(workQueuePanel));
211  }
212
213  /**
214   * Updates the contents of the panel with the entry caches monitoring
215   * information.
216   */
217  public void updateEntryCaches()
218  {
219    entryCachesPanel.updateContents();
220    ((CardLayout)mainPanel.getLayout()).show(mainPanel,
221        getTitle(entryCachesPanel));
222  }
223
224  /**
225   * Updates the contents of the panel with the database environment monitoring
226   * information.
227   */
228  public void updateDBEnvironment()
229  {
230    dbEnvironmentPanel.updateContents();
231    ((CardLayout)mainPanel.getLayout()).show(mainPanel,
232        getTitle(dbEnvironmentPanel));
233  }
234
235  /** Updates the contents of the panel with the JAVA information. */
236  public void updateJavaInformation()
237  {
238    javaInformationPanel.updateContents();
239    ((CardLayout)mainPanel.getLayout()).show(mainPanel,
240        getTitle(javaInformationPanel));
241  }
242
243  /**
244   * Returns the title for a given panel. It will be used to update the
245   * CardLayout.
246   * @param panel the panel we want to get the title from.
247   * @return the title for a given panel.
248   */
249  protected String getTitle(JPanel panel)
250  {
251    return panel.getClass().toString();
252  }
253}