@@ -40,12 +40,13 @@ public class McpOptionsPanel extends AbstractParamPanel {
4040
4141 private static final long serialVersionUID = 1L ;
4242
43+ private JCheckBox enabledCheckBox ;
4344 private ZapNumberSpinner portSpinner ;
4445 private JCheckBox securityKeyEnabledCheckBox ;
4546 private JPasswordField securityKeyField ;
4647 private JButton generateKeyButton ;
47- private JCheckBox recordInHistoryCheckBox ;
4848 private JCheckBox secureOnlyCheckBox ;
49+ private JCheckBox recordInHistoryCheckBox ;
4950
5051 public McpOptionsPanel () {
5152 super ();
@@ -58,6 +59,12 @@ public McpOptionsPanel() {
5859
5960 int row = 0 ;
6061
62+ panel .add (
63+ getEnabledCheckBox (),
64+ LayoutHelper .getGBC (
65+ 0 , row , GridBagConstraints .REMAINDER , 1.0 , new Insets (2 , 2 , 2 , 2 )));
66+ row ++;
67+
6168 JLabel portLabel = new JLabel (Constant .messages .getString ("mcp.optionspanel.port.label" ));
6269 portLabel .setLabelFor (getPortSpinner ());
6370 panel .add (
@@ -111,6 +118,26 @@ public McpOptionsPanel() {
111118 add (panel );
112119 }
113120
121+ private JCheckBox getEnabledCheckBox () {
122+ if (enabledCheckBox == null ) {
123+ enabledCheckBox =
124+ new JCheckBox (Constant .messages .getString ("mcp.optionspanel.enabled.label" ));
125+ enabledCheckBox .addItemListener (
126+ e -> {
127+ boolean enabled = enabledCheckBox .isSelected ();
128+ getPortSpinner ().setEnabled (enabled );
129+ getSecurityKeyField ()
130+ .setEnabled (
131+ enabled && getSecurityKeyEnabledCheckBox ().isSelected ());
132+ getSecurityKeyEnabledCheckBox ().setEnabled (enabled );
133+ getGenerateKeyButton ().setEnabled (enabled );
134+ getSecureOnlyCheckBox ().setEnabled (enabled );
135+ getRecordInHistoryCheckBox ().setEnabled (enabled );
136+ });
137+ }
138+ return enabledCheckBox ;
139+ }
140+
114141 private ZapNumberSpinner getPortSpinner () {
115142 if (portSpinner == null ) {
116143 portSpinner = new ZapNumberSpinner (1 , McpParam .DEFAULT_PORT , 65535 );
@@ -137,6 +164,14 @@ private JPasswordField getSecurityKeyField() {
137164 return securityKeyField ;
138165 }
139166
167+ private JCheckBox getSecureOnlyCheckBox () {
168+ if (secureOnlyCheckBox == null ) {
169+ secureOnlyCheckBox =
170+ new JCheckBox (Constant .messages .getString ("mcp.optionspanel.secureonly.label" ));
171+ }
172+ return secureOnlyCheckBox ;
173+ }
174+
140175 private JCheckBox getRecordInHistoryCheckBox () {
141176 if (recordInHistoryCheckBox == null ) {
142177 recordInHistoryCheckBox =
@@ -146,14 +181,6 @@ private JCheckBox getRecordInHistoryCheckBox() {
146181 return recordInHistoryCheckBox ;
147182 }
148183
149- private JCheckBox getSecureOnlyCheckBox () {
150- if (secureOnlyCheckBox == null ) {
151- secureOnlyCheckBox =
152- new JCheckBox (Constant .messages .getString ("mcp.optionspanel.secureonly.label" ));
153- }
154- return secureOnlyCheckBox ;
155- }
156-
157184 private JButton getGenerateKeyButton () {
158185 if (generateKeyButton == null ) {
159186 generateKeyButton =
@@ -164,7 +191,7 @@ private JButton getGenerateKeyButton() {
164191 e -> {
165192 getSecurityKeyField ().setText (McpParam .generateRandomKey ());
166193 getSecurityKeyEnabledCheckBox ().setSelected (true );
167- getSecurityKeyField ().setEnabled (true );
194+ getSecurityKeyField ().setEnabled (getEnabledCheckBox (). isSelected () );
168195 });
169196 }
170197 return generateKeyButton ;
@@ -175,16 +202,26 @@ public void initParam(Object obj) {
175202 OptionsParam options = (OptionsParam ) obj ;
176203 McpParam param = options .getParamSet (McpParam .class );
177204
205+ boolean enabled = param .isEnabled ();
206+ getEnabledCheckBox ().setSelected (enabled );
178207 getPortSpinner ().setValue (param .getPort ());
208+ getPortSpinner ().setEnabled (enabled );
179209 getSecurityKeyEnabledCheckBox ().setSelected (param .isSecurityKeyEnabled ());
210+ getSecurityKeyEnabledCheckBox ().setEnabled (enabled );
180211 getSecurityKeyField ().setText (param .getSecurityKey ());
181- getSecurityKeyField ().setEnabled (param .isSecurityKeyEnabled ());
182- getRecordInHistoryCheckBox ().setSelected ( param . isRecordInHistory () );
212+ getSecurityKeyField ().setEnabled (enabled && param .isSecurityKeyEnabled ());
213+ getGenerateKeyButton ().setEnabled ( enabled );
183214 getSecureOnlyCheckBox ().setSelected (param .isSecureOnly ());
215+ getSecureOnlyCheckBox ().setEnabled (enabled );
216+ getRecordInHistoryCheckBox ().setSelected (param .isRecordInHistory ());
217+ getRecordInHistoryCheckBox ().setEnabled (enabled );
184218 }
185219
186220 @ Override
187221 public void validateParam (Object obj ) throws Exception {
222+ if (!getEnabledCheckBox ().isSelected ()) {
223+ return ;
224+ }
188225 int port = getPortSpinner ().getValue ();
189226 if (port < 1 || port > 65535 ) {
190227 throw new IllegalStateException (
@@ -204,11 +241,12 @@ public void saveParam(Object obj) throws Exception {
204241 OptionsParam options = (OptionsParam ) obj ;
205242 McpParam param = options .getParamSet (McpParam .class );
206243
244+ param .setEnabled (getEnabledCheckBox ().isSelected ());
207245 param .setPort (getPortSpinner ().getValue ());
208246 param .setSecurityKeyEnabled (getSecurityKeyEnabledCheckBox ().isSelected ());
209247 param .setSecurityKey (new String (getSecurityKeyField ().getPassword ()));
210- param .setRecordInHistory (getRecordInHistoryCheckBox ().isSelected ());
211248 param .setSecureOnly (getSecureOnlyCheckBox ().isSelected ());
249+ param .setRecordInHistory (getRecordInHistoryCheckBox ().isSelected ());
212250 }
213251
214252 @ Override
0 commit comments