001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.panelborder;
035:
036: import com.icesoft.faces.component.CSS_DEFAULT;
037: import com.icesoft.faces.component.ext.taglib.Util;
038:
039: import javax.faces.component.UIComponent;
040: import javax.faces.component.html.HtmlPanelGroup;
041: import javax.faces.context.FacesContext;
042: import javax.faces.el.ValueBinding;
043: import java.util.ArrayList;
044: import java.util.List;
045:
046: /**
047: * PanelBorder is a JSF component class that represent an ICEfaces border layout
048: * panel. The "north", "west", "east", "center" and "south" named facets
049: * represent the components responsible for rendering the north, west, east,
050: * center and south areas of the PanelBorder.
051: * <p/>
052: * This component extends the JSF HtmlPanelGroup component.
053: * <p/>
054: * By default this component is rendered by the "com.icesoft.faces.BorderLayout"
055: * renderer type.
056: *
057: * @version beta 1.0
058: */
059: public class PanelBorder extends HtmlPanelGroup {
060: public static final String COMPONENT_TYPE = "com.icesoft.faces.BorderLayout";
061: public static final String COMPONENT_FAMILY = "javax.faces.Panel";
062: public static final String DEFAULT_RENDERER_TYPE = "com.icesoft.faces.BorderLayout";
063:
064: public static final String NORTH_LAYOUT = "north";
065: public static final String WEST_LAYOUT = "west";
066: public static final String CENTER_LAYOUT = "center";
067: public static final String EAST_LAYOUT = "east";
068: public static final String SOUTH_LAYOUT = "south";
069:
070: private String _layout = null;
071: private String styleClass = null;
072: private String style = null;
073: private String align = null;
074: private String border = null;
075: private String bgcolor = null;
076: private String cellpadding = null;
077: private String cellspacing = null;
078: private String frame = null;
079: private String rules = null;
080: private String summary = null;
081: private String height = null;
082: private String width = null;
083: private String dir = null;
084: private String lang = null;
085: private String title = null;
086: private String renderedOnUserRole = null;
087:
088: List defaultLayout = new ArrayList();
089:
090: /**
091: * <p>Return the value of the <code>north</code> property.</p>
092: */
093: public UIComponent getNorth() {
094: return (UIComponent) getFacet(PanelBorder.NORTH_LAYOUT);
095: }
096:
097: /**
098: * <p>Return the value of the <code>west</code> property.</p>
099: */
100: public UIComponent getWest() {
101: return (UIComponent) getFacet(PanelBorder.WEST_LAYOUT);
102: }
103:
104: /**
105: * <p>Return the value of the <code>east</code> property.</p>
106: */
107: public UIComponent getEast() {
108: return (UIComponent) getFacet(PanelBorder.EAST_LAYOUT);
109: }
110:
111: /**
112: * <p>Return the value of the <code>center</code> property.</p>
113: */
114: public UIComponent getCenter() {
115: return (UIComponent) getFacet(PanelBorder.CENTER_LAYOUT);
116: }
117:
118: /**
119: * <p>Return the value of the <code>south</code> property.</p>
120: */
121: public UIComponent getSouth() {
122: return (UIComponent) getFacet(PanelBorder.SOUTH_LAYOUT);
123: }
124:
125: /**
126: * <p>Return the value of the <code>rendered</code> property.</p>
127: */
128: public boolean isRendered() {
129: if (!Util.isRenderedOnUserRole(this )) {
130: return false;
131: }
132: return super .isRendered();
133: }
134:
135: public PanelBorder() {
136: setRendererType(DEFAULT_RENDERER_TYPE);
137: defaultLayout.add(PanelBorder.NORTH_LAYOUT);
138: defaultLayout.add(PanelBorder.EAST_LAYOUT);
139: defaultLayout.add(PanelBorder.SOUTH_LAYOUT);
140: defaultLayout.add(PanelBorder.WEST_LAYOUT);
141: defaultLayout.add(PanelBorder.CENTER_LAYOUT);
142: }
143:
144: /**
145: * <p>Return the value of the <code>COMPONENT_FAMILY</code> of this
146: * component.</p>
147: */
148: public String getFamily() {
149: return COMPONENT_FAMILY;
150: }
151:
152: /**
153: * <p>Set the value of the <code>layout</code> property.</p>
154: */
155: public void setLayout(String layout) {
156: _layout = layout;
157: }
158:
159: /**
160: * @deprecated <p>Return the value of the <code>layout</code> property.
161: * </p>
162: */
163: public String getLayout() {
164: if (_layout != null) {
165: return _layout;
166: }
167: ValueBinding vb = getValueBinding("layout");
168: return vb != null ? (String) vb.getValue(getFacesContext())
169: : "none";
170: }
171:
172: /**
173: * <p>Return the value of the <code>northClass</code> property.</p>
174: */
175: public String getNorthClass() {
176: return Util.getQualifiedStyleClass(this ,
177: CSS_DEFAULT.PANEL_BORDER_DEFAULT_NORTH_CLASS);
178: }
179:
180: /**
181: * <p>Return the value of the <code>westClass</code> property.</p>
182: */
183: public String getWestClass() {
184: return Util.getQualifiedStyleClass(this ,
185: CSS_DEFAULT.PANEL_BORDER_DEFAULT_WEST_CLASS);
186: }
187:
188: /**
189: * <p>Return the value of the <code>eastClass</code> property.</p>
190: */
191: public String getEastClass() {
192: return Util.getQualifiedStyleClass(this ,
193: CSS_DEFAULT.PANEL_BORDER_DEFAULT_EAST_CLASS);
194: }
195:
196: /**
197: * <p>Return the value of the <code>centerClass</code> property.</p>
198: */
199: public String getCenterClass() {
200: return Util.getQualifiedStyleClass(this ,
201: CSS_DEFAULT.PANEL_BORDER_DEFAULT_CENTER_CLASS);
202: }
203:
204: /**
205: * <p>Return the value of the <code>southClass</code> property.</p>
206: */
207: public String getSouthClass() {
208: return Util.getQualifiedStyleClass(this ,
209: CSS_DEFAULT.PANEL_BORDER_DEFAULT_SOUTH_CLASS);
210: }
211:
212: /**
213: * <p>Set the value of the <code>styleClass</code> property.</p>
214: */
215: public void setStyleClass(String styleClass) {
216: this .styleClass = styleClass;
217: }
218:
219: /**
220: * <p>Return the value of the <code>styleClass</code> property.</p>
221: */
222: public String getStyleClass() {
223: return Util.getQualifiedStyleClass(this , styleClass,
224: CSS_DEFAULT.PANEL_BORDER_DEFAULT, "styleClass");
225:
226: }
227:
228: /**
229: * <p>Return the value of the <code>style</code> property.</p>
230: */
231: public String getStyle() {
232: if (style != null) {
233: return style;
234: }
235: ValueBinding vb = getValueBinding("style");
236: return vb != null ? (String) vb.getValue(getFacesContext())
237: : null;
238: }
239:
240: /**
241: * <p>Set the value of the <code>style</code> property.</p>
242: */
243: public void setStyle(String style) {
244: this .style = style;
245: }
246:
247: /**
248: * <p>Gets the state of the instance as a <code>Serializable</code>
249: * Object.</p>
250: */
251: public Object saveState(FacesContext context) {
252: Object values[] = new Object[17];
253: values[0] = super .saveState(context);
254: values[1] = _layout;
255: values[2] = styleClass;
256: values[3] = renderedOnUserRole;
257: values[4] = align;
258: values[5] = border;
259: values[6] = bgcolor;
260: values[7] = cellpadding;
261: values[8] = cellspacing;
262: values[9] = frame;
263: values[10] = rules;
264: values[11] = summary;
265: values[12] = height;
266: values[13] = width;
267: values[14] = dir;
268: values[15] = lang;
269: values[16] = title;
270: return ((Object) (values));
271: }
272:
273: /**
274: * <p>Perform any processing required to restore the state from the entries
275: * in the state Object.</p>
276: */
277: public void restoreState(FacesContext context, Object state) {
278: Object values[] = (Object[]) state;
279: super .restoreState(context, values[0]);
280: _layout = (String) values[1];
281: styleClass = (String) values[2];
282: renderedOnUserRole = (String) values[3];
283: align = (String) values[4];
284: border = (String) values[5];
285: bgcolor = (String) values[6];
286: cellpadding = (String) values[7];
287: cellspacing = (String) values[8];
288: frame = (String) values[9];
289: rules = (String) values[10];
290: summary = (String) values[11];
291: height = (String) values[12];
292: width = (String) values[13];
293: dir = (String) values[14];
294: lang = (String) values[15];
295: title = (String) values[16];
296: }
297:
298: /**
299: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
300: */
301: public void setRenderedOnUserRole(String renderedOnUserRole) {
302: this .renderedOnUserRole = renderedOnUserRole;
303: }
304:
305: /**
306: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
307: */
308: public String getRenderedOnUserRole() {
309: if (renderedOnUserRole != null) {
310: return renderedOnUserRole;
311: }
312: ValueBinding vb = getValueBinding("renderedOnUserRole");
313: return vb != null ? (String) vb.getValue(getFacesContext())
314: : null;
315: }
316:
317: public void setAlign(String align) {
318: this .align = align;
319: }
320:
321: public void setBorder(String border) {
322: this .border = border;
323: }
324:
325: public void setBgcolor(String bgcolor) {
326: this .bgcolor = bgcolor;
327: }
328:
329: public void setCellpadding(String cellpadding) {
330: this .cellpadding = cellpadding;
331: }
332:
333: public void setCellspacing(String cellspacing) {
334: this .cellspacing = cellspacing;
335: }
336:
337: public void setFrame(String frame) {
338: this .frame = frame;
339: }
340:
341: public void setHeight(String height) {
342: this .height = height;
343: }
344:
345: public void setRules(String rules) {
346: this .rules = rules;
347: }
348:
349: public void setSummary(String summary) {
350: this .summary = summary;
351: }
352:
353: public void setWidth(String width) {
354: this .width = width;
355: }
356:
357: public void setDir(String dir) {
358: this .dir = dir;
359: }
360:
361: public void setLang(String lang) {
362: this .lang = lang;
363: }
364:
365: public void setTitle(String title) {
366: this .title = title;
367: }
368:
369: /**
370: * @return the value of align property
371: */
372: public String getAlign() {
373: if (align != null) {
374: return align;
375: }
376: ValueBinding vb = getValueBinding("align");
377: return vb != null ? (String) vb.getValue(getFacesContext())
378: : null;
379: }
380:
381: /**
382: * @return the value of border property
383: */
384: public String getBorder() {
385: if (border != null) {
386: return border;
387: }
388: ValueBinding vb = getValueBinding("border");
389: return vb != null ? (String) vb.getValue(getFacesContext())
390: : null;
391: }
392:
393: /**
394: * @return the value of bgcolor property
395: */
396: public String getBgcolor() {
397: if (bgcolor != null) {
398: return bgcolor;
399: }
400: ValueBinding vb = getValueBinding("bgcolor");
401: return vb != null ? (String) vb.getValue(getFacesContext())
402: : null;
403: }
404:
405: /**
406: * @return the value of cellpadding property
407: */
408: public String getCellpadding() {
409: if (cellpadding != null) {
410: return cellpadding;
411: }
412: ValueBinding vb = getValueBinding("cellpadding");
413: return vb != null ? (String) vb.getValue(getFacesContext())
414: : null;
415: }
416:
417: /**
418: * @return the value of cellspacing property
419: */
420: public String getCellspacing() {
421: if (cellspacing != null) {
422: return cellspacing;
423: }
424: ValueBinding vb = getValueBinding("cellspacing");
425: return vb != null ? (String) vb.getValue(getFacesContext())
426: : null;
427: }
428:
429: /**
430: * @return the value of frame property
431: */
432: public String getFrame() {
433: if (frame != null) {
434: return frame;
435: }
436: ValueBinding vb = getValueBinding("frame");
437: return vb != null ? (String) vb.getValue(getFacesContext())
438: : null;
439: }
440:
441: /**
442: * @return the value of rules property
443: */
444: public String getRules() {
445: if (rules != null) {
446: return rules;
447: }
448: ValueBinding vb = getValueBinding("rules");
449: return vb != null ? (String) vb.getValue(getFacesContext())
450: : null;
451: }
452:
453: /**
454: * @return the value of summary property
455: */
456: public String getSummary() {
457: if (summary != null) {
458: return summary;
459: }
460: ValueBinding vb = getValueBinding("summary");
461: return vb != null ? (String) vb.getValue(getFacesContext())
462: : null;
463: }
464:
465: /**
466: * @return the value of height property
467: */
468: public String getHeight() {
469: if (height != null) {
470: return height;
471: }
472: ValueBinding vb = getValueBinding("height");
473: return vb != null ? (String) vb.getValue(getFacesContext())
474: : null;
475: }
476:
477: /**
478: * @return the value of width property
479: */
480: public String getWidth() {
481: if (width != null) {
482: return width;
483: }
484: ValueBinding vb = getValueBinding("width");
485: return vb != null ? (String) vb.getValue(getFacesContext())
486: : null;
487: }
488:
489: /**
490: * @return the value of dir property
491: */
492: public String getDir() {
493: if (dir != null) {
494: return dir;
495: }
496: ValueBinding vb = getValueBinding("dir");
497: return vb != null ? (String) vb.getValue(getFacesContext())
498: : null;
499: }
500:
501: /**
502: * @return the value of lang property
503: */
504: public String getLang() {
505: if (lang != null) {
506: return lang;
507: }
508: ValueBinding vb = getValueBinding("lang");
509: return vb != null ? (String) vb.getValue(getFacesContext())
510: : null;
511: }
512:
513: /**
514: * @return the value of title property
515: */
516: public String getTitle() {
517: if (title != null) {
518: return title;
519: }
520: ValueBinding vb = getValueBinding("title");
521: return vb != null ? (String) vb.getValue(getFacesContext())
522: : null;
523: }
524:
525: private boolean renderCenter = true;
526: private boolean renderCenterSet = false;
527:
528: public boolean isRenderCenter() {
529: if (getLayout().endsWith(PanelBorder.CENTER_LAYOUT)) {
530: return false;
531: }
532: if (getLayout().equalsIgnoreCase(
533: PanelBorderRenderer.DEFAULT_LAYOUT)) {
534: return true;
535: }
536: if (this .renderCenterSet) {
537: return (this .renderCenter);
538: }
539: ValueBinding vb = getValueBinding("renderCenter");
540: if (vb != null) {
541: return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
542: } else {
543: return (this .renderCenter);
544: }
545: }
546:
547: public void setRenderCenter(boolean renderCenter) {
548: if (renderCenter != this .renderCenter) {
549: this .renderCenter = renderCenter;
550: }
551: this .renderCenterSet = true;
552: }
553:
554: private boolean renderEast = true;
555: private boolean renderEastSet = false;
556:
557: public boolean isRenderEast() {
558: if (getLayout().endsWith(PanelBorder.EAST_LAYOUT)
559: || getLayout().equalsIgnoreCase(
560: PanelBorderRenderer.CENTER_ONLY)) {
561: return false;
562: }
563: if (getLayout().equalsIgnoreCase(
564: PanelBorderRenderer.DEFAULT_LAYOUT)) {
565: return true;
566: }
567: if (this .renderEastSet) {
568: return (this .renderEast);
569: }
570: ValueBinding vb = getValueBinding("renderEast");
571: if (vb != null) {
572: return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
573: } else {
574: return (this .renderEast);
575: }
576: }
577:
578: public void setRenderEast(boolean renderEast) {
579: if (renderEast != this .renderEast) {
580: this .renderEast = renderEast;
581: }
582: this .renderEastSet = true;
583: }
584:
585: private boolean renderNorth = true;
586: private boolean renderNorthSet = false;
587:
588: public boolean isRenderNorth() {
589: if (getLayout().endsWith(PanelBorder.NORTH_LAYOUT)
590: || getLayout().equalsIgnoreCase(
591: PanelBorderRenderer.CENTER_ONLY)) {
592: return false;
593: }
594: if (getLayout().equalsIgnoreCase(
595: PanelBorderRenderer.DEFAULT_LAYOUT)) {
596: return true;
597: }
598: if (this .renderNorthSet) {
599: return (this .renderNorth);
600: }
601: ValueBinding vb = getValueBinding("renderNorth");
602: if (vb != null) {
603: return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
604: } else {
605: return (this .renderNorth);
606: }
607: }
608:
609: public void setRenderNorth(boolean renderNorth) {
610: if (renderNorth != this .renderNorth) {
611: this .renderNorth = renderNorth;
612: }
613: this .renderNorthSet = true;
614: }
615:
616: private boolean renderSouth = true;
617: private boolean renderSouthSet = false;
618:
619: public boolean isRenderSouth() {
620: if (getLayout().endsWith(PanelBorder.SOUTH_LAYOUT)
621: || getLayout().equalsIgnoreCase(
622: PanelBorderRenderer.CENTER_ONLY)) {
623: return false;
624: }
625: if (getLayout().equalsIgnoreCase(
626: PanelBorderRenderer.DEFAULT_LAYOUT)) {
627: return true;
628: }
629: if (this .renderSouthSet) {
630: return (this .renderSouth);
631: }
632: ValueBinding vb = getValueBinding("renderSouth");
633: if (vb != null) {
634: return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
635: } else {
636: return (this .renderSouth);
637: }
638: }
639:
640: public void setRenderSouth(boolean renderSouth) {
641: if (renderSouth != this .renderSouth) {
642: this .renderSouth = renderSouth;
643: }
644: this .renderSouthSet = true;
645: }
646:
647: private boolean renderWest = true;
648: private boolean renderWestSet = false;
649:
650: public boolean isRenderWest() {
651: if (getLayout().endsWith(PanelBorder.WEST_LAYOUT)
652: || getLayout().equalsIgnoreCase(
653: PanelBorderRenderer.CENTER_ONLY)) {
654: return false;
655: }
656: if (getLayout().equalsIgnoreCase(
657: PanelBorderRenderer.DEFAULT_LAYOUT)) {
658: return true;
659: }
660: if (this .renderWestSet) {
661: return (this .renderWest);
662: }
663: ValueBinding vb = getValueBinding("renderWest");
664: if (vb != null) {
665: return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
666: } else {
667: return (this .renderWest);
668: }
669: }
670:
671: public void setRenderWest(boolean renderWest) {
672: if (renderWest != this .renderWest) {
673: this .renderWest = renderWest;
674: }
675: this .renderWestSet = true;
676: }
677:
678: public List getLayoutAsList() {
679:
680: if (isRenderCenter()) {
681: if (!defaultLayout.contains(PanelBorder.CENTER_LAYOUT)) {
682: defaultLayout.add(PanelBorder.CENTER_LAYOUT);
683: }
684: } else {
685: defaultLayout.remove(PanelBorder.CENTER_LAYOUT);
686: }
687: if (isRenderEast()) {
688: if (!defaultLayout.contains(PanelBorder.EAST_LAYOUT)) {
689: defaultLayout.add(PanelBorder.EAST_LAYOUT);
690: }
691: } else {
692: defaultLayout.remove(PanelBorder.EAST_LAYOUT);
693: }
694: if (isRenderNorth()) {
695: if (!defaultLayout.contains(PanelBorder.NORTH_LAYOUT)) {
696: defaultLayout.add(PanelBorder.NORTH_LAYOUT);
697: }
698: } else {
699: defaultLayout.remove(PanelBorder.NORTH_LAYOUT);
700: }
701: if (isRenderSouth()) {
702: if (!defaultLayout.contains(PanelBorder.SOUTH_LAYOUT)) {
703: defaultLayout.add(PanelBorder.SOUTH_LAYOUT);
704: }
705: } else {
706: defaultLayout.remove(PanelBorder.SOUTH_LAYOUT);
707: }
708: if (isRenderWest()) {
709: if (!defaultLayout.contains(PanelBorder.WEST_LAYOUT)) {
710: defaultLayout.add(PanelBorder.WEST_LAYOUT);
711: }
712: } else {
713: defaultLayout.remove(PanelBorder.WEST_LAYOUT);
714: }
715:
716: return defaultLayout;
717: }
718:
719: }
|