001 package jcxCreate.ide;
002
003 import java.text.MessageFormat;
004 import com.bea.ide.control.ControlWizardSimple;
005 import javax.swing.JComponent;
006
007 /*
008 * Represents an insert dialog for the XQuery control. While
009 * this dialog doesn't provide any special user interface, it
010 * does provide the text that the IDE should insert into
011 * newly created JCX files.
012 */
013 public class XQueryWizard extends ControlWizardSimple
014 {
015 private boolean m_createExtension = false;
016
017 String m_jcxPackage = null;
018 String m_jcxName = null;
019
020 /*
021 * Tell the IDE how to configure the insert dialog. This dialog
022 * should provide an option to use an existing JCX file, or to
023 * create a new one.
024 */
025 public int getConfigurationInfo()
026 {
027 return CONFIG_CREATE_EXTENSION_FILE |
028 CONFIG_INSERT_INSTANCE;
029 }
030
031 /*
032 * Provide a place for the IDE to tell this code whether the
033 * user has asked to create a new JCX or not.
034 */
035 public void setConfiguration(int config)
036 {
037 m_createExtension =
038 ((config & ControlWizardSimple.CONFIG_CREATE_EXTENSION_FILE) != 0);
039 }
040
041 /*
042 * Tell the IDE what to use for custom insert dialog user interface.
043 * None is needed here.
044 */
045 public JComponent getComponent()
046 {
047 return null;
048 }
049
050 /*
051 * Provide a place for code that should execute when the user clicks the
052 * Create button on the insert dialog.
053 */
054 public boolean onFinish()
055 {
056 if (super.onFinish() == false){
057 return false;
058 } else {
059 return true;
060 }
061 }
062
063 /*
064 * Provides a way for the IDE to pass in the package name
065 * that should be specified at the top of a new JCX file.
066 */
067 public void setPackage(String packageName)
068 {
069 m_jcxPackage = packageName;
070 }
071
072 /*
073 * Provides a way for the IDE to pass in the name of the
074 * interface defined in a new JCX file.
075 */
076 public void setName(String name)
077 {
078 m_jcxName = name;
079 }
080
081 /*
082 * Provides a place for the IDE to retrieve the content that it
083 * should insert into newly created JCX files. Here, the package name
084 * and interface name passed in by the IDE are inserted into a
085 * template using the MessageFormat class.
086 */
087 public String getExtensionFileContent(){
088 // did they ask for an extension?
089 String jcxTemplate = this.getTemplate();
090
091 String jcxContent =
092 MessageFormat.format(jcxTemplate, new Object[] {m_jcxPackage, m_jcxName});
093
094 return jcxContent;
095 }
096
097 /*
098 * Returns a template for text to be inserted into a new JCX file.
099 */
100 private String getTemplate(){
101 String template =
102 "package {0}; \n\n " +
103 "import com.bea.control.*; \n " +
104 "import com.bea.xml.XmlCursor; \n " +
105 "import jcxCreate.XQuery; \n\n " +
106
107 "public interface {1} extends XQuery, com.bea.control.ControlExtension \n " +
108 "'{' \n \n" +
109
110 " /* \n" +
111 " * A version number for this JCX. This will be incremented in new versions of \n" +
112 " * this control to ensure that conversations for instances of earlier \n" +
113 " * versions were invalid. \n" +
114 " */ \n" +
115 " static final long serialVersionUID = 1L; \n \n" +
116
117 " /* Replace the following method with your own. Be sure \n" +
118 " * that your method returns an XmlCursor and that its \n" +
119 " * parameter is a File object to contain the XML against \n" +
120 " * which to execute the XQuery expression. \n" +
121 " */ \n \n" +
122
123 " /** \n" +
124 " * @jc:query expression=\"$this/purchase-order/line-item[price <= 20.00]\" \n" +
125 " */ \n" +
126 " XmlCursor selectLineItem(String filePath); \n \n" +
127
128 "'}' \n ";
129 return template;
130 }
131
132 }
|