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.main;
020:
021: import java.awt.Container;
022: import java.util.Collection;
023: import java.util.Collections;
024: import java.util.Iterator;
025:
026: import com.jeta.forms.gui.form.FormComponent;
027: import com.jeta.swingbuilder.gui.editor.FormEditor;
028: import com.jeta.swingbuilder.gui.formmgr.AbstractFormManager;
029: import com.jeta.swingbuilder.gui.formmgr.FormManagerDesignUtils;
030:
031: /**
032: * The main form manager for the application.
033: *
034: * @author Jeff Tassin
035: */
036: public class MainFormManager extends AbstractFormManager {
037: /**
038: * @undirected
039: */
040: private MainFrame m_frame;
041:
042: /**
043: * ctor
044: */
045: public MainFormManager(MainFrame frame) {
046: super (frame, frame);
047: m_frame = frame;
048: }
049:
050: /**
051: * Closes the form in the editor.
052: */
053: public void closeForm(String formId) {
054: FormComponent form = getForm(formId);
055: Collection child_forms = null;
056: if (form != null) {
057: child_forms = FormManagerDesignUtils.getNestedForms(this ,
058: form);
059: }
060:
061: if (m_frame != null)
062: m_frame.removeForm(formId);
063: FormManagerDesignUtils.clearUnreferencedForms();
064: }
065:
066: /**
067: * @return the form that is currently active in the editor
068: */
069: public Container getCurrentEditor() {
070: if (m_frame != null)
071: return m_frame.getCurrentEditor();
072: else
073: return null;
074: }
075:
076: /**
077: * @return true if the given form is opened in a top level editor.
078: */
079: public boolean isOpened(String formId) {
080: if (m_frame == null)
081: return false;
082: else
083: return (m_frame.getForm(formId) != null);
084: }
085:
086: /**
087: * @return true if the given formId is opened in any editor either as a top
088: * level form or as a nest
089: */
090: public boolean isReferenced(String formId) {
091: /**
092: * check if any opened editors have the given form opened as a nested
093: * child. If so, then simply return. Otherwise, we can safely remove the
094: * form from the cache
095: */
096: Collection editors = m_frame == null ? Collections.EMPTY_LIST
097: : m_frame.getEditors();
098: Iterator iter = editors.iterator();
099: while (iter.hasNext()) {
100: FormEditor editor = (FormEditor) iter.next();
101: FormComponent fc = editor.getForm();
102: if (FormManagerDesignUtils.containsForm(fc, formId))
103: return true;
104: }
105:
106: return false;
107: }
108:
109: /**
110: * Only shows the form in the editor. No synchronization is made with any
111: * other views.
112: */
113: public void showForm(String formId) {
114: FormComponent fc = getForm(formId);
115: if (fc != null) {
116: if (m_frame != null)
117: m_frame.showForm(fc);
118: } else {
119: System.out.println("MainFormManager.showForm failed: "
120: + formId);
121: assert (false);
122: }
123: }
124: }
|