001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc;
005:
006: import org.dijon.Button;
007: import org.dijon.ButtonGroup;
008: import org.dijon.Dialog;
009: import org.dijon.DialogResource;
010: import org.dijon.Label;
011: import org.dijon.PagedView;
012:
013: import com.tc.admin.common.XTextField;
014: import com.tc.admin.common.XTextPane;
015: import com.terracottatech.config.Include;
016: import com.terracottatech.config.OnLoad;
017:
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020:
021: /*
022: * TODO: Merge this with the one in the Eclipse plugin.
023: */
024:
025: public class OnLoadDialog extends Dialog {
026: private Include m_include;
027: private Label m_classExprLabel;
028: private ButtonGroup m_selectorGroup;
029: private PagedView m_pagedView;
030: private XTextField m_methodNameField;
031: private XTextPane m_codePane;
032:
033: private static final String NOOP_VIEW = "NoOp";
034: private static final String CALL_VIEW = "Call";
035: private static final String EXECUTE_VIEW = "Execute";
036:
037: private static SessionIntegratorContext CONTEXT = SessionIntegrator
038: .getContext();
039:
040: public OnLoadDialog() {
041: super (CONTEXT.frame);
042: load(CONTEXT.topRes.findDialog("OnLoadDialog"));
043: }
044:
045: public void load(DialogResource dialogRes) {
046: super .load(dialogRes);
047:
048: m_classExprLabel = (Label) findComponent("ClassExpressionLabel");
049:
050: m_selectorGroup = (ButtonGroup) findComponent("Selector");
051: m_selectorGroup.addActionListener(new ActionListener() {
052: public void actionPerformed(ActionEvent ae) {
053: m_pagedView.setPage(m_selectorGroup.getSelected());
054: m_pagedView.revalidate();
055: m_pagedView.repaint();
056: }
057: });
058:
059: m_pagedView = (PagedView) findComponent("Views");
060: m_methodNameField = (XTextField) findComponent("MethodNameField");
061: m_codePane = (XTextPane) findComponent("CodePane");
062:
063: Button closeButton = (Button) findComponent("CloseButton");
064: closeButton.addActionListener(new ActionListener() {
065: public void actionPerformed(ActionEvent ae) {
066: String selected = m_selectorGroup.getSelected();
067:
068: if (selected.equals(NOOP_VIEW)) {
069: ensureOnLoadUnset();
070: } else {
071: OnLoad onLoad = ensureOnLoad();
072:
073: if (selected.equals(CALL_VIEW)) {
074: String methodName = m_methodNameField.getText()
075: .trim();
076:
077: if (methodName == null
078: || methodName.length() == 0) {
079: ensureOnLoadUnset();
080: } else {
081: if (onLoad.isSetExecute()) {
082: onLoad.unsetExecute();
083: }
084: onLoad.setMethod(methodName);
085: }
086: } else {
087: String code = m_codePane.getText().trim();
088:
089: if (code == null || code.length() == 0) {
090: ensureOnLoadUnset();
091: } else {
092: if (onLoad.isSetMethod()) {
093: onLoad.unsetMethod();
094: }
095: onLoad.setExecute(code);
096: }
097: }
098: }
099:
100: setVisible(false);
101: CONTEXT.frame.modelChanged();
102: }
103: });
104:
105: Button cancelButton = (Button) findComponent("CancelButton");
106: cancelButton.addActionListener(new ActionListener() {
107: public void actionPerformed(ActionEvent ae) {
108: setVisible(false);
109: }
110: });
111: }
112:
113: private OnLoad ensureOnLoad() {
114: OnLoad onLoad = m_include.getOnLoad();
115: return onLoad != null ? onLoad : m_include.addNewOnLoad();
116: }
117:
118: private void ensureOnLoadUnset() {
119: if (m_include.isSetOnLoad()) {
120: m_include.unsetOnLoad();
121: }
122: }
123:
124: public void setInclude(Include include) {
125: m_include = include;
126: m_classExprLabel.setText(include.getClassExpression());
127:
128: OnLoad onLoad = include.getOnLoad();
129: String view = NOOP_VIEW;
130:
131: m_codePane.setText(null);
132: m_methodNameField.setText(null);
133:
134: if (onLoad != null) {
135: if (onLoad.isSetExecute()) {
136: view = EXECUTE_VIEW;
137: m_codePane.setText(onLoad.getExecute());
138: } else if (onLoad.isSetMethod()) {
139: view = CALL_VIEW;
140: m_methodNameField.setText(onLoad.getMethod());
141: }
142: }
143:
144: m_pagedView.setPage(view);
145: m_selectorGroup.setSelected(view);
146: }
147:
148: public Include getInclude() {
149: return m_include;
150: }
151:
152: public void edit(Include include) {
153: setInclude(include);
154: center(getOwner());
155: setVisible(true);
156: }
157: }
|