File: OperationNodeRHP.java

package info (click to toggle)
idm-console-framework 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 6,640 kB
  • sloc: java: 70,430; makefile: 486; sh: 345; xml: 254; perl: 23
file content (222 lines) | stat: -rw-r--r-- 8,016 bytes parent folder | download | duplicates (5)
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
/** BEGIN COPYRIGHT BLOCK
 * Copyright (C) 2001 Sun Microsystems, Inc.  Used by permission.
 * Copyright (C) 2005 Red Hat, Inc.
 * All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation version
 * 2.1 of the License.
 *                                                                                 
 * This library 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
 * Lesser General Public License for more details.
 *                                                                                 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * END COPYRIGHT BLOCK **/
package supermail.configuration;

import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.border.*;
import com.netscape.management.client.*;
import com.netscape.management.client.util.*;
import com.netscape.management.client.console.ConsoleInfo;
import com.netscape.management.nmclf.SuiConstants;
import com.netscape.management.nmclf.SuiOptionPane;

/**
 * Inplementation for the Configuration Node right-hand panel.
 * The panel is shown when the node is selected.
 * This class illistrates the following techniqes:
 * 1) How to crate a panel with a proper spacing (see create*() methods)
 * 2) How to externelize a class and use ResourceSet for externelized strings (_i18n)
 * 3) How to interact with the Framework status bar (see setStatusBusy())
 *
 */
public class OperationNodeRHP extends JPanel implements SuiConstants
{
    static ResourceSet _resource;
    static String _i18nStartDescription, _i18nStopDescription;
    static String _i18nStart, _i18nStop, _i18nHelp;
    static String _i18nServerStarted, _i18nServerStopped;
    
    static {
        _resource = new ResourceSet("supermail.supermail");
        _i18nStartDescription =_resource.getString("op", "StartDescription");
        _i18nStopDescription =_resource.getString("op", "StopDescription");
        _i18nStart = _resource.getString("op", "Start");
        _i18nStop = _resource.getString("op", "Stop");
        _i18nServerStarted = _resource.getString("op", "ServerStarted");
        _i18nServerStopped = _resource.getString("op", "ServerStopped");
    }    
    
    ConsoleInfo _consoleInfo;
    JButton _btnStart, _btnStop;

    /**
     * Constructor
     */
	public OperationNodeRHP(ConsoleInfo consoleInfo)
	{
	    _consoleInfo = consoleInfo;
	    createPanelLayout();
    	}


    /**
     * Layout the panel content
     */
    private void createPanelLayout() {
        setLayout(new BorderLayout());
        setBorder(new EmptyBorder(COMPONENT_SPACE, COMPONENT_SPACE, COMPONENT_SPACE, COMPONENT_SPACE));
        add(createStartStopPanel(), BorderLayout.NORTH);
    }    


    /**
     * Create a subpanel consisting of start/stop button and instruction text
     */
    private JPanel createStartStopPanel() {
        JPanel p = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        int row=0;

		MultilineLabel mlLabel = new MultilineLabel(_i18nStartDescription, 2, 50);
        gbc.insets     = new Insets(SEPARATED_COMPONENT_SPACE,0,0,0);
        gbc.gridx      = 0;
        gbc.gridy      = row;
        gbc.gridwidth  = 2;
        gbc.gridheight = 1;
        gbc.weightx    = 1.0;
        gbc.weighty    = 0.0;
        gbc.anchor     = gbc.WEST;
        gbc.fill       = gbc.NONE;
        p.add(mlLabel, gbc);
        row++;

        _btnStart = new JButton(_i18nStart);
        _btnStart.addActionListener(_cmdListener);
        gbc.insets     = new Insets(COMPONENT_SPACE,0,0,0);
        gbc.gridx      = 0;
        gbc.gridy      = row;
        gbc.gridwidth  = 1;
        gbc.gridheight = 1;
        gbc.weightx    = 1.0;
        gbc.weighty    = 0.0;
        gbc.anchor     = gbc.WEST;
        gbc.fill       = gbc.NONE;
        p.add(_btnStart, gbc);

		JLabel spacer = new JLabel(" ");
        gbc.insets     = new Insets(COMPONENT_SPACE,0,0,0);
        gbc.gridx      = 1;
        gbc.gridy      = row;
        gbc.gridwidth  = 1;
        gbc.gridheight = 1;
        gbc.weightx    = 1.0;
        gbc.weighty    = 0.0;
        gbc.anchor     = gbc.WEST;
        gbc.fill       = gbc.HORIZONTAL;
        p.add(spacer, gbc);
        row++;

		mlLabel = new MultilineLabel(_i18nStopDescription, 2, 50);
        gbc.insets     = new Insets(SEPARATED_COMPONENT_SPACE,0,0,0);
        gbc.gridx      = 0;
        gbc.gridy      = row;
        gbc.gridwidth  = 2;
        gbc.gridheight = 1;
        gbc.weightx    = 1.0;
        gbc.weighty    = 0.0;
        gbc.anchor     = gbc.WEST;
        gbc.fill       = gbc.NONE;
        p.add(mlLabel, gbc);
        row++;


        _btnStop = new JButton(_i18nStop);
        _btnStop.addActionListener(_cmdListener);
        gbc.insets     = new Insets(COMPONENT_SPACE,0,0,0);
        gbc.gridx      = 0;
        gbc.gridy      = row;
        gbc.gridwidth  = 2;
        gbc.gridheight = 1;
        gbc.weightx    = 1.0;
        gbc.weighty    = 0.0;
        gbc.anchor     = gbc.WEST;
        gbc.fill       = gbc.NONE;
        p.add(_btnStop, gbc);
        row++;

        return p;

    }

    
    /**
     * Dispatch button press event to appropriate methods
     */
    ActionListener _cmdListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == _btnStart) {
                startServer();
            }
            else if (e.getSource() == _btnStop) {
                stopServer();
            }    
            System.err.println(e.getActionCommand());
        }
    };        

    /**
     * A simulation for the start server method. A real-life example would communicate with
     * the back-end to stop the server.
     */
    protected void startServer() {
        setBusyStatus(_i18nStart, true);        
        try { Thread.currentThread().sleep(2000); } catch (Exception e) {}
        setBusyStatus("", false);
        SuiOptionPane.showMessageDialog(this, _i18nServerStarted, _i18nStart, SuiOptionPane.INFORMATION_MESSAGE);
    }    

    /**
     * A simulation for the stop server method. A real-life example would communicate with
     * the back-end to stop the server.
     */
    protected void stopServer() {
        setBusyStatus(_i18nStop, true);        
        try { Thread.currentThread().sleep(2000); } catch (Exception e) {}
        setBusyStatus("", false);
        SuiOptionPane.showMessageDialog(this, _i18nServerStopped, _i18nStop, SuiOptionPane.INFORMATION_MESSAGE);
    }
    
 
    /**
     * Busy status indicators
     * Busy status is denoted with the change of cursor to "wait" , setting the state of 
     * the ProgressStatus component on the Framework status bar to "busy:, and setting the text
     * on the Framework status bar.
     */    
    private void setBusyStatus(String status, boolean isBusy) {

		JFrame frame = (JFrame)SwingUtilities.getAncestorOfClass(JFrame.class, this);
		ResourcePage page = (ResourcePage)SwingUtilities.getAncestorOfClass(ResourcePage.class, this);
		ResourceModel rpm = (ResourceModel)page.getModel();

		if (isBusy) {
			frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
			rpm.fireChangeStatusItemState(null, Framework.STATUS_TEXT, status);
			rpm.fireChangeStatusItemState(null, ResourcePage.STATUS_PROGRESS, StatusItemProgress.STATE_BUSY);
		}
		else {
			frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			rpm.fireChangeStatusItemState(null, Framework.STATUS_TEXT, status);
			rpm.fireChangeStatusItemState(null, ResourcePage.STATUS_PROGRESS, new Integer(0));
		}
	}	
}