001 package insertWizardCustom.ide;
002
003 import com.bea.control.Issue;
004 import com.bea.ide.Application;
005 import com.bea.ide.control.ControlWizard;
006 import com.bea.ide.core.MessageSvc;
007 import com.bea.ide.core.ResourceSvc;
008 import com.bea.ide.ui.browser.BrowserSvc;
009 import com.bea.ide.ui.output.OutputSvc;
010 import com.bea.ide.util.swing.DialogUtil;
011 import java.awt.Frame;
012 import java.awt.Insets;
013 import java.awt.KeyEventDispatcher;
014 import java.awt.KeyboardFocusManager;
015 import java.awt.event.FocusEvent;
016 import java.awt.event.FocusListener;
017 import java.awt.event.KeyEvent;
018 import java.awt.event.MouseEvent;
019 import java.awt.event.MouseListener;
020 import java.net.URL;
021 import javax.swing.JButton;
022 import javax.swing.JComponent;
023 import javax.swing.JDialog;
024 import javax.swing.JEditorPane;
025 import javax.swing.JFileChooser;
026 import javax.swing.JLabel;
027 import javax.swing.JPanel;
028 import javax.swing.JScrollPane;
029 import javax.swing.JTabbedPane;
030 import javax.swing.JTextArea;
031 import javax.swing.JTextField;
032 import javax.swing.event.DocumentEvent;
033 import javax.swing.event.DocumentListener;
034 import javax.swing.event.HyperlinkEvent;
035 import javax.swing.event.HyperlinkListener;
036
037 /**
038 * A dialog implementation for the IDE to display when the user chooses to
039 * add or insert a CustomWiz control.
040 */
041 public class CustomInsertDialog extends JDialog
042 {
043 protected String m_variableName = new String();
044 protected String m_jcxName = new String();
045 /**
046 * This variable is used in this dialog's logic to indicate
047 * whether a new JCX may be created. This value is retrieved
048 * by the CustomInsertWizard instance for this control for
049 * passing to the IDE through the wizard's implementation of the
050 * onFinish method.
051 */
052 protected boolean m_controlInsertRequested = false;
053 private boolean m_jcxNameIsGood = false;
054 private boolean m_variableNameIsGood = false;
055 private CustomInsertWizard m_wizard = null;
056 private Frame m_parent = null;
057
058 // Declare variables for the user interface components.
059 private JButton m_btnCancel;
060 private JButton m_btnCreate;
061 private JEditorPane m_editIntroduction;
062 private JLabel m_lblJcxOptions;
063 private JLabel m_lblNewJcx;
064 private JLabel m_lblVariableName;
065 private JPanel m_pnlCreateCancel;
066 private JPanel m_pnlMessages;
067 private JPanel m_pnlTab1;
068 private JPanel m_pnlTab2;
069 private JPanel m_pnlVariableJCXName;
070 private JScrollPane m_scrIntroduction;
071 private JScrollPane m_scrMessages;
072 private JTabbedPane m_tabTabbedPane;
073 private JTextField m_txtNewJcx;
074 private JTextField m_txtVariableName;
075 private JTextArea m_txtaMessages;
076 private DialogLinkListener m_linkListener;
077 private DialogFocusListener m_focusListener;
078 private DialogMouseListener m_mouseListener;
079 private DialogDocumentListener m_documentListener;
080
081 /**
082 * Constructs the dialog with a parent (the WebLogic Workshop
083 * window) and an instance of the wizard. The wizard instance will be
084 * used to retrieve information about the current context.
085 *
086 * @param parent A Frame representing the WebLogic Workshop main window.
087 * @param wizard The current wizard instance.
088 */
089 public CustomInsertDialog(Frame parent, CustomInsertWizard wizard)
090 {
091 super(parent, true);
092 // Variables for the control's wizard and for the WebLogic Workshop frame.
093 m_wizard = wizard;
094 m_parent = parent;
095 // Assemble the UI components.
096 initComponents();
097 // Set this dialog's size.
098 this.setSize(499, 561);
099 // This dialog cannot be resized.
100 this.setResizable(false);
101 // Set the title bar text.
102 this.setTitle("Insert Control - CustomWiz");
103 }
104
105 /**
106 * Displays this dialog.
107 */
108 public void show()
109 {
110 /**
111 * Add a key event dispatcher to listen for ENTER and ESC keystrokes.
112 */
113 DialogKeyEventDispatcher dked = new DialogKeyEventDispatcher();
114 KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(dked);
115 super.show();
116 KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(dked);
117 }
118
119 /**
120 * Assemble the user interface for this dialog. All of the work
121 * to assemble this dialog's user interface is done in this method.
122 */
123 private void initComponents()
124 {
125 java.awt.GridBagConstraints gridBagConstraints;
126
127 /*
128 * Initialize the user interface components.
129 */
130 m_tabTabbedPane = new JTabbedPane();
131 m_pnlTab1 = new JPanel();
132 m_scrIntroduction = new JScrollPane();
133 m_editIntroduction = new JEditorPane();
134 m_pnlTab2 = new JPanel();
135 m_pnlVariableJCXName = new JPanel();
136 m_lblVariableName = new JLabel();
137 m_txtVariableName = new JTextField();
138 m_lblJcxOptions = new JLabel();
139 m_lblNewJcx = new JLabel();
140 m_txtNewJcx = new JTextField();
141 m_pnlMessages = new JPanel();
142 m_scrMessages = new JScrollPane();
143 m_txtaMessages = new JTextArea();
144 m_pnlCreateCancel = new JPanel();
145 m_btnCreate = new JButton();
146 m_btnCancel = DialogUtil.getCancelButton();
147 m_linkListener = new DialogLinkListener();
148 m_focusListener = new DialogFocusListener();
149 m_mouseListener = new DialogMouseListener();
150 m_documentListener = new DialogDocumentListener();
151
152 /**
153 * Set the layout style for this dialog.
154 */
155 getContentPane().setLayout(new java.awt.GridBagLayout());
156
157 // Specify what should happen when the dialog closes.
158 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
159 addWindowListener(new java.awt.event.WindowAdapter()
160 {
161 public void windowClosing(java.awt.event.WindowEvent evt)
162 {
163 closeDialog(evt);
164 }
165 });
166
167 /*
168 * Assemble the panel that makes up the first tab of this dialog.
169 */
170 m_pnlTab1.setLayout(new java.awt.GridBagLayout());
171
172 /*
173 * m_editIntroduction is the JEditorPane that displays the HTML
174 * introduction to this sample. m_scrIntroduction is the JScrollPane
175 * that contains it and provides a vertical scroll bar.
176 */
177 m_editIntroduction.setContentType("text/html");
178 // Connect a listener to handle clicks to links in the introduction.
179 m_editIntroduction.addHyperlinkListener(m_linkListener);
180 m_editIntroduction.setEditable(false);
181 m_editIntroduction.setMargin(new Insets(0, 0, 0, 8));
182 m_editIntroduction.setSize(m_editIntroduction.getSize());
183 m_scrIntroduction.setViewportView(m_editIntroduction);
184 m_scrIntroduction.setAutoscrolls(true);
185
186 /*
187 * Use the application's classloader to find the HTML file
188 * to load in the introduction pane. Set that URL as the
189 * content of the pane.
190 */
191 ClassLoader loader = Thread.currentThread().getContextClassLoader();
192 URL introUrl = loader.getResource("insertWizardCustom/ide/html/introduction.html");
193 try
194 {
195 m_editIntroduction.setPage(introUrl);
196 }
197 catch (java.io.IOException ioe)
198 {
199 ioe.printStackTrace();
200 }
201
202 /*
203 * Swing provides several "layout styles" -- ways to structure the components
204 * of a user interface. For the most part, this dialog uses GridBagLayout
205 * as its style. In a gridbag layout, components are structured based on a grid
206 * and their position in the grid. This includes X and Y axes, number of
207 * grid points in width or height, "weight" relative to other components,
208 * where the component is anchored (top, right, left, etc), and so on.
209 *
210 * You use a GridBagConstraint instance to set these component properties,
211 * then add the component to its parent along with the constraint instance.
212 *
213 * Here, the constraint instance is used to set layout properties for
214 * m_scrIntroduction, the JScrollPane that contains the pane used to
215 * display introduction HTML.
216 */
217 gridBagConstraints = new java.awt.GridBagConstraints();
218 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
219 gridBagConstraints.weightx = 1.0;
220 gridBagConstraints.weighty = 1.0;
221 gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
222 // Add the scroll pane to the panel on the first tab.
223 m_pnlTab1.add(m_scrIntroduction, gridBagConstraints);
224
225 m_tabTabbedPane.setName("tabs");
226
227 /*
228 * Add the first tab panel as the UI component to the tabbed pane.
229 */
230 m_tabTabbedPane.addTab("Introduction", m_pnlTab1);
231
232 /*
233 * Assemble the panel that makes up the first tab of this dialog.
234 */
235 m_pnlTab2.setLayout(new java.awt.GridBagLayout());
236
237 /*
238 * Set layout of components in this panel to null. Its components will be
239 * arranged through explicit coordinates.
240 */
241 m_pnlVariableJCXName.setLayout(null);
242
243 /*
244 * Define the variable name label and box and add them to the panel.
245 */
246 m_lblVariableName.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
247 m_lblVariableName.setText("Variable name for this control:");
248 m_lblVariableName.setBounds(0, 20, 163, 16);
249 m_pnlVariableJCXName.add(m_lblVariableName);
250
251 m_txtVariableName.setHorizontalAlignment(javax.swing.JTextField.LEFT);
252 m_txtVariableName.setName("variable_name_box");
253 m_txtVariableName.setToolTipText("Enter the name for a variable of this control type.");
254 // Connect a listener that will handle receiving focus.
255 m_txtVariableName.addFocusListener(m_focusListener);
256 // Connect a listener that will handle changes to the box's contents.
257 m_txtVariableName.getDocument().addDocumentListener(m_documentListener);
258 m_txtVariableName.setBounds(160, 20, 295, 20);
259 m_pnlVariableJCXName.add(m_txtVariableName);
260
261 /**
262 * Define the JCX name label and box and add them to the panel.
263 */
264 m_lblNewJcx.setText("JCX name for this control:");
265 m_lblNewJcx.setBounds(0, 62, 163, 16);
266 m_pnlVariableJCXName.add(m_lblNewJcx);
267
268 m_txtNewJcx.setToolTipText("Enter the name of the JCX to create");
269 m_txtNewJcx.setName("new_jcx_name_box");
270 // Connect a listener that will handle receiving focus.
271 m_txtNewJcx.addFocusListener(m_focusListener);
272 // Connect a listener that will handle changes to the box's contents.
273 m_txtNewJcx.getDocument().addDocumentListener(m_documentListener);
274 m_txtNewJcx.setBounds(140, 62, 315, 20);
275 m_pnlVariableJCXName.add(m_txtNewJcx);
276
277 /**
278 * Define this panel's relationship to other components on
279 * the tab, then add the panel to the tab.
280 */
281 gridBagConstraints = new java.awt.GridBagConstraints();
282 gridBagConstraints.gridx = 0;
283 gridBagConstraints.gridy = 0;
284 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
285 gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12);
286 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
287 gridBagConstraints.weightx = 1.0;
288 gridBagConstraints.weighty = 1.0;
289 m_pnlTab2.add(m_pnlVariableJCXName, gridBagConstraints);
290
291 /**
292 * Define the message panel and text area, then add them to the
293 * tab.
294 */
295 m_pnlMessages.setLayout(new java.awt.GridBagLayout());
296 m_pnlMessages.setPreferredSize(m_pnlMessages.getPreferredSize());
297 m_txtaMessages.setLineWrap(true);
298 m_txtaMessages.setWrapStyleWord(true);
299 m_txtaMessages.setMargin(new Insets(6, 6, 6, 6));
300 m_txtaMessages.setSize(m_txtaMessages.getSize());
301 m_txtaMessages.setEditable(false);
302 m_scrMessages.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
303 m_scrMessages.setViewportView(m_txtaMessages);
304 gridBagConstraints = new java.awt.GridBagConstraints();
305 gridBagConstraints.gridx = 0;
306 gridBagConstraints.gridy = 1;
307 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
308 gridBagConstraints.weightx = 1.0;
309 gridBagConstraints.weighty = 1.0;
310 m_pnlMessages.add(m_scrMessages, gridBagConstraints);
311 gridBagConstraints = new java.awt.GridBagConstraints();
312 gridBagConstraints.gridx = 0;
313 gridBagConstraints.gridy = 1;
314 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
315 gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10);
316 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
317 gridBagConstraints.weightx = 1.0;
318 gridBagConstraints.weighty = 3.5;
319 m_pnlTab2.add(m_pnlMessages, gridBagConstraints);
320
321 // Add the tab to the group of tabs.
322 m_tabTabbedPane.addTab("Name the Control", m_pnlTab2);
323
324 /**
325 * Add the tabs to the dialog. getContentPane returns this
326 * dialog's content pane.
327 */
328 gridBagConstraints = new java.awt.GridBagConstraints();
329 gridBagConstraints.gridx = 0;
330 gridBagConstraints.gridy = 0;
331 gridBagConstraints.gridwidth = 2;
332 gridBagConstraints.gridheight = 1;
333 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
334 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
335 gridBagConstraints.insets = new java.awt.Insets(6, 6, 15, 6);
336 gridBagConstraints.weightx = 1.0;
337 gridBagConstraints.weighty = 1.0;
338 // Connect a listener that will handle mouse clicks.
339 m_tabTabbedPane.addMouseListener(m_mouseListener);
340 getContentPane().add(m_tabTabbedPane, gridBagConstraints);
341
342 /*
343 * Define the panel that holds the Create and Cancel buttons,
344 * then add it to the dialog.
345 */
346 m_pnlCreateCancel.setLayout(new java.awt.GridBagLayout());
347 m_btnCreate.setText("Create");
348 m_btnCreate.setName("create_button");
349 // Connect a listener that will handle mouse clicks.
350 m_btnCreate.addMouseListener(m_mouseListener);
351 // Because the first tab is visible by default, disable the Create button.
352 m_btnCreate.setEnabled(false);
353 gridBagConstraints = new java.awt.GridBagConstraints();
354 gridBagConstraints.gridx = 0;
355 gridBagConstraints.gridy = 2;
356 gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 100);
357 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
358 gridBagConstraints.weightx = 1.0;
359 gridBagConstraints.weighty = 1.0;
360 m_pnlCreateCancel.add(m_btnCreate, gridBagConstraints);
361 m_btnCancel.setText("Cancel");
362 m_btnCancel.setName("cancel_button");
363 // Connect a listener that will handle mouse clicks.
364 m_btnCancel.addMouseListener(m_mouseListener);
365 gridBagConstraints = new java.awt.GridBagConstraints();
366 gridBagConstraints.gridx = 0;
367 gridBagConstraints.gridy = 2;
368 gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12);
369 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
370 gridBagConstraints.weightx = 1.0;
371 gridBagConstraints.weighty = 1.0;
372 m_pnlCreateCancel.add(m_btnCancel, gridBagConstraints);
373 gridBagConstraints = new java.awt.GridBagConstraints();
374 gridBagConstraints.gridx = 0;
375 gridBagConstraints.gridy = 3;
376 gridBagConstraints.gridwidth = 2;
377 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
378 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
379 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
380 getContentPane().add(m_pnlCreateCancel, gridBagConstraints);
381
382 /*
383 * If the user tried to add a CustomWiz control by clicking File -> New
384 * (or by right-clicking in the Application pane), then don't show the second tab.
385 * The user does not want to add this control as an instance to a container (yet),
386 * and has already been prompted for a JCX name.
387 *
388 * If the user has clicked the Insert menu (or right-clicked Design View), the second
389 * tab will be displayed. In that scenario, the IDE will set configuration as
390 * a sum of CONFIG_CREATE_EXTENSION_FILE and CONFIG_INSERT_INSTANCE.
391 */
392 if (m_wizard.m_requestedConfig == CustomInsertWizard.CONFIG_CREATE_EXTENSION_FILE)
393 {
394 // Disable the tab at index 1 (the second tab).
395 m_tabTabbedPane.setEnabledAt(1, false);
396 // Hide the Create button because it's not relevant in this case.
397 m_btnCreate.setVisible(false);
398 // Select the Cancel button (which is relabeled below).
399 m_btnCancel.setSelected(true);
400 // Relabel the Cancel button to Done.
401 m_btnCancel.setLabel("Done");
402 }
403
404 // Sizes the window to preferred size.
405 pack();
406 }
407
408 /** Closes the dialog */
409 private void closeDialog(java.awt.event.WindowEvent evt)
410 {
411 setVisible(false);
412 }
413
414 /**
415 * Prints messages to the dialog's bottom pane as the user
416 * shifts focus to components in the user interface.
417 */
418 private void printActionMessage(String messageText)
419 {
420 m_txtaMessages.append(messageText + "\n");
421 }
422
423 /**
424 * Displays a dialog that contains messages resulting from
425 * validating JCX or variable names. This method is called if there
426 * are validation issues when the Create button is clicked.
427 *
428 * @param issues Issues that arose while validating dialog values.
429 * @param proposedName The name that was validated.
430 */
431 private void displayIssues(Issue[] issues, String proposedName)
432 {
433 StringBuffer issueMessages = new StringBuffer();
434 for (int i = 0; i < issues.length; i++)
435 {
436 issueMessages.append(issues[i].getDescription() + "\n");
437 if (issues[i].getPrescription() != null)
438 {
439 issueMessages.append(issues[i].getPrescription() + "\n");
440 }
441 }
442 DialogUtil.showErrorDialog(issueMessages.toString());
443 }
444
445 /**
446 * Enables the Create button if there are values in both the
447 * variable and JCX name boxes; otherwise, disables the Create
448 * button.
449 */
450 private void checkForEntries()
451 {
452 if (!m_txtNewJcx.getText().equals("") && !m_txtVariableName.getText().equals(""))
453 {
454 m_btnCreate.setEnabled(true);
455 }
456 else
457 {
458 m_btnCreate.setEnabled(false);
459 }
460 }
461
462 /**
463 * Evaluates the contents of the dialog's text boxes,
464 * validating those boxes' values.
465 *
466 * @param componentName The name of the UI component that
467 * received an action -- ie, the Create or Cancel button.
468 */
469 private void evaluateDialog(String componentName)
470 {
471 /**
472 * If the user presses return when focus is on the create button,
473 * variable name box, or either of the JCX name boxes, do the same
474 * thing: check that there are allowable variable names and
475 * JCX names, and handle errors accordingly.
476 */
477 if (componentName.equals("create_button"))
478 {
479
480 /*
481 * If the second tab is visible, validate the input in the
482 * variable and JCX name boxes.
483 */
484 if (m_pnlTab2.isVisible())
485 {
486 /*
487 * If there's text in the variable name box,
488 * assign that text value to a variable. If there's no text,
489 * prompt the user to enter some. Also, set a boolean
490 * variable to false so it can be checked along with the
491 * presence of a JCX name value later.
492 */
493 if (!m_txtVariableName.getText().equals(""))
494 {
495 m_variableName = m_txtVariableName.getText();
496 }
497 else if (m_txtVariableName.getText().equals(""))
498 {
499 m_variableNameIsGood = false;
500 DialogUtil.showErrorDialog("Please specify a variable name.");
501 }
502 /*
503 * If there's text in the JCX name box,
504 * assign that text value to a variable. If there's no text,
505 * prompt the user to enter some. Also, set a boolean
506 * variable to false so it can be checked along with the
507 * presence of a variable name value later.
508 */
509 if (!m_txtNewJcx.getText().equals(""))
510 {
511 m_jcxName = m_txtNewJcx.getText();
512 }
513 else if (m_txtNewJcx.getText().equals(""))
514 {
515 m_jcxNameIsGood = false;
516 DialogUtil.showErrorDialog("Please specify a JCX name.");
517 }
518 /*
519 * If both boxes have values, validate those values for use as
520 * Java code in WebLogic Workshop. If there are issues,
521 * report the issues to the user.
522 */
523 if (!m_jcxName.equals("") && !m_variableName.equals(""))
524 {
525 Issue[] jcxIssues = m_wizard.getNameValidator().validateExtensionName(m_jcxName);
526 Issue[] variableIssues = m_wizard.getNameValidator().validateInstanceName(m_variableName);
527 if (jcxIssues != null)
528 {
529 m_jcxNameIsGood = false;
530 displayIssues(jcxIssues, m_jcxName);
531 }
532 if (variableIssues != null)
533 {
534 m_variableNameIsGood = false;
535 displayIssues(variableIssues, m_variableName);
536 }
537 if (variableIssues == null)
538 {
539 m_variableNameIsGood = true;
540 }
541 if (jcxIssues == null)
542 {
543 m_jcxNameIsGood = true;
544 }
545 /*
546 * After validation, if both the variable and JCX name boxes have
547 * valid values, signal that it's okay to insert the control
548 * and close the dialog.
549 */
550 if (m_jcxNameIsGood && m_variableNameIsGood)
551 {
552 m_controlInsertRequested = true;
553 closeDialog(null);
554 }
555 }
556 }
557 }
558
559 /*
560 * The "Cancel" button needs to be handled as "OK" in one
561 * circumstance.
562 */
563 if (componentName.equals("cancel_button"))
564 {
565 /*
566 * If CONFIG_CREATE_EXTENSION_FILE is the requested configuration,
567 * it means that the users reached this dialog through File -> New -> Java Control
568 * (or a related command). They've already named the control, so we
569 * change the Cancel button to an OK button (see code in initComponents), set
570 * "requested" to true, and close the dialog.
571 */
572 if (m_wizard.m_requestedConfig == CustomInsertWizard.CONFIG_CREATE_EXTENSION_FILE)
573 {
574 m_controlInsertRequested = true;
575 closeDialog(null);
576 }
577 /*
578 * For other configurations, we presented a cancel button and
579 * set "requested" to false when it is clicked.
580 */
581 else
582 {
583 m_controlInsertRequested = false;
584 closeDialog(null);
585 }
586 }
587 }
588
589
590 /**
591 * A m_focusListener implementation simply to present messages about
592 * how different pieces of the dialog user interface contribute to the
593 * control's insertion.
594 *
595 * Note that it can be it can be difficult to debug a focus listener with
596 * WebLogic Workshop's debugger. This is because a breakpoint set in the
597 * listener will immediately be hit again when you attempt to switch back
598 * to the instance launched when you started debugging. Instead of using
599 * the debugger, you can print messages to the Output pane using the
600 * message service, in this way:
601 *
602 * MessageSvc.get().debugLog("My debugging message.");
603 *
604 * This is an alternative to using System.out, which is unavailable when
605 * a console window is not displayed.
606 */
607 private class DialogFocusListener implements FocusListener
608 {
609 /**
610 * Received when a component that has added this listener receives
611 * focus. This event handler is used to print messages to the
612 * dialog's message window as the variable and JCX name boxes
613 * receive focus.
614 *
615 * @param event The details of the event.
616 */
617 public void focusGained(FocusEvent event)
618 {
619 String componentName = ((JComponent)event.getSource()).getName();
620
621 /*
622 * If the component that received focus is a text field, then it
623 * must be the variable or JCX name box. Print a descriptive
624 * message.
625 */
626 if (event.getSource() instanceof JTextField)
627 {
628 if (componentName.equals("variable_name_box"))
629 {
630 String message = "Control variable name: \n" +
631 "The name entered here is stored in a dialog " +
632 "variable. When the Create button is clicked, the value is " +
633 "checked and validated within this dialog. If the " +
634 "value is valid, the control wizard retrieves the value from " +
635 "from this dialog and holds it for retrieval by the IDE through " +
636 "the wizard's getInstanceName method.\n";
637 printActionMessage(message);
638 }
639 if (componentName.equals("new_jcx_name_box"))
640 {
641 String message = "New JCX name: \n" +
642 "The name entered here is stored in a dialog " +
643 "variable. When the Create button is clicked, the value is " +
644 "checked and validated within this dialog. If the " +
645 "value is valid, the control wizard retrieves the value from " +
646 "from this dialog and holds it for retrieval by the IDE through " +
647 "the wizard's getExtensionName method.\n";
648 printActionMessage(message);
649 }
650 }
651 }
652
653 /**
654 * Not implemented. This dialog doesn't do anything special when focus
655 * leaves a component.
656 */
657 public void focusLost(FocusEvent arg0){}
658 }
659
660 /**
661 * Handles hyperlinks events within the JEditorPane component
662 * in the "Introduction" pane of the dialog. This
663 * code launches a browser to display the HTML page at the other
664 * end of the clicked link.
665 */
666 private class DialogLinkListener implements HyperlinkListener
667 {
668 /**
669 * Handles a hyperlink click.
670 *
671 * @param event The details of the event.
672 */
673 public void hyperlinkUpdate(HyperlinkEvent event)
674 {
675 if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
676 {
677 // Use the browser service to display the page.
678 BrowserSvc.get().invokeBrowser(event.getURL(), true);
679 }
680 }
681 }
682
683 /**
684 * An event listener to listen for mouse actions in this dialog.
685 * In particular, if the event is a mouse click on one of the dialog's
686 * tabs, this listener enables or disables the "Create" button. If
687 * the mouse click is on the first tab ("Introduction"), the button is disabled. It would
688 * be counterintuitive to allow the user to click Create from the first tab, which
689 * does not prompt for information needed to create the control.
690 */
691 private class DialogMouseListener implements MouseListener
692 {
693 /**
694 * Handles a mouse click event.
695 *
696 * @param event The click event.
697 */
698 public void mouseClicked(MouseEvent event)
699 {
700 /**
701 * If a tab was clicked, enable or disable the Create button to
702 * based on which tab was clicked and whether there are values
703 * in the variable and JCX name boxes.
704 */
705 if (event.getSource() instanceof JTabbedPane)
706 {
707 /*
708 * If the first tab was clicked, disable the Create button.
709 */
710 if (((JTabbedPane)event.getSource()).getSelectedIndex() == 0)
711 {
712 m_btnCreate.setEnabled(false);
713 }
714 /*
715 * If the second tab was clicked, call a function that finds out
716 * if there's text in the variable and JCX name boxes, and
717 * enables or disables the Create button accordingly.
718 */
719 else if (((JTabbedPane)event.getSource()).getSelectedIndex() == 1)
720 {
721 checkForEntries();
722 }
723 }
724 /*
725 * If a the Create or Cancel button was clicked, handle it with the
726 * evaluateDialog function.
727 */
728 else if (event.getSource() instanceof JButton)
729 {
730 String componentName = ((JComponent)event.getSource()).getName();
731 evaluateDialog(componentName);
732 }
733 }
734
735 // These methods aren't needed in this dialog.
736 public void mouseEntered(MouseEvent event){}
737 public void mouseExited(MouseEvent event){}
738 public void mousePressed(MouseEvent event){}
739 public void mouseReleased(MouseEvent event){}
740 }
741
742 /**
743 * A listener to handle ENTER and ESC keystrokes. A key event dispatcher
744 * handles keystrokes before they can be consumed by other components in the
745 * user interface.
746 */
747 private class DialogKeyEventDispatcher implements KeyEventDispatcher
748 {
749 /**
750 * Receives key strokes sent to the dialog, handling only the ENTER
751 * and ESC keys.
752 *
753 * @param event The details of the event.
754 */
755 public boolean dispatchKeyEvent(KeyEvent event)
756 {
757 /*
758 * Handle an ENTER keystroke.
759 */
760 if (event.getKeyCode() == KeyEvent.VK_ENTER)
761 {
762 /*
763 * If the Create button is enabled, then the second tab must be
764 * visible and there are values in the variable and JCX name
765 * boxes. Do the same name value checking that would be done if the
766 * Create button had been clicked.
767 */
768 if (m_btnCreate.isEnabled())
769 {
770 String componentName = ((JComponent)event.getSource()).getName();
771 evaluateDialog("create_button");
772 }
773 /*
774 * If the current configuration specifies creating a new JCX file, then
775 * the user reached this dialog through File -> New -> Java Control. Just
776 * signal that the control may be added, and close the dialog.
777 */
778 if (m_wizard.m_requestedConfig == ControlWizard.CONFIG_CREATE_EXTENSION_FILE)
779 {
780 m_controlInsertRequested = true;
781 closeDialog(null);
782 }
783 }
784 /*
785 * Handle an ESC keystroke. Signal that the control may not be inserted
786 * and close the dialog.
787 */
788 if (event.getKeyCode() == KeyEvent.VK_ESCAPE)
789 {
790 m_controlInsertRequested = false;
791 closeDialog(null);
792 }
793 return false;
794 }
795 }
796
797 /**
798 * A listener to handle keystrokes in the variable and JCX name
799 * text boxes. All three methods of this class simply call a function
800 * that enables or disables the Create button depending on whether
801 * there's text in the boxes.
802 */
803 private class DialogDocumentListener implements DocumentListener
804 {
805 public void changedUpdate(DocumentEvent event)
806 {
807 checkForEntries();
808 }
809 public void insertUpdate(DocumentEvent event)
810 {
811 checkForEntries();
812 }
813 public void removeUpdate(DocumentEvent event)
814 {
815 checkForEntries();
816 }
817 }
818 }
|