summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/status/StatusPanel.java
blob: 394a567cd8f53fd283bc84c3038c5aa59df05c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.admin.certsrv.status;

import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import com.netscape.admin.certsrv.*;
import javax.swing.event.*;
import java.awt.event.*;
import com.netscape.management.client.*;
import com.netscape.management.client.util.*;
import com.netscape.admin.certsrv.connection.*;
import com.netscape.certsrv.common.*;

/**
 * Status to be placed at the right hand side
 *
 * @author Jack Pan-Chen
 * @version $Revision$, $Date$
 * @see com.netscape.admin.certsrv.status
 */
public class StatusPanel extends CMSBasePanel
    implements IResourceSelectionListener, IRefreshTab, IRefreshTabPanel
{
    /*==========================================================
     * variables
     *==========================================================*/
    private static String PANEL_NAME = "STATUSPANEL";

    protected boolean mInit = false;    // true if this panel is initialized
    protected JPanel mStatPanel, mActionPanel;  //panels
    protected JButton mRefresh, mHelp;  //action buttons
    protected JLabel mServerName, mServerVersion, mInstallDate, mServerStart, mServerTime;

    protected CMSBaseResourceModel mModel;
    private AdminConnection mConnection;
    private static final String HELPINDEX = "status-certsrv-help";

    /*==========================================================
     * constructors
     *==========================================================*/
    public StatusPanel(CMSBaseResourceModel model) {
        super(PANEL_NAME);
        model.addIResourceSelectionListener(this);
        mModel = model;
        mConnection = model.getServerInfo().getAdmin();
    }

    /*==========================================================
	 * public methods
     *==========================================================*/

    /**
     * Actual Instanciation of the UI components
     */
    public void init() {
        setLayout(new BorderLayout());

        //======== stat panel ========================
		mStatPanel = createStatPanel();
		mStatPanel.setBorder(new EmptyBorder(DIFFERENT_COMPONENT_SPACE,COMPONENT_SPACE,COMPONENT_SPACE,COMPONENT_SPACE));
		add("Center",mStatPanel);

		//====== action panel ========================
		mActionPanel = createActionPanel();
		add("South",mActionPanel);
		refresh();
    }

    /*==========================================================
	 * EVNET HANDLER METHODS
     *==========================================================*/

    //== IResourceListener ===

    public void select(IResourceObject parent, Object viewInstance) {
        if (!mInit) {
            init();
            mInit = true;
        }

        //refresh the screen
        invalidate();
        validate();
        repaint(1);
    }

    public boolean unselect(IResourceObject parent, Object viewInstance) {
        return true;
    }

    public CMSBasePanel getSelectedTab() {
        return this;    
    }
    
    //=== ACTIONLISTENER =====================
    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(mRefresh)) {
            Debug.println("StatusPanel: Refresh");
            refresh();
        }
        if (e.getSource().equals(mHelp)) {
            CMSAdminUtil.help(HELPINDEX);
        }
    }


    /*==========================================================
	 * protected methods
     *==========================================================*/

    /**
     * create action button panel
     */
    protected JPanel createActionPanel() {
        //actionlister to this object
        mRefresh = makeJButton("REFRESH");
        mHelp = makeJButton("HELP");
		JButton[] buttons = { mRefresh,mHelp };
		return makeJButtonPanel(buttons,true,true);
    }

    /**
     * create log listing panel
     */
    protected JPanel createStatPanel() {
        JPanel outPanel = new JPanel();
        GridBagLayout gb2 = new GridBagLayout();
        GridBagConstraints gbc2 = new GridBagConstraints();
        outPanel.setLayout(gb2);

		JPanel panel = new JPanel();
		GridBagLayout gb = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        panel.setLayout(gb);
        panel.setBorder(CMSAdminUtil.makeTitledBorder(mResource, PANEL_NAME, "GENERALINFO"));

        CMSAdminUtil.resetGBC(gbc2);
        gbc2.anchor = gbc2.NORTH;
        gbc2.weightx = 1.0;
        gbc2.weighty = 1.0;
        gbc2.gridwidth = gbc2.REMAINDER;
        gbc2.gridheight = gbc2.REMAINDER;
        outPanel.add(panel, gbc2);

        CMSAdminUtil.resetGBC(gbc);
        JLabel label1 = makeJLabel("SERVERNAME");
        mServerName = new JLabel();
        CMSAdminUtil.addEntryField(panel, label1, mServerName, gbc);

        CMSAdminUtil.resetGBC(gbc);
        JLabel label2 = makeJLabel("SERVERVERSION");
        mServerVersion = new JLabel();
        CMSAdminUtil.addEntryField(panel, label2, mServerVersion, gbc);

        CMSAdminUtil.resetGBC(gbc);
        JLabel label5 = makeJLabel("INSTALLDATE");
        mInstallDate = new JLabel();
        CMSAdminUtil.addEntryField(panel, label5, mInstallDate, gbc);
        
        CMSAdminUtil.resetGBC(gbc);
        JLabel label3 = makeJLabel("SERVERSTARTUP");
        mServerStart = new JLabel();
        CMSAdminUtil.addEntryField(panel, label3, mServerStart, gbc);

        CMSAdminUtil.resetGBC(gbc);
        gbc.gridheight = gbc.REMAINDER;
        gbc.weighty = 1.0;
        JLabel label4 = makeJLabel("SERVERTIME");
        mServerTime = new JLabel();
        gbc.fill = gbc.NONE;
        gbc.weightx = 0.0;
        gbc.gridwidth = 1;
        gbc.gridx = 0;
        gbc.anchor = gbc.EAST;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,COMPONENT_SPACE,0);
        panel.add( label4, gbc );

        gbc.gridx++;
        gbc.anchor = gbc.WEST;
        gbc.fill = gbc.HORIZONTAL;
        gbc.weightx = 1.0;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,
      		                            COMPONENT_SPACE,COMPONENT_SPACE);
        panel.add( mServerTime, gbc );

		return outPanel;
    }


    //=============================================
	// SEND REQUESTS TO THE SERVER SIDE
	//=============================================

	//retrieve stat from server
	public void refresh() {

	    NameValuePairs params = new NameValuePairs();
	    params.add(Constants.PR_STAT_STARTUP,"");
	    params.add(Constants.PR_STAT_TIME,"");

        NameValuePairs response;
        mModel.progressStart();
        try {
            response = mConnection.read(DestDef.DEST_SERVER_ADMIN,
                               ScopeDef.SC_STAT,
                               Constants.RS_ID_CONFIG,
                               params);
        } catch (EAdminException e) {
            //display error dialog
            CMSAdminUtil.showErrorDialog(mModel.getFrame(), mResource,
                                         e.toString(), ERROR_MESSAGE);
            mModel.progressStop();                             
            return;
        }
        
        mModel.progressStop();
        Debug.println("StatusPanel: refresh() "+ response.toString());

        //populate data
        mServerName.setText(response.getValue(Constants.PR_STAT_INSTANCEID));
        mServerVersion.setText(response.getValue(Constants.PR_STAT_VERSION));
        mInstallDate.setText(response.getValue(Constants.PR_STAT_INSTALLDATE));
        mServerStart.setText(response.getValue(Constants.PR_STAT_STARTUP));
        mServerTime.setText(response.getValue(Constants.PR_STAT_TIME));
	}

}