001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)SelectDatasetForChart.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package charting.configure;
030:
031: import org.openesb.tools.charting.persist.ChartApplicationBeansContainer;
032: import org.openesb.tools.charting.persist.DataBean;
033: import org.openesb.tools.extchart.jfchart.Chart;
034: import org.openesb.tools.extchart.jfchart.data.DataAccess;
035: import org.openesb.tools.extchart.property.JFChartConstants;
036: import com.sun.rave.web.ui.appbase.AbstractPageBean;
037: import com.sun.web.ui.component.Body;
038: import com.sun.web.ui.component.Button;
039: import com.sun.web.ui.component.DropDown;
040: import com.sun.web.ui.component.Form;
041: import com.sun.web.ui.component.Head;
042: import com.sun.web.ui.component.Html;
043: import com.sun.web.ui.component.Label;
044: import com.sun.web.ui.component.Link;
045: import com.sun.web.ui.component.Page;
046: import com.sun.web.ui.model.Option;
047: import com.sun.web.ui.model.SingleSelectOptionsList;
048: import java.util.ArrayList;
049: import java.util.Iterator;
050: import java.util.Map;
051: import java.util.logging.Logger;
052: import javax.faces.FacesException;
053: import javax.faces.event.ValueChangeEvent;
054:
055: /**
056: * <p>Page bean that corresponds to a similarly named JSP page. This
057: * class contains component definitions (and initialization code) for
058: * all components that you have defined on this page, as well as
059: * lifecycle methods and event handlers where you may add behavior
060: * to respond to incoming events.</p>
061: */
062: public class SelectDatasetForChart extends AbstractPageBean {
063: // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
064: private int __placeholder;
065:
066: /**
067: * <p>Automatically managed component initialization. <strong>WARNING:</strong>
068: * This method is automatically generated, so any user-specified code inserted
069: * here is subject to being replaced.</p>
070: */
071: private void _init() throws Exception {
072: }
073:
074: private Page page1 = new Page();
075:
076: public Page getPage1() {
077: return page1;
078: }
079:
080: public void setPage1(Page p) {
081: this .page1 = p;
082: }
083:
084: private Html html1 = new Html();
085:
086: public Html getHtml1() {
087: return html1;
088: }
089:
090: public void setHtml1(Html h) {
091: this .html1 = h;
092: }
093:
094: private Head head1 = new Head();
095:
096: public Head getHead1() {
097: return head1;
098: }
099:
100: public void setHead1(Head h) {
101: this .head1 = h;
102: }
103:
104: private Link link1 = new Link();
105:
106: public Link getLink1() {
107: return link1;
108: }
109:
110: public void setLink1(Link l) {
111: this .link1 = l;
112: }
113:
114: private Body body1 = new Body();
115:
116: public Body getBody1() {
117: return body1;
118: }
119:
120: public void setBody1(Body b) {
121: this .body1 = b;
122: }
123:
124: private Form form1 = new Form();
125:
126: public Form getForm1() {
127: return form1;
128: }
129:
130: public void setForm1(Form f) {
131: this .form1 = f;
132: }
133:
134: private Label label1 = new Label();
135:
136: public Label getLabel1() {
137: return label1;
138: }
139:
140: public void setLabel1(Label l) {
141: this .label1 = l;
142: }
143:
144: private Label label2 = new Label();
145:
146: public Label getLabel2() {
147: return label2;
148: }
149:
150: public void setLabel2(Label l) {
151: this .label2 = l;
152: }
153:
154: private DropDown dropDown1 = new DropDown();
155:
156: public DropDown getDropDown1() {
157: return dropDown1;
158: }
159:
160: public void setDropDown1(DropDown dd) {
161: this .dropDown1 = dd;
162: }
163:
164: private SingleSelectOptionsList dropDown1DefaultOptions = new SingleSelectOptionsList();
165:
166: public SingleSelectOptionsList getDropDown1DefaultOptions() {
167: return dropDown1DefaultOptions;
168: }
169:
170: public void setDropDown1DefaultOptions(SingleSelectOptionsList ssol) {
171: this .dropDown1DefaultOptions = ssol;
172: }
173:
174: private DropDown dropDown2 = new DropDown();
175:
176: public DropDown getDropDown2() {
177: return dropDown2;
178: }
179:
180: public void setDropDown2(DropDown dd) {
181: this .dropDown2 = dd;
182: }
183:
184: private SingleSelectOptionsList dropDown2DefaultOptions = new SingleSelectOptionsList();
185:
186: public SingleSelectOptionsList getDropDown2DefaultOptions() {
187: return dropDown2DefaultOptions;
188: }
189:
190: public void setDropDown2DefaultOptions(SingleSelectOptionsList ssol) {
191: this .dropDown2DefaultOptions = ssol;
192: }
193:
194: private Button button1 = new Button();
195:
196: public Button getButton1() {
197: return button1;
198: }
199:
200: public void setButton1(Button b) {
201: this .button1 = b;
202: }
203:
204: // </editor-fold>
205:
206: /**
207: * <p>Construct a new Page bean instance.</p>
208: */
209: public SelectDatasetForChart() {
210: }
211:
212: /**
213: * <p>Callback method that is called whenever a page is navigated to,
214: * either directly via a URL, or indirectly via page navigation.
215: * Customize this method to acquire resources that will be needed
216: * for event handlers and lifecycle methods, whether or not this
217: * page is performing post back processing.</p>
218: *
219: * <p>Note that, if the current request is a postback, the property
220: * values of the components do <strong>not</strong> represent any
221: * values submitted with this request. Instead, they represent the
222: * property values that were saved for this view when it was rendered.</p>
223: */
224: public void init() {
225: // Perform initializations inherited from our superclass
226: super .init();
227: // Perform application initialization that must complete
228: // *before* managed components are initialized
229: // TODO - add your own initialiation code here
230:
231: // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
232: // Initialize automatically managed components
233: // *Note* - this logic should NOT be modified
234: try {
235: _init();
236: } catch (Exception e) {
237: log("SelectDatasetForChart Initialization Failure", e);
238: throw e instanceof FacesException ? (FacesException) e
239: : new FacesException(e);
240: }
241:
242: // </editor-fold>
243: // Perform application initialization that must complete
244: // *after* managed components are initialized
245: // TODO - add your own initialization code here
246: }
247:
248: /**
249: * <p>Callback method that is called after the component tree has been
250: * restored, but before any event processing takes place. This method
251: * will <strong>only</strong> be called on a postback request that
252: * is processing a form submit. Customize this method to allocate
253: * resources that will be required in your event handlers.</p>
254: */
255: public void preprocess() {
256: }
257:
258: /**
259: * <p>Callback method that is called just before rendering takes place.
260: * This method will <strong>only</strong> be called for the page that
261: * will actually be rendered (and not, for example, on a page that
262: * handled a postback and then navigated to a different page). Customize
263: * this method to allocate resources that will be required for rendering
264: * this page.</p>
265: */
266: public void prerender() {
267: }
268:
269: /**
270: * <p>Callback method that is called after rendering is completed for
271: * this request, if <code>init()</code> was called (regardless of whether
272: * or not this was the page that was actually rendered). Customize this
273: * method to release resources acquired in the <code>init()</code>,
274: * <code>preprocess()</code>, or <code>prerender()</code> methods (or
275: * acquired during execution of an event handler).</p>
276: */
277: public void destroy() {
278: }
279:
280: private static Logger mLogger = Logger
281: .getLogger("/configure/SelectDatasetForChart.jsp");
282:
283: private SingleSelectOptionsList l = new SingleSelectOptionsList();
284:
285: public SingleSelectOptionsList getOptions() {
286:
287: //ArrayList al = new ArrayList();
288: //if(l== null) {
289: // l = new SingleSelectOptionsList();
290: Map m = getChartApplicationBeansContainer().getAllDataBeans();
291: Option[] options = new Option[m.size()];
292: Iterator iter = m.values().iterator();
293: int ind = 0;
294: String selVal = null;
295: while (iter.hasNext()) {
296: DataBean bean = (DataBean) iter.next();
297: String val = bean.getDisplayName();
298: String key = bean.getID();
299: Option opt1 = new Option();
300: opt1.setLabel(val);
301: opt1.setValue(key);
302: selVal = key;
303: options[ind++] = opt1;
304: }
305:
306: l.setOptions(options);
307: //l.setSelectedValue(selVal);
308:
309: return l;
310: }
311:
312: SingleSelectOptionsList ll = new SingleSelectOptionsList();
313:
314: public SingleSelectOptionsList getChartOptions() {
315: ArrayList al = new ArrayList();
316: String dbID = (String) this .getDropDown1().getSelected();
317: mLogger.info("The id is " + dbID);
318: DataBean dbBean = getChartApplicationBeansContainer()
319: .getDataBeanByID(dbID);
320: String dsType = null;
321: if (dbBean == null) {
322: dsType = JFChartConstants.CATEGORY_DATASET;
323: } else {
324: dsType = dbBean.getDataSetType();
325: }
326: Map m = Chart.getAllowedChartsForDatasetType(dsType);
327: Option[] options = new Option[m.size()];
328: Iterator iter = m.keySet().iterator();
329: int ind = 0;
330: while (iter.hasNext()) {
331: String key = (String) iter.next();
332: String val = (String) m.get(key);
333: Option opt1 = new Option();
334: opt1.setLabel(val);
335: opt1.setValue(key);
336: options[ind++] = opt1;
337: }
338:
339: ll.setOptions(options);
340:
341: return ll;
342:
343: }
344:
345: private ChartApplicationBeansContainer getChartApplicationBeansContainer() {
346: return (ChartApplicationBeansContainer) getBean("ChartApplicationBeansContainer");
347:
348: }
349:
350: public String button1_action() {
351: // TODO: Process the button click action. Return value is a navigation
352: // case name where null will return to the same page.
353: String dbID = (String) this .getDropDown1().getSelected();
354: String cType = (String) this .getDropDown2().getSelected();
355: //String q = (String)this.getTextArea1().getText();
356: DataBean dbBean = getChartApplicationBeansContainer()
357: .getDataBeanByID(dbID);
358: DataAccess da = dbBean.getDataAccessObject();
359: //SQLDataAccess sqlDA = new SQLDataAccess(dsType,q);
360: //SampleDemoDataAccess da = new SampleDemoDataAccess(dsType);
361: getChartApplicationBeansContainer()
362: .getCurrentChartBeanOnEditor().setChartDataBeanID(
363: dbBean.getID());
364: getChartApplicationBeansContainer()
365: .getCurrentChartBeanOnEditor()
366: .setChartPropertiesForDataset(dbBean.getDataSetType(),
367: cType);
368:
369: mLogger.info("Returning success after creating data bean");
370: return "chart";
371: }
372:
373: public void dropDown1_processValueChange(ValueChangeEvent event) {
374: mLogger.info("Drop down selected" + event.getNewValue());
375: }
376:
377: }
|