001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2004, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020:
021: package com.salmonllc.jsp;
022:
023: /////////////////////////
024: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/JspSubReportContainer.java $
025: //$Author: Dan $
026: //$Revision: 2 $
027: //$Modtime: 8/27/04 10:17a $
028: /////////////////////////
029:
030: import java.util.Vector;
031:
032: import com.salmonllc.html.HtmlComponent;
033: import com.salmonllc.html.HtmlPage;
034: import com.salmonllc.html.events.SubReportEvent;
035: import com.salmonllc.html.events.SubReportListener;
036: import com.salmonllc.html.events.SubmitListener;
037: import com.salmonllc.sql.DataStoreBuffer;
038:
039: /**
040: * This class is can be used by JspDataTables to allow nested reports
041: */
042:
043: public class JspSubReportContainer extends JspContainer {
044:
045: private Vector _listeners;
046:
047: public JspSubReportContainer(String name, HtmlPage p) {
048: super (name, p);
049: }
050:
051: /**
052: * This method adds a listener the will be notified when this report is
053: * invoked.
054: *
055: * @param l
056: * The listener to add.
057: */
058: public void addSubReportListener(SubReportListener l) {
059: if (_listeners == null)
060: _listeners = new Vector();
061:
062: for (int i = 0; i < _listeners.size(); i++) {
063: if (((SubmitListener) _listeners.elementAt(i)) == l)
064: return;
065: }
066:
067: _listeners.addElement(l);
068: }
069:
070: /**
071: * This method removes a listener from the list that will be notified when
072: * the report is invoked.
073: *
074: * @param l
075: * The listener to remove.
076: */
077: public void removeSubReportListener(SubmitListener l) {
078: if (_listeners == null)
079: return;
080:
081: for (int i = 0; i < _listeners.size(); i++) {
082: if (((SubmitListener) _listeners.elementAt(i)) == l) {
083: _listeners.removeElementAt(i);
084: return;
085: }
086: }
087: }
088:
089: /**
090: * Framework method, do not call directly
091: */
092: public void notifyListeners() throws Exception {
093: if (_listeners == null || _listeners.size() == 0)
094: return;
095: HtmlComponent parent = getParent();
096: while (parent != null && !(parent instanceof JspDataTable))
097: parent = parent.getParent();
098:
099: int parentRow = -1;
100: DataStoreBuffer parentDs = null;
101: if (parent != null) {
102: parentRow = ((JspDataTable) parent).getLastRenderedRow();
103: parentDs = ((JspDataTable) parent).getDataStoreBuffer();
104: }
105: SubReportEvent e = new SubReportEvent(this ,
106: (JspDataTable) parent, parentDs, parentRow);
107:
108: for (int i = 0; i < _listeners.size(); i++) {
109: SubReportListener l = (SubReportListener) _listeners
110: .elementAt(i);
111: l.subReportInvoked(e);
112: }
113: }
114:
115: }
|