Line 0
Link Here
|
|
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
8 |
* |
9 |
* The contents of this file are subject to the terms of either the GNU |
10 |
* General Public License Version 2 only ("GPL") or the Common |
11 |
* Development and Distribution License("CDDL") (collectively, the |
12 |
* "License"). You may not use this file except in compliance with the |
13 |
* License. You can obtain a copy of the License at |
14 |
* http://www.netbeans.org/cddl-gplv2.html |
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
16 |
* specific language governing permissions and limitations under the |
17 |
* License. When distributing the software, include this License Header |
18 |
* Notice in each file and include the License file at |
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
20 |
* particular file as subject to the "Classpath" exception as provided |
21 |
* by Oracle in the GPL Version 2 section of the License file that |
22 |
* accompanied this code. If applicable, add the following below the |
23 |
* License Header, with the fields enclosed by brackets [] replaced by |
24 |
* your own identifying information: |
25 |
* "Portions Copyrighted [year] [name of copyright owner]" |
26 |
* |
27 |
* Contributor(s): |
28 |
* |
29 |
* The Original Software is NetBeans. The Initial Developer of the Original |
30 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun |
31 |
* Microsystems, Inc. All Rights Reserved. |
32 |
* |
33 |
* If you wish your version of this file to be governed by only the CDDL |
34 |
* or only the GPL Version 2, indicate your decision by adding |
35 |
* "[Contributor] elects to include this software in this distribution |
36 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
37 |
* single choice of license, a recipient has the option to distribute |
38 |
* your version of this file under either the CDDL, the GPL Version 2 or |
39 |
* to extend the choice of license to its licensees as provided above. |
40 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
41 |
* Version 2 license, then the option applies only if the new code is |
42 |
* made subject to such option by the copyright holder. |
43 |
*/ |
44 |
|
45 |
package org.netbeans.modules.gsf.testrunner; |
46 |
|
47 |
//import org.netbeans.modules.gsf.testrunner.CommonSettings; |
48 |
//import org.netbeans.modules.gsf.testrunner.ClassNameTextField; |
49 |
import java.awt.*; |
50 |
import java.awt.event.ActionListener; |
51 |
import java.awt.event.ItemEvent; |
52 |
import java.awt.event.ItemListener; |
53 |
import java.util.List; |
54 |
import java.util.*; |
55 |
import javax.swing.*; |
56 |
import javax.swing.border.Border; |
57 |
import javax.swing.border.CompoundBorder; |
58 |
import javax.swing.border.TitledBorder; |
59 |
import javax.swing.event.ChangeEvent; |
60 |
import javax.swing.event.ChangeListener; |
61 |
import javax.swing.plaf.UIResource; |
62 |
import javax.swing.text.JTextComponent; |
63 |
import org.netbeans.api.java.classpath.ClassPath; |
64 |
import org.netbeans.api.java.project.JavaProjectConstants; |
65 |
import org.netbeans.api.project.FileOwnerQuery; |
66 |
import org.netbeans.api.project.Project; |
67 |
import org.netbeans.api.project.SourceGroup; |
68 |
import org.netbeans.api.project.SourceGroupModifier; |
69 |
import org.netbeans.modules.gsf.testrunner.ClassNameTextField; |
70 |
//import org.netbeans.modules.gsf.testrunner.CommonSettings; |
71 |
//import org.netbeans.modules.gsf.testrunner.GuiUtils; |
72 |
import org.netbeans.modules.gsf.testrunner.MessageStack; |
73 |
import org.netbeans.modules.gsf.testrunner.api.CommonSettings; |
74 |
import org.netbeans.modules.gsf.testrunner.api.CommonTestUtil; |
75 |
import org.netbeans.modules.gsf.testrunner.api.GuiUtils; |
76 |
import org.netbeans.modules.gsf.testrunner.api.SelfResizingPanel; |
77 |
import org.openide.DialogDescriptor; |
78 |
import org.openide.DialogDisplayer; |
79 |
import org.openide.awt.Mnemonics; |
80 |
import org.openide.filesystems.FileObject; |
81 |
import org.openide.filesystems.FileUtil; |
82 |
import org.openide.loaders.DataFolder; |
83 |
import org.openide.loaders.DataObject; |
84 |
import org.openide.nodes.Node; |
85 |
import org.openide.util.HelpCtx; |
86 |
import org.openide.util.Lookup; |
87 |
import org.openide.util.NbBundle; |
88 |
|
89 |
|
90 |
/** |
91 |
* |
92 |
* @author vstejskal |
93 |
* @author Marian Petras |
94 |
*/ |
95 |
@SuppressWarnings("serial") |
96 |
public class CommonTestsCfgOfCreate extends SelfResizingPanel implements ChangeListener { |
97 |
|
98 |
/** suffix of test classes */ |
99 |
private static final String TEST_CLASS_SUFFIX = "Test"; //NOI18N |
100 |
|
101 |
/** |
102 |
* nodes selected when the Create Tests action was invoked |
103 |
*/ |
104 |
private Node[] nodes; |
105 |
/** whether the tests will be created for multiple classes */ |
106 |
private boolean multipleClasses; |
107 |
/** whether a single package/folder is selected */ |
108 |
private boolean singlePackage; |
109 |
/** whether a single class is selected */ |
110 |
private boolean singleClass; |
111 |
/** test class name specified in the form (or <code>null</code>) */ |
112 |
private String testClassName; |
113 |
/** registered change listeners */ |
114 |
private List<ChangeListener> changeListeners; |
115 |
/** */ |
116 |
private String initialMessage; |
117 |
/** */ |
118 |
private List<String> testingFrameworks; |
119 |
// public static final String JUNIT_TEST_FRAMEWORK = "JUnit"; //NOI18N |
120 |
// public static final String TESTNG_TEST_FRAMEWORK = "TestNG"; //NOI18N |
121 |
private String selectedTestingFramework = null; |
122 |
|
123 |
/** |
124 |
* is at least one target folder/source group available? |
125 |
* |
126 |
* @see #isAcceptable() |
127 |
*/ |
128 |
private boolean hasTargetFolders = false; |
129 |
|
130 |
/** |
131 |
* is the entered class name non-empty and valid? |
132 |
* |
133 |
* @see #isAcceptable() |
134 |
*/ |
135 |
private boolean classNameValid; |
136 |
|
137 |
/** |
138 |
* is the current form contents acceptable? |
139 |
* |
140 |
* @see #isAcceptable() |
141 |
*/ |
142 |
private boolean isAcceptable; |
143 |
|
144 |
/** layer index for a message about an empty set of target folders */ |
145 |
private static final int MSG_TYPE_NO_TARGET_FOLDERS = 0; |
146 |
/** layer index for a message about invalid class name */ |
147 |
private static final int MSG_TYPE_CLASSNAME_INVALID = 1; |
148 |
/** layer index for a message about non-default class name */ |
149 |
private static final int MSG_TYPE_CLASSNAME_NOT_DEFAULT = 2; |
150 |
/** layer index for a message about modified files */ |
151 |
private static final int MSG_TYPE_MODIFIED_FILES = 3; |
152 |
/** */ |
153 |
private MessageStack msgStack = new MessageStack(4); |
154 |
|
155 |
public CommonTestsCfgOfCreate(Node[] nodes) { |
156 |
assert (nodes != null) && (nodes.length != 0); |
157 |
this.nodes = nodes; |
158 |
} |
159 |
|
160 |
/** |
161 |
* Creates a configuration panel. |
162 |
* |
163 |
* @param nodes nodes selected when the Create Tests action was invoked |
164 |
* @param isShowMsgFilesWillBeSaved if {@code true} then a warning message |
165 |
* like "Warning: All modified files will be saved." will be |
166 |
* displayed on the panel, otherwise (i.e. if {@code false}) then |
167 |
* the message won't be displayed. |
168 |
*/ |
169 |
public void createCfgPanel(boolean isShowMsgFilesWillBeSaved) { |
170 |
// assert (nodes != null) && (nodes.length != 0); |
171 |
// this.nodes = nodes; |
172 |
multipleClasses = checkMultipleClasses(); |
173 |
|
174 |
initBundle(); |
175 |
try { |
176 |
initComponents(); |
177 |
if(isShowMsgFilesWillBeSaved) { |
178 |
String msg = bundle.getString("MSG_MODIFIED_FILES"); // NOI18N |
179 |
setMessage(msg, MSG_TYPE_MODIFIED_FILES); |
180 |
} |
181 |
setBorder(BorderFactory.createEmptyBorder(12, 12, 0, 11)); |
182 |
addAccessibleDescriptions(); |
183 |
initializeCheckBoxStates(); |
184 |
fillFormData(); |
185 |
checkAcceptability(); |
186 |
setupUserInteraction(); |
187 |
|
188 |
/* |
189 |
* checkAcceptability() must not be called |
190 |
* before initializeCheckBoxStates() and fillFormData() |
191 |
* setupUserInteraction must not be called |
192 |
* before initializeCheckBoxStates() |
193 |
*/ |
194 |
|
195 |
} finally { |
196 |
unlinkBundle(); |
197 |
} |
198 |
} |
199 |
|
200 |
private void addAccessibleDescriptions() { |
201 |
|
202 |
// window |
203 |
this.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.AD")); |
204 |
|
205 |
// text-field and combo-box |
206 |
|
207 |
if (this.tfClassName != null) { |
208 |
this.tfClassName.setToolTipText( |
209 |
bundle.getString("CommonTestsCfgOfCreate.clsName.toolTip"));//NOI18N |
210 |
this.tfClassName.getAccessibleContext().setAccessibleName( |
211 |
bundle.getString("CommonTestsCfgOfCreate.clsName.AN")); //NOI18N |
212 |
this.tfClassName.getAccessibleContext().setAccessibleDescription( |
213 |
bundle.getString("CommonTestsCfgOfCreate.clsName.AD")); //NOI18N |
214 |
} |
215 |
|
216 |
this.cboxLocation.setToolTipText( |
217 |
bundle.getString("CommonTestsCfgOfCreate.location.toolTip")); //NOI18N |
218 |
this.cboxLocation.getAccessibleContext().setAccessibleName( |
219 |
bundle.getString("CommonTestsCfgOfCreate.location.AN")); //NOI18N |
220 |
this.cboxLocation.getAccessibleContext().setAccessibleDescription( |
221 |
bundle.getString("CommonTestsCfgOfCreate.location.AD")); //NOI18N |
222 |
|
223 |
this.cboxLocation.setToolTipText( |
224 |
bundle.getString("CommonTestsCfgOfCreate.framework.toolTip")); //NOI18N |
225 |
this.cboxLocation.getAccessibleContext().setAccessibleName( |
226 |
bundle.getString("CommonTestsCfgOfCreate.framework.AN")); //NOI18N |
227 |
this.cboxLocation.getAccessibleContext().setAccessibleDescription( |
228 |
bundle.getString("CommonTestsCfgOfCreate.framework.AD")); //NOI18N |
229 |
|
230 |
// check boxes |
231 |
this.chkPublic.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkPublic.toolTip")); |
232 |
this.chkPublic.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkPublic.AD")); |
233 |
|
234 |
this.chkProtected.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkProtected.toolTip")); |
235 |
this.chkProtected.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkProtected.AD")); |
236 |
|
237 |
this.chkPackage.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkPackage.toolTip")); |
238 |
this.chkPackage.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkPackage.AD")); |
239 |
|
240 |
this.chkComments.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkComments.toolTip")); |
241 |
this.chkComments.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkComments.AD")); |
242 |
|
243 |
this.chkContent.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkContent.toolTip")); |
244 |
this.chkContent.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkContent.AD")); |
245 |
|
246 |
this.chkJavaDoc.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkJavaDoc.toolTip")); |
247 |
this.chkJavaDoc.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkJavaDoc.AD")); |
248 |
|
249 |
if (multipleClasses) { |
250 |
this.chkExceptions.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkExceptions.toolTip")); |
251 |
this.chkExceptions.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkExceptions.AD")); |
252 |
|
253 |
this.chkAbstractImpl.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkAbstractImpl.toolTip")); |
254 |
this.chkAbstractImpl.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkAbstractImpl.AD")); |
255 |
|
256 |
this.chkPackagePrivateClasses.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkPackagePrivateClasses.toolTip")); |
257 |
this.chkPackagePrivateClasses.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkPackagePrivateClasses.AD")); |
258 |
|
259 |
this.chkGenerateSuites.setToolTipText(bundle.getString("CommonTestsCfgOfCreate.chkGenerateSuites.toolTip")); |
260 |
this.chkGenerateSuites.getAccessibleContext().setAccessibleDescription(bundle.getString("CommonTestsCfgOfCreate.chkGenerateSuites.AD")); |
261 |
} |
262 |
|
263 |
} |
264 |
|
265 |
/** |
266 |
* Checks whether multiple classes may be selected. |
267 |
* It also detects whether exactly one package/folder or exactly one class |
268 |
* is selected and sets values of variables {@link #singlePackage} |
269 |
* and {@link #singleClass} accordingly. |
270 |
* |
271 |
* @return <code>false</code> if there is exactly one node selected |
272 |
* and the node represents a single <code>DataObject</code>, |
273 |
* not a folder or another <code>DataObject</code> container; |
274 |
* <code>true</code> otherwise |
275 |
*/ |
276 |
private boolean checkMultipleClasses() { |
277 |
if (nodes.length > 1) { |
278 |
return true; |
279 |
} |
280 |
|
281 |
Lookup nodeLookup = nodes[0].getLookup(); |
282 |
if (nodeLookup.lookup(DataObject.Container.class) != null) { |
283 |
singlePackage = nodeLookup.lookup(DataFolder.class) |
284 |
!= null; |
285 |
return true; |
286 |
} |
287 |
|
288 |
singleClass = false; |
289 |
DataObject dataObj = nodeLookup.lookup(DataObject.class); |
290 |
if (dataObj == null) { |
291 |
return true; |
292 |
} |
293 |
|
294 |
singleClass = dataObj.getPrimaryFile().isData(); |
295 |
return !singleClass; |
296 |
} |
297 |
|
298 |
/** |
299 |
* Displays a configuration dialog and updates JUnit options according |
300 |
* to the user's settings. |
301 |
* |
302 |
* @param nodes nodes selected when the Create Test action was invoked |
303 |
*/ |
304 |
public boolean configure() { |
305 |
|
306 |
// create and display the dialog: |
307 |
String title = NbBundle.getMessage(GuiUtils.class, |
308 |
"CommonTestsCfgOfCreate.Title"); //NOI18N |
309 |
ChangeListener changeListener; |
310 |
final JButton btnOK = new JButton( |
311 |
NbBundle.getMessage(GuiUtils.class, "LBL_OK")); //NOI18N |
312 |
btnOK.getAccessibleContext().setAccessibleName(NbBundle.getMessage(GuiUtils.class, "AN_OK")); |
313 |
btnOK.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(GuiUtils.class, "AD_OK")); |
314 |
btnOK.setEnabled(isAcceptable()); |
315 |
addChangeListener(changeListener = new ChangeListener() { |
316 |
@Override |
317 |
public void stateChanged(ChangeEvent e) { |
318 |
btnOK.setEnabled(isAcceptable()); |
319 |
} |
320 |
}); |
321 |
|
322 |
Object returned = DialogDisplayer.getDefault().notify( |
323 |
new DialogDescriptor ( |
324 |
this, |
325 |
title, |
326 |
true, //modal |
327 |
new Object[] {btnOK, DialogDescriptor.CANCEL_OPTION}, |
328 |
btnOK, //initial value |
329 |
DialogDescriptor.DEFAULT_ALIGN, |
330 |
new HelpCtx(CommonTestsCfgOfCreate.class), |
331 |
(ActionListener) null |
332 |
)); |
333 |
removeChangeListener(changeListener); |
334 |
|
335 |
if (returned == btnOK) { |
336 |
rememberCheckBoxStates(); |
337 |
testClassName = (tfClassName != null) ? tfClassName.getText() |
338 |
: null; |
339 |
return true; |
340 |
} |
341 |
return false; |
342 |
} |
343 |
|
344 |
/** |
345 |
* Returns whether a test for a single class is to be created. |
346 |
* |
347 |
* @return true if there is only one node selected and the node |
348 |
* represents a class |
349 |
*/ |
350 |
public boolean isSingleClass() { |
351 |
return singleClass; |
352 |
} |
353 |
|
354 |
public boolean isSinglePackage() { |
355 |
return singlePackage; |
356 |
} |
357 |
|
358 |
/** |
359 |
* Returns the class name entered in the text-field. |
360 |
* |
361 |
* @return class name entered in the form, |
362 |
* or <code>null</code> if the form did not contain |
363 |
* the field for entering class name |
364 |
*/ |
365 |
public String getTestClassName() { |
366 |
return testClassName; |
367 |
} |
368 |
|
369 |
/** resource bundle used during initialization of this panel */ |
370 |
public ResourceBundle bundle; |
371 |
|
372 |
/** |
373 |
* Reads JUnit settings and initializes checkboxes accordingly. |
374 |
* |
375 |
* @see #rememberCheckBoxStates |
376 |
*/ |
377 |
private void initializeCheckBoxStates() { |
378 |
final CommonSettings settings = CommonSettings.getDefault(); |
379 |
|
380 |
chkPublic.setSelected(settings.isMembersPublic()); |
381 |
chkProtected.setSelected(settings.isMembersProtected()); |
382 |
chkPackage.setSelected(settings.isMembersPackage()); |
383 |
chkComments.setSelected(settings.isBodyComments()); |
384 |
chkContent.setSelected(settings.isBodyContent()); |
385 |
chkJavaDoc.setSelected(settings.isJavaDoc()); |
386 |
if (multipleClasses) { |
387 |
chkGenerateSuites.setSelected(settings.isGenerateSuiteClasses()); |
388 |
chkPackagePrivateClasses.setSelected( |
389 |
settings.isIncludePackagePrivateClasses()); |
390 |
chkAbstractImpl.setSelected(settings.isGenerateAbstractImpl()); |
391 |
chkExceptions.setSelected(settings.isGenerateExceptionClasses()); |
392 |
} |
393 |
chkSetUp.setSelected(settings.isGenerateSetUp()); |
394 |
chkTearDown.setSelected(settings.isGenerateTearDown()); |
395 |
} |
396 |
|
397 |
/** |
398 |
* Stores settings given by checkbox states to JUnit settings. |
399 |
* |
400 |
* @see #initializeCheckBoxStatesf |
401 |
*/ |
402 |
private void rememberCheckBoxStates() { |
403 |
final CommonSettings settings = CommonSettings.getDefault(); |
404 |
|
405 |
settings.setMembersPublic(chkPublic.isSelected()); |
406 |
settings.setMembersProtected(chkProtected.isSelected()); |
407 |
settings.setMembersPackage(chkPackage.isSelected()); |
408 |
settings.setBodyComments(chkComments.isSelected()); |
409 |
settings.setBodyContent(chkContent.isSelected()); |
410 |
settings.setJavaDoc(chkJavaDoc.isSelected()); |
411 |
if (multipleClasses) { |
412 |
settings.setGenerateSuiteClasses(chkGenerateSuites.isSelected()); |
413 |
settings.setIncludePackagePrivateClasses( |
414 |
chkPackagePrivateClasses.isSelected()); |
415 |
settings.setGenerateAbstractImpl(chkAbstractImpl.isSelected()); |
416 |
settings.setGenerateExceptionClasses(chkExceptions.isSelected()); |
417 |
} |
418 |
settings.setGenerateSetUp(chkSetUp.isSelected()); |
419 |
settings.setGenerateTearDown(chkTearDown.isSelected()); |
420 |
} |
421 |
|
422 |
/** |
423 |
* Loads a resource bundle so that it can be used during intialization |
424 |
* of this panel. |
425 |
* |
426 |
* @see #unlinkBundle |
427 |
*/ |
428 |
private void initBundle() { |
429 |
bundle = NbBundle.getBundle(GuiUtils.class); |
430 |
} |
431 |
|
432 |
/** |
433 |
* Nulls the resource bundle so that it is not held in memory when it is |
434 |
* not used. |
435 |
* |
436 |
* @see #initBundle |
437 |
*/ |
438 |
private void unlinkBundle() { |
439 |
bundle = null; |
440 |
} |
441 |
|
442 |
/** |
443 |
* This method is called from within the constructor to initialize the form. |
444 |
*/ |
445 |
private void initComponents() { |
446 |
setLayout(new BorderLayout(0, 12)); |
447 |
|
448 |
add(createNameAndLocationPanel(), BorderLayout.NORTH); |
449 |
add(createMessagePanel(), BorderLayout.CENTER); |
450 |
add(createCodeGenPanel(), BorderLayout.SOUTH); |
451 |
} |
452 |
|
453 |
/** |
454 |
*/ |
455 |
private void setupUserInteraction() { |
456 |
final ItemListener listener = new CheckBoxListener(); |
457 |
|
458 |
chkPublic.addItemListener(listener); |
459 |
chkProtected.addItemListener(listener); |
460 |
chkPackage.addItemListener(listener); |
461 |
} |
462 |
|
463 |
/** |
464 |
* Listener object that listens on state changes of some check-boxes. |
465 |
*/ |
466 |
private final class CheckBoxListener implements ItemListener { |
467 |
public CheckBoxListener () {} |
468 |
|
469 |
@Override |
470 |
public void itemStateChanged(ItemEvent e) { |
471 |
final Object source = e.getSource(); |
472 |
|
473 |
assert source == chkPublic |
474 |
|| source == chkProtected |
475 |
|| source == chkPackage; |
476 |
checkAcceptability(); |
477 |
} |
478 |
|
479 |
} |
480 |
|
481 |
// public String getTestingFramework() { |
482 |
// Object selectedTestingFramework = cboxFramework.getSelectedItem(); |
483 |
// if(selectedTestingFramework == null) { |
484 |
// return null; |
485 |
// } |
486 |
// return selectedTestingFramework.toString().equals(TESTNG_TEST_FRAMEWORK) ? TESTNG_TEST_FRAMEWORK : JUNIT_TEST_FRAMEWORK; |
487 |
// } |
488 |
|
489 |
private String getTestingFrameworkFolder() { |
490 |
Object tf = cboxFramework.getSelectedItem(); |
491 |
if(tf == null) { |
492 |
return ""; |
493 |
} |
494 |
return tf.toString().equals(GuiUtils.TESTNG_TEST_FRAMEWORK) ? "testng." : ""; //NOI18N |
495 |
} |
496 |
|
497 |
private void fireFrameworkChanged() { |
498 |
if (tfClassName != null) { |
499 |
DataObject dataObj = nodes[0].getLookup().lookup(DataObject.class); |
500 |
FileObject fileObj = dataObj.getPrimaryFile(); |
501 |
|
502 |
ClassPath cp = ClassPath.getClassPath(fileObj, ClassPath.SOURCE); |
503 |
String className = cp.getResourceName(fileObj, '.', false); |
504 |
|
505 |
String prefilledName = getTestingFrameworkFolder() + className + TEST_CLASS_SUFFIX; |
506 |
tfClassName.setText(prefilledName); |
507 |
tfClassName.setDefaultText(prefilledName); |
508 |
tfClassName.setCaretPosition(prefilledName.length()); |
509 |
} |
510 |
setSelectedTestingFramework(); |
511 |
} |
512 |
|
513 |
private void setSelectedTestingFramework() { |
514 |
Object tf = cboxFramework.getSelectedItem(); |
515 |
if(tf != null) { |
516 |
selectedTestingFramework = tf.toString(); |
517 |
} |
518 |
} |
519 |
|
520 |
public String getSelectedTestingFramework() { |
521 |
return selectedTestingFramework; |
522 |
} |
523 |
|
524 |
public void addTestingFrameworks(ArrayList<String> testingFrameworksToAdd) { |
525 |
for(String testingFramework : testingFrameworksToAdd) { |
526 |
testingFrameworks.add(testingFramework); |
527 |
} |
528 |
cboxFramework.setModel(new DefaultComboBoxModel(testingFrameworks.toArray())); |
529 |
fireFrameworkChanged(); |
530 |
} |
531 |
|
532 |
/** |
533 |
*/ |
534 |
private Component createNameAndLocationPanel() { |
535 |
JPanel panel = new JPanel(); |
536 |
|
537 |
final boolean askForClassName = singleClass; |
538 |
|
539 |
JLabel lblClassToTest = new JLabel(); |
540 |
JLabel lblClassName = askForClassName ? new JLabel() : null; |
541 |
JLabel lblLocation = new JLabel(); |
542 |
JLabel lblFramework = new JLabel(); |
543 |
|
544 |
String classToTestKey = singlePackage |
545 |
? "LBL_PackageToTest" //NOI18N |
546 |
: singleClass |
547 |
? "LBL_ClassToTest" //NOI18N |
548 |
: "LBL_MultipleClassesSelected"; //NOI18N |
549 |
|
550 |
Mnemonics.setLocalizedText( |
551 |
lblClassToTest, |
552 |
NbBundle.getMessage(GuiUtils.class, classToTestKey)); |
553 |
if (askForClassName) { |
554 |
Mnemonics.setLocalizedText( |
555 |
lblClassName, |
556 |
NbBundle.getMessage(GuiUtils.class, "LBL_ClassName")); //NOI18N |
557 |
} |
558 |
Mnemonics.setLocalizedText( |
559 |
lblLocation, |
560 |
NbBundle.getMessage(GuiUtils.class, "LBL_Location")); //NOI18N |
561 |
Mnemonics.setLocalizedText( |
562 |
lblFramework, |
563 |
NbBundle.getMessage(GuiUtils.class, "LBL_Framework")); //NOI18N |
564 |
|
565 |
if (singlePackage || singleClass) { |
566 |
lblClassToTestValue = new JLabel(); |
567 |
} |
568 |
if (askForClassName) { |
569 |
tfClassName = new ClassNameTextField(); |
570 |
tfClassName.setChangeListener(this); |
571 |
} |
572 |
cboxLocation = new JComboBox(); |
573 |
cboxFramework = new JComboBox(); |
574 |
testingFrameworks = new ArrayList<String>(); |
575 |
cboxFramework.setModel(new DefaultComboBoxModel(testingFrameworks.toArray())); |
576 |
cboxFramework.addItemListener(new java.awt.event.ItemListener() { |
577 |
@Override |
578 |
public void itemStateChanged(java.awt.event.ItemEvent evt) { |
579 |
fireFrameworkChanged(); |
580 |
} |
581 |
}); |
582 |
|
583 |
if (askForClassName) { |
584 |
lblClassName.setLabelFor(tfClassName); |
585 |
} |
586 |
lblLocation.setLabelFor(cboxLocation); |
587 |
lblFramework.setLabelFor(cboxFramework); |
588 |
|
589 |
if (lblClassToTestValue != null) { |
590 |
Font labelFont = javax.swing.UIManager.getDefaults() |
591 |
.getFont("TextField.font"); //NOI18N |
592 |
if (labelFont != null) { |
593 |
lblClassToTestValue.setFont(labelFont); |
594 |
} |
595 |
} |
596 |
|
597 |
panel.setLayout(new GridBagLayout()); |
598 |
|
599 |
GridBagConstraints gbcLeft = new GridBagConstraints(); |
600 |
gbcLeft.anchor = GridBagConstraints.WEST; |
601 |
gbcLeft.insets.bottom = 12; |
602 |
gbcLeft.insets.right = 6; |
603 |
|
604 |
GridBagConstraints gbcRight = new GridBagConstraints(); |
605 |
gbcRight.anchor = GridBagConstraints.WEST; |
606 |
gbcRight.insets.bottom = 12; |
607 |
gbcRight.weightx = 1.0f; |
608 |
gbcRight.fill = GridBagConstraints.BOTH; |
609 |
gbcRight.gridwidth = GridBagConstraints.REMAINDER; |
610 |
|
611 |
if (lblClassToTestValue != null) { |
612 |
panel.add(lblClassToTest, gbcLeft); |
613 |
panel.add(lblClassToTestValue, gbcRight); |
614 |
} else { |
615 |
panel.add(lblClassToTest, gbcRight); |
616 |
} |
617 |
if (askForClassName) { |
618 |
panel.add(lblClassName, gbcLeft); |
619 |
panel.add(tfClassName, gbcRight); |
620 |
} |
621 |
panel.add(lblLocation, gbcLeft); |
622 |
panel.add(cboxLocation, gbcRight); |
623 |
gbcLeft.insets.bottom = 0; |
624 |
gbcRight.insets.bottom = 0; |
625 |
panel.add(lblFramework, gbcLeft); |
626 |
panel.add(cboxFramework, gbcRight); |
627 |
|
628 |
return panel; |
629 |
} |
630 |
|
631 |
/** |
632 |
*/ |
633 |
private void checkClassNameValidity() { |
634 |
if (tfClassName == null) { |
635 |
classNameValid = true; |
636 |
return; |
637 |
} |
638 |
|
639 |
String key = null; |
640 |
final int state = tfClassName.getStatus(); |
641 |
switch (state) { |
642 |
case ClassNameTextField.STATUS_EMPTY: |
643 |
key = "MSG_ClassnameMustNotBeEmpty"; //NOI18N |
644 |
break; |
645 |
case ClassNameTextField.STATUS_INVALID: |
646 |
key = "MSG_InvalidClassName"; //NOI18N |
647 |
break; |
648 |
case ClassNameTextField.STATUS_VALID_NOT_DEFAULT: |
649 |
key = "MSG_ClassNameNotDefault"; //NOI18N |
650 |
break; |
651 |
case ClassNameTextField.STATUS_VALID_END_NOT_TEST: |
652 |
key = "MSG_ClassNameEndNotTest"; //NOI18N |
653 |
break; |
654 |
} |
655 |
if (state != ClassNameTextField.STATUS_VALID_NOT_DEFAULT) { |
656 |
setMessage(null, MSG_TYPE_CLASSNAME_NOT_DEFAULT); |
657 |
} |
658 |
setMessage((key != null) |
659 |
? NbBundle.getMessage(GuiUtils.class, key) |
660 |
: null, |
661 |
MSG_TYPE_CLASSNAME_INVALID); |
662 |
|
663 |
classNameValid = |
664 |
(state == ClassNameTextField.STATUS_VALID) |
665 |
|| (state == ClassNameTextField.STATUS_VALID_NOT_DEFAULT); |
666 |
} |
667 |
|
668 |
/** |
669 |
* This method gets called if status of contents of the Class Name |
670 |
* text field changes. See <code>STATUS_xxx</code> constants |
671 |
* in class <code>ClassNameTextField</code>. |
672 |
* |
673 |
* @param e event describing the state change event |
674 |
* (unused in this method) |
675 |
*/ |
676 |
@Override |
677 |
public void stateChanged(ChangeEvent e) { |
678 |
checkClassNameValidity(); |
679 |
checkAcceptability(); |
680 |
} |
681 |
|
682 |
/** |
683 |
*/ |
684 |
private void checkAcceptability() { |
685 |
final boolean wasAcceptable = isAcceptable; |
686 |
isAcceptable = hasTargetFolders && classNameValid; |
687 |
if (isAcceptable != wasAcceptable) { |
688 |
fireStateChange(); |
689 |
} |
690 |
} |
691 |
|
692 |
/** |
693 |
* Are the values filled in the form acceptable? |
694 |
* |
695 |
* @see #addChangeListener |
696 |
*/ |
697 |
private boolean isAcceptable() { |
698 |
return isAcceptable; |
699 |
} |
700 |
|
701 |
/** |
702 |
* This method is called the first time this panel's children are painted. |
703 |
* By default, this method just calls {@link #adjustWindowSize()}. |
704 |
* |
705 |
* @param g <code>Graphics</code> used to paint this panel's children |
706 |
*/ |
707 |
@Override |
708 |
protected void paintedFirstTime(java.awt.Graphics g) { |
709 |
if (initialMessage != null) { |
710 |
displayMessage(initialMessage); |
711 |
initialMessage = null; |
712 |
} |
713 |
} |
714 |
|
715 |
/** |
716 |
* Displays a given message in the message panel and resizes the dialog |
717 |
* if necessary. If the message cannot be displayed immediately, |
718 |
* because of this panel not displayed (painted) yet, displaying the message |
719 |
* is deferred until this panel is painted. |
720 |
* |
721 |
* @param message message to be displayed, or <code>null</code> if |
722 |
* the currently displayed message (if any) should be |
723 |
* removed |
724 |
*/ |
725 |
private void setMessage(final String message, final int msgType) { |
726 |
String msgToDisplay = msgStack.setMessage(msgType, message); |
727 |
if (msgToDisplay == null) { |
728 |
return; //no change |
729 |
} |
730 |
|
731 |
/* display the message: */ |
732 |
if (!isPainted()) { |
733 |
initialMessage = msgToDisplay; |
734 |
} else { |
735 |
displayMessage(msgToDisplay); |
736 |
} |
737 |
} |
738 |
|
739 |
/** |
740 |
* Displays a given message in the message panel and resizes the dialog |
741 |
* if necessary. |
742 |
* |
743 |
* @param message message to be displayed, or <code>null</code> if |
744 |
* the currently displayed message (if any) should be |
745 |
* removed |
746 |
* @see #adjustWindowSize() |
747 |
*/ |
748 |
private void displayMessage(String message) { |
749 |
if (message == null) { |
750 |
message = ""; //NOI18N |
751 |
} |
752 |
|
753 |
txtAreaMessage.setText(message); |
754 |
adjustWindowSize(); |
755 |
} |
756 |
|
757 |
/** |
758 |
*/ |
759 |
private Component createMessagePanel() { |
760 |
Color color = UIManager.getColor("nb.errorForeground"); //NOI18N |
761 |
if (color == null) { |
762 |
color = new Color(89, 79, 191); //RGB suggested by Bruce in #28466 |
763 |
} |
764 |
txtAreaMessage = GuiUtils.createMultilineLabel("", color); //NOI18N |
765 |
return txtAreaMessage; |
766 |
} |
767 |
|
768 |
/** |
769 |
* Creates a panel containing controls for settings code generation options. |
770 |
* |
771 |
* @return created panel |
772 |
*/ |
773 |
private Component createCodeGenPanel() { |
774 |
|
775 |
/* create the components: */ |
776 |
String[] chkBoxIDs; |
777 |
JCheckBox[] chkBoxes; |
778 |
if (multipleClasses) { |
779 |
chkBoxIDs = new String[] { |
780 |
GuiUtils.CHK_PUBLIC, |
781 |
GuiUtils.CHK_PROTECTED, |
782 |
GuiUtils.CHK_PACKAGE, |
783 |
GuiUtils.CHK_PACKAGE_PRIVATE_CLASSES, |
784 |
GuiUtils.CHK_ABSTRACT_CLASSES, |
785 |
GuiUtils.CHK_EXCEPTION_CLASSES, |
786 |
GuiUtils.CHK_SUITES, |
787 |
GuiUtils.CHK_SETUP, |
788 |
GuiUtils.CHK_TEARDOWN, |
789 |
GuiUtils.CHK_METHOD_BODIES, |
790 |
GuiUtils.CHK_JAVADOC, |
791 |
GuiUtils.CHK_HINTS |
792 |
}; |
793 |
} else { |
794 |
chkBoxIDs = new String[] { |
795 |
GuiUtils.CHK_PUBLIC, |
796 |
GuiUtils.CHK_PROTECTED, |
797 |
GuiUtils.CHK_PACKAGE, |
798 |
null, // CHK_PACKAGE_PRIVATE_CLASSES, |
799 |
null, // CHK_ABSTRACT_CLASSES, |
800 |
null, // CHK_EXCEPTION_CLASSES, |
801 |
null, // CHK_SUITES, |
802 |
GuiUtils.CHK_SETUP, |
803 |
GuiUtils.CHK_TEARDOWN, |
804 |
GuiUtils.CHK_METHOD_BODIES, |
805 |
GuiUtils.CHK_JAVADOC, |
806 |
GuiUtils.CHK_HINTS |
807 |
}; |
808 |
} |
809 |
chkBoxes = GuiUtils.createCheckBoxes(chkBoxIDs); |
810 |
int i = 0; |
811 |
chkPublic = chkBoxes[i++]; |
812 |
chkProtected = chkBoxes[i++]; |
813 |
chkPackage = chkBoxes[i++]; |
814 |
chkPackagePrivateClasses = chkBoxes[i++]; //may be null |
815 |
chkAbstractImpl = chkBoxes[i++]; //may be null |
816 |
chkExceptions = chkBoxes[i++]; //may be null |
817 |
chkGenerateSuites = chkBoxes[i++]; //may be null |
818 |
chkSetUp = chkBoxes[i++]; |
819 |
chkTearDown = chkBoxes[i++]; |
820 |
chkContent = chkBoxes[i++]; |
821 |
chkJavaDoc = chkBoxes[i++]; |
822 |
chkComments = chkBoxes[i++]; |
823 |
|
824 |
/* create groups of checkboxes: */ |
825 |
JComponent methodAccessLevels = GuiUtils.createChkBoxGroup( |
826 |
bundle.getString("CommonTestsCfgOfCreate.groupAccessLevels"), //NOI18N |
827 |
new JCheckBox[] {chkPublic, chkProtected, chkPackage}); |
828 |
JComponent classTypes = null; |
829 |
JComponent optionalClasses = null; |
830 |
if (multipleClasses) { |
831 |
classTypes = GuiUtils.createChkBoxGroup( |
832 |
bundle.getString("CommonTestsCfgOfCreate.groupClassTypes"), //NOI18N |
833 |
new JCheckBox[] {chkPackagePrivateClasses, |
834 |
chkAbstractImpl, chkExceptions}); |
835 |
optionalClasses = GuiUtils.createChkBoxGroup( |
836 |
bundle.getString("CommonTestsCfgOfCreate.groupOptClasses"), //NOI18N |
837 |
new JCheckBox[] {chkGenerateSuites}); |
838 |
} |
839 |
JComponent optionalCode = GuiUtils.createChkBoxGroup( |
840 |
bundle.getString("CommonTestsCfgOfCreate.groupOptCode"), //NOI18N |
841 |
new JCheckBox[] {chkSetUp, chkTearDown, chkContent}); |
842 |
JComponent optionalComments = GuiUtils.createChkBoxGroup( |
843 |
bundle.getString("CommonTestsCfgOfCreate.groupOptComments"), //NOI18N |
844 |
new JCheckBox[] {chkJavaDoc, chkComments}); |
845 |
|
846 |
/* create the left column of options: */ |
847 |
Box leftColumn = Box.createVerticalBox(); |
848 |
leftColumn.add(methodAccessLevels); |
849 |
if (multipleClasses) { |
850 |
leftColumn.add(Box.createVerticalStrut(11)); |
851 |
leftColumn.add(classTypes); |
852 |
} else { |
853 |
/* |
854 |
* This strut ensures that width of the left column is not limited. |
855 |
* If it was limited, the rigth column would not move when the |
856 |
* dialog is horizontally resized. |
857 |
*/ |
858 |
leftColumn.add(Box.createVerticalStrut(0)); |
859 |
} |
860 |
leftColumn.add(Box.createVerticalGlue()); |
861 |
|
862 |
/* create the right column of options: */ |
863 |
Box rightColumn = Box.createVerticalBox(); |
864 |
if (multipleClasses) { |
865 |
rightColumn.add(optionalClasses); |
866 |
rightColumn.add(Box.createVerticalStrut(11)); |
867 |
} |
868 |
rightColumn.add(optionalCode); |
869 |
rightColumn.add(Box.createVerticalStrut(11)); |
870 |
rightColumn.add(optionalComments); |
871 |
rightColumn.add(Box.createVerticalGlue()); |
872 |
|
873 |
/* compose the final panel: */ |
874 |
//JPanel jpCodeGen = new SizeRestrictedPanel(false, true); |
875 |
JPanel jpCodeGen = new JPanel(); |
876 |
jpCodeGen.setLayout(new BoxLayout(jpCodeGen, BoxLayout.X_AXIS)); |
877 |
jpCodeGen.add(leftColumn); |
878 |
jpCodeGen.add(Box.createHorizontalStrut(24)); |
879 |
jpCodeGen.add(rightColumn); |
880 |
|
881 |
/* decorate the panel: */ |
882 |
addTitledBorder(jpCodeGen, |
883 |
new Insets(12, 12, 11, 12), |
884 |
bundle.getString("CommonTestsCfgOfCreate.jpCodeGen.title"));//NOI18N |
885 |
|
886 |
/* tune the layout: */ |
887 |
methodAccessLevels.setAlignmentX(0.0f); |
888 |
if (multipleClasses) { |
889 |
classTypes.setAlignmentX(0.0f); |
890 |
optionalClasses.setAlignmentX(0.0f); |
891 |
} |
892 |
optionalCode.setAlignmentX(0.0f); |
893 |
optionalComments.setAlignmentX(0.0f); |
894 |
|
895 |
return jpCodeGen; |
896 |
} |
897 |
|
898 |
/** |
899 |
* Adds a border and a title around a given component. |
900 |
* If the component already has some border, it is overridden (not kept). |
901 |
* |
902 |
* @param component component the border and title should be added to |
903 |
* @param insets insets between the component and the titled border |
904 |
* @param title text of the title |
905 |
*/ |
906 |
private static void addTitledBorder(JComponent component, |
907 |
Insets insets, |
908 |
String title) { |
909 |
Border insideBorder = BorderFactory.createEmptyBorder( |
910 |
insets.top, insets.left, insets.bottom, insets.right); |
911 |
Border outsideBorder = new TitledBorder( |
912 |
BorderFactory.createEtchedBorder(), title); |
913 |
component.setBorder(new CompoundBorder(outsideBorder, insideBorder)); |
914 |
} |
915 |
|
916 |
/** |
917 |
*/ |
918 |
public FileObject getTargetFolder() { |
919 |
Object selectedLocation = cboxLocation.getSelectedItem(); |
920 |
|
921 |
if (selectedLocation == null) { |
922 |
return null; |
923 |
} |
924 |
|
925 |
if (selectedLocation instanceof SourceGroup) { |
926 |
return ((SourceGroup) selectedLocation).getRootFolder(); |
927 |
} |
928 |
assert selectedLocation instanceof FileObject; //root folder |
929 |
return (FileObject) selectedLocation; |
930 |
} |
931 |
|
932 |
/** |
933 |
* Initializes form in the Test Settings panel of the dialog. |
934 |
*/ |
935 |
private void fillFormData() { |
936 |
final DataObject dataObj = nodes[0].getLookup().lookup(DataObject.class); |
937 |
final FileObject fileObj = dataObj.getPrimaryFile(); |
938 |
|
939 |
if (singleClass) { |
940 |
assert nodes.length == 1; |
941 |
|
942 |
ClassPath cp = ClassPath.getClassPath(fileObj, ClassPath.SOURCE); |
943 |
String className = cp.getResourceName(fileObj, '.', false); |
944 |
lblClassToTestValue.setText(className); |
945 |
|
946 |
if (tfClassName != null) { |
947 |
String prefilledName = getTestingFrameworkFolder() + className + TEST_CLASS_SUFFIX; |
948 |
tfClassName.setText(prefilledName); |
949 |
tfClassName.setDefaultText(prefilledName); |
950 |
tfClassName.setCaretPosition(prefilledName.length()); |
951 |
} |
952 |
} else if (singlePackage) { |
953 |
assert nodes.length == 1; |
954 |
|
955 |
ClassPath cp = ClassPath.getClassPath(fileObj, ClassPath.SOURCE); |
956 |
String packageName = cp.getResourceName(fileObj, '.', true); |
957 |
if (packageName.length() == 0) { |
958 |
packageName = NbBundle.getMessage( |
959 |
GuiUtils.class, |
960 |
"DefaultPackageName"); //NOI18N |
961 |
} |
962 |
lblClassToTestValue.setText(packageName); |
963 |
} else { |
964 |
//PENDING |
965 |
} |
966 |
|
967 |
setupLocationChooser(fileObj); |
968 |
|
969 |
checkClassNameValidity(); |
970 |
} |
971 |
|
972 |
/** |
973 |
*/ |
974 |
private void setupLocationChooser(FileObject refFileObject) { |
975 |
Object[] targetFolders = CommonTestUtil.getTestTargets(refFileObject); |
976 |
if (targetFolders.length == 0) { |
977 |
Project owner = FileOwnerQuery.getOwner(refFileObject); |
978 |
if (owner != null) { |
979 |
if (SourceGroupModifier.createSourceGroup(owner, JavaProjectConstants.SOURCES_TYPE_JAVA, JavaProjectConstants.SOURCES_HINT_TEST) != null) { |
980 |
targetFolders = CommonTestUtil.getTestTargets(refFileObject); |
981 |
} |
982 |
} |
983 |
} |
984 |
|
985 |
if (targetFolders.length != 0) { |
986 |
hasTargetFolders = true; |
987 |
cboxLocation.setModel(new DefaultComboBoxModel(targetFolders)); |
988 |
cboxLocation.setRenderer(new LocationChooserRenderer()); |
989 |
} else { |
990 |
hasTargetFolders = false; |
991 |
//PENDING - message text: |
992 |
String msgNoTargetsFound = NbBundle.getMessage( |
993 |
getClass(), |
994 |
refFileObject.isFolder() |
995 |
? "MSG_NoTestTarget_Fo" //NOI18N |
996 |
: "MSG_NoTestTarget_Fi",//NOI18N |
997 |
refFileObject.getNameExt()); |
998 |
setMessage(msgNoTargetsFound, MSG_TYPE_NO_TARGET_FOLDERS); |
999 |
disableComponents(); |
1000 |
} |
1001 |
} |
1002 |
|
1003 |
/** |
1004 |
* Renderer which specially handles values of type |
1005 |
* <code>SourceGroup</code> and <code>FileObject</code>. |
1006 |
* It displays display names of these objects, instead of their default |
1007 |
* string representation (<code>toString()</code>). |
1008 |
* |
1009 |
* @see SourceGroup#getDisplayName() |
1010 |
* @see FileUtil#getFileDisplayName(FileObject) |
1011 |
*/ |
1012 |
private final class LocationChooserRenderer extends JLabel implements ListCellRenderer, UIResource { |
1013 |
|
1014 |
public LocationChooserRenderer () { |
1015 |
setOpaque(true); |
1016 |
} |
1017 |
|
1018 |
@Override |
1019 |
public Component getListCellRendererComponent( |
1020 |
JList list, |
1021 |
Object value, |
1022 |
int index, |
1023 |
boolean isSelected, |
1024 |
boolean cellHasFocus) { |
1025 |
// #93658: GTK needs name to render cell renderer "natively" |
1026 |
setName("ComboBox.listRenderer"); // NOI18N |
1027 |
|
1028 |
String text = value instanceof SourceGroup |
1029 |
? ((SourceGroup) value).getDisplayName() |
1030 |
: value instanceof FileObject |
1031 |
? FileUtil.getFileDisplayName((FileObject) value) |
1032 |
: value.toString(); |
1033 |
setText(text); |
1034 |
|
1035 |
if ( isSelected ) { |
1036 |
setBackground(list.getSelectionBackground()); |
1037 |
setForeground(list.getSelectionForeground()); |
1038 |
} |
1039 |
else { |
1040 |
setBackground(list.getBackground()); |
1041 |
setForeground(list.getForeground()); |
1042 |
} |
1043 |
|
1044 |
return this; |
1045 |
} |
1046 |
|
1047 |
// #93658: GTK needs name to render cell renderer "natively" |
1048 |
@Override |
1049 |
public String getName() { |
1050 |
String name = super.getName(); |
1051 |
return name == null ? "ComboBox.renderer" : name; // NOI18N |
1052 |
} |
1053 |
|
1054 |
} |
1055 |
|
1056 |
/** |
1057 |
* Registers a change listener. |
1058 |
* Registered change listeners are notified when acceptability |
1059 |
* of values in the form changes. |
1060 |
* |
1061 |
* @param l listener to be registered |
1062 |
* @see #isAcceptable |
1063 |
* @see #removeChangeListener |
1064 |
*/ |
1065 |
private void addChangeListener(ChangeListener l) { |
1066 |
if (changeListeners == null) { |
1067 |
changeListeners = new ArrayList<ChangeListener>(3); |
1068 |
} |
1069 |
changeListeners.add(l); |
1070 |
} |
1071 |
|
1072 |
/** |
1073 |
* Unregisters the given change listener. |
1074 |
* If the given listener has not been registered before, calling this |
1075 |
* method does not have any effect. |
1076 |
* |
1077 |
* @param l change listener to be removed |
1078 |
* @see #addChangeListener |
1079 |
*/ |
1080 |
private void removeChangeListener(ChangeListener l) { |
1081 |
if (changeListeners != null |
1082 |
&& changeListeners.remove(l) |
1083 |
&& changeListeners.isEmpty()) { |
1084 |
changeListeners = null; |
1085 |
} |
1086 |
} |
1087 |
|
1088 |
/** |
1089 |
* Notifies all registered change listeners about a change. |
1090 |
* |
1091 |
* @see #addChangeListener |
1092 |
*/ |
1093 |
private void fireStateChange() { |
1094 |
if (changeListeners != null) { |
1095 |
ChangeEvent e = new ChangeEvent(this); |
1096 |
for (Iterator i = changeListeners.iterator(); i.hasNext(); ) { |
1097 |
((ChangeListener) i.next()).stateChanged(e); |
1098 |
} |
1099 |
} |
1100 |
} |
1101 |
|
1102 |
/** |
1103 |
* Disables all interactive visual components of this dialog |
1104 |
* except the OK, Cancel and Help buttons. |
1105 |
*/ |
1106 |
private void disableComponents() { |
1107 |
final Stack<Container> stack = new Stack<Container>(); |
1108 |
stack.push(this); |
1109 |
|
1110 |
while (!stack.empty()) { |
1111 |
Container container = stack.pop(); |
1112 |
Component comps[] = container.getComponents(); |
1113 |
for (int i = 0; i < comps.length; i++) { |
1114 |
final java.awt.Component comp = comps[i]; |
1115 |
|
1116 |
if (comp == txtAreaMessage) { |
1117 |
continue; |
1118 |
} |
1119 |
if (comp instanceof JPanel) { |
1120 |
JPanel panel = (JPanel) comp; |
1121 |
stack.push(panel); |
1122 |
|
1123 |
final Border border = panel.getBorder(); |
1124 |
if (border != null) { |
1125 |
disableBorderTitles(border); |
1126 |
} |
1127 |
continue; |
1128 |
} |
1129 |
comp.setEnabled(false); |
1130 |
if (comp instanceof java.awt.Container) { |
1131 |
Container nestedCont = (Container) comp; |
1132 |
if (nestedCont.getComponentCount() != 0) { |
1133 |
stack.push(nestedCont); |
1134 |
} |
1135 |
} |
1136 |
} |
1137 |
} |
1138 |
} |
1139 |
|
1140 |
/** |
1141 |
*/ |
1142 |
private static void disableBorderTitles(Border border) { |
1143 |
|
1144 |
if (border instanceof TitledBorder) { |
1145 |
disableBorderTitle((TitledBorder) border); |
1146 |
return; |
1147 |
} |
1148 |
|
1149 |
if (!(border instanceof CompoundBorder)) { |
1150 |
return; |
1151 |
} |
1152 |
|
1153 |
Stack<CompoundBorder> stack = new Stack<CompoundBorder>(); |
1154 |
stack.push((CompoundBorder) border); |
1155 |
while (!stack.empty()) { |
1156 |
CompoundBorder cb = stack.pop(); |
1157 |
|
1158 |
Border b; |
1159 |
b = cb.getOutsideBorder(); |
1160 |
if (b instanceof CompoundBorder) { |
1161 |
stack.push((CompoundBorder) b); |
1162 |
} else if (b instanceof TitledBorder) { |
1163 |
disableBorderTitle((TitledBorder) b); |
1164 |
} |
1165 |
|
1166 |
b = cb.getInsideBorder(); |
1167 |
if (b instanceof CompoundBorder) { |
1168 |
stack.push((CompoundBorder) b); |
1169 |
} else if (b instanceof TitledBorder) { |
1170 |
disableBorderTitle((TitledBorder) b); |
1171 |
} |
1172 |
} |
1173 |
} |
1174 |
|
1175 |
/** |
1176 |
*/ |
1177 |
private static void disableBorderTitle(TitledBorder border) { |
1178 |
final Color color = UIManager.getColor( |
1179 |
"Label.disabledForeground"); //NOI18N |
1180 |
if (color != null) { |
1181 |
border.setTitleColor(color); |
1182 |
} |
1183 |
} |
1184 |
|
1185 |
private JLabel lblClassToTestValue; |
1186 |
private ClassNameTextField tfClassName; |
1187 |
private JTextComponent txtAreaMessage; |
1188 |
private JComboBox cboxLocation; |
1189 |
private JComboBox cboxFramework; |
1190 |
private JCheckBox chkAbstractImpl; |
1191 |
private JCheckBox chkComments; |
1192 |
private JCheckBox chkContent; |
1193 |
private JCheckBox chkExceptions; |
1194 |
private JCheckBox chkGenerateSuites; |
1195 |
private JCheckBox chkJavaDoc; |
1196 |
private JCheckBox chkPackage; |
1197 |
private JCheckBox chkPackagePrivateClasses; |
1198 |
private JCheckBox chkProtected; |
1199 |
private JCheckBox chkPublic; |
1200 |
private JCheckBox chkSetUp; |
1201 |
private JCheckBox chkTearDown; |
1202 |
|
1203 |
} |