001: /* Displayable.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: May 22, 2007 5:48:16 PM, Created by henrichen
010: }}IS_NOTE
011:
012: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019:
020: package org.zkoss.mil;
021:
022: import org.zkoss.lang.Objects;
023: import org.zkoss.xml.HTMLs;
024: import org.zkoss.zk.ui.Page;
025:
026: /**
027: * Root components that can be directly kids of a Page.
028: * @author henrichen
029: */
030: abstract public class Displayable extends MilComponent {
031: private static final long serialVersionUID = 200705221758L;
032:
033: private String _title;
034: private String _ticker;
035:
036: protected Displayable() {
037: setVisible(false); //default to false
038: }
039:
040: /**
041: * Get the title of this Displayable.
042: * @return the title
043: */
044: public String getTitle() {
045: return _title;
046: }
047:
048: /**
049: * Set the new title of this Displayable.
050: * @param title the new title.
051: */
052: public void setTitle(String title) {
053: if (title != null && title.length() == 0) {
054: title = null;
055: }
056: if (!Objects.equals(_title, title)) {
057: _title = title;
058: smartUpdate("tt", title);
059: }
060: }
061:
062: /**
063: * Get the assoicated ticker id.
064: * @return ticker's id.
065: */
066: public String getTicker() {
067: return _ticker;
068: }
069:
070: /**
071: * Set the associated ticker id (Ticker must be defined before calling this method).
072: * @param ticker the ticker id of the associated Ticker.
073: */
074: public void setTicker(String ticker) {
075: if (ticker != null && ticker.length() == 0) {
076: ticker = null;
077: }
078:
079: if (!Objects.equals(_ticker, ticker)) {
080: _ticker = ticker;
081: smartUpdate("tc", ticker);
082: }
083: }
084:
085: /**
086: * Override to guarantee that always only one Displayable is visible in ZK Mobile.
087: */
088: public boolean setVisible(boolean b) {
089: final boolean old = super .setVisible(b);
090: if (old != b) {
091: changeCurrentVisible(b);
092: }
093: return old;
094: }
095:
096: private void changeCurrentVisible(boolean b) {
097: final Page page = getPage();
098: if (page != null) {
099: Displayable current = (Displayable) page
100: .getAttribute("CURRENT_DISPLAYABLE");
101: if (b) {
102: if (current != this ) {
103: page.setAttribute("CURRENT_DISPLAYABLE", this );
104: if (current != null)
105: current.setVisible(false);
106: }
107: } else if (current == this ) {
108: page.setAttribute("CURRENT_DISPLAYABLE", null);
109: }
110: }
111: }
112:
113: public void setPage(Page page) {
114: final Page old = getPage();
115: super .setPage(page);
116: if (old != page && page != null && isVisible()) {
117: changeCurrentVisible(true);
118: }
119: }
120:
121: public String getInnerAttrs() {
122: final StringBuffer sb = new StringBuffer(64);
123:
124: if (_title != null) {
125: HTMLs.appendAttribute(sb, "tt", _title); //title
126: }
127: if (_ticker != null) {
128: HTMLs.appendAttribute(sb, "tc", _ticker); //ticker
129: }
130: if (isVisible()) {
131: HTMLs.appendAttribute(sb, "cr", "t");
132: }
133: return sb.toString();
134: }
135: }
|