001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library 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 GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.formmgr;
020:
021: import com.jeta.forms.gui.beans.JETABean;
022: import com.jeta.forms.gui.common.FormException;
023: import com.jeta.forms.gui.common.FormUtils;
024: import com.jeta.forms.gui.form.FormComponent;
025: import com.jeta.forms.gui.form.GridComponent;
026: import com.jeta.forms.gui.formmgr.FormManager;
027: import com.jeta.forms.logger.FormsLogger;
028: import com.jeta.forms.store.memento.ComponentMemento;
029: import com.jeta.forms.store.memento.StateRequest;
030: import com.jeta.open.registry.JETARegistry;
031:
032: /**
033: * This class acts as a place-holder for a FormComponent. This is needed because
034: * we can have multiple views opened for the same FormComponent. For example, in
035: * one view, a FormComponent could be part of a nest. In another view, this
036: * component could be in a top level view.
037: *
038: * @author Jeff Tassin
039: */
040: public class FormSurrogate extends GridComponent {
041: /**
042: * @directed
043: */
044: private FormComponent m_form;
045:
046: /**
047: * ctor
048: */
049: public FormSurrogate(FormComponent form) {
050: m_form = form;
051: }
052:
053: /**
054: * @return the Form associated with this surrogate.
055: */
056: public String getId() {
057: return m_form.getId();
058: }
059:
060: /**
061: * @return the form that this surrogate represents.
062: */
063: public FormComponent getForm() {
064: return m_form;
065: }
066:
067: /**
068: * Print for debugging
069: */
070: public void print() {
071: FormsLogger.debug("FormSurrogate formid: " + getId());
072: }
073:
074: /**
075: * Sets the state of this component from a previously stored state
076: */
077: public void setState(ComponentMemento memento) throws FormException {
078: assert (false);
079: }
080:
081: public JETABean getBean() {
082: return m_form.getBean();
083: }
084:
085: /**
086: * @returns the state of this component which can be persisted.
087: */
088: public ComponentMemento getState(StateRequest sr)
089: throws FormException {
090: FormManager fmgr = (FormManager) JETARegistry
091: .lookup(FormManager.COMPONENT_ID);
092: FormComponent fc = fmgr.getForm(getId());
093: if (FormUtils.isDebug()) {
094: if (fc != m_form) {
095: System.out
096: .println("FormSurrogate.getState failed. id: "
097: + getId() + " form manager result: "
098: + fc);
099: assert (false);
100: }
101: }
102: System.out.println(" formsurrogate.getState: "
103: + fc.getChildView().getName());
104: return m_form.getState(sr);
105: }
106: }
|