KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > AddModuleDialog


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc;
6
7 import org.dijon.ContainerResource;
8 import org.dijon.TextField;
9
10 import com.tc.admin.common.XContainer;
11
12 import java.awt.event.HierarchyEvent JavaDoc;
13 import java.awt.event.HierarchyListener JavaDoc;
14
15 import javax.swing.JOptionPane JavaDoc;
16
17 public class AddModuleDialog extends XContainer {
18
19   private static SessionIntegratorContext CONTEXT = SessionIntegrator.getContext();
20   private TextField m_nameField;
21   private TextField m_versionField;
22
23   public AddModuleDialog() {
24     super();
25     load(CONTEXT.topRes.findComponent("ModulesDialog"));
26   }
27
28   public void load(ContainerResource containerRes) {
29     super.load(containerRes);
30     m_nameField = (TextField) findComponent("ModuleNameField");
31     m_versionField = (TextField) findComponent("ModuleVersionField");
32
33     addHierarchyListener(new HierarchyListener JavaDoc() {
34       private volatile boolean working;
35
36       public void hierarchyChanged(HierarchyEvent JavaDoc he) {
37         if (working) return;
38         working = true;
39         new Thread JavaDoc() {
40           public void run() {
41             try {
42               Thread.sleep(400);
43               m_nameField.requestFocusInWindow();
44               working = false;
45             } catch (Exception JavaDoc e) {
46               // ignore
47
}
48           }
49         }.start();
50       }
51     });
52   }
53
54   public String JavaDoc[] prompt() {
55     reset();
56     int option = JOptionPane.showOptionDialog(this, this, "Enter Module Information", JOptionPane.OK_CANCEL_OPTION,
57                                               JOptionPane.QUESTION_MESSAGE, null, null, null);
58
59     if (option == JOptionPane.OK_OPTION) {
60       String JavaDoc[] values = new String JavaDoc[2];
61       values[0] = m_nameField.getText().trim();
62       values[1] = m_versionField.getText().trim();
63       if (!values[0].equals("") || !values[0].equals("")) return values;
64     }
65     return null;
66   }
67
68   private void reset() {
69     m_nameField.setText("");
70     m_versionField.setText("");
71   }
72 }
73
Popular Tags