1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.swing.control; |
|
27 |
|
28 import java.awt.event.*; |
|
29 import java.net.URL; |
|
30 import java.util.List; |
|
31 import java.util.logging.Level; |
|
32 import javax.help.HelpSet; |
|
33 import com.oracle.solaris.vp.panel.common.ClientContext; |
|
34 import com.oracle.solaris.vp.panel.common.control.*; |
|
35 import com.oracle.solaris.vp.panel.common.model.PanelDescriptor; |
|
36 import com.oracle.solaris.vp.util.misc.ChangeableAggregator; |
|
37 import com.oracle.solaris.vp.util.swing.SettingsPanel; |
|
38 |
|
39 /** |
|
40 * {@code SettingsControl} extends class {@link SwingControl} to provide |
|
41 * support for {@link SettingsPanel}s. |
|
42 */ |
|
43 public class SettingsControl<P extends PanelDescriptor, |
|
44 C extends SettingsPanel> extends SwingControl<P, C> { |
|
45 |
|
46 // |
|
47 // Constructors |
|
48 // |
|
49 |
|
50 public SettingsControl(String id, String name, ClientContext context) { |
|
51 super(id, name, context); |
|
52 } |
|
53 |
|
54 public SettingsControl(String id, String name, P descriptor) { |
|
55 super(id, name, descriptor); |
|
56 } |
|
57 |
|
58 // |
|
59 // SwingControl methods |
|
60 // |
|
61 |
|
62 /** |
|
63 * Returns {@code getComponent().getChangeableAggregator()}. |
|
64 */ |
|
65 @Override |
|
66 public ChangeableAggregator getChangeableAggregator() { |
|
67 C comp = getComponent(); |
|
68 if (comp != null) { |
|
69 return comp.getChangeableAggregator(); |
|
70 } |
|
71 return null; |
|
72 } |
|
73 |
|
74 // |
|
75 // SettingsControl methods |
|
76 // |
|
77 |
|
78 /** |
|
79 * Adds a listener to the <strong>Apply</strong> button of this {@code |
|
80 * SettingsControl}'s {@link SettingsPanel} to invoke this {@link |
|
81 * Control}'s save action. |
|
82 */ |
|
83 protected void addDefaultApplyAction() { |
|
84 getComponent().getButtonBar().getApplyButton().addActionListener( |
|
85 new ActionListener() { |
|
86 @Override |
|
87 public void actionPerformed(ActionEvent e) { |
|
88 getSaveAction().asyncInvoke(); |
|
89 } |
|
90 }); |
|
91 } |
|
92 |
|
93 /** |
|
94 * Adds a listener to the <strong>Back</strong> button of this {@code |
|
95 * SettingsControl}'s {@link SettingsPanel} to navigate up one level in |
|
96 * the navigation stack. |
|
97 */ |
|
98 protected void addDefaultBackAction() { |
|
99 getComponent().getButtonBar().getBackButton().addActionListener( |
|
100 new ActionListener() { |
|
101 @Override |
|
102 public void actionPerformed(ActionEvent e) { |
|
103 getNavigator().goToAsync(false, SettingsControl.this, |
|
104 Navigator.PARENT_NAVIGABLE); |
|
105 } |
|
106 }); |
|
107 } |
|
108 |
|
109 /** |
|
110 * Adds a listener to the <strong>Cancel</strong> button of this {@code |
|
111 * SettingsControl}'s {@link SettingsPanel} to call {@link #doQuit}, if |
|
112 * {@code quit} is {@code true}, or {@link #doCancel}, if {@code quit} is |
|
113 * {@code false}. |
|
114 */ |
|
115 protected void addDefaultCancelAction(final boolean quit) { |
|
116 getComponent().getButtonBar().getCancelButton().addActionListener( |
|
117 new ActionListener() { |
|
118 @Override |
|
119 public void actionPerformed(ActionEvent e) { |
|
120 if (quit) { |
|
121 doQuit(); |
|
122 } else { |
|
123 doCancel(); |
|
124 } |
|
125 } |
|
126 }); |
|
127 } |
|
128 |
|
129 /** |
|
130 * Adds a listener to the <strong>Close</strong> button of this {@code |
|
131 * SettingsControl}'s {@link SettingsPanel} to call {@link |
|
132 * #doSaveAndQuit}, if {@code quit} is {@code true}, or {@link #doOkay}, if |
|
133 * {@code quit} is {@code false}. |
|
134 */ |
|
135 protected void addDefaultCloseAction(final boolean quit) { |
|
136 getComponent().getButtonBar().getCloseButton().addActionListener( |
|
137 new ActionListener() { |
|
138 @Override |
|
139 public void actionPerformed(ActionEvent e) { |
|
140 if (quit) { |
|
141 doSaveAndQuit(); |
|
142 } else { |
|
143 doOkay(); |
|
144 } |
|
145 } |
|
146 }); |
|
147 } |
|
148 |
|
149 /** |
|
150 * Adds a listener to the <strong>Help</strong> button of this {@code |
|
151 * SettingsControl}'s {@link SettingsPanel} to search through the navigation |
|
152 * stack, from top to bottom, for a {@code Control} with a non-{@code null} |
|
153 * {@link Control#getHelpURL help URL}, then show it. |
|
154 */ |
|
155 protected void addDefaultHelpAction() { |
|
156 getComponent().getButtonBar().getHelpButton().addActionListener( |
|
157 new ActionListener() { |
|
158 @Override |
|
159 public void actionPerformed(ActionEvent e) { |
|
160 PanelDescriptor descriptor = getPanelDescriptor(); |
|
161 HelpSet helpSet = descriptor.getHelpSet(); |
|
162 if (helpSet == null) { |
|
163 getLog().log(Level.SEVERE, "no help set found for " + |
|
164 descriptor.getClass().getName()); |
|
165 return; |
|
166 } |
|
167 |
|
168 URL url = null; |
|
169 |
|
170 List<Control> controls = getNavigator().getPath(); |
|
171 for (int i = controls.size() - 1; i >= 0; i--) { |
|
172 Control control = controls.get(i); |
|
173 url = control.getHelpURL(helpSet); |
|
174 if (url != null) { |
|
175 break; |
|
176 } |
|
177 } |
|
178 |
|
179 if (url == null) { |
|
180 getLog().log(Level.SEVERE, String.format( |
|
181 "help set found but no URL provided: " + |
|
182 helpSet.getHelpSetURL())); |
|
183 return; |
|
184 } |
|
185 |
|
186 ClientContext context = getClientContext(); |
|
187 context.getHelpBroker().setCurrentURL(url); |
|
188 context.showHelp(); |
|
189 } |
|
190 }); |
|
191 } |
|
192 |
|
193 /** |
|
194 * Adds a listener to the <strong>Okay</strong> button of this {@code |
|
195 * SettingsControl}'s {@link SettingsPanel} to call {@link |
|
196 * #doSaveAndQuit}, if {@code quit} is {@code true}, or {@link #doOkay}, if |
|
197 * {@code quit} is {@code false}. |
|
198 */ |
|
199 protected void addDefaultOkayAction(final boolean quit) { |
|
200 getComponent().getButtonBar().getOkayButton().addActionListener( |
|
201 new ActionListener() { |
|
202 @Override |
|
203 public void actionPerformed(ActionEvent e) { |
|
204 if (quit) { |
|
205 doSaveAndQuit(); |
|
206 } else { |
|
207 doOkay(); |
|
208 } |
|
209 } |
|
210 }); |
|
211 } |
|
212 |
|
213 /** |
|
214 * Adds a listener to the <strong>Quit</strong> button of this {@code |
|
215 * SettingsControl}'s {@link SettingsPanel} to close this instance. |
|
216 */ |
|
217 protected void addDefaultQuitAction() { |
|
218 getComponent().getButtonBar().getQuitButton().addActionListener( |
|
219 new ActionListener() { |
|
220 @Override |
|
221 public void actionPerformed(ActionEvent e) { |
|
222 doQuit(); |
|
223 } |
|
224 }); |
|
225 } |
|
226 |
|
227 /** |
|
228 * Adds a listener to the <strong>Reset</strong> button of this {@code |
|
229 * SettingsControl}'s {@link SettingsPanel} to invoke this {@link |
|
230 * Control}'s reset action. |
|
231 */ |
|
232 protected void addDefaultResetAction() { |
|
233 getComponent().getButtonBar().getResetButton().addActionListener( |
|
234 new ActionListener() { |
|
235 @Override |
|
236 public void actionPerformed(ActionEvent e) { |
|
237 getResetAction().asyncInvoke(); |
|
238 } |
|
239 }); |
|
240 } |
|
241 } |
|