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