001: /*
002: * $Id: OptionTransferSelect.java 558460 2007-07-22 04:16:29Z jholmes $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import java.util.LinkedHashMap;
024: import java.util.Map;
025:
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.apache.struts2.views.annotations.StrutsTag;
032: import org.apache.struts2.views.annotations.StrutsTagAttribute;
033:
034: import com.opensymphony.xwork2.util.ValueStack;
035:
036: /**
037: * <!-- START SNIPPET: javadoc -->
038: *
039: * Create a option transfer select component which is basically two <select ...>
040: * tag with buttons in the middle of them allowing options in each of the
041: * <select ...> to be moved between themselves. Will auto-select all its
042: * elements upon its containing form submision.
043: *
044: * <!-- END SNIPPET: javadoc -->
045: *
046: * <p/>
047: *
048: *
049: * <!-- START SNIPPET: notice -->
050: *
051: * NOTE: The id and doubleId need not be supplied as they will generated provided
052: * that the optiontransferselect tag is being used in a form tag. The generated id
053: * and doubleId will be <form_id>_<optiontransferselect_doubleName> and
054: * <form_id>_<optiontransferselect_doubleName> respectively.
055: *
056: * <!-- END SNIPPET: notice -->
057: *
058: * <p/>
059: *
060: * <pre>
061: * <!-- START SNIPPET: example -->
062: *
063: * <-- minimum configuration -->
064: * <s:optiontransferselect
065: * label="Favourite Cartoons Characters"
066: * name="leftSideCartoonCharacters"
067: * list="{'Popeye', 'He-Man', 'Spiderman'}"
068: * doubleName="rightSideCartoonCharacters"
069: * doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}"
070: * />
071: *
072: * <-- possible configuration -->
073: * <s:optiontransferselect
074: * label="Favourite Cartoons Characters"
075: * name="leftSideCartoonCharacters"
076: * leftTitle="Left Title"
077: * rightTitle="Right Title"
078: * list="{'Popeye', 'He-Man', 'Spiderman'}"
079: * multiple="true"
080: * headerKey="headerKey"
081: * headerValue="--- Please Select ---"
082: * emptyOption="true"
083: * doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}"
084: * doubleName="rightSideCartoonCharacters"
085: * doubleHeaderKey="doubleHeaderKey"
086: * doubleHeaderValue="--- Please Select ---"
087: * doubleEmptyOption="true"
088: * doubleMultiple="true"
089: * />
090: *
091: * <!-- END SNIPPET: example -->
092: * </pre>
093: *
094: */
095: @StrutsTag(name="optiontransferselect",tldTagClass="org.apache.struts2.views.jsp.ui.OptionTransferSelectTag",description="Renders an input form")
096: public class OptionTransferSelect extends DoubleListUIBean {
097:
098: private static final Log _log = LogFactory
099: .getLog(OptionTransferSelect.class);
100:
101: private static final String TEMPLATE = "optiontransferselect";
102:
103: protected String allowAddToLeft;
104: protected String allowAddToRight;
105: protected String allowAddAllToLeft;
106: protected String allowAddAllToRight;
107: protected String allowSelectAll;
108: protected String allowUpDownOnLeft;
109: protected String allowUpDownOnRight;
110:
111: protected String leftTitle;
112: protected String rightTitle;
113:
114: protected String buttonCssClass;
115: protected String buttonCssStyle;
116:
117: protected String addToLeftLabel;
118: protected String addToRightLabel;
119: protected String addAllToLeftLabel;
120: protected String addAllToRightLabel;
121: protected String selectAllLabel;
122: protected String leftUpLabel;
123: protected String leftDownlabel;
124: protected String rightUpLabel;
125: protected String rightDownLabel;
126:
127: protected String addToLeftOnclick;
128: protected String addToRightOnclick;
129: protected String addAllToLeftOnclick;
130: protected String addAllToRightOnclick;
131: protected String selectAllOnclick;
132: protected String upDownOnLeftOnclick;
133: protected String upDownOnRightOnclick;
134:
135: public OptionTransferSelect(ValueStack stack,
136: HttpServletRequest request, HttpServletResponse response) {
137: super (stack, request, response);
138: }
139:
140: protected String getDefaultTemplate() {
141: return TEMPLATE;
142: }
143:
144: public void evaluateExtraParams() {
145: super .evaluateExtraParams();
146:
147: Object doubleValue = null;
148:
149: // override DoubleListUIBean's
150: if (doubleList != null) {
151: doubleValue = findValue(doubleList);
152: addParameter("doubleList", doubleValue);
153: }
154: if (size == null || size.trim().length() <= 0) {
155: addParameter("size", "15");
156: }
157: if (doubleSize == null || doubleSize.trim().length() <= 0) {
158: addParameter("doubleSize", "15");
159: }
160: if (multiple == null || multiple.trim().length() <= 0) {
161: addParameter("multiple", Boolean.TRUE);
162: }
163: if (doubleMultiple == null
164: || doubleMultiple.trim().length() <= 0) {
165: addParameter("doubleMultiple", Boolean.TRUE);
166: }
167:
168: // buttonCssClass
169: if (buttonCssClass != null
170: && buttonCssClass.trim().length() > 0) {
171: addParameter("buttonCssClass", buttonCssClass);
172: }
173:
174: // buttonCssStyle
175: if (buttonCssStyle != null
176: && buttonCssStyle.trim().length() > 0) {
177: addParameter("buttonCssStyle", buttonCssStyle);
178: }
179:
180: // allowSelectAll
181: addParameter("allowSelectAll",
182: allowSelectAll != null ? findValue(allowSelectAll,
183: Boolean.class) : Boolean.TRUE);
184:
185: // allowAddToLeft
186: addParameter("allowAddToLeft",
187: allowAddToLeft != null ? findValue(allowAddToLeft,
188: Boolean.class) : Boolean.TRUE);
189:
190: // allowAddToRight
191: addParameter("allowAddToRight",
192: allowAddToRight != null ? findValue(allowAddToRight,
193: Boolean.class) : Boolean.TRUE);
194:
195: // allowAddAllToLeft
196: addParameter("allowAddAllToLeft",
197: allowAddAllToLeft != null ? findValue(
198: allowAddAllToLeft, Boolean.class)
199: : Boolean.TRUE);
200:
201: // allowAddAllToRight
202: addParameter("allowAddAllToRight",
203: allowAddAllToRight != null ? findValue(
204: allowAddAllToRight, Boolean.class)
205: : Boolean.TRUE);
206:
207: // allowUpDownOnLeft
208: addParameter("allowUpDownOnLeft",
209: allowUpDownOnLeft != null ? findValue(
210: allowUpDownOnLeft, Boolean.class)
211: : Boolean.TRUE);
212:
213: // allowUpDownOnRight
214: addParameter("allowUpDownOnRight",
215: allowUpDownOnRight != null ? findValue(
216: allowUpDownOnRight, Boolean.class)
217: : Boolean.TRUE);
218:
219: // leftTitle
220: if (leftTitle != null) {
221: addParameter("leftTitle",
222: findValue(leftTitle, String.class));
223: }
224:
225: // rightTitle
226: if (rightTitle != null) {
227: addParameter("rightTitle", findValue(rightTitle,
228: String.class));
229: }
230:
231: // addToLeftLabel
232: addParameter("addToLeftLabel",
233: addToLeftLabel != null ? findValue(addToLeftLabel,
234: String.class) : "<-");
235:
236: // addToRightLabel
237: addParameter("addToRightLabel",
238: addToRightLabel != null ? findValue(addToRightLabel,
239: String.class) : "->");
240:
241: // addAllToLeftLabel
242: addParameter("addAllToLeftLabel",
243: addAllToLeftLabel != null ? findValue(
244: addAllToLeftLabel, String.class) : "<<--");
245:
246: // addAllToRightLabel
247: addParameter("addAllToRightLabel",
248: addAllToRightLabel != null ? findValue(
249: addAllToRightLabel, String.class) : "-->>");
250:
251: // selectAllLabel
252: addParameter("selectAllLabel",
253: selectAllLabel != null ? findValue(selectAllLabel,
254: String.class) : "<*>");
255:
256: // leftUpLabel
257: addParameter("leftUpLabel", leftUpLabel != null ? findValue(
258: leftUpLabel, String.class) : "^");
259:
260: // leftDownLabel
261: addParameter("leftDownLabel",
262: leftDownlabel != null ? findValue(leftDownlabel,
263: String.class) : "v");
264:
265: // rightUpLabel
266: addParameter("rightUpLabel", rightUpLabel != null ? findValue(
267: rightUpLabel, String.class) : "^");
268:
269: // rightDownlabel
270: addParameter("rightDownLabel",
271: rightDownLabel != null ? findValue(rightDownLabel,
272: String.class) : "v");
273:
274: // selectAllOnclick
275: addParameter("selectAllOnclick",
276: selectAllOnclick != null ? findValue(selectAllOnclick,
277: String.class) : "");
278:
279: // addToLeftOnclick
280: addParameter("addToLeftOnclick",
281: addToLeftOnclick != null ? findValue(addToLeftOnclick,
282: String.class) : "");
283:
284: // addToRightOnclick
285: addParameter("addToRightOnclick",
286: addToRightOnclick != null ? findValue(
287: addToRightOnclick, String.class) : "");
288:
289: // addAllToLeftOnclick
290: addParameter("addAllToLeftOnclick",
291: addAllToLeftOnclick != null ? findValue(
292: addAllToLeftOnclick, String.class) : "");
293:
294: // addAllToRightOnclick
295: addParameter("addAllToRightOnclick",
296: addAllToRightOnclick != null ? findValue(
297: addAllToRightOnclick, String.class) : "");
298:
299: // upDownOnLeftOnclick
300: addParameter("upDownOnLeftOnclick",
301: upDownOnLeftOnclick != null ? findValue(
302: upDownOnLeftOnclick, String.class) : "");
303:
304: // upDownOnRightOnclick
305: addParameter("upDownOnRightOnclick",
306: upDownOnRightOnclick != null ? findValue(
307: upDownOnRightOnclick, String.class) : "");
308:
309: // inform the form component our select tag infos, so they know how to select
310: // its elements upon onsubmit
311: Form formAncestor = (Form) findAncestor(Form.class);
312: if (formAncestor != null) {
313:
314: // inform ancestor form that we are having a customOnsubmit (see form-close.ftl [simple theme])
315: enableAncestorFormCustomOnsubmit();
316:
317: // key -> select tag id, value -> headerKey (if exists)
318: Map formOptiontransferselectIds = (Map) formAncestor
319: .getParameters().get("optiontransferselectIds");
320: Map formOptiontransferselectDoubleIds = (Map) formAncestor
321: .getParameters().get(
322: "optiontransferselectDoubleIds");
323:
324: // init lists
325: if (formOptiontransferselectIds == null) {
326: formOptiontransferselectIds = new LinkedHashMap();
327: }
328: if (formOptiontransferselectDoubleIds == null) {
329: formOptiontransferselectDoubleIds = new LinkedHashMap();
330: }
331:
332: // id
333: String tmpId = (String) getParameters().get("id");
334: String tmpHeaderKey = (String) getParameters().get(
335: "headerKey");
336: if (tmpId != null
337: && (!formOptiontransferselectIds.containsKey(tmpId))) {
338: formOptiontransferselectIds.put(tmpId, tmpHeaderKey);
339: }
340:
341: // doubleId
342: String tmpDoubleId = (String) getParameters().get(
343: "doubleId");
344: String tmpDoubleHeaderKey = (String) getParameters().get(
345: "doubleHeaderKey");
346: if (tmpDoubleId != null
347: && (!formOptiontransferselectDoubleIds
348: .containsKey(tmpDoubleId))) {
349: formOptiontransferselectDoubleIds.put(tmpDoubleId,
350: tmpDoubleHeaderKey);
351: }
352:
353: formAncestor.getParameters().put("optiontransferselectIds",
354: formOptiontransferselectIds);
355: formAncestor.getParameters().put(
356: "optiontransferselectDoubleIds",
357: formOptiontransferselectDoubleIds);
358:
359: } else {
360: _log
361: .warn("form enclosing optiontransferselect "
362: + this
363: + " not found, auto select upon form submit of optiontransferselect will not work");
364: }
365: }
366:
367: public String getAddAllToLeftLabel() {
368: return addAllToLeftLabel;
369: }
370:
371: @StrutsTagAttribute(description="Set Add To Left button label")
372: public void setAddAllToLeftLabel(String addAllToLeftLabel) {
373: this .addAllToLeftLabel = addAllToLeftLabel;
374: }
375:
376: public String getAddAllToRightLabel() {
377: return addAllToRightLabel;
378: }
379:
380: @StrutsTagAttribute(description="Set Add All To Right button label")
381: public void setAddAllToRightLabel(String addAllToRightLabel) {
382: this .addAllToRightLabel = addAllToRightLabel;
383: }
384:
385: public String getAddToLeftLabel() {
386: return addToLeftLabel;
387: }
388:
389: @StrutsTagAttribute(description="Set Add To Left button label")
390: public void setAddToLeftLabel(String addToLeftLabel) {
391: this .addToLeftLabel = addToLeftLabel;
392: }
393:
394: public String getAddToRightLabel() {
395: return addToRightLabel;
396: }
397:
398: @StrutsTagAttribute(description="Set Add To Right button label")
399: public void setAddToRightLabel(String addToRightLabel) {
400: this .addToRightLabel = addToRightLabel;
401: }
402:
403: public String getAllowAddAllToLeft() {
404: return allowAddAllToLeft;
405: }
406:
407: @StrutsTagAttribute(description="Enable Add All To Left button")
408: public void setAllowAddAllToLeft(String allowAddAllToLeft) {
409: this .allowAddAllToLeft = allowAddAllToLeft;
410: }
411:
412: public String getAllowAddAllToRight() {
413: return allowAddAllToRight;
414: }
415:
416: @StrutsTagAttribute(description="Enable Add All To Right button")
417: public void setAllowAddAllToRight(String allowAddAllToRight) {
418: this .allowAddAllToRight = allowAddAllToRight;
419: }
420:
421: public String getAllowAddToLeft() {
422: return allowAddToLeft;
423: }
424:
425: @StrutsTagAttribute(description="Enable Add To Left button")
426: public void setAllowAddToLeft(String allowAddToLeft) {
427: this .allowAddToLeft = allowAddToLeft;
428: }
429:
430: public String getAllowAddToRight() {
431: return allowAddToRight;
432: }
433:
434: @StrutsTagAttribute(description="Enable Add To Right button")
435: public void setAllowAddToRight(String allowAddToRight) {
436: this .allowAddToRight = allowAddToRight;
437: }
438:
439: public String getLeftTitle() {
440: return leftTitle;
441: }
442:
443: @StrutsTagAttribute(description="Enable up / down on the left side")
444: public void setAllowUpDownOnLeft(String allowUpDownOnLeft) {
445: this .allowUpDownOnLeft = allowUpDownOnLeft;
446: }
447:
448: public String getAllowUpDownOnLeft() {
449: return this .allowUpDownOnLeft;
450: }
451:
452: @StrutsTagAttribute(description="Enable up / down on the right side")
453: public void setAllowUpDownOnRight(String allowUpDownOnRight) {
454: this .allowUpDownOnRight = allowUpDownOnRight;
455: }
456:
457: public String getAllowUpDownOnRight() {
458: return this .allowUpDownOnRight;
459: }
460:
461: @StrutsTagAttribute(description="Set Left title")
462: public void setLeftTitle(String leftTitle) {
463: this .leftTitle = leftTitle;
464: }
465:
466: public String getRightTitle() {
467: return rightTitle;
468: }
469:
470: @StrutsTagAttribute(description="Set Right title")
471: public void setRightTitle(String rightTitle) {
472: this .rightTitle = rightTitle;
473: }
474:
475: @StrutsTagAttribute(description="Enable Select All button")
476: public void setAllowSelectAll(String allowSelectAll) {
477: this .allowSelectAll = allowSelectAll;
478: }
479:
480: public String getAllowSelectAll() {
481: return this .allowSelectAll;
482: }
483:
484: @StrutsTagAttribute(description="Set Select All button label")
485: public void setSelectAllLabel(String selectAllLabel) {
486: this .selectAllLabel = selectAllLabel;
487: }
488:
489: public String getSelectAllLabel() {
490: return this .selectAllLabel;
491: }
492:
493: @StrutsTagAttribute(description="Set buttons css class")
494: public void setButtonCssClass(String buttonCssClass) {
495: this .buttonCssClass = buttonCssClass;
496: }
497:
498: public String getButtonCssClass() {
499: return buttonCssClass;
500: }
501:
502: @StrutsTagAttribute(description="Set button css style")
503: public void setButtonCssStyle(String buttonCssStyle) {
504: this .buttonCssStyle = buttonCssStyle;
505: }
506:
507: public String getButtonCssStyle() {
508: return this .buttonCssStyle;
509: }
510:
511: @StrutsTagAttribute(description="Up label for the left side")
512: public void setLeftUpLabel(String leftUpLabel) {
513: this .leftUpLabel = leftUpLabel;
514: }
515:
516: public String getLeftUpLabel() {
517: return this .leftUpLabel;
518: }
519:
520: @StrutsTagAttribute(description="Down label for the left side.")
521: public void setLeftDownLabel(String leftDownLabel) {
522: this .leftDownlabel = leftDownLabel;
523: }
524:
525: public String getLeftDownLabel() {
526: return this .leftDownlabel;
527: }
528:
529: @StrutsTagAttribute(description="Up label for the right side.")
530: public void setRightUpLabel(String rightUpLabel) {
531: this .rightUpLabel = rightUpLabel;
532: }
533:
534: public String getRightUpLabel() {
535: return this .rightUpLabel;
536: }
537:
538: @StrutsTagAttribute(description="Down label for the left side.")
539: public void setRightDownLabel(String rightDownlabel) {
540: this .rightDownLabel = rightDownlabel;
541: }
542:
543: public String getRightDownLabel() {
544: return rightDownLabel;
545: }
546:
547: public String getAddAllToLeftOnclick() {
548: return addAllToLeftOnclick;
549: }
550:
551: @StrutsTagAttribute(description="Javascript to run after Add All To Left button pressed")
552: public void setAddAllToLeftOnclick(String addAllToLeftOnclick) {
553: this .addAllToLeftOnclick = addAllToLeftOnclick;
554: }
555:
556: public String getAddAllToRightOnclick() {
557: return addAllToRightOnclick;
558: }
559:
560: @StrutsTagAttribute(description="Javascript to run after Add All To Right button pressed")
561: public void setAddAllToRightOnclick(String addAllToRightOnclick) {
562: this .addAllToRightOnclick = addAllToRightOnclick;
563: }
564:
565: public String getAddToLeftOnclick() {
566: return addToLeftOnclick;
567: }
568:
569: @StrutsTagAttribute(description="Javascript to run after Add To Left button pressed")
570: public void setAddToLeftOnclick(String addToLeftOnclick) {
571: this .addToLeftOnclick = addToLeftOnclick;
572: }
573:
574: public String getAddToRightOnclick() {
575: return addToRightOnclick;
576: }
577:
578: @StrutsTagAttribute(description="Javascript to run after Add To Right button pressed")
579: public void setAddToRightOnclick(String addToRightOnclick) {
580: this .addToRightOnclick = addToRightOnclick;
581: }
582:
583: @StrutsTagAttribute(description="Javascript to run after up / down on the left side buttons pressed")
584: public void setUpDownOnLeftOnclick(String upDownOnLeftOnclick) {
585: this .upDownOnLeftOnclick = upDownOnLeftOnclick;
586: }
587:
588: public String getUpDownOnLeftOnclick() {
589: return this .upDownOnLeftOnclick;
590: }
591:
592: @StrutsTagAttribute(description="Javascript to run after up / down on the right side buttons pressed")
593: public void setUpDownOnRightOnclick(String upDownOnRightOnclick) {
594: this .upDownOnRightOnclick = upDownOnRightOnclick;
595: }
596:
597: public String getUpDownOnRightOnclick() {
598: return this .upDownOnRightOnclick;
599: }
600:
601: @StrutsTagAttribute(description="Javascript to run after Select All button pressed")
602: public void setSelectAllOnclick(String selectAllOnclick) {
603: this .selectAllOnclick = selectAllOnclick;
604: }
605:
606: public String getSelectAllOnclick() {
607: return this.selectAllOnclick;
608: }
609: }
|