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 2015 ForgeRock AS.
026 */
027package org.opends.guitools.controlpanel.ui;
028
029import static org.opends.messages.AdminToolMessages.*;
030
031import java.awt.Component;
032import java.awt.GridBagConstraints;
033import java.util.ArrayList;
034import java.util.List;
035
036import javax.swing.Box;
037import javax.swing.JLabel;
038
039import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
040import org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes;
041import org.opends.guitools.controlpanel.datamodel.MonitoringAttributes;
042import org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
043import org.opends.guitools.controlpanel.util.Utilities;
044
045/**
046 * The panel displaying the system information monitoring panel.
047 */
048public class SystemInformationMonitoringPanel extends GeneralMonitoringPanel
049{
050  private static final long serialVersionUID = 9031734563298069830L;
051  static List<MonitoringAttributes> operations = new ArrayList<>();
052  {
053    operations.add(BasicMonitoringAttributes.SYSTEM_NAME);
054    operations.add(BasicMonitoringAttributes.OPERATING_SYSTEM);
055    operations.add(BasicMonitoringAttributes.AVAILABLE_CPUS);
056    operations.add(BasicMonitoringAttributes.USED_MEMORY);
057    operations.add(BasicMonitoringAttributes.FREE_USED_MEMORY);
058    operations.add(BasicMonitoringAttributes.MAX_MEMORY);
059  }
060  private ArrayList<JLabel> monitoringLabels = new ArrayList<>();
061  {
062    for (int i=0; i<operations.size(); i++)
063    {
064      monitoringLabels.add(Utilities.createDefaultLabel());
065    }
066  }
067
068  /**
069   * Default constructor.
070   */
071  public SystemInformationMonitoringPanel()
072  {
073    super();
074    createLayout();
075  }
076
077  /** {@inheritDoc} */
078  public Component getPreferredFocusComponent()
079  {
080    return monitoringLabels.get(0);
081  }
082
083  /**
084   * Creates the layout of the panel (but the contents are not populated here).
085   */
086  private void createLayout()
087  {
088    GridBagConstraints gbc = new GridBagConstraints();
089    JLabel lTitle = Utilities.createTitleLabel(
090        INFO_CTRL_PANEL_SYSTEM_INFORMATION.get());
091    gbc.fill = GridBagConstraints.NONE;
092    gbc.anchor = GridBagConstraints.WEST;
093    gbc.gridwidth = 2;
094    gbc.gridx = 0;
095    gbc.gridy = 0;
096    gbc.insets.top = 5;
097    gbc.insets.bottom = 7;
098    add(lTitle, gbc);
099
100    gbc.insets.bottom = 0;
101    gbc.insets.top = 10;
102    gbc.gridy ++;
103    gbc.anchor = GridBagConstraints.WEST;
104    gbc.gridwidth = 1;
105    for (int i=0; i<operations.size(); i++)
106    {
107      JLabel l = Utilities.createPrimaryLabel(getLabel(operations.get(i)));
108      gbc.gridy ++;
109      gbc.insets.left = 0;
110      gbc.gridx = 0;
111      gbc.weightx = 0.0;
112      gbc.gridwidth = 1;
113      add(l, gbc);
114      gbc.insets.left = 10;
115      gbc.gridx = 1;
116      gbc.gridwidth = 2;
117      add(monitoringLabels.get(i), gbc);
118    }
119
120    gbc.gridx = 0;
121    gbc.gridy ++;
122    gbc.fill = GridBagConstraints.BOTH;
123    gbc.weightx = 1.0;
124    gbc.weighty = 1.0;
125    gbc.gridwidth = 3;
126    add(Box.createGlue(), gbc);
127
128    setBorder(PANEL_BORDER);
129  }
130
131  /**
132   * Updates the contents of the panel.
133   *
134   */
135  public void updateContents()
136  {
137    ServerDescriptor server = null;
138    if (getInfo() != null)
139    {
140      server = getInfo().getServerDescriptor();
141    }
142    CustomSearchResult csr = null;
143    if (server != null)
144    {
145      csr = server.getSystemInformationMonitor();
146    }
147    if (csr != null)
148    {
149      updateMonitoringInfo(operations, monitoringLabels, csr);
150    }
151    else
152    {
153      for (JLabel l : monitoringLabels)
154      {
155        l.setText(NO_VALUE_SET.toString());
156      }
157    }
158  }
159}