001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2009 Sun Microsystems, Inc. 015 * Portions Copyright 2015 ForgeRock AS. 016 */ 017package org.opends.guitools.controlpanel.ui; 018 019import static org.opends.messages.AdminToolMessages.*; 020 021import java.awt.Component; 022import java.awt.GridBagConstraints; 023import java.util.ArrayList; 024import java.util.List; 025 026import javax.swing.Box; 027import javax.swing.JLabel; 028 029import org.opends.guitools.controlpanel.datamodel.CustomSearchResult; 030import org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes; 031import org.opends.guitools.controlpanel.datamodel.MonitoringAttributes; 032import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; 033import org.opends.guitools.controlpanel.util.Utilities; 034 035/** 036 * The panel displaying the system information monitoring panel. 037 */ 038public class SystemInformationMonitoringPanel extends GeneralMonitoringPanel 039{ 040 private static final long serialVersionUID = 9031734563298069830L; 041 static List<MonitoringAttributes> operations = new ArrayList<>(); 042 { 043 operations.add(BasicMonitoringAttributes.SYSTEM_NAME); 044 operations.add(BasicMonitoringAttributes.OPERATING_SYSTEM); 045 operations.add(BasicMonitoringAttributes.AVAILABLE_CPUS); 046 operations.add(BasicMonitoringAttributes.USED_MEMORY); 047 operations.add(BasicMonitoringAttributes.FREE_USED_MEMORY); 048 operations.add(BasicMonitoringAttributes.MAX_MEMORY); 049 } 050 private ArrayList<JLabel> monitoringLabels = new ArrayList<>(); 051 { 052 for (int i=0; i<operations.size(); i++) 053 { 054 monitoringLabels.add(Utilities.createDefaultLabel()); 055 } 056 } 057 058 /** 059 * Default constructor. 060 */ 061 public SystemInformationMonitoringPanel() 062 { 063 super(); 064 createLayout(); 065 } 066 067 /** {@inheritDoc} */ 068 public Component getPreferredFocusComponent() 069 { 070 return monitoringLabels.get(0); 071 } 072 073 /** 074 * Creates the layout of the panel (but the contents are not populated here). 075 */ 076 private void createLayout() 077 { 078 GridBagConstraints gbc = new GridBagConstraints(); 079 JLabel lTitle = Utilities.createTitleLabel( 080 INFO_CTRL_PANEL_SYSTEM_INFORMATION.get()); 081 gbc.fill = GridBagConstraints.NONE; 082 gbc.anchor = GridBagConstraints.WEST; 083 gbc.gridwidth = 2; 084 gbc.gridx = 0; 085 gbc.gridy = 0; 086 gbc.insets.top = 5; 087 gbc.insets.bottom = 7; 088 add(lTitle, gbc); 089 090 gbc.insets.bottom = 0; 091 gbc.insets.top = 10; 092 gbc.gridy ++; 093 gbc.anchor = GridBagConstraints.WEST; 094 gbc.gridwidth = 1; 095 for (int i=0; i<operations.size(); i++) 096 { 097 JLabel l = Utilities.createPrimaryLabel(getLabel(operations.get(i))); 098 gbc.gridy ++; 099 gbc.insets.left = 0; 100 gbc.gridx = 0; 101 gbc.weightx = 0.0; 102 gbc.gridwidth = 1; 103 add(l, gbc); 104 gbc.insets.left = 10; 105 gbc.gridx = 1; 106 gbc.gridwidth = 2; 107 add(monitoringLabels.get(i), gbc); 108 } 109 110 gbc.gridx = 0; 111 gbc.gridy ++; 112 gbc.fill = GridBagConstraints.BOTH; 113 gbc.weightx = 1.0; 114 gbc.weighty = 1.0; 115 gbc.gridwidth = 3; 116 add(Box.createGlue(), gbc); 117 118 setBorder(PANEL_BORDER); 119 } 120 121 /** 122 * Updates the contents of the panel. 123 * 124 */ 125 public void updateContents() 126 { 127 ServerDescriptor server = null; 128 if (getInfo() != null) 129 { 130 server = getInfo().getServerDescriptor(); 131 } 132 CustomSearchResult csr = null; 133 if (server != null) 134 { 135 csr = server.getSystemInformationMonitor(); 136 } 137 if (csr != null) 138 { 139 updateMonitoringInfo(operations, monitoringLabels, csr); 140 } 141 else 142 { 143 for (JLabel l : monitoringLabels) 144 { 145 l.setText(NO_VALUE_SET.toString()); 146 } 147 } 148 } 149}