-
Notifications
You must be signed in to change notification settings - Fork 33
/
BrokerPropsDialog.java
151 lines (123 loc) · 4.46 KB
/
BrokerPropsDialog.java
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
/*
* Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.messaging.jmq.admin.apps.console;
import java.awt.Frame;
import javax.swing.JOptionPane;
import com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin;
import com.sun.messaging.jmq.admin.event.BrokerAdminEvent;
/**
* This dialog is used for viewing/changing the connection properties of a broker.
* <P>
* Note: This dialog is not used to query a broker's attributes (as in "imqcmd query bkr").
* <P>
*/
public class BrokerPropsDialog extends BrokerDialog {
private static final long serialVersionUID = 3753850379230524087L;
private BrokerAdmin ba;
public BrokerPropsDialog(Frame parent) {
super(parent, acr.getString(acr.I_BROKER_PROPS), (OK | CANCEL | CLOSE | HELP));
setHelpId(ConsoleHelpID.BROKER_PROPS);
}
@Override
public void doOK() {
String brokerName = brokerNameTF.getText();
brokerName = brokerName.trim();
if (brokerName.equals("")) {
JOptionPane.showOptionDialog(this, acr.getString(acr.E_NO_BROKER_NAME),
acr.getString(acr.I_ADD_BROKER) + ": " + acr.getString(acr.I_ERROR_CODE, acr.E_NO_BROKER_NAME), JOptionPane.YES_NO_OPTION,
JOptionPane.ERROR_MESSAGE, null, close, close[0]);
return;
}
// Check to make sure host and port are non-empty
if (!isValidString(hostTF.getText()) || !isValidString(portTF.getText())) {
JOptionPane.showOptionDialog(this, acr.getString(acr.E_NO_BROKER_HOST_PORT),
acr.getString(acr.I_ADD_BROKER) + ": " + acr.getString(acr.I_ERROR_CODE, acr.E_NO_BROKER_HOST_PORT), JOptionPane.YES_NO_OPTION,
JOptionPane.ERROR_MESSAGE, null, close, close[0]);
return;
}
BrokerAdminEvent bae = new BrokerAdminEvent(this, BrokerAdminEvent.UPDATE_BROKER_ENTRY);
bae.setConnectAttempt(false);
bae.setBrokerName(brokerName);
bae.setHost(hostTF.getText());
bae.setPort(Integer.parseInt(portTF.getText()));
bae.setUsername(userTF.getText());
bae.setPassword(String.valueOf(passwdTF.getPassword()));
bae.setOKAction(true);
fireAdminEventDispatched(bae);
}
@Override
public void doCancel() {
setVisible(false);
clearFields();
}
// not used
@Override
public void doReset() {
}
@Override
public void doClear() {
}
@Override
public void doClose() {
setVisible(false);
clearFields();
}
@Override
public void setVisible(boolean visible) {
if (visible) {
if (ba.isConnected()) {
setEditable(false);
} else {
setEditable(true);
}
}
super.setVisible(visible);
}
public void setBrokerCObj(BrokerCObj bCObj) {
String tmp;
if (bCObj == null) {
clearFields();
return;
}
ba = bCObj.getBrokerAdmin();
tmp = ba.getKey();
brokerNameTF.setText(tmp);
tmp = ba.getBrokerHost();
hostTF.setText(tmp);
tmp = ba.getBrokerPort();
portTF.setText(tmp);
tmp = ba.getUserName();
userTF.setText(tmp);
tmp = ba.getPassword();
passwdTF.setText(tmp);
}
@Override
protected void setEditable(boolean editable) {
if (editable) {
okButton.setVisible(true);
closeButton.setVisible(false);
cancelButton.setVisible(true);
buttonPanel.doLayout();
} else {
okButton.setVisible(false);
closeButton.setVisible(true);
cancelButton.setVisible(false);
buttonPanel.doLayout();
}
super.setEditable(editable);
}
}