001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.console.base;
009:
010: //base classes
011: import java.util.ArrayList;
012:
013: //project specific classes
014: import org.jfolder.common.tagging.ConceptTagMessageHolder;
015: import org.jfolder.common.web.template.SubmitActionContext;
016:
017: //other classes
018:
019: public class ConsolePageMessageHolder {
020:
021: //
022: private final static int INFORMATION = ConceptTagMessageHolder.INFORMATION;
023: private final static int WARNING = ConceptTagMessageHolder.WARNING;
024: private final static int ERROR = ConceptTagMessageHolder.ERROR;
025:
026: //
027: private SubmitActionContext sac = null;
028: private boolean sacPresent = false;
029: //
030: private String headerMessage = null;
031: private int headerType = INFORMATION;
032: private boolean headerPresent = false;
033: //
034: private ArrayList subMessages = null;
035: //
036: private String ctHandle = null;
037:
038: //
039: private ConsolePageMessageHolder() {
040: reset();
041: }
042:
043: public void reset() {
044: //
045: this .sac = null;
046: this .sacPresent = false;
047: //
048: this .headerMessage = null;
049: this .headerType = INFORMATION;
050: this .headerPresent = false;
051: //
052: this .subMessages = new ArrayList();
053: }
054:
055: public final static ConsolePageMessageHolder newInstance() {
056: return new ConsolePageMessageHolder();
057: }
058:
059: //
060: public void setCtHandle(String inHandle) {
061: this .ctHandle = inHandle;
062: }
063:
064: public String getCtHandle() {
065: return this .ctHandle;
066: }
067:
068: //
069: public void setInformationHeader(String inHeader) {
070: this .headerPresent = true;
071: this .headerMessage = inHeader;
072: this .headerType = INFORMATION;
073: }
074:
075: public void setWarningHeader(String inHeader) {
076: this .headerPresent = true;
077: this .headerMessage = inHeader;
078: this .headerType = WARNING;
079: }
080:
081: public void setErrorHeader(String inHeader) {
082: this .headerPresent = true;
083: this .headerMessage = inHeader;
084: this .headerType = ERROR;
085: }
086:
087: //
088: public boolean isHeaderPresent() {
089: return this .headerPresent;
090: }
091:
092: public String getHeaderMessage() {
093: return this .headerMessage;
094: }
095:
096: public boolean isHeaderInformation() {
097: return (this .headerType == INFORMATION);
098: }
099:
100: public boolean isHeaderWarning() {
101: return (this .headerType == WARNING);
102: }
103:
104: public boolean isHeaderError() {
105: return (this .headerType == ERROR);
106: }
107:
108: //
109: public void setSubmitActionContext(SubmitActionContext inSac) {
110: this .sacPresent = true;
111: this .sac = inSac;
112: }
113:
114: public boolean isSubmitActionContextPresent() {
115: return this .sacPresent;
116: }
117:
118: public SubmitActionContext getSubmitActionContext() {
119: return this .sac;
120: }
121:
122: //
123: public ConsolePageMessageHolder createSubMessage() {
124:
125: ConsolePageMessageHolder outValue = newInstance();
126:
127: this .subMessages.add(outValue);
128:
129: return outValue;
130: }
131:
132: public void addSubMessage(ConsolePageMessageHolder inCpmh) {
133: this .subMessages.add(inCpmh);
134: }
135:
136: public int getSubMessageCount() {
137: return this .subMessages.size();
138: }
139:
140: public ConsolePageMessageHolder getSubMessage(int inIndex) {
141:
142: ConsolePageMessageHolder outValue = null;
143:
144: Object o = this .subMessages.get(inIndex);
145: outValue = (ConsolePageMessageHolder) o;
146:
147: return outValue;
148: }
149:
150: //
151: public boolean isEmpty() {
152:
153: boolean outValue = false;
154:
155: //
156: boolean notEmpty = false;
157: //
158: notEmpty |= this .headerPresent;
159: notEmpty |= this .sacPresent;
160: //
161: for (int i = 0; i < getSubMessageCount(); i++) {
162: notEmpty |= !getSubMessage(i).isEmpty();
163: }
164:
165: //
166: outValue = !notEmpty;
167:
168: return outValue;
169: }
170:
171: //
172: public boolean isHighestLevelInformation() {
173: return (getHighestType() == INFORMATION);
174: }
175:
176: public boolean isHighestLevelWarning() {
177: return (getHighestType() == WARNING);
178: }
179:
180: public boolean isHighestLevelError() {
181: return (getHighestType() == ERROR);
182: }
183:
184: protected int getHighestType() {
185:
186: int outValue = this .headerType;
187:
188: for (int i = 0; i < getSubMessageCount(); i++) {
189: int nextHighestType = getSubMessage(i).getHighestType();
190: if (outValue < nextHighestType) {
191: outValue = nextHighestType;
192: }
193: }
194:
195: return outValue;
196: }
197:
198: //
199: public int getTotalMessageCount() {
200:
201: int outValue = 0;
202:
203: if (this .headerPresent) {
204: outValue++;
205: }
206: for (int i = 0; i < getSubMessageCount(); i++) {
207: ConsolePageMessageHolder nextCpmh = getSubMessage(i);
208: outValue = outValue + nextCpmh.getTotalMessageCount();
209: }
210:
211: return outValue;
212: }
213: }
|