KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > dialogs > OnLoadDialog


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

4 package org.terracotta.dso.dialogs;
5
6 import org.dijon.Button;
7 import org.dijon.ButtonGroup;
8 import org.dijon.Dialog;
9 import org.dijon.DialogResource;
10 import org.dijon.Label;
11 import org.dijon.PagedView;
12
13 import org.terracotta.dso.TcPlugin;
14 import com.tc.admin.common.XTextField;
15 import com.tc.admin.common.XTextPane;
16 import com.terracottatech.config.Include;
17 import com.terracottatech.config.OnLoad;
18
19 import java.awt.Frame JavaDoc;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22
23 /*
24  * TODO: Merge this with the one in the Configurator.
25  */

26
27 public class OnLoadDialog extends Dialog {
28   private static DialogResource m_dialogRes;
29
30   private Include m_include;
31   private Label m_classExprLabel;
32   private ButtonGroup m_selectorGroup;
33   private PagedView m_pagedView;
34   private XTextField m_methodNameField;
35   private XTextPane m_codePane;
36   
37   private static final String JavaDoc NOOP_VIEW = "NoOp";
38   private static final String JavaDoc CALL_VIEW = "Call";
39   private static final String JavaDoc EXECUTE_VIEW = "Execute";
40   
41   static {
42     m_dialogRes = TcPlugin.getDefault().getResources().findDialog("OnLoadDialog");
43   }
44
45   public OnLoadDialog(Frame JavaDoc frame) {
46     super(frame);
47     load(m_dialogRes);
48     setModal(true);
49   }
50
51   public void load(DialogResource dialogRes) {
52     super.load(dialogRes);
53
54     m_classExprLabel = (Label)findComponent("ClassExpressionLabel");
55     
56     m_selectorGroup = (ButtonGroup)findComponent("Selector");
57     m_selectorGroup.addActionListener(new ActionListener JavaDoc() {
58       public void actionPerformed(ActionEvent JavaDoc ae) {
59         m_pagedView.setPage(m_selectorGroup.getSelected());
60         m_pagedView.revalidate();
61         m_pagedView.repaint();
62       }
63     });
64     
65     m_pagedView = (PagedView)findComponent("Views");
66     m_methodNameField = (XTextField)findComponent("MethodNameField");
67     m_codePane = (XTextPane)findComponent("CodePane");
68
69     Button closeButton = (Button)findComponent("CloseButton");
70     closeButton.addActionListener(new ActionListener JavaDoc() {
71       public void actionPerformed(ActionEvent JavaDoc ae) {
72         String JavaDoc selected = m_selectorGroup.getSelected();
73         
74         if(selected.equals(NOOP_VIEW)) {
75           ensureOnLoadUnset();
76         }
77         else {
78           OnLoad onLoad = ensureOnLoad();
79           
80           if(selected.equals(CALL_VIEW)) {
81             String JavaDoc methodName = m_methodNameField.getText().trim();
82             
83             if(methodName == null || methodName.length() == 0) {
84               ensureOnLoadUnset();
85             }
86             else {
87               if(onLoad.isSetExecute()) {
88                 onLoad.unsetExecute();
89               }
90               onLoad.setMethod(methodName);
91             }
92           }
93           else {
94             String JavaDoc code = m_codePane.getText().trim();
95             
96             if(code == null || code.length() == 0) {
97               ensureOnLoadUnset();
98             }
99             else {
100               if(onLoad.isSetMethod()) {
101                 onLoad.unsetMethod();
102               }
103               onLoad.setExecute(code);
104             }
105           }
106         }
107         
108         setVisible(false);
109       }
110     });
111     
112     Button cancelButton = (Button)findComponent("CancelButton");
113     cancelButton.addActionListener(new ActionListener JavaDoc() {
114       public void actionPerformed(ActionEvent JavaDoc ae) {
115         setVisible(false);
116       }
117     });
118   }
119   
120   private OnLoad ensureOnLoad() {
121     OnLoad onLoad = m_include.getOnLoad();
122     return onLoad != null ? onLoad : m_include.addNewOnLoad();
123   }
124   
125   private void ensureOnLoadUnset() {
126     if(m_include.isSetOnLoad()) {
127       m_include.unsetOnLoad();
128     }
129   }
130   
131   public void setInclude(Include include) {
132     m_include = include;
133     m_classExprLabel.setText(include.getClassExpression());
134     
135     OnLoad onLoad = include.getOnLoad();
136     String JavaDoc view = NOOP_VIEW;
137     
138     m_codePane.setText(null);
139     m_methodNameField.setText(null);
140     
141     if(onLoad != null) {
142       if(onLoad.isSetExecute()) {
143         view = EXECUTE_VIEW;
144         m_codePane.setText(onLoad.getExecute());
145       }
146       else if(onLoad.isSetMethod()) {
147         view = CALL_VIEW;
148         m_methodNameField.setText(onLoad.getMethod());
149       }
150     }
151     
152     m_pagedView.setPage(view);
153     m_selectorGroup.setSelected(view);
154   }
155   
156   public Include getInclude() {
157     return m_include;
158   }
159   
160   public void edit(Include include) {
161     setInclude(include);
162     center((java.awt.Component JavaDoc)getOwner());
163     setVisible(true);
164   }
165 }
166
Popular Tags